PageRenderTime 86ms CodeModel.GetById 11ms app.highlight 66ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 540 lines | 457 code | 69 blank | 14 comment | 19 complexity | 5b9c9d1e64c88de9b73e8e47ae813c0d MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Component;
  4import java.awt.event.ActionEvent;
  5import java.awt.event.ActionListener;
  6import java.text.MessageFormat;
  7import java.util.Date;
  8import javax.swing.JSpinner;
  9import javax.swing.SpinnerNumberModel;
 10import mpv5.data.PropertyStore;
 11import mpv5.db.common.*;
 12import mpv5.db.objects.Item;
 13import mpv5.globals.Messages;
 14import mpv5.logging.Log;
 15import mpv5.i18n.LanguageManager;
 16import mpv5.ui.dialogs.ControlApplet;
 17import mpv5.ui.dialogs.Popup;
 18import mpv5.usermanagement.MPSecurityManager;
 19import mpv5.db.objects.User;
 20import mpv5.globals.GlobalSettings;
 21import mpv5.handler.FormatHandler;
 22import mpv5.handler.MPEnum;
 23import mpv5.handler.VariablesHandler;
 24import mpv5.ui.dialogs.Notificator;
 25import mpv5.utils.models.MPComboBoxModelItem;
 26import mpv5.utils.models.MPTableModel;
 27import mpv5.utils.tables.TableFormat;
 28
 29/**
 30 *
 31 *
 32 */
 33public class ControlPanel_Formats extends javax.swing.JPanel implements ControlApplet {
 34
 35    private static final long serialVersionUID = 1L;
 36    /**
 37     * This unique name identifies this control applet
 38     */
 39    public final String UNAME = "formats";
 40    private Integer currentUser;
 41    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 42
 43    public ControlPanel_Formats() {
 44        if (MPSecurityManager.checkAdminAccess()) {
 45            initComponents();
 46            refresh();
 47            setTable();
 48            setVisible(true);
 49            setacL();
 50        }
 51    }
 52
 53    public ControlPanel_Formats(User user) {
 54        if (MPSecurityManager.checkAdminAccess()) {
 55            initComponents();
 56            refresh();
 57            setdata(user);
 58            setVisible(true);
 59            setacL();
 60        }
 61    }
 62
 63    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 64    private void initComponents() {
 65
 66        jPanel1 = new javax.swing.JPanel();
 67        jPanel2 = new javax.swing.JPanel();
 68        jScrollPane1 = new javax.swing.JScrollPane();
 69        jTable1 = new javax.swing.JTable();
 70        jButton5 = new javax.swing.JButton();
 71        jPanel3 = new javax.swing.JPanel();
 72        jComboBox1 = new javax.swing.JComboBox();
 73        jLabel1 = new javax.swing.JLabel();
 74        labeledTextField1 = new mpv5.ui.beans.LabeledTextField();
 75        labeledSpinner1 = new mpv5.ui.beans.LabeledSpinner();
 76        jLabel4 = new javax.swing.JLabel();
 77        labeledSpinner2 = new mpv5.ui.beans.LabeledSpinner();
 78        jLabel3 = new javax.swing.JLabel();
 79        locales = new javax.swing.JComboBox();
 80        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 81        labeledCombobox2 = new mpv5.ui.beans.LabeledCombobox();
 82        labeledCombobox3 = new mpv5.ui.beans.LabeledCombobox();
 83        jLabel2 = new javax.swing.JLabel();
 84        jPanel6 = new javax.swing.JPanel();
 85        jButton3 = new javax.swing.JButton();
 86
 87        setBackground(new java.awt.Color(255, 255, 255));
 88        setName("Form"); // NOI18N
 89        setLayout(new java.awt.BorderLayout());
 90
 91        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
 92        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 93        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Formats.jPanel1.border.title"))); // NOI18N
 94        jPanel1.setName("jPanel1"); // NOI18N
 95
 96        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Formats.jPanel2.border.title"))); // NOI18N
 97        jPanel2.setName("jPanel2"); // NOI18N
 98
 99        jScrollPane1.setName("jScrollPane1"); // NOI18N
100
101        jTable1.setModel(new javax.swing.table.DefaultTableModel(
102            new Object [][] {
103
104            },
105            new String [] {
106
107            }
108        ));
109        jTable1.setName("jTable1"); // NOI18N
110        jScrollPane1.setViewportView(jTable1);
111
112        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/2leftarrow.png"))); // NOI18N
113        jButton5.setText(bundle.getString("ControlPanel_Formats.jButton5.text")); // NOI18N
114        jButton5.setToolTipText(bundle.getString("ControlPanel_Formats.jButton5.toolTipText")); // NOI18N
115        jButton5.setName("jButton5"); // NOI18N
116        jButton5.addActionListener(new java.awt.event.ActionListener() {
117            public void actionPerformed(java.awt.event.ActionEvent evt) {
118                jButton5ActionPerformed(evt);
119            }
120        });
121
122        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
123        jPanel3.setName("jPanel3"); // NOI18N
124
125        jComboBox1.setName("jComboBox1"); // NOI18N
126        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
127            public void itemStateChanged(java.awt.event.ItemEvent evt) {
128                jComboBox1ItemStateChanged(evt);
129            }
130        });
131        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
132            public void actionPerformed(java.awt.event.ActionEvent evt) {
133                jComboBox1ActionPerformed(evt);
134            }
135        });
136
137        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/32/1downarrow.png"))); // NOI18N
138        jLabel1.setText(bundle.getString("ControlPanel_Formats.jLabel1.text")); // NOI18N
139        jLabel1.setName("jLabel1"); // NOI18N
140
141        labeledTextField1.set_Label(bundle.getString("ControlPanel_Formats.labeledTextField1._Label")); // NOI18N
142        labeledTextField1.setName("labeledTextField1"); // NOI18N
143
144        labeledSpinner1.set_Label(bundle.getString("ControlPanel_Formats.labeledSpinner1._Label")); // NOI18N
145        labeledSpinner1.setName("labeledSpinner1"); // NOI18N
146
147        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
148        jLabel4.setText(bundle.getString("ControlPanel_Formats.jLabel4.text")); // NOI18N
149        jLabel4.setName("jLabel4"); // NOI18N
150
151        labeledSpinner2.set_Label(bundle.getString("ControlPanel_Formats.labeledSpinner2._Label")); // NOI18N
152        labeledSpinner2.setName("labeledSpinner2"); // NOI18N
153
154        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
155        jLabel3.setText(bundle.getString("ControlPanel_Formats.jLabel3.text")); // NOI18N
156        jLabel3.setName("jLabel3"); // NOI18N
157
158        locales.setName("locales"); // NOI18N
159
160        labeledCombobox1.set_Label(bundle.getString("ControlPanel_Formats.labeledCombobox1._Label_1")); // NOI18N
161        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
162
163        labeledCombobox2.set_Label(bundle.getString("ControlPanel_Formats.labeledCombobox2._Label_1")); // NOI18N
164        labeledCombobox2.setName("labeledCombobox2"); // NOI18N
165
166        labeledCombobox3.set_Label(bundle.getString("ControlPanel_Formats.labeledCombobox3._Label_1")); // NOI18N
167        labeledCombobox3.setName("labeledCombobox3"); // NOI18N
168
169        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
170        jLabel2.setText(bundle.getString("ControlPanel_Formats.jLabel2.text")); // NOI18N
171        jLabel2.setName("jLabel2"); // NOI18N
172
173        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
174        jPanel3.setLayout(jPanel3Layout);
175        jPanel3Layout.setHorizontalGroup(
176            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177            .addGroup(jPanel3Layout.createSequentialGroup()
178                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
179                    .addComponent(labeledTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
180                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
181                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
182                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
183                            .addGroup(jPanel3Layout.createSequentialGroup()
184                                .addComponent(labeledCombobox3, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
185                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
186                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
187                            .addComponent(labeledCombobox1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
188                            .addComponent(labeledCombobox2, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE))
189                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190                        .addComponent(jLabel1))
191                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
192                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
193                    .addGroup(jPanel3Layout.createSequentialGroup()
194                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195                            .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
196                            .addComponent(labeledSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197                            .addComponent(locales, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
198                        .addGap(0, 255, Short.MAX_VALUE)))
199                .addContainerGap())
200        );
201        jPanel3Layout.setVerticalGroup(
202            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203            .addGroup(jPanel3Layout.createSequentialGroup()
204                .addContainerGap()
205                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206                    .addComponent(labeledCombobox3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
207                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
208                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209                .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
210                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
213                    .addComponent(labeledCombobox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
214                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
215                .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
216                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
217                .addComponent(jLabel2)
218                .addGap(11, 11, 11)
219                .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
220                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
221                .addComponent(jLabel4)
222                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223                .addComponent(labeledSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225                .addComponent(jLabel3)
226                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
227                .addComponent(locales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
228                .addContainerGap(40, Short.MAX_VALUE))
229        );
230
231        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
232        jPanel2.setLayout(jPanel2Layout);
233        jPanel2Layout.setHorizontalGroup(
234            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235            .addGroup(jPanel2Layout.createSequentialGroup()
236                .addGap(15, 15, 15)
237                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
238                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239                .addComponent(jButton5)
240                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
241                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
243        );
244        jPanel2Layout.setVerticalGroup(
245            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246            .addGroup(jPanel2Layout.createSequentialGroup()
247                .addGap(5, 5, 5)
248                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
249                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
250                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
251                        .addComponent(jButton5)
252                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
253                .addContainerGap(17, Short.MAX_VALUE))
254        );
255
256        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
257        jPanel1.setLayout(jPanel1Layout);
258        jPanel1Layout.setHorizontalGroup(
259            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
261        );
262        jPanel1Layout.setVerticalGroup(
263            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
265        );
266
267        add(jPanel1, java.awt.BorderLayout.CENTER);
268
269        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
270        jPanel6.setName("jPanel6"); // NOI18N
271        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
272
273        jButton3.setText(bundle.getString("ControlPanel_Formats.jButton3.text")); // NOI18N
274        jButton3.setName("jButton3"); // NOI18N
275        jButton3.addActionListener(new java.awt.event.ActionListener() {
276            public void actionPerformed(java.awt.event.ActionEvent evt) {
277                jButton3ActionPerformed(evt);
278            }
279        });
280        jPanel6.add(jButton3);
281
282        add(jPanel6, java.awt.BorderLayout.PAGE_END);
283    }// </editor-fold>//GEN-END:initComponents
284
285    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
286        test();
287}//GEN-LAST:event_jButton3ActionPerformed
288
289    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
290    }//GEN-LAST:event_jComboBox1ItemStateChanged
291
292    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
293
294        currentUser = Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId());
295        try {
296            setLocale(currentUser);
297        } catch (Exception e) {
298            Log.Debug(e);
299        }
300        setTable();
301    }//GEN-LAST:event_jComboBox1ActionPerformed
302
303    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
304        if (test()) {
305            save();
306        }
307    }//GEN-LAST:event_jButton5ActionPerformed
308
309    public void setValues(PropertyStore values) {
310    }
311
312    public String getUname() {
313        return UNAME;
314    }
315
316    public void reset() {
317    }
318    // Variables declaration - do not modify//GEN-BEGIN:variables
319    private javax.swing.JButton jButton3;
320    private javax.swing.JButton jButton5;
321    private javax.swing.JComboBox jComboBox1;
322    private javax.swing.JLabel jLabel1;
323    private javax.swing.JLabel jLabel2;
324    private javax.swing.JLabel jLabel3;
325    private javax.swing.JLabel jLabel4;
326    private javax.swing.JPanel jPanel1;
327    private javax.swing.JPanel jPanel2;
328    private javax.swing.JPanel jPanel3;
329    private javax.swing.JPanel jPanel6;
330    private javax.swing.JScrollPane jScrollPane1;
331    private javax.swing.JTable jTable1;
332    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
333    private mpv5.ui.beans.LabeledCombobox labeledCombobox2;
334    private mpv5.ui.beans.LabeledCombobox labeledCombobox3;
335    private mpv5.ui.beans.LabeledSpinner labeledSpinner1;
336    private mpv5.ui.beans.LabeledSpinner labeledSpinner2;
337    private mpv5.ui.beans.LabeledTextField labeledTextField1;
338    private javax.swing.JComboBox locales;
339    // End of variables declaration//GEN-END:variables
340
341    public void refresh() {
342        locales.setModel(LanguageManager.getLocalesAsComboBoxModel());
343        setLocale(mpv5.db.objects.User.getCurrentUser().__getIDS());
344        labeledSpinner1.getSpinner().setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
345        labeledSpinner1.getSpinner().setEditor(new JSpinner.NumberEditor(labeledSpinner1.getSpinner()));
346        labeledSpinner1.getSpinner().updateUI();
347
348        labeledSpinner2.getSpinner().setModel(new SpinnerNumberModel(0, -1000, Integer.MAX_VALUE, 1));
349        labeledSpinner2.getSpinner().setEditor(new JSpinner.NumberEditor(labeledSpinner2.getSpinner()));
350        labeledSpinner2.getSpinner().updateUI();
351
352        try {
353            QueryCriteria2 q = new QueryCriteria2();
354            q.and(new QueryParameter(Context.getUser(), "groupsids", User.getCurrentUser().__getGroupsids(), QueryParameter.EQUALS));
355            jComboBox1.setModel(MPComboBoxModelItem.toModel(QueryHandler.instanceOf().clone(Context.getUser()).getColumns(new String[]{"ids", "cname"}, 0, q)));
356        } catch (NodataFoundException ex) {
357        }
358        try {
359            labeledCombobox1.setModel(QueryHandler.instanceOf().clone(Context.getFormats()).select("inttype,cname", (String[]) null));
360        } catch (Exception e) {
361        }
362        try {
363            labeledCombobox2.setModel(VariablesHandler.GENERIC_VARS.values());
364        } catch (Exception e) {
365        }
366        try {
367            labeledCombobox3.setModel(MPComboBoxModelItem.toModel((MPEnum[]) FormatHandler.TYPES.values()));
368        } catch (Exception e) {
369        }
370
371        labeledTextField1.setText(FormatHandler.INTEGERPART_IDENTIFIER);
372        labeledCombobox3.getComboBox().setSelectedIndex(0);
373
374        setUser();
375        setTable();
376
377    }
378
379    @Override
380    public Component getAndRemoveActionPanel() {
381        this.remove(jPanel6);
382        validate();
383        return jPanel6;
384    }
385
386    private void save() {
387        String oval = labeledTextField1.getText();
388        //set start value
389        if (labeledSpinner1.getSpinner().getValue() != null && Integer.valueOf(labeledSpinner1.getSpinner().getValue().toString()).intValue() > 0) {
390            labeledTextField1.setText(FormatHandler.START_VALUE_IDENTIFIER + Integer.valueOf(labeledSpinner1.getSpinner().getValue().toString()) + FormatHandler.START_VALUE_IDENTIFIER + oval);
391        }
392
393        QueryCriteria c = new QueryCriteria("inttype", Integer.valueOf(labeledCombobox3.getSelectedItem().getId()));
394        c.addAndCondition("usersids", Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId()));
395        QueryHandler.instanceOf().clone(Context.getFormats()).delete(c);
396        QueryData what = new QueryData();
397        what.add("inttype", Integer.valueOf(labeledCombobox3.getSelectedItem().getId()));
398        what.add("cname", labeledTextField1.getText());
399        what.add("usersids", Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId()));
400        QueryHandler.instanceOf().clone(Context.getFormats()).insert(what, null);
401        try {
402            User u = (User) User.getObject(Context.getUser(), Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId()));
403            u.getProperties().changeProperty("item.date.locale", ((MPComboBoxModelItem) locales.getSelectedItem()).getId());
404            u.saveProperties();
405        } catch (Exception ex) {
406            Log.Debug(ex);
407        }
408
409        if (oval.contains("[")
410                && String.valueOf(labeledSpinner2.get_Value()).equals("0")) {
411            Notificator.raiseNotification("If you use dynamic parts in your number format, you MUST define a position from where to parse the number from!\n "
412                    + "If you do not define a parse position, the defined format may not work as expected.", true);//FIXME i18n
413        }
414        try {
415            GlobalSettings.setProperty(new MessageFormat(oval).toPattern() + "_startposition", String.valueOf(labeledSpinner2.get_Value()));
416            GlobalSettings.save();
417        } catch (Exception ex) {
418            Log.Debug(ex);
419        }
420
421        setTable();
422        labeledTextField1.setText("");
423        labeledSpinner1.getSpinner().setValue(0);
424        labeledSpinner2.getSpinner().setValue(0);
425        labeledCombobox1.setModel(QueryHandler.instanceOf().clone(Context.getFormats()).select("inttype,cname", (String[]) null));
426        Popup.notice(Messages.RESTART_REQUIRED);
427    }
428
429    private void setTable() {
430        try {
431            Object[][] d = QueryHandler.instanceOf().clone(Context.getFormats()).select("cname, inttype", new QueryCriteria("usersids", currentUser));
432            for (int i = 0; i < d.length; i++) {
433                MPEnum[] t = FormatHandler.TYPES.values();
434                for (int j = 0; j < t.length; j++) {
435                    MPEnum mPEnum = t[j];
436                    if (mPEnum.getId() == Integer.valueOf(d[i][1].toString()).intValue()) {
437                        d[i][1] = mPEnum.getName();
438                        break;
439                    }
440                }
441            }
442            jTable1.setModel(new MPTableModel(d));
443            TableFormat.hideHeader(jTable1);
444        } catch (NodataFoundException ex) {
445            Log.Debug(ex);
446        }
447    }
448
449    private void setUser() {
450        try {
451            if (currentUser == null) {
452                currentUser = mpv5.db.objects.User.getCurrentUser().getID();
453                jComboBox1.setSelectedIndex(MPComboBoxModelItem.getItemID(String.valueOf(currentUser), jComboBox1.getModel()));
454            } else {
455                currentUser = Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId());
456            }
457
458            setLocale(currentUser);
459        } catch (Exception e) {
460        }
461    }
462
463    private void setacL() {
464
465        labeledCombobox1.getComboBox().addActionListener(new ActionListener() {
466
467            @Override
468            public void actionPerformed(ActionEvent e) {
469                labeledTextField1.setText(labeledCombobox1.getSelectedItem());
470                String prop = GlobalSettings.getProperty(new MessageFormat(labeledTextField1.getText()).toPattern() + "_startposition");
471                if (prop != null) {
472                    try {
473                        int pos = Integer.valueOf(prop);
474                        labeledSpinner2.set_Value(pos);
475                    } catch (NumberFormatException numberFormatException) {
476                        Log.Debug(numberFormatException);
477                    }
478                }
479            }
480        });
481
482        labeledCombobox2.getComboBox().addActionListener(new ActionListener() {
483
484            @Override
485            public void actionPerformed(ActionEvent e) {
486                labeledTextField1.set_Text(labeledCombobox2.getSelectedItem().getValue() + labeledTextField1.get_Text());
487            }
488        });
489    }
490
491    private void setdata(User user) {
492        jComboBox1.setSelectedIndex(MPComboBoxModelItem.getItemID(String.valueOf(user.getID()), jComboBox1.getModel()));
493        setLocale(user.__getIDS());
494    }
495
496    private boolean test() {
497
498//        if (!labeledTextField1.getText().contains(FormatHandler.INTEGERPART_IDENTIFIER.substring(0, 3))) {
499//            labeledTextField1.set_Text(labeledTextField1.getText() + FormatHandler.INTEGERPART_IDENTIFIER);
500//        }
501        try {
502            User u = (User) User.getObject(Context.getUser(), Integer.valueOf(((MPComboBoxModelItem) jComboBox1.getSelectedItem()).getId()));
503            u.getProperties().changeProperty("item.date.locale", ((MPComboBoxModelItem) locales.getSelectedItem()).getId());
504            u.save();
505        } catch (Exception ex) {
506            Log.Debug(ex);
507        }
508
509        String str = "";
510        Item b = (Item) DatabaseObject.getObject(Context.getItem());
511        b.setIDS(1);
512        b.avoidNulls();
513
514        try {
515            FormatHandler fh = new FormatHandler(b);
516            str = fh.toString(new FormatHandler.YMessageFormat((VariablesHandler.parse(labeledTextField1.getText(), b)).substring(Integer.valueOf(labeledSpinner1.get_Value().toString())), null), Integer.valueOf(labeledSpinner1.get_Value().toString()));
517            str = Messages.THE_RESULT + str;
518
519            return Popup.OK_dialog(str, Messages.NOTICE.getValue());
520        } catch (Exception exception) {
521            Popup.error(exception);
522            return false;
523        }
524    }
525
526    private void setLocale(int userid) {
527        User u;
528        try {
529            u = new User(userid);
530            Log.Debug(this, u + ": " + u.getProperties().getProperty("item.date.locale"));
531            if (u.getProperties().hasProperty("item.date.locale")) {
532                locales.setSelectedIndex(MPComboBoxModelItem.getItemID(u.getProperties().getProperty("item.date.locale"), locales.getModel()));
533            } else {
534                locales.setSelectedIndex(MPComboBoxModelItem.getItemID(mpv5.db.objects.User.getCurrentUser().__getLocale(), locales.getModel()));
535            }
536        } catch (NodataFoundException ex) {
537            Log.Debug(ex);
538        }
539    }
540}