PageRenderTime 167ms CodeModel.GetById 60ms app.highlight 61ms RepoModel.GetById 39ms app.codeStats 1ms

/src/mpv5/ui/dialogs/ScheduleDayEvent.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 386 lines | 316 code | 45 blank | 25 comment | 13 complexity | b549a211f895569d4722d5245b6f7756 MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * SplashScreen.java
  8 *
  9 * Created on 30.03.2009, 21:55:52
 10 */
 11package mpv5.ui.dialogs;
 12
 13import java.util.ArrayList;
 14import java.util.Date;
 15
 16import mpv5.db.common.Context;
 17import mpv5.db.common.DatabaseObject;
 18import mpv5.db.common.NodataFoundException;
 19import mpv5.db.objects.Item;
 20import mpv5.db.objects.Schedule;
 21import mpv5.globals.Headers;
 22import mpv5.globals.Messages;
 23import mpv5.logging.Log;
 24import mpv5.ui.misc.Position;
 25import mpv5.utils.date.DateConverter;
 26import mpv5.utils.models.MPTableModel;
 27import mpv5.utils.tables.TableFormat;
 28
 29/**
 30 *
 31 *  
 32 */
 33public class ScheduleDayEvent extends javax.swing.JFrame {
 34
 35    private static final long serialVersionUID = 1L;
 36    private static ScheduleDayEvent icke;
 37    private Schedule dataOwner;
 38
 39    public static ScheduleDayEvent instanceOf() {
 40        if (icke == null) {
 41            icke = new ScheduleDayEvent();
 42        }
 43        return icke;
 44    }
 45    private String text = "";
 46
 47    private ScheduleDayEvent() {
 48        initComponents();
 49        text = jLabel3.getText();
 50        refresh(null);
 51        labeledCombobox1.setSearchEnabled(true);
 52        labeledCombobox1.setContext(Context.getInvoice());
 53        setAlwaysOnTop(true);
 54        new Position(this);
 55    }
 56
 57    @Override
 58    public void dispose() {
 59        setVisible(false);
 60    }
 61
 62    public void setDate(Date tday) {
 63        labeledDateChooser1.setDate(DateConverter.addDays(tday, 0));
 64        labeledDateChooser2.setDate(DateConverter.addYear(tday));
 65    }
 66
 67    /** This method is called from within the constructor to
 68     * initialize the form.
 69     * WARNING: Do NOT modify this code. The content of this method is
 70     * always regenerated by the Form Editor.
 71     */
 72    @SuppressWarnings("unchecked")
 73    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 74    private void initComponents() {
 75
 76        jPanel1 = new javax.swing.JPanel();
 77        jScrollPane1 = new javax.swing.JScrollPane();
 78        jTable1 = new javax.swing.JTable();
 79        jLabel3 = new javax.swing.JLabel();
 80        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 81        labeledSpinner1 = new mpv5.ui.beans.LabeledSpinner();
 82        jLabel1 = new javax.swing.JLabel();
 83        labeledDateChooser1 = new mpv5.ui.beans.LabeledDateChooser();
 84        labeledDateChooser2 = new mpv5.ui.beans.LabeledDateChooser();
 85        jPanel2 = new javax.swing.JPanel();
 86        jButton2 = new javax.swing.JButton();
 87        jSeparator1 = new javax.swing.JSeparator();
 88        jSeparator3 = new javax.swing.JSeparator();
 89        jButton3 = new javax.swing.JButton();
 90        jSeparator2 = new javax.swing.JSeparator();
 91        jButton1 = new javax.swing.JButton();
 92        jButton4 = new javax.swing.JButton();
 93        jButton5 = new javax.swing.JButton();
 94
 95        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 96        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 97        setTitle(bundle.getString("ScheduleDayEvent.title")); // NOI18N
 98        setAlwaysOnTop(true);
 99        setName("Form"); // NOI18N
100
101        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ScheduleDayEvent.jPanel1.border.title"))); // NOI18N
102        jPanel1.setName("jPanel1"); // NOI18N
103
104        jScrollPane1.setName("jScrollPane1"); // NOI18N
105
106        jTable1.setModel(new javax.swing.table.DefaultTableModel(
107            new Object [][] {
108                {},
109                {},
110                {},
111                {}
112            },
113            new String [] {
114
115            }
116        ));
117        jTable1.setName("jTable1"); // NOI18N
118        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
119            public void mouseClicked(java.awt.event.MouseEvent evt) {
120                jTable1MouseClicked(evt);
121            }
122        });
123        jScrollPane1.setViewportView(jTable1);
124
125        jLabel3.setText(bundle.getString("ScheduleDayEvent.jLabel3.text")); // NOI18N
126        jLabel3.setName("jLabel3"); // NOI18N
127
128        labeledCombobox1.set_Label(bundle.getString("ScheduleDayEvent.labeledCombobox1._Label")); // NOI18N
129        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
130
131        labeledSpinner1.set_Label(bundle.getString("ScheduleDayEvent.labeledSpinner1._Label")); // NOI18N
132        labeledSpinner1.setName("labeledSpinner1"); // NOI18N
133
134        jLabel1.setText(bundle.getString("ScheduleDayEvent.jLabel1.text")); // NOI18N
135        jLabel1.setName("jLabel1"); // NOI18N
136
137        labeledDateChooser1.setToolTipText(bundle.getString("ScheduleDayEvent.labeledDateChooser1.toolTipText")); // NOI18N
138        labeledDateChooser1.set_Label(bundle.getString("ScheduleDayEvent.labeledDateChooser1._Label")); // NOI18N
139        labeledDateChooser1.setName("labeledDateChooser1"); // NOI18N
140
141        labeledDateChooser2.set_Label(bundle.getString("ScheduleDayEvent.labeledDateChooser2._Label")); // NOI18N
142        labeledDateChooser2.setName("labeledDateChooser2"); // NOI18N
143
144        jPanel2.setName("jPanel2"); // NOI18N
145
146        jButton2.setText(bundle.getString("ScheduleDayEvent.jButton2.text")); // NOI18N
147        jButton2.setName("jButton2"); // NOI18N
148        jButton2.addActionListener(new java.awt.event.ActionListener() {
149            public void actionPerformed(java.awt.event.ActionEvent evt) {
150                jButton2ActionPerformed(evt);
151            }
152        });
153        jPanel2.add(jButton2);
154
155        jSeparator1.setName("jSeparator1"); // NOI18N
156        jPanel2.add(jSeparator1);
157
158        jSeparator3.setName("jSeparator3"); // NOI18N
159        jPanel2.add(jSeparator3);
160
161        jButton3.setText(bundle.getString("ScheduleDayEvent.jButton3.text")); // NOI18N
162        jButton3.setName("jButton3"); // NOI18N
163        jButton3.addActionListener(new java.awt.event.ActionListener() {
164            public void actionPerformed(java.awt.event.ActionEvent evt) {
165                jButton3ActionPerformed(evt);
166            }
167        });
168        jPanel2.add(jButton3);
169
170        jSeparator2.setName("jSeparator2"); // NOI18N
171        jPanel2.add(jSeparator2);
172
173        jButton1.setText(bundle.getString("ScheduleDayEvent.jButton1.text")); // NOI18N
174        jButton1.setName("jButton1"); // NOI18N
175        jButton1.addActionListener(new java.awt.event.ActionListener() {
176            public void actionPerformed(java.awt.event.ActionEvent evt) {
177                jButton1ActionPerformed(evt);
178            }
179        });
180        jPanel2.add(jButton1);
181
182        jButton4.setText(bundle.getString("ScheduleDayEvent.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        jPanel2.add(jButton4);
190
191        jButton5.setText(bundle.getString("ScheduleDayEvent.jButton5.text")); // NOI18N
192        jButton5.setName("jButton5"); // NOI18N
193        jButton5.addActionListener(new java.awt.event.ActionListener() {
194            public void actionPerformed(java.awt.event.ActionEvent evt) {
195                jButton5ActionPerformed(evt);
196            }
197        });
198
199        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
200        jPanel1.setLayout(jPanel1Layout);
201        jPanel1Layout.setHorizontalGroup(
202            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203            .addGroup(jPanel1Layout.createSequentialGroup()
204                .addContainerGap()
205                .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
206                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
207                .addComponent(jLabel1)
208                .addContainerGap(96, Short.MAX_VALUE))
209            .addGroup(jPanel1Layout.createSequentialGroup()
210                .addContainerGap()
211                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212                    .addComponent(labeledDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213                    .addComponent(labeledDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
214                .addContainerGap(107, Short.MAX_VALUE))
215            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
216            .addGroup(jPanel1Layout.createSequentialGroup()
217                .addContainerGap()
218                .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
219                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
220                .addComponent(jButton5)
221                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
222            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
223            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
224                .addContainerGap(47, Short.MAX_VALUE)
225                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
226        );
227        jPanel1Layout.setVerticalGroup(
228            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229            .addGroup(jPanel1Layout.createSequentialGroup()
230                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231                    .addGroup(jPanel1Layout.createSequentialGroup()
232                        .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
233                        .addGap(18, 18, 18)
234                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
235                            .addComponent(jLabel1)
236                            .addComponent(labeledSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
237                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
238                        .addComponent(labeledDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
239                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240                        .addComponent(labeledDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
241                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
242                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243                .addComponent(jLabel3)
244                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
246                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
247                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
248        );
249
250        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
251
252        pack();
253    }// </editor-fold>//GEN-END:initComponents
254
255    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
256        dispose();
257    }//GEN-LAST:event_jButton2ActionPerformed
258
259    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
260        Schedule d = (Schedule) jTable1.getModel().getValueAt(jTable1.convertRowIndexToModel(jTable1.getSelectedRow()), 0);
261        if (d != null) {
262            try {
263                labeledCombobox1.setModel(d.getItem());
264            } catch (NodataFoundException ex) {
265                Log.Debug(ex);
266            }
267
268            labeledDateChooser1.setDate(d.__getStartdate());
269            labeledDateChooser2.setDate(d.__getStopdate());
270            labeledSpinner1.setValue(d.__getIntervalmonth());
271            dataOwner = d;
272        }
273
274    }//GEN-LAST:event_jTable1MouseClicked
275
276    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
277        save(new Schedule());
278        try {
279            refresh(dataOwner.getItem());
280        } catch (NodataFoundException ex) {
281            Log.Debug(ex);
282        }
283    }//GEN-LAST:event_jButton4ActionPerformed
284
285    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
286        save(dataOwner);
287        try {
288            refresh(dataOwner.getItem());
289        } catch (Exception ex) {
290        }
291    }//GEN-LAST:event_jButton1ActionPerformed
292
293    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
294        if (dataOwner != null && dataOwner.isExisting()) {
295            dataOwner.delete();
296            try {
297                refresh(dataOwner.getItem());
298            } catch (NodataFoundException ex) {
299                Log.Debug(ex);
300            }
301        }
302    }//GEN-LAST:event_jButton3ActionPerformed
303
304    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
305        try {
306            mpv5.YabsViewProxy.instance().getIdentifierView().addTab(DatabaseObject.getObject(Context.getItem(), Integer.valueOf(labeledCombobox1.getSelectedItem().getId())));
307        } catch (Exception ex) {
308            Log.Debug(this, ex.getMessage());
309        }
310    }//GEN-LAST:event_jButton5ActionPerformed
311    // Variables declaration - do not modify//GEN-BEGIN:variables
312    private javax.swing.JButton jButton1;
313    private javax.swing.JButton jButton2;
314    private javax.swing.JButton jButton3;
315    private javax.swing.JButton jButton4;
316    private javax.swing.JButton jButton5;
317    private javax.swing.JLabel jLabel1;
318    private javax.swing.JLabel jLabel3;
319    private javax.swing.JPanel jPanel1;
320    private javax.swing.JPanel jPanel2;
321    private javax.swing.JScrollPane jScrollPane1;
322    private javax.swing.JSeparator jSeparator1;
323    private javax.swing.JSeparator jSeparator2;
324    private javax.swing.JSeparator jSeparator3;
325    private javax.swing.JTable jTable1;
326    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
327    private mpv5.ui.beans.LabeledDateChooser labeledDateChooser1;
328    private mpv5.ui.beans.LabeledDateChooser labeledDateChooser2;
329    private mpv5.ui.beans.LabeledSpinner labeledSpinner1;
330    // End of variables declaration//GEN-END:variables
331
332    private void refresh(Item dao) {
333        labeledSpinner1.setValue(1);
334        if (dao != null) {
335            jLabel3.setText(text + " " + dao);
336        }
337        ArrayList<Schedule> data = Schedule.getEvents(dao);
338        Object[][] d = new Object[data.size()][];
339        for (int i = 0; i < data.size(); i++) {
340            Schedule schedule = data.get(i);
341            d[i] = schedule.toArray();
342        }
343        jTable1.setModel(new MPTableModel(d, Headers.SCHEDULE_LIST));
344        TableFormat.resizeCols(jTable1, new Integer[]{150}, true);
345    }
346
347    private void save(Schedule s) {
348        if (s != null) {
349            try {
350                Item i = (Item) DatabaseObject.getObject(Context.getItem(),
351                        Integer.valueOf(labeledCombobox1.getSelectedItem().getId()));
352                s.setCname("(" + Messages.SCHEDULE + ") " + i.toString());
353                s.setItemsids(i.__getIDS());
354                s.setGroupsids(i.__getGroupsids());
355                s.setIntervalmonth(Integer.valueOf(labeledSpinner1.getSpinner().getValue().toString()));
356                s.setStartdate(labeledDateChooser1.getDate());
357                s.setStopdate(labeledDateChooser2.getDate());
358                s.setUsersids(mpv5.db.objects.User.getCurrentUser().__getIDS());
359                s.setNextdate(DateConverter.addMonths(labeledDateChooser1.getDate(),
360                        s.__getIntervalmonth()));
361                s.setContactsids(i.__getContactsids());
362                s.setEventtype(1);
363                if (s.save()) {
364                    dataOwner = s;
365                    Popup.notice(Messages.SCHEDULE_NEXT
366                            + DateConverter.getDefDateString(DateConverter.addMonths(labeledDateChooser1.getDate(),
367                            s.__getIntervalmonth())));
368                }
369            } catch (Exception ex) {
370                Log.Debug(this, ex.getMessage());
371                Notificator.raiseNotification(ex, true);
372            }
373        }
374    }
375
376    /**
377     *
378     * @param dataOwner
379     */
380    public void setItem(Item dataOwner) {
381        labeledCombobox1.setModel(dataOwner);
382        setDate(new Date());
383        refresh(dataOwner);
384        setVisible(true);
385    }
386}