PageRenderTime 149ms CodeModel.GetById 60ms app.highlight 65ms RepoModel.GetById 15ms app.codeStats 1ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 618 lines | 529 code | 75 blank | 14 comment | 74 complexity | a91cf897064f69f1a00606932da34c0f MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Cursor;
  4import java.awt.event.ActionEvent;
  5import java.awt.event.ActionListener;
  6import java.io.File;
  7import java.lang.reflect.Method;
  8import java.math.BigDecimal;
  9import java.util.ArrayList;
 10import java.util.List;
 11import javax.swing.DefaultListModel;
 12import javax.swing.filechooser.FileFilter;
 13import mpv5.db.common.Context;
 14import mpv5.db.common.DatabaseObject;
 15import mpv5.db.common.NodataFoundException;
 16import mpv5.db.objects.*;
 17import mpv5.logging.Log;
 18
 19import mpv5.ui.dialogs.DialogForFile;
 20import mpv5.ui.dialogs.Popup;
 21import mpv5.ui.dialogs.WizardMaster;
 22import mpv5.ui.dialogs.Wizardable;
 23import mpv5.utils.files.FileReaderWriter;
 24import mpv5.utils.models.MPTableModel;
 25import mpv5.utils.numberformat.FormatNumber;
 26import mpv5.utils.tables.ExcelAdapter;
 27import mpv5.utils.tables.TableFormat;
 28import mpv5.utils.text.RandomText;
 29import mpv5.utils.ui.TextFieldUtils;
 30
 31/**
 32 *
 33 *
 34 */
 35public class wizard_CSVImport2_1 extends javax.swing.JPanel implements Wizardable {
 36
 37    private static final long serialVersionUID = -8347532498124147821L;
 38    private WizardMaster master;
 39
 40    public wizard_CSVImport2_1(WizardMaster w) {
 41        this.master = w;
 42        initComponents();
 43        jTable1.setModel(new MPTableModel(new Object[0][0]));
 44        labeledTextChooser1.setFilter(new FileFilter() {
 45
 46            @Override
 47            public boolean accept(File f) {
 48                return (f.isDirectory() || ((f.canRead()) && (f.getName().endsWith("csv"))));
 49            }
 50
 51            @Override
 52            public String getDescription() {
 53                return "Importable files";
 54            }
 55        });
 56
 57        setContactFields();
 58        jTable1.getTableHeader().setReorderingAllowed(false);
 59        jTable1.getTableHeader().setResizingAllowed(true);
 60
 61        labeledCombobox1.setModel(Context.getImportableContexts(), true);
 62        labeledCombobox1.getComboBox().addActionListener(new ActionListener() {
 63
 64            @Override
 65            public void actionPerformed(ActionEvent e) {
 66                setContext();
 67            }
 68        });
 69
 70        new ExcelAdapter(jTable1);
 71        labeledTextChooser1.setModalityParent(this);
 72    }
 73
 74    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 75    private void initComponents() {
 76
 77        buttonGroup1 = new javax.swing.ButtonGroup();
 78        jTabbedPane1 = new javax.swing.JTabbedPane();
 79        jPanel1 = new javax.swing.JPanel();
 80        jScrollPane1 = new javax.swing.JScrollPane();
 81        jTable1 = new javax.swing.JTable();
 82        labeledTextChooser1 = new mpv5.ui.beans.LabeledTextChooser();
 83        jButton1 = new javax.swing.JButton();
 84        jButton2 = new javax.swing.JButton();
 85        labeledTextField1 = new mpv5.ui.beans.LabeledTextField();
 86        jScrollPane2 = new javax.swing.JScrollPane();
 87        jList1 = new javax.swing.JList();
 88        jButton3 = new javax.swing.JButton();
 89        jButton4 = new javax.swing.JButton();
 90        jRadioButton1 = new javax.swing.JRadioButton();
 91        jRadioButton2 = new javax.swing.JRadioButton();
 92        jRadioButton3 = new javax.swing.JRadioButton();
 93        labeledCombobox1 = new mpv5.ui.beans.LabeledCombobox();
 94
 95        setBackground(new java.awt.Color(255, 255, 255));
 96        setName("Form"); // NOI18N
 97        setLayout(new java.awt.BorderLayout());
 98
 99        jTabbedPane1.setName("jTabbedPane1"); // NOI18N
100
101        jPanel1.setName("jPanel1"); // NOI18N
102
103        jScrollPane1.setName("jScrollPane1"); // NOI18N
104
105        jTable1.setAutoCreateRowSorter(true);
106        jTable1.setModel(new javax.swing.table.DefaultTableModel(
107            new Object [][] {
108
109            },
110            new String [] {
111
112            }
113        ));
114        jTable1.setName("jTable1"); // NOI18N
115        jScrollPane1.setViewportView(jTable1);
116
117        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
118        labeledTextChooser1.set_Label(bundle.getString("wizard_CSVImport2_1.labeledTextChooser1._Label")); // NOI18N
119        labeledTextChooser1.setName("labeledTextChooser1"); // NOI18N
120
121        jButton1.setText(bundle.getString("wizard_CSVImport2_1.jButton1.text")); // NOI18N
122        jButton1.setName("jButton1"); // NOI18N
123        jButton1.addActionListener(new java.awt.event.ActionListener() {
124            public void actionPerformed(java.awt.event.ActionEvent evt) {
125                jButton1ActionPerformed(evt);
126            }
127        });
128
129        jButton2.setText(bundle.getString("wizard_CSVImport2_1.jButton2.text")); // NOI18N
130        jButton2.setName("jButton2"); // NOI18N
131        jButton2.addActionListener(new java.awt.event.ActionListener() {
132            public void actionPerformed(java.awt.event.ActionEvent evt) {
133                jButton2ActionPerformed(evt);
134            }
135        });
136
137        labeledTextField1.set_Label(bundle.getString("wizard_CSVImport2_1.labeledTextField1._Label")); // NOI18N
138        labeledTextField1.set_Text(bundle.getString("wizard_CSVImport2_1.labeledTextField1._Text")); // NOI18N
139        labeledTextField1.setName("labeledTextField1"); // NOI18N
140
141        jScrollPane2.setName("jScrollPane2"); // NOI18N
142
143        jList1.setModel(new javax.swing.AbstractListModel() {
144            String[] strings = { " " };
145            public int getSize() { return strings.length; }
146            public Object getElementAt(int i) { return strings[i]; }
147        });
148        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
149        jList1.setName("jList1"); // NOI18N
150        jScrollPane2.setViewportView(jList1);
151
152        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/arrow-down.png"))); // NOI18N
153        jButton3.setName("jButton3"); // NOI18N
154        jButton3.addActionListener(new java.awt.event.ActionListener() {
155            public void actionPerformed(java.awt.event.ActionEvent evt) {
156                jButton3ActionPerformed(evt);
157            }
158        });
159
160        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mpv5/resources/images/16/arrow-up.png"))); // NOI18N
161        jButton4.setName("jButton4"); // NOI18N
162        jButton4.addActionListener(new java.awt.event.ActionListener() {
163            public void actionPerformed(java.awt.event.ActionEvent evt) {
164                jButton4ActionPerformed(evt);
165            }
166        });
167
168        buttonGroup1.add(jRadioButton1);
169        jRadioButton1.setText(bundle.getString("wizard_CSVImport2_1.jRadioButton1.text")); // NOI18N
170        jRadioButton1.setName("jRadioButton1"); // NOI18N
171        jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
172            public void itemStateChanged(java.awt.event.ItemEvent evt) {
173                jRadioButton1ItemStateChanged(evt);
174            }
175        });
176        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
177            public void actionPerformed(java.awt.event.ActionEvent evt) {
178                jRadioButton1ActionPerformed(evt);
179            }
180        });
181
182        buttonGroup1.add(jRadioButton2);
183        jRadioButton2.setSelected(true);
184        jRadioButton2.setText(bundle.getString("wizard_CSVImport2_1.jRadioButton2.text")); // NOI18N
185        jRadioButton2.setName("jRadioButton2"); // NOI18N
186        jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
187            public void itemStateChanged(java.awt.event.ItemEvent evt) {
188                jRadioButton2ItemStateChanged(evt);
189            }
190        });
191        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
192            public void actionPerformed(java.awt.event.ActionEvent evt) {
193                jRadioButton2ActionPerformed(evt);
194            }
195        });
196
197        buttonGroup1.add(jRadioButton3);
198        jRadioButton3.setText(bundle.getString("wizard_CSVImport2_1.jRadioButton3.text")); // NOI18N
199        jRadioButton3.setName("jRadioButton3"); // NOI18N
200        jRadioButton3.addItemListener(new java.awt.event.ItemListener() {
201            public void itemStateChanged(java.awt.event.ItemEvent evt) {
202                jRadioButton3ItemStateChanged(evt);
203            }
204        });
205        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
206            public void actionPerformed(java.awt.event.ActionEvent evt) {
207                jRadioButton3ActionPerformed(evt);
208            }
209        });
210
211        labeledCombobox1.set_Label(bundle.getString("wizard_CSVImport2_1.labeledCombobox1._Label")); // NOI18N
212        labeledCombobox1.setEnabled(false);
213        labeledCombobox1.setName("labeledCombobox1"); // NOI18N
214
215        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
216        jPanel1.setLayout(jPanel1Layout);
217        jPanel1Layout.setHorizontalGroup(
218            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219            .addGroup(jPanel1Layout.createSequentialGroup()
220                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
221                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
224                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
225                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE))
227            .addGroup(jPanel1Layout.createSequentialGroup()
228                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
230                        .addComponent(labeledTextChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
231                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
232                        .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
233                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
234                        .addComponent(jButton2)
235                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
236                        .addComponent(jButton1))
237                    .addGroup(jPanel1Layout.createSequentialGroup()
238                        .addComponent(jRadioButton1)
239                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240                        .addComponent(jRadioButton2)
241                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
242                        .addComponent(jRadioButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
243                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
244                        .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
245                .addContainerGap())
246        );
247        jPanel1Layout.setVerticalGroup(
248            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
250                .addContainerGap()
251                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252                    .addGroup(jPanel1Layout.createSequentialGroup()
253                        .addComponent(jButton4)
254                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
255                        .addComponent(jButton3))
256                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
257                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE))
258                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
260                    .addComponent(labeledCombobox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
261                    .addComponent(jRadioButton3)
262                    .addComponent(jRadioButton2)
263                    .addComponent(jRadioButton1))
264                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
265                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
266                    .addComponent(labeledTextChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
267                    .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
268                    .addComponent(jButton2)
269                    .addComponent(jButton1))
270                .addContainerGap())
271        );
272
273        jTabbedPane1.addTab(bundle.getString("wizard_CSVImport2_1.jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N
274
275        add(jTabbedPane1, java.awt.BorderLayout.CENTER);
276    }// </editor-fold>//GEN-END:initComponents
277
278    private void setContext() {
279        if (jRadioButton1.isSelected()) {
280            setProductFields();
281        } else if (jRadioButton2.isSelected()) {
282            setContactFields();
283        } else if (jRadioButton3.isSelected()) {
284            setFields();
285        }
286    }
287    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
288
289        master.setCursor(Cursor.WAIT_CURSOR);
290        showm();
291
292}//GEN-LAST:event_jButton1ActionPerformed
293
294    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
295        File f = new File(labeledTextChooser1.get_Text(true));
296        master.setCursor(Cursor.WAIT_CURSOR);
297        readcsv(f);
298        master.setCursor(Cursor.DEFAULT_CURSOR);
299    }//GEN-LAST:event_jButton2ActionPerformed
300
301    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
302        try {
303            DefaultListModel m = (DefaultListModel) jList1.getModel();
304            Object o = m.getElementAt(jList1.getSelectedIndex());
305            Object old = m.getElementAt(jList1.getSelectedIndex() + 1);
306            int pos = jList1.getSelectedIndex();
307            m.set(pos + 1, o);
308            m.set(pos, old);
309            jList1.setModel(m);
310            jList1.setSelectedIndex(pos + 1);
311        } catch (Exception e) {
312        }
313}//GEN-LAST:event_jButton3ActionPerformed
314
315    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
316
317        try {
318            DefaultListModel m = (DefaultListModel) jList1.getModel();
319            Object o = m.getElementAt(jList1.getSelectedIndex());
320            Object old = m.getElementAt(jList1.getSelectedIndex() - 1);
321            int pos = jList1.getSelectedIndex();
322            m.set(pos - 1, o);
323            m.set(pos, old);
324            jList1.setModel(m);
325            jList1.setSelectedIndex(pos - 1);
326        } catch (Exception e) {
327        }
328}//GEN-LAST:event_jButton4ActionPerformed
329
330    private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
331        jRadioButton2ItemStateChanged(evt);
332}//GEN-LAST:event_jRadioButton1ItemStateChanged
333
334    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
335}//GEN-LAST:event_jRadioButton1ActionPerformed
336
337    private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton2ItemStateChanged
338        setContext();
339}//GEN-LAST:event_jRadioButton2ItemStateChanged
340
341    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
342}//GEN-LAST:event_jRadioButton2ActionPerformed
343
344    private void jRadioButton3ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton3ItemStateChanged
345        setContext();
346        labeledCombobox1.setEnabled(jRadioButton3.isSelected());
347    }//GEN-LAST:event_jRadioButton3ItemStateChanged
348
349    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
350    }//GEN-LAST:event_jRadioButton3ActionPerformed
351    // Variables declaration - do not modify//GEN-BEGIN:variables
352    private javax.swing.ButtonGroup buttonGroup1;
353    private javax.swing.JButton jButton1;
354    private javax.swing.JButton jButton2;
355    private javax.swing.JButton jButton3;
356    private javax.swing.JButton jButton4;
357    private javax.swing.JList jList1;
358    private javax.swing.JPanel jPanel1;
359    private javax.swing.JRadioButton jRadioButton1;
360    private javax.swing.JRadioButton jRadioButton2;
361    private javax.swing.JRadioButton jRadioButton3;
362    private javax.swing.JScrollPane jScrollPane1;
363    private javax.swing.JScrollPane jScrollPane2;
364    private javax.swing.JTabbedPane jTabbedPane1;
365    private javax.swing.JTable jTable1;
366    private mpv5.ui.beans.LabeledCombobox labeledCombobox1;
367    private mpv5.ui.beans.LabeledTextChooser labeledTextChooser1;
368    private mpv5.ui.beans.LabeledTextField labeledTextField1;
369    // End of variables declaration//GEN-END:variables
370
371    public boolean next() {
372        if (labeledTextChooser1.hasText()) {
373            master.getStore().addProperty("file", labeledTextChooser1.get_Text(true));
374//            master.getStore().addProperty("separator", jComboBox1.getSelectedItem().toString());
375            master.getNext().load();
376            return true;
377        } else {
378            return false;
379        }
380    }
381
382    public boolean back() {
383        return false;
384    }
385
386    public void load() {
387    }
388
389    private void readcsv(File f) {
390        String[] lines;
391        Log.Debug(this, "Reading : " + f);
392        MPTableModel mo;
393        if (f.isFile()) {
394
395            String separator = labeledTextField1.getText();
396            if (separator.length() > 0) {
397
398                FileReaderWriter r = new FileReaderWriter(f);
399                lines = r.readLines();
400                String[][] data = new String[lines.length][];
401                if (lines != null && lines.length > 0) {
402
403                    for (int i = 0; i < lines.length; i++) {
404                        String[] line = lines[i].split(separator);
405                        data[i] = line;
406                    }
407                } else {
408                    Log.Debug(this, "No lines found in file : " + f);
409                }
410
411                mo = new MPTableModel(data);
412                mo.setEditable(true);
413                jTable1.setModel(mo);
414            } else {
415                Log.Debug(this, "No separator ");
416                TextFieldUtils.blinkerRed(labeledTextField1);
417            }
418        } else {
419            Log.Debug(this, "Not a file : " + f);
420        }
421    }
422
423    private void showm() {
424        final Context t;
425        if (jRadioButton1.isSelected()) {
426            t = Context.getProduct();
427        } else if (jRadioButton2.isSelected()) {
428            t = Context.getContact();
429        } else {
430            t = (Context) labeledCombobox1.getSelectedItem().getIdObject();
431        }
432        Runnable runnable = new Runnable() {
433
434            @Override
435            public void run() {
436                int count = 0;
437                try {
438                    setCursor(new Cursor(Cursor.WAIT_CURSOR));
439
440                    TableFormat.stopEditing(jTable1);
441
442                    Object[][] data = ((MPTableModel) jTable1.getModel()).getData();
443                    Object[] keys = ((DefaultListModel) jList1.getModel()).toArray();
444                    count = 0;
445
446                    for (int i = 0; i < data.length; i++) {
447                        Object[] line = data[i];
448                        DatabaseObject c = DatabaseObject.getObject(t);
449                        for (int j = 0; j < keys.length; j++) {
450                            Object key = keys[j];
451                            if (j < line.length && line[j] != null && line[j].toString().length() > 0) {
452                                try {
453                                    line[j] = line[j].toString().replace("\"", "");
454//                                Log.Debug(this, "Setting " + key + " to " + line[j]);
455                                    if (key.toString().equals("TAX")) {
456                                        int taxid = Tax.getTaxId(FormatNumber.parseDezimal(line[j].toString().trim()));
457                                        if (taxid > 0) {
458                                            ((Product) c).setTaxids(taxid);
459                                        } else {
460                                            Tax tax = new Tax();
461                                            tax.setTaxvalue(new BigDecimal(line[j].toString().replace("%", "").trim()));
462                                            tax.setIdentifier("autogenerated_" + RandomText.getNumberText());
463                                            tax.setCountry(User.getCurrentUser().__getDefcountry());
464                                            tax.saveImport();
465                                            ((Product) c).setTaxids(tax.__getIDS());
466                                        }
467                                    } else if (key.toString().equals("NETBUYPRICE")) {
468                                        ((Product) c).setInternalnetvalue(FormatNumber.parseDezimal(line[j].toString().trim()));
469
470                                    } else if (key.toString().equals("NETSALEPRICE")) {
471                                        ((Product) c).setExternalnetvalue(FormatNumber.parseDezimal(line[j].toString().trim()));
472
473                                    } else if (key.toString().equals("SUPPLIER")) {
474                                        Contact sup = null;
475                                        try {
476                                            sup = (Contact) DatabaseObject.getObject(Context.getContact(), line[j].toString());
477                                        } catch (NodataFoundException nodataFoundException) {
478                                        }
479                                        if (sup != null) {
480                                            ((Product) c).setSuppliersids(sup.__getIDS());
481                                        } else {
482                                            Contact con = new Contact();
483                                            con.setCname(line[j].toString());
484                                            con.setisSupplier(true);
485                                            con.saveImport();
486                                            ((Product) c).setSuppliersids(con.__getIDS());
487                                        }
488
489                                    } else if (key.toString().equals("MANUFACTURER")) {
490                                        Contact sup = null;
491                                        try {
492                                            sup = (Contact) DatabaseObject.getObject(Context.getContact(), line[j].toString());
493                                        } catch (NodataFoundException nodataFoundException) {
494                                        }
495                                        if (sup != null) {
496                                            ((Product) c).setManufacturersids(sup.__getIDS());
497                                        } else {
498                                            Contact con = new Contact();
499                                            con.setCname(line[j].toString());
500                                            con.setisSupplier(true);
501                                            con.saveImport();
502                                            ((Product) c).setManufacturersids(con.__getIDS());
503                                        }
504                                    } else if (key.toString().equals("GROUP")) {
505                                        try {
506                                            Group p = (Group) DatabaseObject.getObject(Context.getGroup(), line[j].toString());
507                                            if (p != null) {
508                                                ((Product) c).setGroupsids(p.__getIDS());
509                                            } else {
510                                                Group con = new Group();
511                                                con.setCname(line[j].toString());
512                                                con.setGroupsids(1);
513                                                con.saveImport();
514                                                ((Product) c).setGroupsids(con.__getIDS());
515                                            }
516                                        } catch (NodataFoundException nodataFoundException) {
517                                        }
518                                    } else {
519//                                        try {
520                                        c.parse(key.toString(), line[j]);
521//                                        } catch (Exception exception) {
522//                                            Log.Debug(me, key + ": " + line[j]);
523//                                        }
524                                    }
525                                } catch (IndexOutOfBoundsException ex) {
526//                                Log.Debug(ex);
527                                } catch (Exception ex) {
528                                    Log.Debug(ex);
529                                }
530                            }
531                        }
532                        c.saveImport();
533                        count++;
534                    }
535                } catch (Exception e) {
536                    Popup.error(e);
537                    Log.Debug(e);
538                } finally {
539                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
540                    Popup.notice(count + " rows imported.");
541                    master.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
542                    master.isEnd(true);
543                }
544            }
545        };
546        if (t != null) {
547            new Thread(runnable).start();
548        }
549    }
550
551    private void setContactFields() {
552        DefaultListModel m = new DefaultListModel();
553        List<Method> p = new ArrayList<Method> (new Contact().setVars().values());
554
555        for (int i = 0; i < p.size(); i++) {
556            Method method = p.get(i);
557            if (!method.getName().toLowerCase().startsWith("setint")
558                    && !method.getName().toLowerCase().startsWith("setdate")
559                    && !method.getName().toLowerCase().endsWith("ids")
560                    && !method.getName().toLowerCase().startsWith("setgroup")) {
561                m.addElement(method.getName().toUpperCase().substring(3));
562            }
563        }
564
565        m.addElement("GROUP");
566
567        jList1.setModel(m);
568    }
569
570    private void setProductFields() {
571
572        DefaultListModel m = new DefaultListModel();
573        List<Method> p = new ArrayList<Method> (new Product().setVars().values());
574
575        for (int i = 0; i < p.size(); i++) {
576            Method method = p.get(i);
577            if (!method.getName().toLowerCase().startsWith("setint")
578                    && !method.getName().toLowerCase().startsWith("setdate")
579                    && !method.getName().toLowerCase().endsWith("ids")
580                    && !method.getName().toLowerCase().endsWith("image")
581                    && !method.getName().toLowerCase().startsWith("setexternal")
582                    && !method.getName().toLowerCase().startsWith("setgroup")) {
583                m.addElement(method.getName().toUpperCase().substring(3));
584            }
585        }
586
587        m.addElement("TAX");
588        m.addElement("SUPPLIER");
589        m.addElement("MANUFACTURER");
590        m.addElement("NETBUYPRICE");
591        m.addElement("NETSALEPRICE");
592
593        m.addElement("GROUP");
594        jList1.setModel(m);
595    }
596
597    private void setFields() {
598        Context c = (Context) labeledCombobox1.getSelectedItem().getIdObject();
599        if (c != null) {
600            DefaultListModel m = new DefaultListModel();
601            List<Method> vars = new ArrayList<Method>(DatabaseObject.getObject(c).setVars().values());
602            for (int i = 0; i < vars.size(); i++) {
603                Method method = vars.get(i);
604                if (!method.getName().toLowerCase().startsWith("setint")
605                        && !method.getName().toLowerCase().startsWith("setdate")
606                        && !method.getName().toLowerCase().endsWith("ids")
607                        && !method.getName().toLowerCase().endsWith("image")
608                        && !method.getName().toLowerCase().startsWith("setexternal")
609                        && !method.getName().toLowerCase().startsWith("setgroup")) {
610                    m.addElement(method.getName().toUpperCase().substring(3));
611                }
612            }
613
614            m.addElement("GROUP");
615            jList1.setModel(m);
616        }
617    }
618}