PageRenderTime 166ms CodeModel.GetById 81ms app.highlight 54ms RepoModel.GetById 26ms app.codeStats 0ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 317 lines | 264 code | 33 blank | 20 comment | 17 complexity | e950556ea34e341fe04395de4f463f02 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.BorderLayout;
  4import java.awt.event.ItemEvent;
  5import java.awt.event.ItemListener;
  6import java.awt.event.KeyEvent;
  7import java.awt.event.MouseEvent;
  8import java.math.BigDecimal;
  9import javax.swing.JFrame;
 10import mpv5.db.common.Context;
 11import mpv5.db.common.NodataFoundException;
 12import mpv5.db.objects.Product;
 13import mpv5.db.objects.SubItem;
 14import mpv5.db.objects.Tax;
 15import mpv5.globals.Messages;
 16import mpv5.utils.models.MPTableModel;
 17import mpv5.utils.numberformat.FormatNumber;
 18
 19/**
 20 *
 21 * 
 22 */
 23public class ProductSelectDialog extends javax.swing.JPanel {
 24
 25    private static ProductSelectDialog me;
 26    private static JFrame frame;
 27
 28    /**
 29     * @param model
 30     * @param row
 31     * @param evt
 32     * @param productid
 33     * @param link
 34     * @param optional
 35     * @return
 36     */
 37    public static ProductSelectDialog instanceOf(MPTableModel model, int row, MouseEvent evt, int productid, Object link, Object optional) {
 38        if (me == null) {
 39            me = new ProductSelectDialog();
 40            frame = new JFrame();
 41            frame.setUndecorated(true);
 42            frame.setAlwaysOnTop(true);
 43            frame.setLayout(new BorderLayout());
 44            frame.add(me, BorderLayout.CENTER);
 45            frame.pack();
 46            frame.setTitle(Messages.ACTION_OPEN.toString());
 47            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 48        }
 49        me.setModel(model);
 50        me.setEvent(evt);
 51        me.setRow(row);
 52        me.setProductid(productid);
 53        if (optional != null) {
 54            me.setOptional(optional.toString());
 55        }
 56        if (link != null) {
 57            me.setLink(link.toString());
 58        }
 59        if (productid > 0) {
 60            try {
 61                me.labeledCombobox1.setSelectedItem(Integer.valueOf(productid));
 62                me.statech();
 63            } catch (Exception e) {
 64            }
 65        }
 66        me.taxrate.setEnabled(!mpv5.db.objects.User.getCurrentUser().getProperties().getProperty("org.openyabs.uiproperty", "hidetaxcolumn"));
 67//        Point p = evt.getLocationOnScreen();
 68//                  p.move(evt.getLocationOnScreen().x - me.getWidth(),
 69//                        mpv5.YabsViewProxy.instance().identifierFrame.getY() + mpv5.YabsViewProxy.instance().identifierFrame.getHeight() - 310);
 70//                  frame.setLocation(p);
 71        frame.setLocation(evt.getLocationOnScreen().x - me.getWidth(), evt.getLocationOnScreen().y);
 72        frame.setResizable(false);
 73        frame.setVisible(true);
 74        return me;
 75    }
 76    private MPTableModel model;
 77    private MouseEvent event;
 78    private int row;
 79    private int pid;
 80    private String optionalt;
 81    private String linkt;
 82
 83    public ProductSelectDialog() {
 84        initComponents();
 85        jButton1.getInsets().set(0, 0, 0, 0);
 86        jButton2.getInsets().set(0, 0, 0, 0);
 87        validate();
 88        link.getTextField().setToolTipText("Google@http://www.google.de");
 89        taxrate.getComboBox().setEditable(false);
 90        taxrate.setSearchEnabled(true);
 91        taxrate.setContext(Context.getTaxes());
 92        taxrate.triggerSearch();
 93        value.set_ValueClass(Double.class);
 94        countt.set_ValueClass(Double.class);
 95        labeledCombobox1.setContext(Context.getProduct());
 96        labeledCombobox1.getComboBox().addItemListener(new ItemListener() {
 97
 98            public void itemStateChanged(ItemEvent e) {
 99                statech();
100            }
101        });
102        labeledCombobox1.triggerSearch();
103        labeledCombobox1.getComboBox().setEditable(true);
104    }
105
106    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
107    private void initComponents() {
108
109        jPanel1 = new javax.swing.JPanel();
110        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
111        jButton1 = new javax.swing.JButton();
112        measure = new mpv5.ui.beans.LabeledTextField();
113        taxrate = new mpv5.ui.beans.LabeledCombobox();
114        value = new mpv5.ui.beans.LabeledTextField();
115        jButton2 = new javax.swing.JButton();
116        link = new mpv5.ui.beans.LabeledTextField();
117        countt = new mpv5.ui.beans.LabeledTextField();
118        opt = new mpv5.ui.beans.LabeledTextField();
119
120        setBackground(new java.awt.Color(255, 255, 255));
121        setName("Form"); // NOI18N
122        setLayout(new java.awt.BorderLayout());
123
124        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
125        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ProductSelectDialog.jPanel1.border.title"))); // NOI18N
126        jPanel1.setName("jPanel1"); // NOI18N
127        jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
128            public void keyPressed(java.awt.event.KeyEvent evt) {
129                jPanel1KeyPressed(evt);
130            }
131        });
132
133        labeledCombobox1.set_Label(bundle.getString("ProductSelectDialog.labeledCombobox1._Label")); // NOI18N
134        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
135        labeledCombobox1.setSearchOnEnterEnabled(true);
136
137        jButton1.setFont(new java.awt.Font("Dialog", 0, 10));
138        jButton1.setText(bundle.getString("ProductSelectDialog.jButton1.text")); // NOI18N
139        jButton1.setName("jButton1"); // NOI18N
140        jButton1.addActionListener(new java.awt.event.ActionListener() {
141            public void actionPerformed(java.awt.event.ActionEvent evt) {
142                jButton1ActionPerformed(evt);
143            }
144        });
145
146        measure.set_Label(bundle.getString("ProductSelectDialog.measure._Label")); // NOI18N
147        measure.setName("measure"); // NOI18N
148
149        taxrate.set_Label(bundle.getString("ProductSelectDialog.taxrate._Label")); // NOI18N
150        taxrate.setName("taxrate"); // NOI18N
151
152        value.set_Label(bundle.getString("ProductSelectDialog.value._Label")); // NOI18N
153        value.setName("value"); // NOI18N
154
155        jButton2.setFont(new java.awt.Font("Dialog", 0, 10));
156        jButton2.setText(bundle.getString("ProductSelectDialog.jButton2.text")); // NOI18N
157        jButton2.setName("jButton2"); // NOI18N
158        jButton2.addActionListener(new java.awt.event.ActionListener() {
159            public void actionPerformed(java.awt.event.ActionEvent evt) {
160                jButton2ActionPerformed(evt);
161            }
162        });
163
164        link.set_Label(bundle.getString("ProductSelectDialog.link._Label")); // NOI18N
165        link.setName("link"); // NOI18N
166
167        countt.set_Label(bundle.getString("ProductSelectDialog.countt._Label")); // NOI18N
168        countt.set_Text(bundle.getString("ProductSelectDialog.countt._Text")); // NOI18N
169        countt.setName("countt"); // NOI18N
170
171        opt.set_Label(bundle.getString("ProductSelectDialog.opt._Label")); // NOI18N
172        opt.setName("opt"); // NOI18N
173
174        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
175        jPanel1.setLayout(jPanel1Layout);
176        jPanel1Layout.setHorizontalGroup(
177            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178            .addGroup(jPanel1Layout.createSequentialGroup()
179                .addContainerGap()
180                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
182                        .addComponent(countt, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
183                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184                        .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))
185                    .addGroup(jPanel1Layout.createSequentialGroup()
186                        .addComponent(measure, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
187                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188                        .addComponent(taxrate, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
189                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190                        .addComponent(value, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
191                    .addComponent(link, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
192                    .addComponent(opt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
193                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
194                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
195                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
196                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
197                .addContainerGap())
198        );
199        jPanel1Layout.setVerticalGroup(
200            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201            .addGroup(jPanel1Layout.createSequentialGroup()
202                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
203                    .addComponent(jButton1, 0, 0, Short.MAX_VALUE)
204                    .addComponent(labeledCombobox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
205                    .addComponent(countt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
206                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
207                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
208                    .addComponent(jButton2)
209                    .addComponent(value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
210                    .addComponent(taxrate, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
211                    .addComponent(measure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
212                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
213                .addComponent(link, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
215                .addComponent(opt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
216                .addGap(37, 37, 37))
217        );
218
219        add(jPanel1, java.awt.BorderLayout.CENTER);
220    }// </editor-fold>//GEN-END:initComponents
221
222    private void statech() {
223        try {
224            Product p = (Product) Product.getObject(Context.getProduct(), Integer.valueOf(labeledCombobox1.getSelectedItem().getId()));
225            measure.setText(p.__getMeasure());
226            value.setText(FormatNumber.formatDezimal(p.findPriceFor(countt.getValue(0d))));
227            taxrate.setSelectedItem(p.__getTaxids());
228            if (linkt == null || linkt.length() == 0) {
229                link.setText(p.__getUrl());
230            } else {
231                link.setText(linkt);
232            }
233        } catch (NodataFoundException ex) {
234            measure.setText("");
235            value.setText("");
236            taxrate.setSelectedItem(0);
237        }
238    }
239
240    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
241        SubItem s;
242        try {
243            s = new SubItem((Product) Product.getObject(Context.getProduct(), Integer.valueOf(labeledCombobox1.getSelectedItem().getId())));
244        } catch (Exception ex) {
245            s = SubItem.getDefaultItem();
246            if (labeledCombobox1.getText() != null) {
247                s.setDescription(labeledCombobox1.getText());
248            }
249        }
250        s.setCountvalue(new BigDecimal(row));
251        BigDecimal f = FormatNumber.parseDezimal(countt.getText());
252        s.setQuantityvalue(f != null ? f : BigDecimal.ONE);
253        s.setLinkurl(link.getText());
254        s.setCname(opt.getText());
255
256        s.setMeasure(measure.getText());
257        try {
258            s.setExternalvalue(FormatNumber.parseDezimal(value.getText()));
259        } catch (Exception e) {
260        }
261        try {
262            s.setTaxpercentvalue(Tax.getTaxValue(Integer.valueOf(taxrate.getSelectedItem().getId())));
263        } catch (Exception numberFormatException) {
264        }
265
266        model.setRowAt(s.getRowData(row), row, 1);
267        frame.setVisible(false);
268    }//GEN-LAST:event_jButton1ActionPerformed
269
270    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
271        frame.setVisible(false);
272    }//GEN-LAST:event_jButton2ActionPerformed
273
274    private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyPressed
275        if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
276            frame.setVisible(false);
277        }
278    }//GEN-LAST:event_jPanel1KeyPressed
279    // Variables declaration - do not modify//GEN-BEGIN:variables
280    private mpv5.ui.beans.LabeledTextField countt;
281    private javax.swing.JButton jButton1;
282    private javax.swing.JButton jButton2;
283    private javax.swing.JPanel jPanel1;
284    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
285    private mpv5.ui.beans.LabeledTextField link;
286    private mpv5.ui.beans.LabeledTextField measure;
287    private mpv5.ui.beans.LabeledTextField opt;
288    private mpv5.ui.beans.LabeledCombobox taxrate;
289    private mpv5.ui.beans.LabeledTextField value;
290    // End of variables declaration//GEN-END:variables
291
292    private void setModel(MPTableModel mode) {
293        model = mode;
294    }
295
296    private void setEvent(MouseEvent evt) {
297        event = evt;
298    }
299
300    private void setRow(int row) {
301        this.row = row;
302    }
303
304    private void setProductid(int productid) {
305        this.pid = productid;
306    }
307
308    private void setOptional(String optional) {
309        this.optionalt = optional;
310        opt.setText(optional);
311    }
312
313    private void setLink(String links) {
314        this.linkt = links;
315        link.setText(links);
316    }
317}