PageRenderTime 105ms CodeModel.GetById 72ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 1ms

/src/mpv5/ui/panels/ProductList.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 463 lines | 391 code | 51 blank | 21 comment | 24 complexity | d2545af0af4454304ea83ec8189b57c8 MD5 | raw file
  1package mpv5.ui.panels;
  2
  3import java.awt.Component;
  4import java.awt.event.ActionEvent;
  5import java.util.ArrayList;
  6import java.util.Date;
  7import java.util.List;
  8import javax.swing.AbstractAction;
  9import javax.swing.JComponent;
 10import javax.swing.table.TableCellRenderer;
 11import mpv5.db.common.Context;
 12import mpv5.db.common.DatabaseObject;
 13import mpv5.db.common.NodataFoundException;
 14import mpv5.db.common.QueryCriteria2;
 15import mpv5.db.common.QueryHandler;
 16import mpv5.db.common.QueryParameter;
 17import mpv5.db.objects.Product;
 18import mpv5.db.objects.ProductGroup;
 19import mpv5.globals.Messages;
 20import mpv5.logging.Log;
 21import mpv5.ui.misc.MPTable;
 22import mpv5.utils.date.vTimeframe;
 23import mpv5.utils.models.MPTableModel;
 24import mpv5.utils.tables.*;
 25import mpv5.ui.misc.TableViewPersistenceHandler;
 26
 27/**
 28 *
 29 *
 30 */
 31public class ProductList extends javax.swing.JPanel implements ListPanel {
 32
 33    private static final long serialVersionUID = 1L;
 34    private Context context = Context.getProduct();
 35    private java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();
 36
 37    /**
 38     * Creates new form ListPanel
 39     */
 40    public ProductList() {
 41        initComponents();
 42        setName("productlist");
 43        labeledCombobox1.setContext(Context.getSupplier());
 44        labeledCombobox1.setSearchEnabled(true);
 45        labeledCombobox2.setContext(Context.getManufacturer());
 46        labeledCombobox2.setSearchEnabled(true);
 47        labeledCombobox1.setEditable(true);
 48        labeledCombobox2.setEditable(true);
 49        prinitingComboBox1.init(listTable);
 50        context.addReference(Context.getContact().getDbIdentity(), "ids", "suppliersids");
 51        context.addReference(Context.getGroup());
 52        ((MPTable) listTable).setPersistanceHandler(new TableViewPersistenceHandler((MPTable) listTable, this));
 53
 54        search.getTextField().addActionListener(new AbstractAction() {
 55            public void actionPerformed(ActionEvent e) {
 56                filltable(search.getText(), null);
 57            }
 58        });
 59    }
 60
 61    /**
 62     * This me4thod is called from within the constructor to initialize the
 63     * form. WARNING: Do NOT modify this code. The content of this method is
 64     * always regenerated by the Form Editor.
 65     */
 66    @SuppressWarnings("unchecked")
 67    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 68    private void initComponents() {
 69
 70        buttonGroup1 = new javax.swing.ButtonGroup();
 71        buttonGroup2 = new javax.swing.ButtonGroup();
 72        jPanel1 = new javax.swing.JPanel();
 73        jScrollPane1 = new javax.swing.JScrollPane();
 74        listTable = new  mpv5.ui.misc.MPTable(this) {
 75            public Component prepareRenderer(TableCellRenderer renderer,
 76                int rowIndex, int vColIndex) {
 77                Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
 78                if (c instanceof JComponent) {
 79                    JComponent jc = (JComponent)c;
 80                    jc.setToolTipText(String.valueOf(getValueAt(rowIndex, vColIndex)));
 81                }
 82                return c;
 83            }
 84        };
 85        jPanel2 = new javax.swing.JPanel();
 86        jPanel3 = new javax.swing.JPanel();
 87        products = new javax.swing.JRadioButton();
 88        both = new javax.swing.JRadioButton();
 89        search = new mpv5.ui.beans.LabeledTextField();
 90        jLabel1 = new javax.swing.JLabel();
 91        services = new javax.swing.JRadioButton();
 92        jButton4 = new javax.swing.JButton();
 93        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 94        jButton3 = new javax.swing.JButton();
 95        labeledCombobox2 = new mpv5.ui.beans.LabeledCombobox();
 96        prinitingComboBox1 = new mpv5.ui.beans.PrinitingComboBox();
 97        jButton1 = new javax.swing.JButton();
 98        jButton2 = new javax.swing.JButton();
 99
100        setName("Form"); // NOI18N
101
102        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle();// NOI18N
103        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ProductList.jPanel1.border.title"))); // NOI18N
104        jPanel1.setName("jPanel1"); // NOI18N
105
106        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
107        jScrollPane1.setName("jScrollPane1"); // NOI18N
108
109        listTable.setAutoCreateRowSorter(true);
110        listTable.setModel(new javax.swing.table.DefaultTableModel(
111            new Object [][] {
112                {},
113                {},
114                {},
115                {}
116            },
117            new String [] {
118
119            }
120        ));
121        listTable.setDragEnabled(true);
122        listTable.setFillsViewportHeight(true);
123        listTable.setName("listTable"); // NOI18N
124        listTable.setShowVerticalLines(false);
125        listTable.addMouseListener(new java.awt.event.MouseAdapter() {
126            public void mouseClicked(java.awt.event.MouseEvent evt) {
127                listTableMouseClicked(evt);
128            }
129        });
130        jScrollPane1.setViewportView(listTable);
131
132        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ProductList.jPanel2.border.title"))); // NOI18N
133        jPanel2.setName("jPanel2"); // NOI18N
134
135        jPanel3.setName("jPanel3"); // NOI18N
136
137        buttonGroup2.add(products);
138        products.setText(bundle.getString("ProductList.products.text")); // NOI18N
139        products.setFocusable(false);
140        products.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
141        products.setMaximumSize(new java.awt.Dimension(333, 20));
142        products.setMinimumSize(new java.awt.Dimension(100, 20));
143        products.setName("products"); // NOI18N
144        products.setPreferredSize(new java.awt.Dimension(100, 20));
145        products.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
146
147        buttonGroup2.add(both);
148        both.setSelected(true);
149        both.setText(bundle.getString("ProductList.both.text")); // NOI18N
150        both.setFocusable(false);
151        both.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
152        both.setMaximumSize(new java.awt.Dimension(333, 20));
153        both.setMinimumSize(new java.awt.Dimension(100, 20));
154        both.setName("both"); // NOI18N
155        both.setPreferredSize(new java.awt.Dimension(100, 20));
156        both.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
157
158        search.set_Label(bundle.getString("ProductList.search._Label")); // NOI18N
159        search.setName("search"); // NOI18N
160        search.setPreferredSize(new java.awt.Dimension(200, 21));
161
162        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD));
163        jLabel1.setText(bundle.getString("ProductList.jLabel1.text")); // NOI18N
164        jLabel1.setName("jLabel1"); // NOI18N
165
166        buttonGroup2.add(services);
167        services.setText(bundle.getString("ProductList.services.text")); // NOI18N
168        services.setFocusable(false);
169        services.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
170        services.setMaximumSize(new java.awt.Dimension(333, 20));
171        services.setMinimumSize(new java.awt.Dimension(100, 20));
172        services.setName("services"); // NOI18N
173        services.setPreferredSize(new java.awt.Dimension(100, 20));
174        services.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
175
176        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/remove.png"))); // NOI18N
177        jButton4.setText(bundle.getString("ProductList.jButton4.text")); // NOI18N
178        jButton4.setBorderPainted(false);
179        jButton4.setName("jButton4"); // NOI18N
180        jButton4.addActionListener(new java.awt.event.ActionListener() {
181            public void actionPerformed(java.awt.event.ActionEvent evt) {
182                jButton4ActionPerformed(evt);
183            }
184        });
185
186        labeledCombobox1.set_Label(bundle.getString("ProductList.labeledCombobox1._Label")); // NOI18N
187        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
188
189        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/remove.png"))); // NOI18N
190        jButton3.setText(bundle.getString("ProductList.jButton3.text")); // NOI18N
191        jButton3.setBorderPainted(false);
192        jButton3.setName("jButton3"); // NOI18N
193        jButton3.addActionListener(new java.awt.event.ActionListener() {
194            public void actionPerformed(java.awt.event.ActionEvent evt) {
195                jButton3ActionPerformed(evt);
196            }
197        });
198
199        labeledCombobox2.set_Label(bundle.getString("ProductList.labeledCombobox2._Label")); // NOI18N
200        labeledCombobox2.setName("labeledCombobox2"); // NOI18N
201
202        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
203        jPanel3.setLayout(jPanel3Layout);
204        jPanel3Layout.setHorizontalGroup(
205            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
207                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
208                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209                .addComponent(products, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
210                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
211                .addComponent(services, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
212                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
213                .addComponent(both, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
214                .addGap(47, 47, 47))
215            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
216                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
217                    .addComponent(search, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
218                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
219                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220                            .addComponent(labeledCombobox2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
221                            .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE))
222                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
223                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
225                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
226                .addGap(165, 165, 165))
227        );
228        jPanel3Layout.setVerticalGroup(
229            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230            .addGroup(jPanel3Layout.createSequentialGroup()
231                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
232                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
233                    .addComponent(products, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
234                    .addComponent(services, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
235                    .addComponent(both, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
236                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237                .addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
239                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
240                    .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
241                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE))
242                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
244                    .addComponent(labeledCombobox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
245                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
246                .addContainerGap())
247        );
248
249        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
250        jPanel2.setLayout(jPanel2Layout);
251        jPanel2Layout.setHorizontalGroup(
252            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253            .addGroup(jPanel2Layout.createSequentialGroup()
254                .addContainerGap()
255                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
256                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
257        );
258        jPanel2Layout.setVerticalGroup(
259            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
261        );
262
263        prinitingComboBox1.setName("prinitingComboBox1"); // NOI18N
264
265        jButton1.setText(bundle.getString("ProductList.jButton1.text")); // NOI18N
266        jButton1.setName("jButton1"); // NOI18N
267        jButton1.addActionListener(new java.awt.event.ActionListener() {
268            public void actionPerformed(java.awt.event.ActionEvent evt) {
269                jButton1ActionPerformed(evt);
270            }
271        });
272
273        jButton2.setText(bundle.getString("ProductList.jButton2.text")); // NOI18N
274        jButton2.setName("jButton2"); // NOI18N
275        jButton2.addActionListener(new java.awt.event.ActionListener() {
276            public void actionPerformed(java.awt.event.ActionEvent evt) {
277                jButton2ActionPerformed(evt);
278            }
279        });
280
281        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
282        jPanel1.setLayout(jPanel1Layout);
283        jPanel1Layout.setHorizontalGroup(
284            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
285            .addComponent(jScrollPane1)
286            .addGroup(jPanel1Layout.createSequentialGroup()
287                .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
288                .addContainerGap())
289            .addGroup(jPanel1Layout.createSequentialGroup()
290                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
291                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
292                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
294                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
295                .addGap(0, 15, Short.MAX_VALUE))
296        );
297        jPanel1Layout.setVerticalGroup(
298            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299            .addGroup(jPanel1Layout.createSequentialGroup()
300                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
301                    .addGroup(jPanel1Layout.createSequentialGroup()
302                        .addContainerGap()
303                        .addComponent(jButton1)
304                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
305                        .addComponent(jButton2))
306                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
307                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
308                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
309                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
310                .addComponent(prinitingComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
311        );
312
313        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
314        this.setLayout(layout);
315        layout.setHorizontalGroup(
316            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
317            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
318        );
319        layout.setVerticalGroup(
320            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
321            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
322        );
323    }// </editor-fold>//GEN-END:initComponents
324
325    private void listTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listTableMouseClicked
326
327        if (evt.getClickCount() > 1) {
328            Selection sel = new Selection(listTable);
329            if (sel.checkID()) {
330                try {
331                    mpv5.YabsViewProxy.instance().getIdentifierView().addTab(DatabaseObject.getObject(Context.getProduct(), sel.getId()));
332                } catch (NodataFoundException ex) {
333                    Log.Debug(ex);
334                }
335            }
336        }
337    }//GEN-LAST:event_listTableMouseClicked
338
339    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
340
341        DatabaseObject d = DatabaseObject.getObject(Context.getProduct());
342        mpv5.YabsViewProxy.instance().getIdentifierView().addTab(d, Messages.NEW_PRODUCT);
343    }//GEN-LAST:event_jButton1ActionPerformed
344
345    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
346        filltable(search.getText(), null);
347    }//GEN-LAST:event_jButton2ActionPerformed
348
349    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
350        labeledCombobox1.setSelectedIndex(-1);
351    }//GEN-LAST:event_jButton3ActionPerformed
352
353    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
354        labeledCombobox2.setSelectedIndex(-1);
355    }//GEN-LAST:event_jButton4ActionPerformed
356    // Variables declaration - do not modify//GEN-BEGIN:variables
357    private javax.swing.JRadioButton both;
358    private javax.swing.ButtonGroup buttonGroup1;
359    private javax.swing.ButtonGroup buttonGroup2;
360    private javax.swing.JButton jButton1;
361    private javax.swing.JButton jButton2;
362    private javax.swing.JButton jButton3;
363    private javax.swing.JButton jButton4;
364    private javax.swing.JLabel jLabel1;
365    private javax.swing.JPanel jPanel1;
366    private javax.swing.JPanel jPanel2;
367    private javax.swing.JPanel jPanel3;
368    private javax.swing.JScrollPane jScrollPane1;
369    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
370    private mpv5.ui.beans.LabeledCombobox labeledCombobox2;
371    private javax.swing.JTable listTable;
372    private mpv5.ui.beans.PrinitingComboBox prinitingComboBox1;
373    private javax.swing.JRadioButton products;
374    private mpv5.ui.beans.LabeledTextField search;
375    private javax.swing.JRadioButton services;
376    // End of variables declaration//GEN-END:variables
377
378    /**
379     * @return the context
380     */
381    public Context getContext() {
382        return context;
383    }
384
385    /**
386     * @param context the context to set
387     */
388    public void setContext(Context context) {
389        this.context = context;
390    }
391
392    public void refresh() {
393    }
394
395    public void flush() {
396        listTable.setModel(null);
397    }
398
399    private void filltable(String search, List<ProductGroup> groups) {
400
401        QueryCriteria2 qc = new QueryCriteria2();
402
403        if (search != null) {
404            List<List<QueryParameter>> ps = new ArrayList<List<QueryParameter>>();
405            List<QueryParameter> not = new ArrayList<QueryParameter>();
406            String[] strings = search.split("\\s+");
407            for (int i = 0; i < strings.length; i++) {
408                ArrayList<QueryParameter> psx = new ArrayList<QueryParameter>();
409                ps.add(psx);
410                String string = strings[i];
411                for (String en : new Product().getStringVars()) {
412                    if (!string.startsWith("-")) {
413                        psx.add(new QueryParameter(Context.getProduct(), en, string, QueryParameter.LIKE));
414                    } else {
415                        not.add(new QueryParameter(Context.getProduct(), en, string.substring(1), QueryParameter.NOTLIKE));
416                    }
417                }
418            }
419            for (int i = 0; i < ps.size(); i++) {
420                qc.or(ps.get(i));
421            }
422
423            qc.and(not);
424        }
425
426        if (!both.isSelected()) {
427            int type = Product.TYPE_PRODUCT;
428            if (services.isSelected()) {
429                type = Product.TYPE_SERVICE;
430            }
431            qc.and(new QueryParameter(Context.getProduct(), "inttype", type, QueryParameter.EQUALS));
432        }
433
434        if (groups != null && !groups.isEmpty()) {
435            List<QueryParameter> ps = new ArrayList<QueryParameter>();
436            for (int i = 0; i < groups.size(); i++) {
437                ProductGroup group = groups.get(i);
438                ps.add(new QueryParameter(Context.getProduct(), "productgroupsids", group.__getIDS(), QueryParameter.EQUALS));
439            }
440            qc.or(ps);
441        }
442
443        if (labeledCombobox1.getValue() != null && labeledCombobox1.getComboBox().getSelectedIndex() != -1) {
444            qc.and(new QueryParameter(context, "suppliersids", Integer.valueOf(labeledCombobox1.getSelectedItem().getId()), QueryParameter.EQUALS));
445        }
446        if (labeledCombobox2.getValue() != null && labeledCombobox2.getComboBox().getSelectedIndex() != -1) {
447            qc.and(new QueryParameter(context, "manufacturersids", Integer.valueOf(labeledCombobox2.getSelectedItem().getId()), QueryParameter.EQUALS));
448        }
449
450        Context c = Context.getProduct();
451        c.addReference(Context.getContact().getDbIdentity(), "ids", "suppliersids");
452        c.addReference(Context.getGroup());
453
454        try {
455            listTable.setModel(new MPTableModel(QueryHandler.instanceOf().clone(c).select(Context.DETAILS_PRODUCTS, qc).getData()));
456        } catch (NodataFoundException ex) {
457            listTable.setModel(new MPTableModel());
458        }
459
460        TableFormat.hideHeader(listTable);
461        validate();
462    }
463}