Java tutorial
// uniCenta oPOS - Touch Friendly Point Of Sale // Copyright (c) 2009-2014 uniCenta // http://www.unicenta.com // // This file is part of uniCenta oPOS // // uniCenta oPOS is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // uniCenta oPOS is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with uniCenta oPOS. If not, see <http://www.gnu.org/licenses/>. package com.openbravo.pos.ticket; import com.openbravo.basic.BasicException; import com.openbravo.data.gui.ComboBoxValModel; import com.openbravo.data.gui.ListQBFModelNumber; import com.openbravo.data.loader.Datas; import com.openbravo.data.loader.QBFCompareEnum; import com.openbravo.data.loader.SentenceList; import com.openbravo.data.loader.SerializerWrite; import com.openbravo.data.loader.SerializerWriteBasic; import com.openbravo.data.user.BrowsableEditableData; import com.openbravo.format.Formats; import com.openbravo.pos.forms.AppLocal; import com.openbravo.pos.forms.AppView; import com.openbravo.pos.forms.DataLogicSales; import com.openbravo.pos.reports.BrowsableEditable; import com.openbravo.pos.reports.ReportEditorCreator; import java.awt.Component; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JTextField; import org.apache.commons.lang.StringEscapeUtils; /** * * @author JG uniCenta */ public class ProductFilter extends javax.swing.JPanel implements ReportEditorCreator, BrowsableEditable { private SentenceList m_sentcat; private ComboBoxValModel m_CategoryModel; private BrowsableEditableData browsableEditableData; /** Creates new form JQBFProduct */ public ProductFilter() { initComponents(); } /** * * @param app */ @Override public void init(AppView app) { DataLogicSales dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales"); // El modelo de categorias m_sentcat = dlSales.getCategoriesList(); m_CategoryModel = new ComboBoxValModel(); // m_jCboName.setModel(new ListQBFModelNumber()); // m_jCboPriceBuy.setModel(new ListQBFModelNumber()); // m_jCboPriceSell.setModel(new ListQBFModelNumber()); m_jCboName.setModel(ListQBFModelNumber.getMandatoryString()); m_jCboName.setSelectedItem(QBFCompareEnum.COMP_RE); m_jCboPriceBuy.setModel(ListQBFModelNumber.getMandatoryNumber()); m_jCboPriceBuy.setSelectedItem(QBFCompareEnum.COMP_EQUALS); m_jCboPriceSell.setModel(ListQBFModelNumber.getMandatoryNumber()); m_jCboPriceSell.setSelectedItem(QBFCompareEnum.COMP_EQUALS); } /** * * @throws BasicException */ @Override public void activate() throws BasicException { List catlist = m_sentcat.list(); catlist.add(0, null); m_CategoryModel = new ComboBoxValModel(catlist); m_jCategory.setModel(m_CategoryModel); } /** * * @return */ @Override public SerializerWrite getSerializerWrite() { return new SerializerWriteBasic( new Datas[] { Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.DOUBLE, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING }); } /** * * @return */ @Override public Component getComponent() { return this; } @Override public void setBrowsableEditableData(BrowsableEditableData browsableEditableData) { this.browsableEditableData = browsableEditableData; } /** * * @return * @throws BasicException */ @Override public Object createValue() throws BasicException { QBFCompareEnum compareEnum = (QBFCompareEnum) m_jCboName.getSelectedItem(); String nameText = m_jName.getText(); Object[] afilter = new Object[12]; if (nameText == null || nameText.equals("")) { afilter[0] = QBFCompareEnum.COMP_NONE; afilter[1] = null; } else if (compareEnum.getCompareInt() == QBFCompareEnum.COMP_RE.getCompareInt()) { afilter[0] = QBFCompareEnum.COMP_RE; afilter[1] = "%" + StringEscapeUtils.escapeSql(nameText) + "%"; } else { afilter[0] = m_jCboName.getSelectedItem(); afilter[1] = nameText; } if (m_jPriceBuy.getText() == null || m_jPriceBuy.getText().equals("")) { afilter[2] = QBFCompareEnum.COMP_NONE; afilter[3] = null; } else { afilter[2] = m_jCboPriceBuy.getSelectedItem(); afilter[3] = Formats.CURRENCY.parseValue(m_jPriceBuy.getText()); } if (m_jPriceSell.getText() == null || m_jPriceSell.getText().equals("")) { afilter[4] = QBFCompareEnum.COMP_NONE; afilter[5] = null; } else { afilter[4] = m_jCboPriceSell.getSelectedItem(); afilter[5] = Formats.CURRENCY.parseValue(m_jPriceSell.getText()); } if (m_CategoryModel.getSelectedKey() == null) { afilter[6] = QBFCompareEnum.COMP_NONE; afilter[7] = null; } else { afilter[6] = QBFCompareEnum.COMP_EQUALS; afilter[7] = m_CategoryModel.getSelectedKey(); } if (m_jBarcode.getText() == null || m_jBarcode.getText().equals("")) { afilter[8] = QBFCompareEnum.COMP_NONE; afilter[9] = null; } else { afilter[8] = QBFCompareEnum.COMP_RE; afilter[9] = "%" + StringEscapeUtils.escapeSql(m_jBarcode.getText()) + "%"; } if (m_jReference.getText() == null || m_jReference.getText().equals("")) { afilter[10] = QBFCompareEnum.COMP_NONE; afilter[11] = null; } else { afilter[10] = QBFCompareEnum.COMP_RE; afilter[11] = "%" + StringEscapeUtils.escapeSql(m_jReference.getText()) + "%"; } return afilter; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel2 = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); m_jBarcode = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); m_jReference = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); m_jCboName = new javax.swing.JComboBox(); m_jName = new javax.swing.JTextField(); m_jPriceBuy = new javax.swing.JTextField(); m_jCboPriceBuy = new javax.swing.JComboBox(); m_jCboPriceSell = new javax.swing.JComboBox(); m_jPriceSell = new javax.swing.JTextField(); m_jCategory = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, AppLocal.getIntString("label.bybarcode"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12))); // NOI18N jPanel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel5.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel5.setText(AppLocal.getIntString("label.prodbarcode")); // NOI18N m_jBarcode.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N m_jBarcode.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { m_jNameFocusGained(evt); } }); m_jBarcode.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { m_jBarcodeKeyReleased(evt); } }); jLabel6.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel6.setText(AppLocal.getIntString("label.prodref")); // NOI18N m_jReference.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N m_jReference.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { m_jReferencem_jNameFocusGained(evt); } }); m_jReference.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { m_jReferenceKeyReleased(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(m_jBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(m_jReference, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(38, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jReference, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jBarcode, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, AppLocal.getIntString("label.byform"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12))); // NOI18N jPanel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel1.setText(AppLocal.getIntString("label.prodcategory")); // NOI18N jLabel3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel3.setText(AppLocal.getIntString("label.prodpricesell")); // NOI18N jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel4.setText(AppLocal.getIntString("label.prodpricebuy")); // NOI18N m_jCboName.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N m_jName.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N m_jName.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { m_jNameFocusGained(evt); } }); m_jName.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { m_jBarcodeKeyReleased(evt); } }); m_jPriceBuy.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N m_jPriceBuy.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { m_jNameFocusGained(evt); } }); m_jPriceBuy.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { m_jBarcodeKeyReleased(evt); } }); m_jCboPriceBuy.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N m_jCboPriceSell.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N m_jPriceSell.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N m_jPriceSell.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { m_jNameFocusGained(evt); } }); m_jPriceSell.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { m_jBarcodeKeyReleased(evt); } }); m_jCategory.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N jLabel2.setText(AppLocal.getIntString("label.prodname")); // NOI18N javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(m_jCboName, javax.swing.GroupLayout.Alignment.TRAILING, 0, 183, Short.MAX_VALUE) .addComponent(m_jCategory, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(m_jPriceBuy, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jCboPriceBuy, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(m_jPriceSell, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jCboPriceSell, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(36, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(m_jCboPriceBuy, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jCboPriceSell, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jCboName, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(m_jPriceSell, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jPriceBuy, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 7, Short.MAX_VALUE)) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); }// </editor-fold>//GEN-END:initComponents private void m_jBarcodeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_m_jBarcodeKeyReleased if (browsableEditableData != null) { try { browsableEditableData.loadData(); } catch (BasicException ex) { Logger.getLogger(ProductFilter.class.getName()).log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_m_jBarcodeKeyReleased private void m_jNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_m_jNameFocusGained if (evt.getComponent() instanceof JTextField) { ((JTextField) evt.getComponent()).selectAll(); } }//GEN-LAST:event_m_jNameFocusGained private void m_jReferencem_jNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_m_jReferencem_jNameFocusGained if (evt.getComponent() instanceof JTextField) { ((JTextField) evt.getComponent()).selectAll(); } }//GEN-LAST:event_m_jReferencem_jNameFocusGained private void m_jReferenceKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_m_jReferenceKeyReleased if (browsableEditableData != null) { try { browsableEditableData.loadData(); } catch (BasicException ex) { Logger.getLogger(ProductFilter.class.getName()).log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_m_jReferenceKeyReleased // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JTextField m_jBarcode; private javax.swing.JComboBox m_jCategory; private javax.swing.JComboBox m_jCboName; private javax.swing.JComboBox m_jCboPriceBuy; private javax.swing.JComboBox m_jCboPriceSell; private javax.swing.JTextField m_jName; private javax.swing.JTextField m_jPriceBuy; private javax.swing.JTextField m_jPriceSell; private javax.swing.JTextField m_jReference; // End of variables declaration//GEN-END:variables }