Search in sources :

Example 6 with CComboBox

use of org.compiere.swing.CComboBox in project adempiere by adempiere.

the class VPAttributeDialog method saveSelection.

//	cmd_zoom
/**
	 *	Save Selection
	 *	@return true if saved
	 */
private boolean saveSelection() {
    if (!m_readWrite)
        return true;
    log.info("");
    MAttributeSet as = m_masi.getMAttributeSet();
    if (as == null)
        return true;
    //
    m_changed = false;
    String mandatory = "";
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        log.fine("Lot=" + fieldLotString.getText());
        String text = fieldLotString.getText();
        m_masi.setLot(text);
        if (as.isLotMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "Lot");
        m_changed = true;
    }
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        log.fine("SerNo=" + fieldSerNo.getText());
        String text = fieldSerNo.getText();
        m_masi.setSerNo(text);
        if (as.isSerNoMandatory() && (text == null || text.length() == 0))
            mandatory += " - " + Msg.translate(Env.getCtx(), "SerNo");
        m_changed = true;
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
        Timestamp ts = (Timestamp) fieldGuaranteeDate.getValue();
        m_masi.setGuaranteeDate(ts);
        if (as.isGuaranteeDateMandatory() && ts == null)
            mandatory += " - " + Msg.translate(Env.getCtx(), "GuaranteeDate");
        m_changed = true;
    }
    //	New Instance
    if (m_changed || m_masi.getM_AttributeSetInstance_ID() == 0) {
        m_masi.save();
        m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
        m_M_AttributeSetInstanceName = m_masi.getDescription();
    }
    //  Save attributes
    if (m_M_AttributeSetInstance_ID > 0 && m_readWrite) {
        //	Save Instance Attributes
        MAttribute[] attributes = as.getMAttributes(!m_productASI);
        for (int i = 0; i < attributes.length; i++) {
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributes[i].getAttributeValueType())) {
                CComboBox editor = (CComboBox) m_editors.get(i);
                MAttributeValue value = (MAttributeValue) editor.getSelectedItem();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
                VNumber editor = (VNumber) m_editors.get(i);
                BigDecimal value = (BigDecimal) editor.getValue();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && value == null)
                    mandatory += " - " + attributes[i].getName();
                //setMAttributeInstance doesn't work without decimal point
                if (value != null && value.scale() == 0)
                    value = value.setScale(1, BigDecimal.ROUND_HALF_UP);
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            } else {
                VString editor = (VString) m_editors.get(i);
                String value = editor.getText();
                log.fine(attributes[i].getName() + "=" + value);
                if (attributes[i].isMandatory() && (value == null || value.length() == 0))
                    mandatory += " - " + attributes[i].getName();
                attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
            }
        }
        m_changed = true;
    }
    //	Save Model
    if (m_changed) {
        m_masi.setDescription();
        m_masi.save();
    }
    m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
    m_M_AttributeSetInstanceName = m_masi.getDescription();
    //
    if (mandatory.length() > 0) {
        ADialog.error(m_WindowNo, this, "FillMandatory", mandatory);
        return false;
    }
    return true;
}
Also used : CComboBox(org.compiere.swing.CComboBox) MAttributeValue(org.compiere.model.MAttributeValue) Timestamp(java.sql.Timestamp) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 7 with CComboBox

use of org.compiere.swing.CComboBox in project adempiere by adempiere.

the class Find method initFindAdvanced.

//	addSelectionColumn
/**
	 *  Init Find GridController
	 */
