PageRenderTime 166ms CodeModel.GetById 60ms app.highlight 61ms RepoModel.GetById 40ms app.codeStats 0ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_External.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 386 lines | 323 code | 50 blank | 13 comment | 4 complexity | 3f9871c108978c2e6b92290efe64f7d2 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import ag.ion.bion.officelayer.application.IApplicationAssistant;
  4import ag.ion.bion.officelayer.application.ILazyApplicationInfo;
  5import ag.ion.bion.officelayer.application.OfficeApplicationException;
  6import ag.ion.bion.officelayer.internal.application.ApplicationAssistant;
  7import enoa.connection.NoaConnection;
  8import java.awt.Component;
  9import java.io.File;
 10import java.io.IOException;
 11import java.util.logging.Level;
 12import java.util.logging.Logger;
 13import javax.swing.SwingUtilities;
 14import mpv5.YabsViewProxy;
 15import mpv5.data.PropertyStore;
 16import mpv5.globals.LocalSettings;
 17import mpv5.globals.Messages;
 18import mpv5.logging.Log;
 19import mpv5.ui.dialogs.ControlApplet;
 20import mpv5.ui.dialogs.Popup;
 21
 22/**
 23 *
 24 *
 25 */
 26public class ControlPanel_External extends javax.swing.JPanel implements ControlApplet {
 27
 28    private static final long serialVersionUID = 1L;
 29    /**
 30     * This unique name identifies this control applet
 31     */
 32    public final String UNAME = "ooo";
 33    private PropertyStore oldvalues;
 34    private static ControlPanel_External ident;
 35
 36    public ControlPanel_External() {
 37        initComponents();
 38        setValues(null);
 39        setVisible(true);
 40    }
 41
 42    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 43    private void initComponents() {
 44
 45        jPanel2 = new javax.swing.JPanel();
 46        labeledTextChooser2 = new mpv5.ui.beans.LabeledTextChooser();
 47        jCheckBox3 = new javax.swing.JCheckBox();
 48        labeledTextField1 = new mpv5.ui.beans.LabeledTextField();
 49        labeledTextField2 = new mpv5.ui.beans.LabeledTextField();
 50        jLabel3 = new javax.swing.JLabel();
 51        jCheckBox1 = new javax.swing.JCheckBox();
 52        jButton5 = new javax.swing.JButton();
 53        jCheckBox2 = new javax.swing.JCheckBox();
 54        jPanel3 = new javax.swing.JPanel();
 55        labeledTextField3 = new mpv5.ui.beans.LabeledTextField();
 56        jPanel1 = new javax.swing.JPanel();
 57        jButton4 = new javax.swing.JButton();
 58        jButton1 = new javax.swing.JButton();
 59        jButton2 = new javax.swing.JButton();
 60        jButton3 = new javax.swing.JButton();
 61
 62        setBackground(new java.awt.Color(255, 255, 255));
 63        setName("Form"); // NOI18N
 64        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
 65
 66        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 67        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_External.jPanel2.border.title"))); // NOI18N
 68        jPanel2.setName("jPanel2"); // NOI18N
 69
 70        labeledTextChooser2.set_Label(bundle.getString("ControlPanel_External.labeledTextChooser2._Label")); // NOI18N
 71        labeledTextChooser2.setName("labeledTextChooser2"); // NOI18N
 72
 73        jCheckBox3.setText(bundle.getString("ControlPanel_External.jCheckBox3.text")); // NOI18N
 74        jCheckBox3.setName("jCheckBox3"); // NOI18N
 75        jCheckBox3.addItemListener(new java.awt.event.ItemListener() {
 76            public void itemStateChanged(java.awt.event.ItemEvent evt) {
 77                jCheckBox3ItemStateChanged(evt);
 78            }
 79        });
 80
 81        labeledTextField1.set_Label(bundle.getString("ControlPanel_External.labeledTextField1._Label")); // NOI18N
 82        labeledTextField1.set_Text(bundle.getString("ControlPanel_External.labeledTextField1._Text")); // NOI18N
 83        labeledTextField1.setEnabled(false);
 84        labeledTextField1.setName("labeledTextField1"); // NOI18N
 85
 86        labeledTextField2.set_Label(bundle.getString("ControlPanel_External.labeledTextField2._Label")); // NOI18N
 87        labeledTextField2.setEnabled(false);
 88        labeledTextField2.setName("labeledTextField2"); // NOI18N
 89
 90        jLabel3.setText(bundle.getString("ControlPanel_External.jLabel3.text")); // NOI18N
 91        jLabel3.setName("jLabel3"); // NOI18N
 92
 93        jCheckBox1.setText(bundle.getString("ControlPanel_External.jCheckBox1.text")); // NOI18N
 94        jCheckBox1.setName("jCheckBox1"); // NOI18N
 95
 96        jButton5.setText(bundle.getString("ControlPanel_External.jButton5.text")); // NOI18N
 97        jButton5.setName(bundle.getString("ControlPanel_External.jButton5.name")); // NOI18N
 98        jButton5.addActionListener(new java.awt.event.ActionListener() {
 99            public void actionPerformed(java.awt.event.ActionEvent evt) {
100                jButton5ActionPerformed(evt);
101            }
102        });
103
104        jCheckBox2.setText(bundle.getString("ControlPanel_External.jCheckBox2.text")); // NOI18N
105        jCheckBox2.setName("jCheckBox2"); // NOI18N
106
107        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
108        jPanel2.setLayout(jPanel2Layout);
109        jPanel2Layout.setHorizontalGroup(
110            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
111            .addGroup(jPanel2Layout.createSequentialGroup()
112                .addContainerGap()
113                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
114                    .addGroup(jPanel2Layout.createSequentialGroup()
115                        .addComponent(jCheckBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
116                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
117                        .addComponent(labeledTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
118                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
119                        .addComponent(labeledTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
120                    .addGroup(jPanel2Layout.createSequentialGroup()
121                        .addComponent(jLabel3)
122                        .addGap(0, 474, Short.MAX_VALUE))
123                    .addGroup(jPanel2Layout.createSequentialGroup()
124                        .addComponent(labeledTextChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
125                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126                        .addComponent(jButton5))
127                    .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
128                    .addComponent(jCheckBox2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE))
129                .addContainerGap())
130        );
131        jPanel2Layout.setVerticalGroup(
132            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133            .addGroup(jPanel2Layout.createSequentialGroup()
134                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
135                    .addComponent(labeledTextChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
136                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
137                .addGap(3, 3, 3)
138                .addComponent(jLabel3)
139                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
140                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
141                    .addComponent(jCheckBox3)
142                    .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
143                    .addComponent(labeledTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
144                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
145                .addComponent(jCheckBox1)
146                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
147                .addComponent(jCheckBox2)
148                .addContainerGap(25, Short.MAX_VALUE))
149        );
150
151        add(jPanel2);
152
153        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_External.jPanel3.border.title"))); // NOI18N
154        jPanel3.setName("jPanel3"); // NOI18N
155
156        labeledTextField3.set_Label(bundle.getString("ControlPanel_External.labeledTextField3._Label")); // NOI18N
157        labeledTextField3.setName("labeledTextField3"); // NOI18N
158
159        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
160        jPanel3.setLayout(jPanel3Layout);
161        jPanel3Layout.setHorizontalGroup(
162            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163            .addGroup(jPanel3Layout.createSequentialGroup()
164                .addContainerGap()
165                .addComponent(labeledTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
166                .addContainerGap(216, Short.MAX_VALUE))
167        );
168        jPanel3Layout.setVerticalGroup(
169            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170            .addGroup(jPanel3Layout.createSequentialGroup()
171                .addContainerGap()
172                .addComponent(labeledTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
173                .addContainerGap(30, Short.MAX_VALUE))
174        );
175
176        add(jPanel3);
177
178        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
179        jPanel1.setName("jPanel1"); // NOI18N
180        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
181
182        jButton4.setText(bundle.getString("ControlPanel_External.jButton4.text")); // NOI18N
183        jButton4.setName("jButton4"); // NOI18N
184        jButton4.addActionListener(new java.awt.event.ActionListener() {
185            public void actionPerformed(java.awt.event.ActionEvent evt) {
186                jButton4ActionPerformed(evt);
187            }
188        });
189        jPanel1.add(jButton4);
190
191        jButton1.setText(bundle.getString("ControlPanel_External.jButton1.text")); // NOI18N
192        jButton1.setName("jButton1"); // NOI18N
193        jButton1.addActionListener(new java.awt.event.ActionListener() {
194            public void actionPerformed(java.awt.event.ActionEvent evt) {
195                jButton1ActionPerformed(evt);
196            }
197        });
198        jPanel1.add(jButton1);
199
200        jButton2.setText(bundle.getString("ControlPanel_External.jButton2.text")); // NOI18N
201        jButton2.setName("jButton2"); // NOI18N
202        jButton2.addActionListener(new java.awt.event.ActionListener() {
203            public void actionPerformed(java.awt.event.ActionEvent evt) {
204                jButton2ActionPerformed(evt);
205            }
206        });
207        jPanel1.add(jButton2);
208
209        jButton3.setText(bundle.getString("ControlPanel_External.jButton3.text")); // NOI18N
210        jButton3.setName("jButton3"); // NOI18N
211        jButton3.addActionListener(new java.awt.event.ActionListener() {
212            public void actionPerformed(java.awt.event.ActionEvent evt) {
213                jButton3ActionPerformed(evt);
214            }
215        });
216        jPanel1.add(jButton3);
217
218        add(jPanel1);
219    }// </editor-fold>//GEN-END:initComponents
220
221    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
222
223        setSettings();
224        LocalSettings.save();
225        Popup.notice(Messages.RESTART_REQUIRED);
226    }//GEN-LAST:event_jButton1ActionPerformed
227
228    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
229        reset();
230    }//GEN-LAST:event_jButton3ActionPerformed
231
232    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
233
234        setSettings();
235        Popup.notice(Messages.RESTART_REQUIRED);
236}//GEN-LAST:event_jButton2ActionPerformed
237
238    private void jCheckBox3ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox3ItemStateChanged
239        labeledTextField1.setEnabled(jCheckBox3.isSelected());
240        labeledTextField2.setEnabled(jCheckBox3.isSelected());
241        labeledTextChooser2.setEnabled(!jCheckBox3.isSelected());
242}//GEN-LAST:event_jCheckBox3ItemStateChanged
243
244    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
245        NoaConnection.clearConnection();
246        Runnable runnable2 = new Runnable() {
247
248            @Override
249            public void run() {
250                //Caching the old values
251                String host = LocalSettings.getProperty(LocalSettings.OFFICE_HOST);
252                String Port = LocalSettings.getProperty(LocalSettings.OFFICE_PORT);
253                String Remote = LocalSettings.getProperty(LocalSettings.OFFICE_REMOTE);
254                String home = LocalSettings.getProperty(LocalSettings.OFFICE_HOME);
255                String use = LocalSettings.getProperty(LocalSettings.OFFICE_USE);
256
257                //Setting Values to test ...
258                LocalSettings.setProperty(LocalSettings.OFFICE_HOST, labeledTextField1.getText());
259                LocalSettings.setProperty(LocalSettings.OFFICE_PORT, jCheckBox3.isSelected() ? labeledTextField2.getText() : "0");
260                LocalSettings.setProperty(LocalSettings.OFFICE_REMOTE, Boolean.toString(jCheckBox3.isSelected()));
261                LocalSettings.setProperty(LocalSettings.OFFICE_USE, "true");
262                LocalSettings.setProperty(LocalSettings.OFFICE_HOME, labeledTextChooser2.get_Text(false));
263
264                mpv5.YabsViewProxy.instance().setWaiting(true);
265                try {
266                    NoaConnection.getConnection().getDesktopService().getFramesCount();
267                    Popup.notice(Messages.OO_DONE_LOADING);
268
269                } catch (Exception e) {
270                    Popup.notice(Messages.ERROR_OCCURED);
271                } finally {
272                    try {
273                        NoaConnection.getConnection().getDesktopService().terminate();
274                        setSettings();
275                        LocalSettings.save();
276                        Popup.notice(Messages.RESTART_REQUIRED);
277                    } catch (Exception ex) {
278                        Log.Debug(ex);
279                    }
280                }
281                mpv5.YabsViewProxy.instance().setWaiting(false);
282
283                //Restore old Values ....
284                LocalSettings.setProperty(LocalSettings.OFFICE_HOST, host);
285                LocalSettings.setProperty(LocalSettings.OFFICE_PORT, Port);
286                LocalSettings.setProperty(LocalSettings.OFFICE_REMOTE, Remote);
287                LocalSettings.setProperty(LocalSettings.OFFICE_HOME, home);
288                LocalSettings.setProperty(LocalSettings.OFFICE_USE, use);
289            }
290        };
291        final Thread startServerThread = new Thread(runnable2);
292        startServerThread.start();
293
294    }//GEN-LAST:event_jButton4ActionPerformed
295
296    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
297
298        Runnable runnable = new Runnable() {
299
300            public void run() {
301                try {
302                    NoaConnection.definePath();
303                    YabsViewProxy.instance().setWaiting(true);
304                    IApplicationAssistant applicationAssistant = new ApplicationAssistant();
305                    ILazyApplicationInfo appInfo = applicationAssistant.getLatestLocalLibreOfficeApplication();
306                    if (appInfo == null) {
307                        appInfo = applicationAssistant.getLatestLocalOpenOfficeOrgApplication();
308                    }
309                    labeledTextChooser2.setText(appInfo.getHome());
310                    YabsViewProxy.instance().setWaiting(false);
311                } catch (OfficeApplicationException ex) {
312                    Log.Debug(ex);
313                }
314            }
315        };
316        SwingUtilities.invokeLater(runnable);
317    }//GEN-LAST:event_jButton5ActionPerformed
318
319    public void setValues(PropertyStore values) {
320        oldvalues = values;
321        try {
322            labeledTextChooser2.set_Text(LocalSettings.getProperty(LocalSettings.OFFICE_HOME));
323            jCheckBox3.setSelected(LocalSettings.getBooleanProperty(LocalSettings.OFFICE_REMOTE));
324            jCheckBox1.setSelected(!LocalSettings.getBooleanProperty(LocalSettings.OFFICE_USE));
325            jCheckBox2.setSelected(LocalSettings.getBooleanProperty(LocalSettings.OFFICE_LOCALSERVER));
326            labeledTextField1.setText(LocalSettings.getProperty(LocalSettings.OFFICE_HOST));
327            labeledTextField2.setText(LocalSettings.getProperty(LocalSettings.OFFICE_PORT));
328            labeledTextField3.setText(LocalSettings.getProperty(LocalSettings.CALCULATOR));
329        } catch (Exception e) {
330            Log.Debug(this, e);
331        }
332    }
333
334    public String getUname() {
335        return UNAME;
336    }
337
338    public void reset() {
339        setValues(oldvalues);
340    }
341    // Variables declaration - do not modify//GEN-BEGIN:variables
342    private javax.swing.JButton jButton1;
343    private javax.swing.JButton jButton2;
344    private javax.swing.JButton jButton3;
345    private javax.swing.JButton jButton4;
346    private javax.swing.JButton jButton5;
347    private javax.swing.JCheckBox jCheckBox1;
348    private javax.swing.JCheckBox jCheckBox2;
349    private javax.swing.JCheckBox jCheckBox3;
350    private javax.swing.JLabel jLabel3;
351    private javax.swing.JPanel jPanel1;
352    private javax.swing.JPanel jPanel2;
353    private javax.swing.JPanel jPanel3;
354    private mpv5.ui.beans.LabeledTextChooser labeledTextChooser2;
355    private mpv5.ui.beans.LabeledTextField labeledTextField1;
356    private mpv5.ui.beans.LabeledTextField labeledTextField2;
357    private mpv5.ui.beans.LabeledTextField labeledTextField3;
358    // End of variables declaration//GEN-END:variables
359
360    private void setSettings() {
361        File f = new File(labeledTextChooser2.get_Text(false));
362        if (!jCheckBox3.isSelected() && !f.isDirectory()) {
363            try {
364                labeledTextChooser2.setText(f.getParentFile().getCanonicalPath());
365            } catch (IOException ex) {
366                Log.Debug(ex);
367            }
368        }
369
370        LocalSettings.setProperty(LocalSettings.OFFICE_HOME, labeledTextChooser2.get_Text(false));
371        LocalSettings.setProperty(LocalSettings.OFFICE_LOCALSERVER, Boolean.toString( jCheckBox2.isSelected()));
372        LocalSettings.setProperty(LocalSettings.OFFICE_USE, Boolean.toString(!jCheckBox1.isSelected()));
373        LocalSettings.setProperty(LocalSettings.OFFICE_REMOTE, Boolean.toString(jCheckBox3.isSelected()));
374        LocalSettings.setProperty(LocalSettings.OFFICE_HOST, labeledTextField1.getText());
375        LocalSettings.setProperty(LocalSettings.OFFICE_PORT, labeledTextField2.getText());
376        LocalSettings.setProperty(LocalSettings.CALCULATOR, labeledTextField3.getText());
377        LocalSettings.apply();
378    }
379
380    @Override
381    public Component getAndRemoveActionPanel() {
382        this.remove(jPanel1);
383        validate();
384        return jPanel1;
385    }
386}