PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

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