private void initFindAdvanced() {
    log.config("");
    advancedTable.setModel(new DefaultTableModel(0, 7));
    advancedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    advancedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    TableCellRenderer renderer = new ProxyRenderer(advancedTable.getDefaultRenderer(Object.class));
    advancedTable.setDefaultRenderer(Object.class, renderer);
    InputMap im = advancedTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final Action tabAction = advancedTable.getActionMap().get(im.get(tab));
    Action tabActionWrapper = new AbstractAction() {

        private static final long serialVersionUID = -6868476640719619801L;

        public void actionPerformed(ActionEvent e) {
            tabAction.actionPerformed(e);
            JTable table = (JTable) e.getSource();
            table.requestFocusInWindow();
        }
    };
    advancedTable.getActionMap().put(im.get(tab), tabActionWrapper);
    KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
    final Action shiftTabAction = advancedTable.getActionMap().get(im.get(shiftTab));
    Action shiftTabActionWrapper = new AbstractAction() {

        private static final long serialVersionUID = 5493691483070046620L;

        public void actionPerformed(ActionEvent e) {
            shiftTabAction.actionPerformed(e);
            JTable table = (JTable) e.getSource();
            table.requestFocusInWindow();
        }
    };
    advancedTable.getActionMap().put(im.get(shiftTab), shiftTabActionWrapper);
    //	0 = Columns
    ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
    for (int c = 0; c < m_findFields.length; c++) {
        GridField field = m_findFields[c];
        String columnName = field.getColumnName();
        String header = field.getHeader();
        if (header == null || header.length() == 0) {
            header = Msg.translate(Env.getCtx(), columnName);
            if (header == null || header.length() == 0)
                continue;
        }
        if (field.isKey())
            header += (" (ID)");
        ValueNamePair pp = new ValueNamePair(columnName, header);
        //	System.out.println(pp + " = " + field);
        items.add(pp);
    }
    columnValueNamePairs = new ValueNamePair[items.size()];
    items.toArray(columnValueNamePairs);
    //	sort alpha
    Arrays.sort(columnValueNamePairs);
    columns = new CComboBox(columnValueNamePairs);
    columns.addActionListener(this);
    TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME);
    tc.setPreferredWidth(120);
    FindCellEditor dce = new FindCellEditor(columns);
    dce.addCellEditorListener(new CellEditorListener() {

        public void editingCanceled(ChangeEvent ce) {
        }

        public void editingStopped(ChangeEvent ce) {
            int col = advancedTable.getSelectedColumn();
            int row = advancedTable.getSelectedRow();
            if (col == INDEX_COLUMNNAME && row >= 0) {
                advancedTable.setValueAt(null, row, INDEX_VALUE);
                advancedTable.setValueAt(null, row, INDEX_VALUE2);
            }
        }
    });
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.translate(Env.getCtx(), "AD_Column_ID"));
    // 0 = And/Or
    andOr = new CComboBox(new String[] { "", Msg.getMsg(Env.getCtx(), "AND"), Msg.getMsg(Env.getCtx(), "OR") });
    tc = advancedTable.getColumnModel().getColumn(INDEX_ANDOR);
    tc.setPreferredWidth(45);
    dce = new FindCellEditor(andOr);
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "And/Or"));
    // 1 = Left Bracket
    leftBrackets = new CComboBox(new String[] { "", "(", "((", "(((" });
    tc = advancedTable.getColumnModel().getColumn(INDEX_LEFTBRACKET);
    tc.setPreferredWidth(25);
    dce = new FindCellEditor(leftBrackets);
    tc.setCellEditor(dce);
    tc.setHeaderValue("(");
    //	3 = Operators
    operators = new CComboBox(MQuery.OPERATORS);
    tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR);
    tc.setPreferredWidth(55);
    dce = new FindCellEditor(operators);
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator"));
    // 	4 = QueryValue
    tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE);
    FindValueEditor fve = new FindValueEditor(this, false);
    tc.setCellEditor(fve);
    tc.setPreferredWidth(120);
    tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue"));
    // 	5 = QueryValue2
    tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2);
    tc.setPreferredWidth(120);
    fve = new FindValueEditor(this, true);
    tc.setCellEditor(fve);
    tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2"));
    // 6 = Right Bracket
    rightBrackets = new CComboBox(new String[] { "", ")", "))", ")))" });
    tc = advancedTable.getColumnModel().getColumn(INDEX_RIGHTBRACKET);
    tc.setPreferredWidth(25);
    dce = new FindCellEditor(rightBrackets);
    tc.setCellEditor(dce);
    tc.setHeaderValue(")");
    // phib: disabled auto-completion as it causes date fields to have to be entered twice
    //AutoCompletion.enable(columns);
    //AutoCompletion.enable(operators);
    //user query
    refreshUserQueries();
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) CComboBox(org.compiere.swing.CComboBox) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) CellEditorListener(javax.swing.event.CellEditorListener) GridField(org.compiere.model.GridField) TableColumn(javax.swing.table.TableColumn) ChangeEvent(javax.swing.event.ChangeEvent) JTable(javax.swing.JTable) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) ValueNamePair(org.compiere.util.ValueNamePair) AbstractAction(javax.swing.AbstractAction)

Example 8 with CComboBox

use of org.compiere.swing.CComboBox in project adempiere by adempiere.

the class VTreeMaintenance method preInit.

//	init
/**
	 * 	Fill Tree Combo
	 */
private void preInit() {
    treeField = new CComboBox(getTreeData());
    treeField.addActionListener(this);
    //
    centerTree = new VTreePanel(m_WindowNo, false, true);
    centerTree.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this);
}
Also used : CComboBox(org.compiere.swing.CComboBox) VTreePanel(org.compiere.grid.tree.VTreePanel)

Example 9 with CComboBox

use of org.compiere.swing.CComboBox in project adempiere by adempiere.

the class VDeleteEntity method preInit.

