PageRenderTime 432ms CodeModel.GetById 161ms app.highlight 181ms RepoModel.GetById 81ms app.codeStats 0ms

/src/mpv5/ui/panels/ActivityConfirmationPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 716 lines | 619 code | 78 blank | 19 comment | 48 complexity | ac7f17b69813722c047e70f8b33c40fa MD5 | raw file
  1package mpv5.ui.panels;
  2
  3import enoa.handler.TemplateHandler;
  4import java.awt.BorderLayout;
  5import java.awt.Color;
  6import java.awt.Component;
  7import java.awt.event.ActionEvent;
  8import java.awt.event.ActionListener;
  9import java.math.BigDecimal;
 10import java.util.Date;
 11import java.util.List;
 12import javax.swing.JComponent;
 13import javax.swing.JTable;
 14import javax.swing.SwingUtilities;
 15import javax.swing.table.TableCellRenderer;
 16import mpv5.db.common.Context;
 17import mpv5.db.common.DatabaseObject;
 18import mpv5.db.common.NodataFoundException;
 19import mpv5.db.objects.ActivityList;
 20import mpv5.db.objects.ActivityListSubItem;
 21import mpv5.db.objects.Contact;
 22import mpv5.db.objects.Favourite;
 23import mpv5.db.objects.Item;
 24import mpv5.db.objects.Product;
 25import mpv5.db.objects.User;
 26import mpv5.globals.Messages;
 27import mpv5.logging.Log;
 28import mpv5.ui.beans.LightMPComboBox;
 29import mpv5.ui.dialogs.DialogForFile;
 30import mpv5.ui.dialogs.Popup;
 31import mpv5.ui.dialogs.subcomponents.ActivityTextAreaDialog;
 32import mpv5.ui.misc.TextFieldUtils;
 33import mpv5.ui.toolbars.DataPanelTB;
 34import mpv5.utils.arrays.ArrayUtilities;
 35import mpv5.utils.export.Export;
 36import mpv5.utils.jobs.Job;
 37import mpv5.utils.models.MPComboBoxModelItem;
 38import mpv5.utils.models.MPTableModel;
 39import mpv5.utils.renderer.TableCellEditorForDate;
 40import mpv5.utils.renderer.TableCellRendererForDezimal;
 41import mpv5.utils.renderer.TextAreaCellEditor;
 42import mpv5.utils.renderer.TextAreaCellRenderer;
 43import mpv5.utils.tables.DynamicTableCalculator;
 44import mpv5.utils.tables.TableFormat;
 45
 46public final class ActivityConfirmationPanel extends javax.swing.JPanel implements DataPanel, ExportablePanel {
 47
 48    private static final long serialVersionUID = 1L;
 49    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 50    private static ActivityConfirmationPanel me;
 51    private ActivityList dataOwner;
 52    private DataPanelTB tb;
 53    private final SearchPanel sp;
 54    private MPTableModel omodel = null;
 55    Thread t = null;
 56
 57    /**
 58     * Singleton
 59     * @return
 60     */
 61    public static ActivityConfirmationPanel instanceOf() {
 62        if (me == null) {
 63            me = new ActivityConfirmationPanel();
 64        }
 65        return me;
 66    }
 67    // Variablen ...
 68    public int contactsids_;
 69    public int orderids_;
 70    public BigDecimal totalamount_;
 71    public String cnumber_;
 72    public String cname_;
 73    public String description_;
 74    public int intaddedby_;
 75    public int ids_;
 76    public Date dateadded_;
 77    public int groupsids_ = 1;
 78    public boolean asproduct_;
 79    private DynamicTableCalculator itemMultiplier;
 80    private LightMPComboBox cb = new LightMPComboBox();
 81    private boolean HEADER_FAILD = false;
 82
 83    /** Creates new form ListPanel */
 84    private ActivityConfirmationPanel() {
 85        initComponents();
 86        setName("ActivityConfirmation");
 87        dataOwner = new ActivityList();
 88        itemtable.getTableHeader().setReorderingAllowed(false);
 89        sp = new SearchPanel(Context.getActivityList(), this);
 90        sp.setVisible(true);
 91        tb = new DataPanelTB(this);
 92        toolbarpanetbp.add(tb, BorderLayout.CENTER);
 93        contact.setContext(Context.getContact());
 94        contact.setSearchEnabled(true);
 95        contact.getComboBox().addActionListener(new ActionListener() {
 96
 97            @Override
 98            @SuppressWarnings("unchecked")
 99            public void actionPerformed(ActionEvent e) {
100                if (e.getModifiers() == 16) {
101                    final MPComboBoxModelItem item = contact.getSelectedItem();
102                    if (item != null && item.isValid()) {
103                        t = new Thread() {
104
105                            @Override
106                            public void run() {
107                                try {
108                                    Log.Debug(this, "Kontakt Zeile :" + item.getId() + " ausgew?hlt.");
109                                    Contact ct = (Contact) DatabaseObject.getObject(Context.getContact(), Integer.valueOf(item.getId()));
110                                    List data = DatabaseObject.getReferencedObjects(ct,
111                                            Context.getOrder());
112                                    order.setModel(data);
113                                } catch (NodataFoundException ex) {
114                                    Log.Debug(this, ex);
115                                }
116                            }
117                        };
118                        t.start();
119                    }
120                }
121            }
122        });
123        refresh();
124        preloadTemplate();
125        number.set_ValueClass(Integer.class);
126    }
127
128    /** This me4thod is called from within the constructor to
129     * initialize the form.
130     * WARNING: Do NOT modify this code. The content of this method is
131     * always regenerated by the Form Editor.
132     */
133    @SuppressWarnings("unchecked")
134    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
135    private void initComponents() {
136
137        jPanel1 = new javax.swing.JPanel();
138        jPanel2 = new javax.swing.JPanel();
139        contact = new mpv5.ui.beans.LabeledCombobox();
140        order = new mpv5.ui.beans.LabeledCombobox();
141        jButton2 = new javax.swing.JButton();
142        jButton3 = new javax.swing.JButton();
143        Project = new mpv5.ui.beans.LabeledTextField();
144        number = new mpv5.ui.beans.LabeledTextField();
145        jScrollPane4 = new javax.swing.JScrollPane();
146        itemtable = new JTable() {
147            private static final long serialVersionUID = 1L;
148
149            public Component prepareRenderer(TableCellRenderer renderer,
150                int rowIndex, int vColIndex) {
151                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
152                if (c instanceof JComponent) {
153                    JComponent jc = (JComponent)c;
154                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
155                }
156                return c;
157            }
158        };
159        itemPanel = new javax.swing.JPanel();
160        addItem = new javax.swing.JButton();
161        delItem = new javax.swing.JButton();
162        upItem = new javax.swing.JButton();
163        upItem1 = new javax.swing.JButton();
164        jLabel1 = new javax.swing.JLabel();
165        total = new javax.swing.JTextField();
166        toolbarpanetbp = new javax.swing.JPanel();
167        SearchBarPane = new javax.swing.JPanel();
168
169        setName("Form"); // NOI18N
170        setLayout(new java.awt.BorderLayout());
171
172        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
173        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ActivityConfirmationPanel.jPanel1.border.title"))); // NOI18N
174        jPanel1.setName("jPanel1"); // NOI18N
175
176        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ActivityConfirmationPanel.jPanel2.border.title"))); // NOI18N
177        jPanel2.setName("jPanel2"); // NOI18N
178
179        contact.set_Label(bundle.getString("ActivityConfirmationPanel.contact._Label")); // NOI18N
180        contact.setName("contact"); // NOI18N
181
182        order.set_Label(bundle.getString("ActivityConfirmationPanel.order._Label")); // NOI18N
183        order.setName("order"); // NOI18N
184
185        jButton2.setText(bundle.getString("ActivityConfirmationPanel.jButton2.text")); // NOI18N
186        jButton2.setName("jButton2"); // NOI18N
187        jButton2.addActionListener(new java.awt.event.ActionListener() {
188            public void actionPerformed(java.awt.event.ActionEvent evt) {
189                jButton2ActionPerformed(evt);
190            }
191        });
192
193        jButton3.setText(bundle.getString("ActivityConfirmationPanel.jButton3.text")); // NOI18N
194        jButton3.setName("jButton3"); // NOI18N
195        jButton3.addActionListener(new java.awt.event.ActionListener() {
196            public void actionPerformed(java.awt.event.ActionEvent evt) {
197                jButton3ActionPerformed(evt);
198            }
199        });
200
201        Project.set_Label(bundle.getString("ActivityConfirmationPanel.Project._Label")); // NOI18N
202        Project.setName("Project"); // NOI18N
203
204        number.set_Label(bundle.getString("ActivityConfirmationPanel.number._Label")); // NOI18N
205        number.setFocusable(false);
206        number.setFont(number.getFont());
207        number.setName("number"); // NOI18N
208
209        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
210        jPanel2.setLayout(jPanel2Layout);
211        jPanel2Layout.setHorizontalGroup(
212            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213            .addGroup(jPanel2Layout.createSequentialGroup()
214                .addContainerGap()
215                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
216                    .addComponent(contact, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
217                    .addComponent(number, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
218                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
219                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
220                    .addGroup(jPanel2Layout.createSequentialGroup()
221                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
222                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
223                        .addComponent(order, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
224                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
226                    .addComponent(Project, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE))
227                .addContainerGap())
228        );
229        jPanel2Layout.setVerticalGroup(
230            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
232                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233                    .addComponent(Project, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
234                    .addComponent(number, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
235                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
236                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237                    .addComponent(contact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238                    .addComponent(jButton3)
239                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
240                        .addComponent(order, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
241                        .addComponent(jButton2))))
242        );
243
244        jScrollPane4.setName("jScrollPane4"); // NOI18N
245
246        itemtable.setAutoCreateRowSorter(true);
247        itemtable.setModel(new javax.swing.table.DefaultTableModel(
248            new Object [][] {
249
250            },
251            new String [] {
252
253            }
254        ));
255        itemtable.setCellSelectionEnabled(true);
256        itemtable.setName("itemtable"); // NOI18N
257        itemtable.setSurrendersFocusOnKeystroke(true);
258        jScrollPane4.setViewportView(itemtable);
259
260        itemPanel.setName("itemPanel"); // NOI18N
261        itemPanel.setOpaque(false);
262
263        addItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/add.png"))); // NOI18N
264        addItem.setName("addItem"); // NOI18N
265        addItem.addActionListener(new java.awt.event.ActionListener() {
266            public void actionPerformed(java.awt.event.ActionEvent evt) {
267                addItemActionPerformed(evt);
268            }
269        });
270
271        delItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/remove.png"))); // NOI18N
272        delItem.setName("delItem"); // NOI18N
273        delItem.addActionListener(new java.awt.event.ActionListener() {
274            public void actionPerformed(java.awt.event.ActionEvent evt) {
275                delItemActionPerformed(evt);
276            }
277        });
278
279        upItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/arrow-up.png"))); // NOI18N
280        upItem.setEnabled(false);
281        upItem.setName("upItem"); // NOI18N
282        upItem.addActionListener(new java.awt.event.ActionListener() {
283            public void actionPerformed(java.awt.event.ActionEvent evt) {
284                upItemActionPerformed(evt);
285            }
286        });
287
288        upItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/arrow-down.png"))); // NOI18N
289        upItem1.setEnabled(false);
290        upItem1.setName("upItem1"); // NOI18N
291        upItem1.addActionListener(new java.awt.event.ActionListener() {
292            public void actionPerformed(java.awt.event.ActionEvent evt) {
293                upItem1ActionPerformed(evt);
294            }
295        });
296
297        javax.swing.GroupLayout itemPanelLayout = new javax.swing.GroupLayout(itemPanel);
298        itemPanel.setLayout(itemPanelLayout);
299        itemPanelLayout.setHorizontalGroup(
300            itemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301            .addComponent(addItem, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
302            .addComponent(delItem, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
303            .addComponent(upItem, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
304            .addComponent(upItem1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
305        );
306        itemPanelLayout.setVerticalGroup(
307            itemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308            .addGroup(itemPanelLayout.createSequentialGroup()
309                .addComponent(addItem)
310                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311                .addComponent(delItem)
312                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
313                .addComponent(upItem)
314                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315                .addComponent(upItem1)
316                .addContainerGap(31, Short.MAX_VALUE))
317        );
318
319        jLabel1.setText(bundle.getString("ActivityConfirmationPanel.jLabel1.text")); // NOI18N
320        jLabel1.setName("jLabel1"); // NOI18N
321
322        total.setText(bundle.getString("ActivityConfirmationPanel.total.text")); // NOI18N
323        total.setName("total"); // NOI18N
324
325        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
326        jPanel1.setLayout(jPanel1Layout);
327        jPanel1Layout.setHorizontalGroup(
328            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329            .addGroup(jPanel1Layout.createSequentialGroup()
330                .addComponent(itemPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
331                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 851, Short.MAX_VALUE))
333            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
334                .addContainerGap(639, Short.MAX_VALUE)
335                .addComponent(jLabel1)
336                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337                .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
338            .addGroup(jPanel1Layout.createSequentialGroup()
339                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
340                .addContainerGap(18, Short.MAX_VALUE))
341        );
342        jPanel1Layout.setVerticalGroup(
343            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
344            .addGroup(jPanel1Layout.createSequentialGroup()
345                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
346                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
347                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
348                    .addComponent(itemPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
349                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
350                .addGap(11, 11, 11)
351                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
352                    .addComponent(jLabel1)
353                    .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
354        );
355
356        add(jPanel1, java.awt.BorderLayout.CENTER);
357
358        toolbarpanetbp.setBorder(javax.swing.BorderFactory.createEtchedBorder());
359        toolbarpanetbp.setName("toolbarpanetbp"); // NOI18N
360        toolbarpanetbp.setLayout(new java.awt.BorderLayout());
361        add(toolbarpanetbp, java.awt.BorderLayout.NORTH);
362
363        SearchBarPane.setName("SearchBarPane"); // NOI18N
364        SearchBarPane.setLayout(new java.awt.BorderLayout());
365        add(SearchBarPane, java.awt.BorderLayout.WEST);
366    }// </editor-fold>//GEN-END:initComponents
367
368    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
369        try {
370            int cid = Integer.valueOf(order.getSelectedItem().getId());
371            Item i = (Item) DatabaseObject.getObject(Context.getOrder(), cid);
372            ItemPanel ip = new ItemPanel(Context.getItem());
373            mpv5.YabsViewProxy.instance().getIdentifierView().addOrShowTab(ip, Messages.TYPE_ORDER.toString());
374            ip.setDataOwner(i, true);
375        } catch (Exception e) {
376            Log.Debug(this, e);
377        }
378    }//GEN-LAST:event_jButton2ActionPerformed
379
380    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
381        try {
382            int cid = Integer.valueOf(contact.getSelectedItem().getId());
383            Contact c = (Contact) DatabaseObject.getObject(Context.getContact(), cid);
384            ContactPanel cp = new ContactPanel(Context.getContact());
385            mpv5.YabsViewProxy.instance().getIdentifierView().addOrShowTab(cp, Messages.TYPE_CONTACT.toString());
386            cp.setDataOwner(c, true);
387        } catch (Exception e) {
388            Log.Debug(this, e);
389        }
390    }//GEN-LAST:event_jButton3ActionPerformed
391
392    private void addItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addItemActionPerformed
393        ((MPTableModel) itemtable.getModel()).addRow(1);
394    }//GEN-LAST:event_addItemActionPerformed
395
396    private void delItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delItemActionPerformed
397        int index = itemtable.getSelectedRow();
398        if (index < 0) {
399            return;
400        }
401        MPTableModel m = (MPTableModel) itemtable.getModel();
402        ActivityListSubItem.addToDeletionQueue(m.getValueAt(index, 0));
403        ((MPTableModel) itemtable.getModel()).removeRow(index);
404    }//GEN-LAST:event_delItemActionPerformed
405
406    private void upItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upItemActionPerformed
407        int index = itemtable.getSelectedRow();
408        if (index <= 0) {
409            return;
410        }
411        ((MPTableModel) itemtable.getModel()).moveRow(index, index, index - 1);
412        itemtable.changeSelection(index - 1, itemtable.getSelectedColumn(), false, false);
413    }//GEN-LAST:event_upItemActionPerformed
414
415    private void upItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upItem1ActionPerformed
416        int index = itemtable.getSelectedRow();
417        if (index < 0 || index >= itemtable.getRowCount() - 1) {
418            return;
419        }
420        ((MPTableModel) itemtable.getModel()).moveRow(index, index, index + 1);
421        itemtable.changeSelection(index + 1, itemtable.getSelectedColumn(), false, false);
422    }//GEN-LAST:event_upItem1ActionPerformed
423    // Variables declaration - do not modify//GEN-BEGIN:variables
424    private mpv5.ui.beans.LabeledTextField Project;
425    private javax.swing.JPanel SearchBarPane;
426    private javax.swing.JButton addItem;
427    private mpv5.ui.beans.LabeledCombobox contact;
428    private javax.swing.JButton delItem;
429    private javax.swing.JPanel itemPanel;
430    private javax.swing.JTable itemtable;
431    private javax.swing.JButton jButton2;
432    private javax.swing.JButton jButton3;
433    private javax.swing.JLabel jLabel1;
434    private javax.swing.JPanel jPanel1;
435    private javax.swing.JPanel jPanel2;
436    private javax.swing.JScrollPane jScrollPane4;
437    private mpv5.ui.beans.LabeledTextField number;
438    private mpv5.ui.beans.LabeledCombobox order;
439    private javax.swing.JPanel toolbarpanetbp;
440    private javax.swing.JTextField total;
441    private javax.swing.JButton upItem;
442    private javax.swing.JButton upItem1;
443    // End of variables declaration//GEN-END:variables
444
445    public void refresh() {
446        Runnable runnable = new Runnable() {
447
448            @Override
449            public void run() {
450                try {
451                    contact.setSelectedIndex(0);
452                    addModel();
453                    formatTable();
454
455                } catch (Exception e) {
456                    Log.Debug(this, e);
457                }
458            }
459        };
460
461        SwingUtilities.invokeLater(runnable);
462    }
463
464    public boolean collectData() {
465        cname_ = Project.getText();
466        if (cname_.length() > 0) {
467            try {
468                groupsids_ = User.getCurrentUser().__getGroupsids();
469                contactsids_ = Integer.parseInt(contact.getSelectedItem().getId());
470                orderids_ = Integer.parseInt(order.getSelectedItem().getId());
471                totalamount_ = new BigDecimal(total.getText().replace(",", "."));
472                cnumber_ = number.getText();
473                HEADER_FAILD = false;
474            } catch (Exception exception) {
475                Log.Debug(exception);
476                HEADER_FAILD = true;
477                return false;
478            }
479
480        } else {
481            HEADER_FAILD = true;
482            return false;
483        }
484
485        List<Object[]> rowsl = ((MPTableModel) itemtable.getModel()).getValidRows(new int[]{5});
486        for (int i = 0; i < rowsl.size(); i++) {
487            Object[] row = rowsl.get(i);
488            if (row[2] == null || row[9].equals(0)) {
489                Popup.error(this, Messages.ACTIVITY_EMPTY_DATE.toString());
490                return false;
491            }
492        }
493        return true;
494    }
495
496    public DatabaseObject getDataOwner() {
497        return dataOwner;
498    }
499
500    public void setDataOwner(DatabaseObject object, boolean populateData) {
501        dataOwner = (ActivityList) object;
502        if (populateData) {
503            dataOwner.setPanelData(this);
504            this.exposeData();
505
506            tb.setFavourite(Favourite.isFavourite(object));
507            tb.setEditable(!object.isReadOnly());
508            try {
509                itemtable.setModel(ActivityListSubItem.toModel(ActivityListSubItem.getList(dataOwner.__getIDS()).toArray(new ActivityListSubItem[0])));
510            } catch (NodataFoundException ex) {
511                Log.Debug(this, ex.getMessage());
512                addModel();
513            }
514            if (((MPTableModel) itemtable.getModel()).getEmptyRows(new int[]{4}) < 2) {
515                ((MPTableModel) itemtable.getModel()).addRow(1);
516            }
517            omodel = (MPTableModel) itemtable.getModel();
518
519            formatTable();
520            ((MPTableModel) itemtable.getModel()).fireTableCellUpdated(0, 0);
521            total.setText(ActivityListSubItem.getModelSum(omodel, dataOwner.__getIDS()).toString());
522            if (object.isReadOnly()) {
523                Popup.notice(Messages.LOCKED_BY);
524            }
525            validate();
526            itemMultiplier.calculateOnce();
527        }
528    }
529
530    public void exposeData() {
531        Project.setText(cname_);
532
533        try {
534            contact.setModel(DatabaseObject.getObject(Context.getContact(), contactsids_));
535            order.setModel(DatabaseObject.getObject(Context.getOrder(), orderids_));
536            total.setText(totalamount_.toString());
537            number.setText(cnumber_);
538        } catch (NodataFoundException ex) {
539            Log.Debug(this, ex.getMessage());
540        }
541    }
542
543    public void paste(DatabaseObject... dbos) {
544        for (DatabaseObject dbo : dbos) {
545            if (dbo.getContext().equals(Context.getProduct())) {
546                MPTableModel m = (MPTableModel) itemtable.getModel();
547                m.addRow(ActivityListSubItem.toRow((Product) dbo).getRowData(m.getValidRows(new int[]{5}).size()));
548
549                itemtable.setModel(m);
550                omodel = m;
551
552            } else if (dbo.getContext().equals(Context.getProductlist())) {
553                setDataOwner(dbo, true);
554            } else {
555                mpv5.YabsViewProxy.instance().addMessage(Messages.NOT_POSSIBLE.toString() + Messages.ACTION_PASTE.toString(), Color.RED);
556            }
557        }
558    }
559
560    public void showRequiredFields() {
561        if (HEADER_FAILD) {
562            TextFieldUtils.blink(Project,
563                    Color.RED);
564            TextFieldUtils.blink(contact,
565                    Color.RED);
566            TextFieldUtils.blink(order,
567                    Color.RED);
568            Project.requestFocus();
569        }
570    }
571
572    public void showSearchBar(boolean show) {
573        SearchBarPane.removeAll();
574
575        if (show) {
576            SearchBarPane.add(sp,
577                    BorderLayout.CENTER);
578            Log.Debug(this,
579                    "Suchfenster eingeblendet");
580        } else {
581            Log.Debug(this,
582                    "Suchfenster ausgeblendet");
583        }
584
585        validate();
586    }
587
588    public void actionAfterSave() {
589        saveActivityListSubItems();
590        omodel = (MPTableModel) itemtable.getModel();
591    }
592
593    public void actionAfterCreate() {
594        ArrayUtilities.replaceColumn(itemtable, 0, null);
595        saveActivityListSubItems();
596        omodel = (MPTableModel) itemtable.getModel();
597    }
598
599    public void actionBeforeCreate() {
600    }
601
602    public void actionBeforeSave() throws ChangeNotApprovedException {
603    }
604
605    public void mail() {
606        Popup.notice(Messages.NOT_YET_IMPLEMENTED.toString());
607    }
608
609    public void print() {
610        if (dataOwner != null && dataOwner.isExisting()) {
611            if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()), dataOwner.templateType())) {
612                Export.print(TemplateHandler.loadTemplate(dataOwner.templateGroupIds(), dataOwner.templateType()), dataOwner);
613            } else {
614                Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
615                Export.print(this);
616            }
617        } else {
618            Export.print(this);
619        }
620    }
621
622    private void saveActivityListSubItems() {
623        if (itemtable.getCellEditor() != null) {
624            try {
625                itemtable.getCellEditor().stopCellEditing();
626            } catch (Exception e) {
627                Log.Debug(this, e);
628            }
629        }
630        ActivityListSubItem.saveModel((MPTableModel) itemtable.getModel(), dataOwner.__getIDS());
631    }
632
633    /**
634     * 
635     */
636    public void formatTable() {
637        //"Internal ID", "ID", "Date", "Count", "Description", "Netto Price", "Tax Value", "Total Price", "Product", "cname"     
638        prepareTable();
639        TableFormat.resizeCols(itemtable, new Integer[]{0, 23, 80, 50, 50, 100, 60, 60, 60, 20, 0, 0}, new Boolean[]{true, true, true, true, true, false, true, true, true, true, true, true});
640        TableFormat.changeBackground(itemtable, 1, Color.LIGHT_GRAY);
641        if (mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("org.openyabs.uiproperty", "hidecolumnquantity")) {
642            TableFormat.stripColumn(itemtable, 4);
643        }
644    }
645
646    private void prepareTable() {
647        itemtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
648        //"Internal ID", "ID", "Date", "Count", "Description", "Netto Price", "Tax Value", "Total Price", "Product", "cname"     
649        TableCellRendererForDezimal tcr = new TableCellRendererForDezimal(itemtable);
650        TableCellEditorForDate de = new TableCellEditorForDate(itemtable);
651        TextAreaCellEditor tace = new TextAreaCellEditor(itemtable);
652        ActivityTextAreaDialog actTextAreaDialog = new ActivityTextAreaDialog(mpv5.YabsViewProxy.instance().getIdentifierFrame(), true);
653        TextAreaCellRenderer.setMAXLINES(10);
654        TextAreaCellRenderer tacr = new TextAreaCellRenderer(itemtable);
655        actTextAreaDialog.setParentTable(itemtable);
656        actTextAreaDialog.okButton.addActionListener(tace);
657        actTextAreaDialog.cancelButton.addActionListener(tace);
658        tace.setDialog(actTextAreaDialog, actTextAreaDialog.textArea);
659        tace.setClickCountToStart(1);
660        de.setEditorTo(2);
661        tace.setEditorTo(5);
662        tcr.setRendererTo(3);
663        tacr.setRendererTo(5);
664        tcr.setRendererTo(6);
665        tcr.setRendererTo(7);
666        tcr.setRendererTo(8);
667
668        itemMultiplier = new DynamicTableCalculator(itemtable, "(([3]*[6])+([3]*[6]%[7]))", new int[]{8});
669        ((MPTableModel) itemtable.getModel()).addCalculator(itemMultiplier);
670        itemMultiplier.addLabel(total, 8);
671    }
672
673    public void pdf() {
674        if (dataOwner != null && dataOwner.isExisting()) {
675            if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()), dataOwner.templateType())) {
676                new Job(Export.createFile(dataOwner.getFormatHandler().toUserString(),
677                        TemplateHandler.loadTemplate(
678                        dataOwner.templateGroupIds(), dataOwner.templateType()),
679                        dataOwner), new DialogForFile(User.getSaveDir(dataOwner))).execute();
680            } else {
681                Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
682            }
683        }
684    }
685
686    public void odt() {
687        if (dataOwner != null && dataOwner.isExisting()) {
688            if (TemplateHandler.isLoaded(Long.valueOf(dataOwner.templateGroupIds()), dataOwner.templateType())) {
689                new Job(Export.sourceFile(
690                        dataOwner.getFormatHandler().toUserString(),
691                        TemplateHandler.loadTemplate(dataOwner.templateGroupIds(), dataOwner.templateType()), dataOwner), new DialogForFile(User.getSaveDir(dataOwner))).execute();
692            } else {
693                Popup.notice(Messages.NO_TEMPLATE_LOADED + " (" + mpv5.db.objects.User.getCurrentUser() + ")");
694            }
695        }
696    }
697
698    private void addModel() {
699        itemtable.setModel(ActivityListSubItem.toModel(new ActivityListSubItem[]{
700                    ActivityListSubItem.getDefaultItem(), ActivityListSubItem.getDefaultItem(),
701                    ActivityListSubItem.getDefaultItem(), ActivityListSubItem.getDefaultItem()
702                }));
703
704        formatTable();
705    }
706
707    private void preloadTemplate() {
708        Runnable runnable = new Runnable() {
709
710            public void run() {
711                TemplateHandler.loadTemplate(Long.valueOf(dataOwner.templateGroupIds()), dataOwner.templateType());
712            }
713        };
714        new Thread(runnable).start();
715    }
716}