/* * MenuItemModifierGroupForm.java * * Created on October 12, 2006, 11:48 PM */ package com.floreantpos.ui.model; import java.util.List; import com.floreantpos.PosRuntimeException; import com.floreantpos.model.MenuItemModifierGroup; import com.floreantpos.model.MenuModifierGroup; import com.floreantpos.model.dao.MenuModifierGroupDAO; import com.floreantpos.swing.ListComboBoxModel; import com.floreantpos.ui.BeanEditor; import com.floreantpos.ui.dialog.POSMessageDialog; /** * * @author mshahriar */ public class MenuItemModifierGroupForm extends BeanEditor { /** Creates new form MenuItemModifierGroupForm */ public MenuItemModifierGroupForm() { this(new MenuItemModifierGroup()); } public MenuItemModifierGroupForm(MenuItemModifierGroup modifierGroup) { initComponents(); try { MenuModifierGroupDAO dao = new MenuModifierGroupDAO(); List<MenuModifierGroup> groups = dao.findAll(); cbModifierGroups.setModel(new ListComboBoxModel(groups)); } catch (Exception e) { throw new PosRuntimeException("Error while retrieving modfier group list."); } setBean(modifierGroup); } /** 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() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); cbModifierGroups = new javax.swing.JComboBox(); tfMinQuantity = new javax.swing.JTextField(); tfMaxQuantity = new javax.swing.JTextField(); jLabel1.setText("Modifier Group:"); jLabel2.setText("Min Quantity:"); jLabel3.setText("Max Quantity:"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel3) .add(jLabel2) .add(jLabel1)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(cbModifierGroups, 0, 256, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, tfMaxQuantity) .add(org.jdesktop.layout.GroupLayout.LEADING, tfMinQuantity, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(cbModifierGroups, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(tfMinQuantity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel3) .add(tfMaxQuantity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox cbModifierGroups; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JTextField tfMaxQuantity; private javax.swing.JTextField tfMinQuantity; // End of variables declaration//GEN-END:variables @Override public boolean save() { return updateModel(); } @Override public void dispose() { } @Override protected void updateView() { MenuItemModifierGroup modifierGroup = (MenuItemModifierGroup) getBean(); if(modifierGroup == null) return; if(modifierGroup.getId() != null) { cbModifierGroups.setSelectedItem(modifierGroup.getModifierGroup()); } tfMinQuantity.setText(String.valueOf(modifierGroup.getMinQuantity())); tfMaxQuantity.setText(String.valueOf(modifierGroup.getMaxQuantity())); } @Override protected boolean updateModel() { int minQuantity = 0; int maxQuantity = 0; try { minQuantity = Integer.parseInt(tfMinQuantity.getText()); maxQuantity = Integer.parseInt(tfMaxQuantity.getText()); } catch (Exception e) {} MenuModifierGroup group = (MenuModifierGroup) cbModifierGroups.getSelectedItem(); if(group == null) { POSMessageDialog.showError(this, "Modifier group is required."); return false; } MenuItemModifierGroup modifierGroup = (MenuItemModifierGroup) getBean(); modifierGroup.setModifierGroup(group); modifierGroup.setMinQuantity(minQuantity); modifierGroup.setMaxQuantity(maxQuantity); return true; } @Override public String getDisplayText() { MenuItemModifierGroup modifierGroup = (MenuItemModifierGroup) getBean(); if(modifierGroup.getId() == null) { return "Add new modifier group in menu item."; } return "Edit modifier group in menu item."; } }