/**
	 * 	Pre Init
	 */
private void preInit() {
    refreshButton = ConfirmPanel.createRefreshButton(false);
    refreshButton.addActionListener(this);
    //	
    dryRun = new CCheckBox(Msg.getMsg(Env.getCtx(), "DryRun"), true);
    clientLabel = new CLabel(Msg.getElement(Env.getCtx(), "AD_Client_ID"));
    clientPick = new CComboBox(getClients());
    clientPick.setSelectedItem(null);
    clientPick.setMandatory(true);
    clientPick.setBackground(false);
    tableLabel = new CLabel(Msg.getElement(Env.getCtx(), "AD_Table_ID"));
    tablePick = new CComboBox(getTables());
    tablePick.setSelectedItem(null);
    tablePick.setMandatory(true);
    tablePick.setBackground(false);
    rootNode = new DefaultMutableTreeNode(null);
    tree = new CheckboxTree(rootNode);
    treePane = new JScrollPane(tree);
    JViewport viewPort = treePane.getViewport();
    viewPort.add(tree);
}
Also used : CLabel(org.compiere.swing.CLabel) JScrollPane(javax.swing.JScrollPane) CComboBox(org.compiere.swing.CComboBox) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckboxTree(it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTree) JViewport(javax.swing.JViewport) CCheckBox(org.compiere.swing.CCheckBox)

Example 10 with CComboBox

use of org.compiere.swing.CComboBox in project adempiere by adempiere.

the class VProductConfigurationBOM method createSelectionPanel.

/**************************************************************************
	 * 	Create Selection Panel
	 *	@param order
	 *	@param invoice
	 *	@param project
	 */
private void createSelectionPanel(boolean order, boolean invoice, boolean project) {
    int row = 0;
    selectionPanel.setBorder(new TitledBorder(Msg.translate(Env.getCtx(), "Selection")));
    productField = new CComboBox(getProducts());
    CLabel label = new CLabel(Msg.translate(Env.getCtx(), "M_Product_ID"));
    label.setLabelFor(productField);
    selectionPanel.add(label, new ALayoutConstraint(row++, 0));
    selectionPanel.add(productField);
    productField.addActionListener(this);
    //	Qty
    label = new CLabel(productQty.getTitle());
    label.setLabelFor(productQty);
    selectionPanel.add(label);
    selectionPanel.add(productQty);
    productQty.setValue(Env.ONE);
    productQty.addActionListener(this);
    if (order) {
        orderField = new CComboBox(getOrders());
        label = new CLabel(Msg.translate(Env.getCtx(), "C_Order_ID"));
        label.setLabelFor(orderField);
        selectionPanel.add(label, new ALayoutConstraint(row++, 0));
        selectionPanel.add(orderField);
        orderField.addActionListener(this);
    }
    if (invoice) {
        invoiceField = new CComboBox(getInvoices());
        label = new CLabel(Msg.translate(Env.getCtx(), "C_Invoice_ID"));
        label.setLabelFor(invoiceField);
        selectionPanel.add(label, new ALayoutConstraint(row++, 0));
        selectionPanel.add(invoiceField);
        invoiceField.addActionListener(this);
    }
    if (project) {
        projectField = new CComboBox(getProjects());
        label = new CLabel(Msg.translate(Env.getCtx(), "C_Project_ID"));
        label.setLabelFor(projectField);
        selectionPanel.add(label, new ALayoutConstraint(row++, 0));
        selectionPanel.add(projectField);
        projectField.addActionListener(this);
    }
    //	Enabled in ActionPerformed
    confirmPanel.getOKButton().setEnabled(false);
    //	Size
    Dimension size = selectionPanel.getPreferredSize();
    size.width = WINDOW_WIDTH;
    selectionPanel.setPreferredSize(size);
}
Also used : CLabel(org.compiere.swing.CLabel) CComboBox(org.compiere.swing.CComboBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) Dimension(java.awt.Dimension) TitledBorder(javax.swing.border.TitledBorder) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Aggregations

CComboBox (org.compiere.swing.CComboBox)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)6 CLabel (org.compiere.swing.CLabel)6 Dimension (java.awt.Dimension)4 KeyNamePair (org.compiere.util.KeyNamePair)3 BorderLayout (java.awt.BorderLayout)2 JScrollPane (javax.swing.JScrollPane)2 JTable (javax.swing.JTable)2 TitledBorder (javax.swing.border.TitledBorder)2 MAttribute (org.compiere.model.MAttribute)2 MAttributeSet (org.compiere.model.MAttributeSet)2 MAttributeValue (org.compiere.model.MAttributeValue)2 CCheckBox (org.compiere.swing.CCheckBox)2 CheckboxTree (it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTree)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1