PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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