PageRenderTime 287ms CodeModel.GetById 130ms app.highlight 86ms RepoModel.GetById 65ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 369 lines | 303 code | 56 blank | 10 comment | 16 complexity | 3c5c779f904e36782dd6be651dbec916 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Component;
  4import javax.swing.DefaultListModel;
  5import javax.swing.ListModel;
  6import javax.swing.SwingUtilities;
  7import mpv5.data.PropertyStore;
  8import mpv5.db.common.Context;
  9import mpv5.db.common.DatabaseObject;
 10import mpv5.db.common.NodataFoundException;
 11import mpv5.db.objects.Group;
 12import mpv5.db.objects.ValueProperty;
 13import mpv5.globals.LocalSettings;
 14import mpv5.logging.Log;
 15import mpv5.ui.dialogs.ControlApplet;
 16import mpv5.ui.dialogs.Popup;
 17import mpv5.ui.dialogs.Search2;
 18
 19/**
 20 *
 21 * 
 22 */
 23public class ControlPanel_ValueProps extends javax.swing.JPanel implements ControlApplet, DatabaseObejctReceiver {
 24
 25    private static final long serialVersionUID = 1L;
 26    /**
 27     * This unique name identifies this control applet
 28     */
 29    public final String UNAME = "valueproperties";
 30    private PropertyStore oldvalues;
 31    private ValueProperty dataOwner;
 32
 33    public ControlPanel_ValueProps() {
 34        initComponents();
 35        setVisible(true);
 36        labeledCombobox1.setEditable(false);
 37        labeledCombobox1.setContext(Context.getValueProperties());
 38        labeledCombobox1.setReceiver(this);
 39        refresh();
 40    }
 41
 42    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 43    private void initComponents() {
 44
 45        jScrollPane6 = new javax.swing.JScrollPane();
 46        jPanel3 = new javax.swing.JPanel();
 47        jScrollPane4 = new javax.swing.JScrollPane();
 48        jList1 = new javax.swing.JList();
 49        jLabel1 = new javax.swing.JLabel();
 50        jLabel2 = new javax.swing.JLabel();
 51        jScrollPane5 = new javax.swing.JScrollPane();
 52        jList2 = new javax.swing.JList();
 53        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 54        jPanel6 = new javax.swing.JPanel();
 55        jButton6 = new javax.swing.JButton();
 56        jScrollPane2 = new javax.swing.JScrollPane();
 57        jTextPane2 = new javax.swing.JTextPane();
 58        labeledTextField1 = new mpv5.ui.beans.LabeledTextField();
 59        jPanel1 = new javax.swing.JPanel();
 60        jButton1 = new javax.swing.JButton();
 61        jButton4 = new javax.swing.JButton();
 62        jButton5 = new javax.swing.JButton();
 63
 64        setName("Form"); // NOI18N
 65        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
 66
 67        jScrollPane6.setName("jScrollPane6"); // NOI18N
 68
 69        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 70        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_ValueProps.jPanel3.border.title"))); // NOI18N
 71        jPanel3.setName("jPanel3"); // NOI18N
 72
 73        jScrollPane4.setName("jScrollPane4"); // NOI18N
 74
 75        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
 76        jList1.setName("jList1"); // NOI18N
 77        jScrollPane4.setViewportView(jList1);
 78
 79        jLabel1.setText(bundle.getString("ControlPanel_ValueProps.jLabel1.text")); // NOI18N
 80        jLabel1.setName("jLabel1"); // NOI18N
 81
 82        jLabel2.setText(bundle.getString("ControlPanel_ValueProps.jLabel2.text")); // NOI18N
 83        jLabel2.setName("jLabel2"); // NOI18N
 84
 85        jScrollPane5.setName("jScrollPane5"); // NOI18N
 86
 87        jList2.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
 88        jList2.setName("jList2"); // NOI18N
 89        jScrollPane5.setViewportView(jList2);
 90
 91        labeledCombobox1.set_Label(bundle.getString("ControlPanel_ValueProps.labeledCombobox1._Label")); // NOI18N
 92        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
 93
 94        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_ValueProps.jPanel6.border.title"))); // NOI18N
 95        jPanel6.setName("jPanel6"); // NOI18N
 96        jPanel6.setPreferredSize(new java.awt.Dimension(200, 100));
 97
 98        jButton6.setText(bundle.getString("ControlPanel_ValueProps.jButton6.text")); // NOI18N
 99        jButton6.setName("jButton6"); // NOI18N
100        jButton6.addActionListener(new java.awt.event.ActionListener() {
101            public void actionPerformed(java.awt.event.ActionEvent evt) {
102                jButton6ActionPerformed(evt);
103            }
104        });
105
106        jScrollPane2.setName("jScrollPane2"); // NOI18N
107
108        jTextPane2.setText(bundle.getString("ControlPanel_ValueProps.jTextPane2.text")); // NOI18N
109        jTextPane2.setName("jTextPane2"); // NOI18N
110        jScrollPane2.setViewportView(jTextPane2);
111
112        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
113        jPanel6.setLayout(jPanel6Layout);
114        jPanel6Layout.setHorizontalGroup(
115            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
116            .addGroup(jPanel6Layout.createSequentialGroup()
117                .addContainerGap()
118                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119                    .addGroup(jPanel6Layout.createSequentialGroup()
120                        .addComponent(jButton6)
121                        .addGap(417, 417, 417))
122                    .addGroup(jPanel6Layout.createSequentialGroup()
123                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
124                        .addContainerGap())))
125        );
126        jPanel6Layout.setVerticalGroup(
127            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
129                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
130                .addGap(13, 13, 13)
131                .addComponent(jButton6))
132        );
133
134        labeledTextField1.set_Label(bundle.getString("ControlPanel_ValueProps.labeledTextField1._Label")); // NOI18N
135        labeledTextField1.setName("labeledTextField1"); // NOI18N
136
137        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
138        jPanel3.setLayout(jPanel3Layout);
139        jPanel3Layout.setHorizontalGroup(
140            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
142                .addComponent(labeledCombobox1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
143                .addComponent(labeledTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
144                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
145                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
147                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
148                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
149                        .addGroup(jPanel3Layout.createSequentialGroup()
150                            .addGap(95, 95, 95)
151                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
152                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
153                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154                            .addComponent(jScrollPane5)))))
155            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)
156        );
157        jPanel3Layout.setVerticalGroup(
158            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
159            .addGroup(jPanel3Layout.createSequentialGroup()
160                .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
161                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163                    .addComponent(jLabel1)
164                    .addComponent(jLabel2))
165                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
168                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
169                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
170                .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
171                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
172                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE))
173        );
174
175        jScrollPane6.setViewportView(jPanel3);
176
177        add(jScrollPane6);
178
179        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
180        jPanel1.setName("jPanel1"); // NOI18N
181        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
182
183        jButton1.setText(bundle.getString("ControlPanel_ValueProps.jButton1.text")); // NOI18N
184        jButton1.setName("jButton1"); // NOI18N
185        jButton1.addActionListener(new java.awt.event.ActionListener() {
186            public void actionPerformed(java.awt.event.ActionEvent evt) {
187                jButton1ActionPerformed(evt);
188            }
189        });
190        jPanel1.add(jButton1);
191
192        jButton4.setText(bundle.getString("ControlPanel_ValueProps.jButton4.text")); // NOI18N
193        jButton4.setName("jButton4"); // NOI18N
194        jButton4.addActionListener(new java.awt.event.ActionListener() {
195            public void actionPerformed(java.awt.event.ActionEvent evt) {
196                jButton4ActionPerformed(evt);
197            }
198        });
199        jPanel1.add(jButton4);
200
201        jButton5.setText(bundle.getString("ControlPanel_ValueProps.jButton5.text")); // NOI18N
202        jButton5.setName("jButton5"); // NOI18N
203        jButton5.addActionListener(new java.awt.event.ActionListener() {
204            public void actionPerformed(java.awt.event.ActionEvent evt) {
205                jButton5ActionPerformed(evt);
206            }
207        });
208        jPanel1.add(jButton5);
209
210        add(jPanel1);
211    }// </editor-fold>//GEN-END:initComponents
212
213    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
214
215        if (dataOwner != null) {
216            dataOwner.delete();
217            refresh();
218            dataOwner = null;
219        }
220    }//GEN-LAST:event_jButton1ActionPerformed
221
222    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
223        prepare();
224        String cname = labeledTextField1.getText(true, "key");
225        String val = "#" + jTextPane2.getText() + "#";
226
227        if (dataOwner == null) {
228            dataOwner = new ValueProperty(cname, val, (Context) jList1.getSelectedValue(), (Group) jList2.getSelectedValue());
229        } else {
230            dataOwner.setValueObj(val);
231            dataOwner.setCname(cname);
232            dataOwner.setContextids(((Context) jList1.getSelectedValue()).getId());
233            dataOwner.setGroup((Group) jList2.getSelectedValue());
234        }
235
236        dataOwner.save();
237        refresh();
238    }//GEN-LAST:event_jButton4ActionPerformed
239
240    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
241        prepare();
242        String cname = labeledTextField1.getText(true, "key");
243        String val = "#" + jTextPane2.getText() + "#";
244        ValueProperty xx = new ValueProperty(cname, val, (Context) jList1.getSelectedValue(), (Group) jList2.getSelectedValue());
245        if (xx.save()) {
246            dataOwner = xx;
247        }
248        refresh();
249    }//GEN-LAST:event_jButton5ActionPerformed
250
251    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
252        DatabaseObject s = Search2.showSearchFor(Context.getItem());
253        if (s != null) {
254            try {
255                Popup.notice(s.evaluate(jTextPane2.getText()));
256            } catch (Exception e) {
257                Popup.error(e);
258            }
259        }
260    }//GEN-LAST:event_jButton6ActionPerformed
261
262    @Override
263    public void setValues(PropertyStore values) {
264        oldvalues = values;
265
266    }
267
268    @Override
269    public String getUname() {
270        return UNAME;
271    }
272
273    @Override
274    public void reset() {
275        setValues(oldvalues);
276    }
277    // Variables declaration - do not modify//GEN-BEGIN:variables
278    private javax.swing.JButton jButton1;
279    private javax.swing.JButton jButton4;
280    private javax.swing.JButton jButton5;
281    private javax.swing.JButton jButton6;
282    private javax.swing.JLabel jLabel1;
283    private javax.swing.JLabel jLabel2;
284    private javax.swing.JList jList1;
285    private javax.swing.JList jList2;
286    private javax.swing.JPanel jPanel1;
287    private javax.swing.JPanel jPanel3;
288    private javax.swing.JPanel jPanel6;
289    private javax.swing.JScrollPane jScrollPane2;
290    private javax.swing.JScrollPane jScrollPane4;
291    private javax.swing.JScrollPane jScrollPane5;
292    private javax.swing.JScrollPane jScrollPane6;
293    private javax.swing.JTextPane jTextPane2;
294    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
295    private mpv5.ui.beans.LabeledTextField labeledTextField1;
296    // End of variables declaration//GEN-END:variables
297
298    private void setSettings() {
299    }
300
301    @Override
302    public Component getAndRemoveActionPanel() {
303        this.remove(jPanel1);
304        validate();
305        return jPanel1;
306    }
307
308    private void refresh() {
309
310        Runnable runnable = new Runnable() {
311
312            public void run() {
313                DefaultListModel def = new DefaultListModel();
314                for (Context c : Context.getCacheableContexts()) {
315                    def.addElement(c);
316                }
317                jList1.setModel(def);
318
319                DefaultListModel def1 = new DefaultListModel();
320                try {
321                    for (DatabaseObject c : Group.getObjects(Context.getGroup())) {
322                        def1.addElement((Group) c);
323                    }
324                } catch (NodataFoundException ex) {
325                    Log.Debug(ex);
326                }
327                jList2.setModel(def1);
328
329                labeledCombobox1.setModel(DatabaseObject.toObjectList(ValueProperty.getGroupProperties()));
330
331            }
332        };
333        SwingUtilities.invokeLater(runnable);
334    }
335
336    public void receive(final DatabaseObject obj) {
337
338        Runnable runnable = new Runnable() {
339
340            public void run() {
341                dataOwner = (ValueProperty) obj;
342                jTextPane2.setText(dataOwner.getValue().toString().replace("#", ""));
343                labeledTextField1.setText(dataOwner.getKey());
344                jList1.setSelectedValue(Context.getByID(((ValueProperty) obj).__getContextids()), true);
345                try {
346                    jList2.setSelectedValue(((ValueProperty) obj).getGroup(), true);
347                } catch ( Exception ex) {
348                    Log.Debug(ex);
349                }
350            }
351        };
352        SwingUtilities.invokeLater(runnable);
353    }
354
355    private void prepare() {
356
357        if (jList1.getSelectedValue() == null) {
358            jList1.setSelectedIndex(0);
359        }
360        if (jList2.getSelectedValue() == null) {
361            jList2.setSelectedIndex(0);
362        }
363        if (jTextPane2.getText().length() == 0) {
364            jTextPane2.setText("return \"\"");
365        }
366
367
368    }
369}