PageRenderTime 533ms CodeModel.GetById 121ms app.highlight 284ms RepoModel.GetById 118ms app.codeStats 0ms

/src/mpv5/ui/panels/ProductListsPanel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 839 lines | 687 code | 112 blank | 40 comment | 53 complexity | 1d2d65afd0e087b3f327bbf7fe65cab6 MD5 | raw file
  1/*
  2This file is part of YaBS.
  3
  4YaBS is free software: you can redistribute it and/or modify
  5it under the terms of the GNU General Public License as published by
  6the Free Software Foundation, either version 3 of the License, or
  7(at your option) any later version.
  8
  9YaBS is distributed in the hope that it will be useful,
 10but WITHOUT ANY WARRANTY; without even the implied warranty of
 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12GNU General Public License for more details.
 13
 14You should have received a copy of the GNU General Public License
 15along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17/*
 18 * ContactPanel.java
 19 *
 20 * Created on Nov 20, 2008, 8:17:28 AM
 21 */
 22package mpv5.ui.panels;
 23
 24import java.awt.BorderLayout;
 25import java.awt.Color;
 26import java.awt.Component;
 27
 28import java.awt.event.ActionEvent;
 29import java.awt.event.ActionListener;
 30import java.awt.event.MouseEvent;
 31import java.awt.event.MouseListener;
 32import java.math.BigDecimal;
 33import java.util.Date;
 34import java.util.List;
 35import javax.swing.JButton;
 36import javax.swing.JComponent;
 37import javax.swing.JTable;
 38import javax.swing.SpinnerNumberModel;
 39import javax.swing.SwingUtilities;
 40import javax.swing.table.TableCellRenderer;
 41import mpv5.db.common.*;
 42import mpv5.db.objects.Product;
 43import mpv5.globals.Messages;
 44import mpv5.db.objects.Favourite;
 45import mpv5.db.objects.Item;
 46import mpv5.db.objects.ProductList;
 47import mpv5.db.objects.ProductlistSubItem;
 48import mpv5.db.objects.SubItem;
 49import mpv5.db.objects.User;
 50import mpv5.logging.Log;
 51import mpv5.ui.dialogs.Popup;
 52import mpv5.ui.toolbars.DataPanelTB;
 53import mpv5.ui.beans.MPCBSelectionChangeReceiver;
 54import mpv5.ui.dialogs.Search2;
 55import mpv5.ui.dialogs.subcomponents.ProductSelectDialog;
 56import mpv5.utils.arrays.ArrayUtilities;
 57import mpv5.utils.export.Export;
 58import mpv5.utils.models.MPComboBoxModelItem;
 59import mpv5.utils.models.MPTableModel;
 60import mpv5.utils.renderer.ButtonEditor;
 61import mpv5.utils.renderer.ButtonRenderer;
 62import mpv5.utils.renderer.CellEditorWithMPComboBox;
 63import mpv5.utils.renderer.TableCellRendererForDezimal;
 64import mpv5.utils.tables.DynamicTableCalculator;
 65import mpv5.utils.tables.TableFormat;
 66import mpv5.utils.ui.TextFieldUtils;
 67
 68/**
 69 *
 70 * 
 71 */
 72public class ProductListsPanel extends javax.swing.JPanel implements DataPanel, MPCBSelectionChangeReceiver {
 73
 74    private static final long serialVersionUID = 1L;
 75    private ProductList dataOwner;
 76    private DataPanelTB tb;
 77    private DynamicTableCalculator itemMultiplier;
 78    private DynamicTableCalculator netCalculator;
 79    private DynamicTableCalculator netCalculator2;
 80    private final SearchPanel sp;
 81    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 82
 83    /**
 84     *
 85     */
 86    public ProductListsPanel() {
 87        initComponents();
 88        setName("productlistpanel");
 89        itemtable.getTableHeader().setReorderingAllowed(false);
 90
 91        sp = new SearchPanel(Context.getProductlist(), this);
 92        sp.setVisible(true);
 93        tb = new mpv5.ui.toolbars.DataPanelTB(this);
 94//        tb.disableButton(1);
 95        tb.disableButton(8);
 96        tb.disableButton(9);
 97        toolbarpanetbp.add(tb, BorderLayout.CENTER);
 98        dataOwner = new ProductList();
 99
100        refresh();
101        addedby.setText(mpv5.db.objects.User.getCurrentUser().getName());
102        groupnameselect.setContext(Context.getGroup());
103        groupnameselect.setSearchEnabled(true);
104        itemtable.getTableHeader().addMouseListener(new MouseListener() {
105
106            @Override
107            public void mouseClicked(MouseEvent e) {
108                if (e.getButton() == MouseEvent.BUTTON2) {
109                    MPTableModel m = (MPTableModel) itemtable.getModel();
110                    if (m.getRowCount() > 0) {
111                        m.addRow(5);
112                    } else {
113
114                        itemtable.setModel(ProductlistSubItem.toModel(new ProductlistSubItem[]{
115                                    ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
116                                    ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
117                                    ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem()
118                                }));
119
120
121                        formatTable();
122
123                    }
124                } else if (e.getButton() == MouseEvent.BUTTON3) {
125
126                    MPTableModel m = (MPTableModel) itemtable.getModel();
127                    Product p = (Product) Popup.SelectValue(Context.getProduct());
128                    if (p != null) {
129                        int row = m.getLastValidRow(new int[]{4});
130                        m.setRowAt(new ProductlistSubItem(p).getRowData(row), row + 1, 1);
131                    }
132                }
133            }
134
135            @Override
136            public void mousePressed(MouseEvent e) {
137            }
138
139            @Override
140            public void mouseReleased(MouseEvent e) {
141            }
142
143            @Override
144            public void mouseEntered(MouseEvent e) {
145            }
146
147            @Override
148            public void mouseExited(MouseEvent e) {
149            }
150        });
151
152        listname.setSearchOnEnterEnabled(true);
153        listname.setParent(this);
154        listname.setSearchField("cname");
155        listname.setContext(Context.getItem());
156
157        ((SpinnerNumberModel) calculator.getSpinner().getModel()).setMinimum(-1000);
158        ((SpinnerNumberModel) calculator.getSpinner().getModel()).setMaximum(1000);
159
160        value.set_ValueClass(BigDecimal.class);
161        netvalue.set_ValueClass(BigDecimal.class);
162
163    }
164
165    @Override
166    public DatabaseObject getDataOwner() {
167        return dataOwner;
168    }
169
170    @Override
171    public void setDataOwner(DatabaseObject object, boolean populate) {
172        dataOwner = (ProductList) object;
173        if (populate) {
174            dataOwner.setPanelData(this);
175            this.exposeData();
176            prinitingComboBox1.init(rightpane);
177            tb.setFavourite(Favourite.isFavourite(object));
178            tb.setEditable(!object.isReadOnly());
179            try {
180
181                itemtable.setModel(ProductlistSubItem.toModel(ProductlistSubItem.getList(dataOwner.__getIDS()).toArray(new ProductlistSubItem[0])));
182            } catch (NodataFoundException ex) {
183                Log.Debug(this, ex.getMessage());
184            } finally {
185            }
186            if (((MPTableModel) itemtable.getModel()).getEmptyRows(new int[]{4}) < 2) {
187                ((MPTableModel) itemtable.getModel()).addRow(1);
188            }
189            omodel = (MPTableModel) itemtable.getModel();
190
191            formatTable();
192            ((MPTableModel) itemtable.getModel()).fireTableCellUpdated(0, 0);
193            if (object.isReadOnly()) {
194                Popup.notice(Messages.LOCKED_BY);
195            }
196            validate();
197        }
198    }
199
200    @Override
201    public void showRequiredFields() {
202        TextFieldUtils.blinkerRed(listname);
203    }
204
205    /** This method is called from within the constructor to
206     * initialize the form.
207     * WARNING: Do NOT modify this code. The content of this method is
208     * always regenerated by the Form Editor.
209     */
210    @SuppressWarnings("unchecked")
211    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
212    private void initComponents() {
213
214        buttonGroup1 = new javax.swing.ButtonGroup();
215        leftpane = new javax.swing.JPanel();
216        rightpane = new javax.swing.JPanel();
217        jPanel1 = new javax.swing.JPanel();
218        listname = new mpv5.ui.beans.LabeledTextField();
219        addedby = new javax.swing.JLabel();
220        prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
221        groupnameselect = new mpv5.ui.beans.LabeledCombobox();
222        jButton2 = new javax.swing.JButton();
223        jButton3 = new javax.swing.JButton();
224        jPanel4 = new javax.swing.JPanel();
225        jScrollPane3 = new javax.swing.JScrollPane();
226        itemtable = new  JTable() {
227            public Component prepareRenderer(TableCellRenderer renderer,
228                int rowIndex, int vColIndex) {
229                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
230                if (c instanceof JComponent) {
231                    JComponent jc = (JComponent)c;
232                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
233                }
234                return c;
235            }
236        };
237        jScrollPane1 = new javax.swing.JScrollPane();
238        notes = new javax.swing.JTextPane();
239        jToolBar2 = new javax.swing.JToolBar();
240        calculator = new mpv5.ui.beans.LabeledSpinner();
241        jButton1 = new javax.swing.JButton();
242        jSeparator12 = new javax.swing.JToolBar.Separator();
243        netvalue = new mpv5.ui.beans.LabeledTextField();
244        jSeparator9 = new javax.swing.JToolBar.Separator();
245        jSeparator6 = new javax.swing.JToolBar.Separator();
246        taxvalue = new mpv5.ui.beans.LabeledTextField();
247        jSeparator10 = new javax.swing.JToolBar.Separator();
248        jSeparator5 = new javax.swing.JToolBar.Separator();
249        value = new mpv5.ui.beans.LabeledTextField();
250        toolbarpanetbp = new javax.swing.JPanel();
251
252        setBackground(javax.swing.UIManager.getDefaults().getColor("InternalFrame.inactiveTitleBackground"));
253        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
254        setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ProductListsPanel.border.title_1"))); // NOI18N
255        setName("Form"); // NOI18N
256        setOpaque(false);
257        setLayout(new java.awt.BorderLayout());
258
259        leftpane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
260        leftpane.setName("leftpane"); // NOI18N
261        leftpane.setLayout(new java.awt.BorderLayout());
262        add(leftpane, java.awt.BorderLayout.WEST);
263
264        rightpane.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
265        rightpane.setName("rightpane"); // NOI18N
266
267        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
268        jPanel1.setName("jPanel1"); // NOI18N
269
270        listname.set_Label(bundle.getString("ProductListsPanel.listname._Label")); // NOI18N
271        listname.setFocusable(false);
272        listname.setFont(listname.getFont());
273        listname.setName("listname"); // NOI18N
274
275        addedby.setFont(addedby.getFont());
276        addedby.setText(bundle.getString("ProductListsPanel.addedby.text")); // NOI18N
277        addedby.setToolTipText(bundle.getString("ProductListsPanel.addedby.toolTipText")); // NOI18N
278        addedby.setBorder(javax.swing.BorderFactory.createEtchedBorder());
279        addedby.setEnabled(false);
280        addedby.setName("addedby"); // NOI18N
281
282        prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
283
284        groupnameselect.set_Label(bundle.getString("ProductListsPanel.groupnameselect._Label")); // NOI18N
285        groupnameselect.setName("groupnameselect"); // NOI18N
286
287        jButton2.setText(bundle.getString("ProductListsPanel.jButton2.text_1")); // NOI18N
288        jButton2.setFocusable(false);
289        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
290        jButton2.setName("jButton2"); // NOI18N
291        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
292        jButton2.addActionListener(new java.awt.event.ActionListener() {
293            public void actionPerformed(java.awt.event.ActionEvent evt) {
294                jButton2ActionPerformed(evt);
295            }
296        });
297
298        jButton3.setText(bundle.getString("ProductListsPanel.jButton3.text")); // NOI18N
299        jButton3.setFocusable(false);
300        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
301        jButton3.setName("jButton3"); // NOI18N
302        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
303        jButton3.addActionListener(new java.awt.event.ActionListener() {
304            public void actionPerformed(java.awt.event.ActionEvent evt) {
305                jButton3ActionPerformed(evt);
306            }
307        });
308
309        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
310        jPanel1.setLayout(jPanel1Layout);
311        jPanel1Layout.setHorizontalGroup(
312            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313            .addGroup(jPanel1Layout.createSequentialGroup()
314                .addContainerGap()
315                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
316                    .addComponent(groupnameselect, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
317                    .addComponent(listname, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
318                    .addGroup(jPanel1Layout.createSequentialGroup()
319                        .addComponent(jButton2)
320                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
321                        .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
322                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, Short.MAX_VALUE)
323                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324                    .addComponent(prinitingComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
325                    .addComponent(addedby, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
326                .addContainerGap())
327        );
328        jPanel1Layout.setVerticalGroup(
329            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
330            .addGroup(jPanel1Layout.createSequentialGroup()
331                .addContainerGap()
332                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
333                    .addComponent(jButton2)
334                    .addComponent(jButton3))
335                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
336                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337                    .addGroup(jPanel1Layout.createSequentialGroup()
338                        .addComponent(listname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
339                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
340                        .addComponent(groupnameselect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
341                    .addGroup(jPanel1Layout.createSequentialGroup()
342                        .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
343                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
344                        .addComponent(addedby, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
345                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
346        );
347
348        jPanel4.setBackground(new java.awt.Color(204, 204, 204));
349        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
350        jPanel4.setName("jPanel4"); // NOI18N
351
352        jScrollPane3.setName("jScrollPane3"); // NOI18N
353
354        itemtable.setModel(new javax.swing.table.DefaultTableModel(
355            new Object [][] {
356
357            },
358            new String [] {
359
360            }
361        ));
362        itemtable.setCellSelectionEnabled(true);
363        itemtable.setName("itemtable"); // NOI18N
364        itemtable.setSurrendersFocusOnKeystroke(true);
365        itemtable.addMouseListener(new java.awt.event.MouseAdapter() {
366            public void mouseClicked(java.awt.event.MouseEvent evt) {
367                itemtableMouseClicked(evt);
368            }
369        });
370        jScrollPane3.setViewportView(itemtable);
371
372        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
373        jPanel4.setLayout(jPanel4Layout);
374        jPanel4Layout.setHorizontalGroup(
375            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
376            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
377        );
378        jPanel4Layout.setVerticalGroup(
379            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
380            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
381        );
382
383        jScrollPane1.setBorder(null);
384        jScrollPane1.setName("jScrollPane1"); // NOI18N
385
386        notes.setBorder(javax.swing.BorderFactory.createEtchedBorder());
387        notes.setText(bundle.getString("ProductListsPanel.notes.text")); // NOI18N
388        notes.setName("notes"); // NOI18N
389        jScrollPane1.setViewportView(notes);
390
391        jToolBar2.setBackground(new java.awt.Color(255, 255, 255));
392        jToolBar2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 102), 1, true));
393        jToolBar2.setFloatable(false);
394        jToolBar2.setRollover(true);
395        jToolBar2.setName("jToolBar2"); // NOI18N
396
397        calculator.set_Label(bundle.getString("ProductListsPanel.calculator._Label")); // NOI18N
398        calculator.setMaximumSize(new java.awt.Dimension(200, 20));
399        calculator.setName("calculator"); // NOI18N
400        jToolBar2.add(calculator);
401
402        jButton1.setText(bundle.getString("ProductListsPanel.jButton1.text")); // NOI18N
403        jButton1.setFocusable(false);
404        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
405        jButton1.setName("jButton1"); // NOI18N
406        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
407        jButton1.addActionListener(new java.awt.event.ActionListener() {
408            public void actionPerformed(java.awt.event.ActionEvent evt) {
409                jButton1ActionPerformed(evt);
410            }
411        });
412        jToolBar2.add(jButton1);
413
414        jSeparator12.setName("jSeparator12"); // NOI18N
415        jSeparator12.setSeparatorSize(new java.awt.Dimension(15, 10));
416        jToolBar2.add(jSeparator12);
417
418        netvalue.set_Label(bundle.getString("ProductListsPanel.netvalue._Label")); // NOI18N
419        netvalue.setName("netvalue"); // NOI18N
420        jToolBar2.add(netvalue);
421
422        jSeparator9.setName("jSeparator9"); // NOI18N
423        jToolBar2.add(jSeparator9);
424
425        jSeparator6.setName("jSeparator6"); // NOI18N
426        jSeparator6.setSeparatorSize(new java.awt.Dimension(15, 10));
427        jToolBar2.add(jSeparator6);
428
429        taxvalue.set_Label(bundle.getString("ProductListsPanel.taxvalue._Label")); // NOI18N
430        taxvalue.setName("taxvalue"); // NOI18N
431        jToolBar2.add(taxvalue);
432
433        jSeparator10.setName("jSeparator10"); // NOI18N
434        jToolBar2.add(jSeparator10);
435
436        jSeparator5.setName("jSeparator5"); // NOI18N
437        jSeparator5.setSeparatorSize(new java.awt.Dimension(15, 10));
438        jToolBar2.add(jSeparator5);
439
440        value.set_Label(bundle.getString("ProductListsPanel.value._Label")); // NOI18N
441        value.setName("value"); // NOI18N
442        jToolBar2.add(value);
443
444        javax.swing.GroupLayout rightpaneLayout = new javax.swing.GroupLayout(rightpane);
445        rightpane.setLayout(rightpaneLayout);
446        rightpaneLayout.setHorizontalGroup(
447            rightpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
448            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
449            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
450            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
451            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
452        );
453        rightpaneLayout.setVerticalGroup(
454            rightpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
455            .addGroup(rightpaneLayout.createSequentialGroup()
456                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
457                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
458                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
459                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
460                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
461                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
462                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
463        );
464
465        add(rightpane, java.awt.BorderLayout.CENTER);
466
467        toolbarpanetbp.setBorder(javax.swing.BorderFactory.createEtchedBorder());
468        toolbarpanetbp.setName("toolbarpanetbp"); // NOI18N
469        toolbarpanetbp.setLayout(new java.awt.BorderLayout());
470        add(toolbarpanetbp, java.awt.BorderLayout.NORTH);
471    }// </editor-fold>//GEN-END:initComponents
472
473    private void itemtableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_itemtableMouseClicked
474
475        MPTableModel m = (MPTableModel) itemtable.getModel();
476        if (!m.hasEmptyRows(new int[]{4})) {
477            m.addRow(2);
478        }
479    }//GEN-LAST:event_itemtableMouseClicked
480    MPTableModel omodel = null;
481    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
482        if (omodel == null) {
483            omodel = (MPTableModel) itemtable.getModel();
484        }
485        if (omodel.getValidRows(new int[]{4}).size() > 0) {
486
487            itemtable.setModel(omodel);
488            ProductlistSubItem.changeValueFields(itemtable, Integer.valueOf(calculator.get_Value().toString()), this);
489            ((MPTableModel) itemtable.getModel()).fireTableCellUpdated(0, 0);
490            ((MPTableModel) itemtable.getModel()).addRow(1);
491
492        }
493    }//GEN-LAST:event_jButton1ActionPerformed
494
495    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
496
497  
498            if (dataOwner == null) {
499                dataOwner = new ProductList();
500            }
501            asproduct_ = true;
502            actionBeforeSave();
503            if (dataOwner.getPanelData(this) && dataOwner.save()) {
504            } else {
505                showRequiredFields();
506            }
507
508            Product p = new Product();
509            p.setCname(dataOwner.__getCname());
510            p.setProductlistsids(dataOwner.__getIDS());
511            p.setExternalnetvalue(value.getValue(BigDecimal.ONE));
512            p.setInternalnetvalue(netvalue.getValue(BigDecimal.ONE));
513            p.setInttype(Product.TYPE_PRODUCT);
514            p.setIntinventorytype(0);
515
516            if (itemtable.getCellEditor() != null) {
517                try {
518                    itemtable.getCellEditor().stopCellEditing();
519                } catch (Exception e) {
520                }
521            }
522            List<Object[]> rowsl = ((MPTableModel) itemtable.getModel()).getValidRows(new int[]{4});
523            Log.Debug(SubItem.class, "Rows found: " + rowsl.size());
524            String descr = "";
525            for (int i = 0; i < rowsl.size(); i++) {
526                Object[] row = rowsl.get(i);
527                for (int j = 0; j < row.length; j++) {
528                    if (row[j] == null) {
529                        row[j] = "";
530                    }
531                }
532                descr += row[4].toString() + "\n";
533            }
534            p.setDescription(descr);
535
536            if (p.save()) {
537                Popup.notice(Messages.BOM_CREATED.toString() + p);
538                mpv5.YabsViewProxy.instance().addTab(p);
539
540            }
541        
542}//GEN-LAST:event_jButton2ActionPerformed
543
544    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
545        final Item i = (Item) Search2.showSearchFor(Context.getInvoice());
546        if (i != null && dataOwner != null && dataOwner.isExisting()) {
547            mpv5.YabsViewProxy.instance().addTab(i);
548            Runnable runnable = new Runnable() {
549                @Override
550                public void run() {
551                    
552                    mpv5.YabsViewProxy.instance().getCurrentTab().paste(dataOwner);
553                }
554            };
555            SwingUtilities.invokeLater(runnable);
556        }
557    }//GEN-LAST:event_jButton3ActionPerformed
558    // Variables declaration - do not modify//GEN-BEGIN:variables
559    private javax.swing.JLabel addedby;
560    private javax.swing.ButtonGroup buttonGroup1;
561    private mpv5.ui.beans.LabeledSpinner calculator;
562    private mpv5.ui.beans.LabeledCombobox groupnameselect;
563    private javax.swing.JTable itemtable;
564    private javax.swing.JButton jButton1;
565    private javax.swing.JButton jButton2;
566    private javax.swing.JButton jButton3;
567    private javax.swing.JPanel jPanel1;
568    private javax.swing.JPanel jPanel4;
569    private javax.swing.JScrollPane jScrollPane1;
570    private javax.swing.JScrollPane jScrollPane3;
571    private javax.swing.JToolBar.Separator jSeparator10;
572    private javax.swing.JToolBar.Separator jSeparator12;
573    private javax.swing.JToolBar.Separator jSeparator5;
574    private javax.swing.JToolBar.Separator jSeparator6;
575    private javax.swing.JToolBar.Separator jSeparator9;
576    private javax.swing.JToolBar jToolBar2;
577    private javax.swing.JPanel leftpane;
578    private mpv5.ui.beans.LabeledTextField listname;
579    private mpv5.ui.beans.LabeledTextField netvalue;
580    private javax.swing.JTextPane notes;
581    private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
582    private javax.swing.JPanel rightpane;
583    private mpv5.ui.beans.LabeledTextField taxvalue;
584    private javax.swing.JPanel toolbarpanetbp;
585    private mpv5.ui.beans.LabeledTextField value;
586    // End of variables declaration//GEN-END:variables
587    public String cname_;
588    public String description_;
589    public int intaddedby_;
590    public int ids_;
591    public Date dateadded_;
592    public int groupsids_ = 1;
593    public boolean asproduct_;
594
595    @Override
596    public boolean collectData() {
597        cname_ = listname.getText();
598        if (cname_.length() > 0) {
599            description_ = notes.getText();
600            if (groupnameselect.getSelectedItem() != null) {
601                groupsids_ = Integer.valueOf(groupnameselect.getSelectedItem().getId());
602                Log.Debug(this, groupnameselect.getSelectedItem().getId());
603            } else {
604                groupsids_ = 1;
605            }
606            return true;
607        } else {
608            showRequiredFields();
609            return false;
610        }
611    }
612
613    @Override
614    public void exposeData() {
615        listname.setText(cname_);
616        notes.setText(description_);
617        try {
618            groupnameselect.setModel(DatabaseObject.getObject(Context.getGroup(), groupsids_));
619        } catch (NodataFoundException ex) {
620            Log.Debug(this, ex.getMessage());
621        }
622
623        addedby.setText(User.getUsername(intaddedby_));
624    }
625
626    @Override
627    public final void refresh() {
628        Runnable runnable = new Runnable() {
629
630            @Override
631            public void run() {
632                try {
633
634                    groupnameselect.setModel(MPComboBoxModelItem.toModel(DatabaseObject.getObject(Context.getGroup(), mpv5.db.objects.User.getCurrentUser().__getGroupsids())));
635                    groupnameselect.setSelectedIndex(0);
636                    itemtable.setModel(ProductlistSubItem.toModel(new ProductlistSubItem[]{
637                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
638                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
639                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
640                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
641                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem(),
642                                ProductlistSubItem.getDefaultItem(), ProductlistSubItem.getDefaultItem()
643                            }));
644                    formatTable();
645
646                } catch (Exception e) {
647                    Log.Debug(this, e);
648                }
649            }
650        };
651
652        SwingUtilities.invokeLater(runnable);
653    }
654
655    /**
656     * 
657     */
658    public void formatTable() {
659
660        prepareTable();
661        TableFormat.resizeCols(itemtable, new Integer[]{0, 23, 53, 63, 100, 83, 63, 63, 0, 0, 0, 20, 20, 0, 0, 0, 0}, new Boolean[]{true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true});
662        TableFormat.changeBackground(itemtable, 1, Color.LIGHT_GRAY);
663        if (mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("org.openyabs.uiproperty", "hidecolumnquantity")) {
664            TableFormat.stripColumn(itemtable, 2);
665        }
666        if (mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("org.openyabs.uiproperty", "hidecolumnmeasure")) {
667            TableFormat.stripColumn(itemtable, 3);
668        }
669
670
671    }
672
673    @Override
674    public void paste(DatabaseObject... dbos) {
675        for (DatabaseObject dbo : dbos) {
676            if (dbo.getContext().equals(Context.getProduct())) {
677                MPTableModel m = (MPTableModel) itemtable.getModel();
678                m.addRow(ProductlistSubItem.toRow((Product) dbo).getRowData(m.getValidRows(new int[]{4}).size()));
679
680                itemtable.setModel(m);
681                omodel = m;
682
683            } else if (dbo.getContext().equals(Context.getProductlist())) {
684                setDataOwner(dbo, true);
685            } else {
686                mpv5.YabsViewProxy.instance().addMessage(Messages.NOT_POSSIBLE.toString() + Messages.ACTION_PASTE.toString(), Color.YELLOW);
687            }
688        }
689    }
690
691    @Override
692    public void showSearchBar(boolean show) {
693        leftpane.removeAll();
694        if (show) {
695            leftpane.add(sp, BorderLayout.CENTER);
696            sp.search();
697        }
698        validate();
699    }
700
701    @Override
702    public void actionAfterSave() {
703        saveProductlistSubItems();
704        omodel = (MPTableModel) itemtable.getModel();
705        if (dataOwner.__isAsproduct()) {
706            try {
707                QueryCriteria c = new QueryCriteria("productlistsids", dataOwner.__getIDS());
708                Product p = (Product) Product.getObjects(Context.getProduct(), c).get(0);
709                p.setCname(dataOwner.__getCname());
710                p.setProductlistsids(dataOwner.__getIDS());
711                p.setExternalnetvalue(value.getValue(BigDecimal.ONE));
712                p.setInternalnetvalue(netvalue.getValue(BigDecimal.ONE));
713                p.setInttype(Product.TYPE_PRODUCT);
714                p.setIntinventorytype(0);
715                if (p.save()) {
716                    Popup.notice(Messages.BOM_CREATED.toString() + p);
717                    mpv5.YabsViewProxy.instance().addTab(p);
718                }
719            } catch (Exception e) {
720                Log.Debug(e);
721            }
722        }
723    }
724
725    @Override
726    public void actionAfterCreate() {
727        ArrayUtilities.replaceColumn(itemtable, 0, null);
728        saveProductlistSubItems();
729        omodel = (MPTableModel) itemtable.getModel();
730    }
731
732    private void saveProductlistSubItems() {
733        if (itemtable.getCellEditor() != null) {
734            try {
735                itemtable.getCellEditor().stopCellEditing();
736            } catch (Exception e) {
737            }
738        }
739        ProductlistSubItem.saveModel((MPTableModel) itemtable.getModel(), dataOwner.__getIDS());
740    }
741
742    @Override
743    public void changeSelection(MPComboBoxModelItem to, Context c) {
744        try {
745            DatabaseObject o = DatabaseObject.getObject(c, Integer.valueOf(to.getId()));
746            int i = itemtable.getSelectedRow();
747            if (i >= 0) {
748                ((MPTableModel) itemtable.getModel()).setRowAt(new ProductlistSubItem((Product) o).getRowData(i), i, 4);
749            }
750        } catch (Exception ex) {
751        }
752    }
753
754    public void actionBeforeCreate() {
755    }
756
757    public void actionBeforeSave() {
758    }
759
760    public void mail() {
761    }
762
763    public void print() {
764        Export.print(this);
765    }
766
767    private void prepareTable() {
768        TableCellRendererForDezimal t = new TableCellRendererForDezimal(itemtable);
769        t.setRendererTo(6);
770        t.setRendererTo(5);
771        t.setRendererTo(2);
772        TableCellRendererForDezimal tc = new TableCellRendererForDezimal(itemtable, new java.awt.Color(161, 176, 190));
773        tc.setRendererTo(7);
774
775        CellEditorWithMPComboBox r = new CellEditorWithMPComboBox(Context.getProduct(), itemtable);
776        r.setEditorTo(4, this, false);
777        itemMultiplier =new DynamicTableCalculator(itemtable, "(([2]*[5])+([2]*[5]%[6]))", new int[]{7});
778        ((MPTableModel) itemtable.getModel()).addCalculator(itemMultiplier);
779        itemMultiplier.addLabel(value, 7);
780
781        netCalculator = new DynamicTableCalculator(itemtable, "([2]*[5]%[6])", new int[]{8});
782        ((MPTableModel) itemtable.getModel()).addCalculator(netCalculator);
783        netCalculator.addLabel(taxvalue, 8);
784
785        netCalculator2 = new DynamicTableCalculator(itemtable, "[2]*[5]", new int[]{9});
786        ((MPTableModel) itemtable.getModel()).addCalculator(netCalculator2);
787        netCalculator2.addLabel(netvalue, 9);
788
789        JButton b1 = new JButton();
790        b1.addMouseListener(new MouseListener() {
791
792            public void mouseClicked(MouseEvent e) {
793            }
794
795            public void mousePressed(MouseEvent e) {
796            }
797
798            public void mouseReleased(MouseEvent e) {
799                ProductSelectDialog.instanceOf((MPTableModel) itemtable.getModel(), itemtable.getSelectedRow(), e, 0, null, null);
800                if (((MPTableModel) itemtable.getModel()).getEmptyRows(new int[]{4}) < 2) {
801                    ((MPTableModel) itemtable.getModel()).addRow(1);
802                }
803            }
804
805            public void mouseEntered(MouseEvent e) {
806            }
807
808            public void mouseExited(MouseEvent e) {
809            }
810        });
811
812        JButton b2 = new JButton();
813        b2.addActionListener(new ActionListener() {
814
815            public void actionPerformed(ActionEvent e) {
816                MPTableModel m = (MPTableModel) itemtable.getModel();
817                int row = itemtable.getSelectedRow();
818                m.setRowAt(ProductlistSubItem.getDefaultItem().getRowData(row), row, 1);
819            }
820        });
821
822        try {
823            itemtable.getColumnModel().getColumn(itemtable.getColumnModel().getColumnIndex("A")).setCellRenderer(new ButtonRenderer());
824        } catch (Exception e) {
825        }
826        try {
827            itemtable.getColumnModel().getColumn(itemtable.getColumnModel().getColumnIndex("A")).setCellEditor(new ButtonEditor(b1));
828        } catch (Exception e) {
829        }
830        try {
831            itemtable.getColumnModel().getColumn(itemtable.getColumnModel().getColumnIndex("C")).setCellRenderer(new ButtonRenderer());
832        } catch (Exception e) {
833        }
834        try {
835            itemtable.getColumnModel().getColumn(itemtable.getColumnModel().getColumnIndex("C")).setCellEditor(new ButtonEditor(b2));
836        } catch (Exception e) {
837        }
838 }
839}