Search in sources :

Example 1 with CComboBox

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

the class VPAttributeDialog method initAttributes.

//	jbInit
/**
	 *	Dyanmic Init.
	 *  @return true if initialized
	 */
private boolean initAttributes() {
    if (m_M_Product_ID == 0 && !m_productWindow)
        return false;
    MAttributeSet as = null;
    if (m_M_Product_ID != 0) {
        //	Get Model
        m_product = MProduct.get(Env.getCtx(), m_M_Product_ID);
        if (m_product.getM_AttributeSetInstance_ID() > 0) {
            m_productASI = true;
            //  The product has an instance associated with it.
            if (m_M_AttributeSetInstance_ID != m_product.getM_AttributeSetInstance_ID()) {
                log.fine("Different ASI than what is specified on Product!");
            }
        } else {
            // Only show product attributes when in the product window.
            m_productASI = m_productWindow;
        }
        m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
        if (m_masi == null) {
            log.severe("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
            return false;
        }
        Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
        //	Get Attribute Set
        as = m_masi.getMAttributeSet();
    } else {
        int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
        m_masi = new MAttributeSetInstance(Env.getCtx(), 0, M_AttributeSet_ID, null);
        as = m_masi.getMAttributeSet();
    }
    //	Product has no Attribute Set
    if (as == null) {
    //ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
    //return false;
    }
    //  always read/write.  The two are exclusive and can't co-exist.  
    if (//	Set Instance Attributes and dialog controls
    !m_productWindow || !m_productASI) {
        if (// Instance attributes possible.  Set up controls.
        !m_productASI) {
            //	New/Edit - Selection
            if (//	new
            m_M_AttributeSetInstance_ID == 0)
                cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "NewRecord"));
            else
                cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "EditRecord"));
            cbNewEdit.addActionListener(this);
            centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
            bSelect.setText(Msg.getMsg(Env.getCtx(), "SelectExisting"));
            bSelect.addActionListener(this);
            centerPanel.add(bSelect, null);
        }
        //	Add the Instance Attributes if any.  If its a product attribute set
        //  this will do nothing.
        MAttribute[] attributes = as.getMAttributes(true);
        log.fine("Instance Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], false, false);
    }
    if (as != null) {
        //  Product attributes can be shown in any window but are read/write in the Product window only.
        //  This will do nothing if it is an instance attribute set. 
        // False = product attribute instances
        MAttribute[] attributes = as.getMAttributes(false);
        log.fine("Product Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], true, !m_productWindow);
    }
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Lot"));
        label.setLabelFor(fieldLotString);
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldLotString, null);
        fieldLotString.setText(m_masi.getLot());
        //	M_Lot_ID
        //	int AD_Column_ID = 9771;	//	M_AttributeSetInstance.M_Lot_ID
        //	fieldLot = new VLookup ("M_Lot_ID", false,false, true, 
        //		MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
        String sql = "SELECT M_Lot_ID, Name " + "FROM M_Lot l " + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p " + "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID() + " AND p.M_Product_ID=l.M_Product_ID)";
        fieldLot = new CComboBox(DB.getKeyNamePairs(sql, true));
        label = new CLabel(Msg.translate(Env.getCtx(), "M_Lot_ID"));
        label.setLabelFor(fieldLot);
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldLot, null);
        if (m_masi.getM_Lot_ID() != 0) {
            for (int i = 1; i < fieldLot.getItemCount(); i++) {
                KeyNamePair pp = (KeyNamePair) fieldLot.getItemAt(i);
                if (pp.getKey() == m_masi.getM_Lot_ID()) {
                    fieldLot.setSelectedIndex(i);
                    fieldLotString.setEditable(false);
                    break;
                }
            }
        }
        fieldLot.addActionListener(this);
        //	New Lot Button
        if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0 && m_readWrite) {
            if (MRole.getDefault().isTableAccess(MLot.Table_ID, false) && MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false) && !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                centerPanel.add(bLot, null);
                bLot.addActionListener(this);
            }
        }
        //	Popup 
        //  popup
        fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));
        mZoom = new CMenuItem(Msg.getMsg(Env.getCtx(), "Zoom"), Env.getImageIcon("Zoom16.gif"));
        mZoom.addActionListener(this);
        popupMenu.add(mZoom);
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "SerNo"));
        label.setLabelFor(fieldSerNo);
        fieldSerNo.setText(m_masi.getSerNo());
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldSerNo, null);
        //	New SerNo Button
        if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0 && m_readWrite) {
            if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                centerPanel.add(bSerNo, null);
                bSerNo.addActionListener(this);
            }
        }
    }
    //	GuaranteeDate
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "GuaranteeDate"));
        label.setLabelFor(fieldGuaranteeDate);
        if (m_M_AttributeSetInstance_ID == 0)
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
        else
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldGuaranteeDate, null);
    }
    if (m_row == 0) {
        ADialog.error(m_WindowNo, this, "PAttributeNoInfo");
    //return false;
    }
    //	New/Edit Window
    if ((!m_productWindow || !m_productASI) && m_AD_Column_ID != 0 && m_readWrite) {
        cbNewEdit.setSelected(m_M_AttributeSetInstance_ID == 0);
        cmd_newEdit();
    }
    //	Attribute Set Instance Description
    CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Description"));
    label.setLabelFor(fieldDescription);
    fieldDescription.setText(m_masi.getDescription());
    fieldDescription.setEditable(false);
    centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
    centerPanel.add(fieldDescription, null);
    //	Window usually to wide (??)
    Dimension dd = centerPanel.getPreferredSize();
    dd.width = Math.min(500, dd.width);
    centerPanel.setPreferredSize(dd);
    return true;
}
Also used : CLabel(org.compiere.swing.CLabel) CComboBox(org.compiere.swing.CComboBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) Dimension(java.awt.Dimension) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) MAttributeSet(org.compiere.model.MAttributeSet) CMenuItem(org.compiere.swing.CMenuItem) KeyNamePair(org.compiere.util.KeyNamePair) MAttribute(org.compiere.model.MAttribute)

Example 2 with CComboBox

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

the class VPAttributeDialog method addAttributeLine.

//	initAttribute
/**
	 * 	Add Attribute Line
	 *	@param attribute attribute
	 * 	@param product product level attribute
	 * 	@param readOnly value is read only
	 */
private void addAttributeLine(MAttribute attribute, boolean product, boolean readOnly) {
    log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
    CLabel label = new CLabel(attribute.getName());
    if (product)
        label.setFont(new Font(label.getFont().getFontName(), Font.BOLD, label.getFont().getSize()));
    if (attribute.getDescription() != null)
        label.setToolTipText(attribute.getDescription());
    centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
    //
    MAttributeInstance instance = attribute.getMAttributeInstance(m_M_AttributeSetInstance_ID);
    if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
        //	optional = null
        MAttributeValue[] values = attribute.getMAttributeValues();
        CComboBox editor = new CComboBox(values);
        boolean found = false;
        if (instance != null) {
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null && values[i].getM_AttributeValue_ID() == instance.getM_AttributeValue_ID()) {
                    editor.setSelectedIndex(i);
                    found = true;
                    break;
                }
            }
            if (found)
                log.fine("Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
            else
                log.warning("Attribute=" + attribute.getName() + " #" + values.length + " - NOT found: " + instance);
        } else
            //	setComboBox
            log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
        VNumber editor = new VNumber(attribute.getName(), attribute.isMandatory(), readOnly, !readOnly, DisplayType.Number, attribute.getName());
        if (instance != null)
            editor.setValue(instance.getValueNumber());
        else
            editor.setValue(Env.ZERO);
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    } else //	Text Field
    {
        VString editor = new VString(attribute.getName(), attribute.isMandatory(), false, true, 20, INSTANCE_VALUE_LENGTH, null, null);
        if (instance != null)
            editor.setText(instance.getValue());
        label.setLabelFor(editor);
        centerPanel.add(editor, null);
        if (readOnly)
            editor.setEnabled(false);
        else
            m_editors.add(editor);
    }
}
Also used : CLabel(org.compiere.swing.CLabel) MAttributeInstance(org.compiere.model.MAttributeInstance) CComboBox(org.compiere.swing.CComboBox) MAttributeValue(org.compiere.model.MAttributeValue) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) Font(java.awt.Font) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 3 with CComboBox

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

the class PreviewPanel method setupPreview.

/**
	 * Create the preview UI components 
	 */
private void setupPreview() {
    JRootPane rootPane = new JRootPane();
    previewPanel.setLayout(new BorderLayout());
    previewPanel.add(rootPane, BorderLayout.CENTER);
    previewPanel.setBorder(BorderFactory.createLineBorder(AdempierePLAF.getSecondary1(), 1));
    GridLayout gridLayout = new GridLayout(1, 3);
    gridLayout.setHgap(4);
    rootPane.getContentPane().setLayout(gridLayout);
    rootPane.setGlassPane(new GlassPane());
    rootPane.getGlassPane().setVisible(true);
    CPanel column1 = new CPanel();
    rootPane.getContentPane().add(column1);
    CPanel column2 = new CPanel();
    rootPane.getContentPane().add(column2);
    CPanel column3 = new CPanel();
    rootPane.getContentPane().add(column3);
    column1.setLayout(new GridBagLayout());
    JTree jtree = new JTree();
    jtree.setFocusable(false);
    jtree.setBorder(BorderFactory.createLineBorder(AdempierePLAF.getSecondary1(), 1));
    column1.add(jtree, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 2, 2), 0, 0));
    CTextField normal = new CTextField("Text Field");
    normal.setFocusable(false);
    column1.add(normal, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 5, 5, 2), 0, 0));
    error.setBackground(true);
    error.setFocusable(false);
    column1.add(error, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 5, 2), 0, 0));
    column2.setLayout(new GridBagLayout());
    JTable jtable = new JTable(s_data, s_columns);
    JScrollPane scrollPane = new JScrollPane(jtable);
    jtable.setFocusable(false);
    scrollPane.setPreferredSize(jtable.getPreferredSize());
    column2.add(scrollPane, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 2, 2, 2), 0, 0));
    mandatory.setMandatory(true);
    mandatory.setFocusable(false);
    column2.add(mandatory, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 5, 2), 0, 0));
    CTextField inactive = new CTextField(s_res.getString("Inactive"));
    inactive.setEnabled(false);
    column2.add(inactive, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 5, 2), 0, 0));
    column3.setLayout(new GridBagLayout());
    CTabbedPane tab = new CTabbedPane();
    column3.add(tab, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 2, 2, 5), 0, 0));
    CComboBox editable = new CComboBox(new Object[] { "Editable" });
    editable.setEditable(true);
    editable.setFocusable(false);
    column3.add(editable, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 5, 2), 0, 0));
    CComboBox choice = new CComboBox(new Object[] { "Choice" });
    choice.setEditable(false);
    choice.setFocusable(false);
    column3.add(choice, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 5, 5), 0, 0));
    tabPage1.setLayout(new BoxLayout(tabPage1, BoxLayout.Y_AXIS));
    JRadioButton radio = new JRadioButton("Radio");
    radio.setSelected(true);
    radio.setMargin(new Insets(5, 5, 5, 5));
    radio.setFocusable(false);
    radio.setOpaque(false);
    tabPage1.add(radio);
    CCheckBox checkBox = new CCheckBox("Checkbox");
    checkBox.setSelected(true);
    checkBox.setMargin(new Insets(5, 5, 5, 5));
    checkBox.setFocusable(false);
    tabPage1.add(checkBox);
    CLabel label = new CLabel("Label");
    label.setHorizontalAlignment(JLabel.LEFT);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    tabPage1.add(label);
    button.setMargin(new Insets(5, 5, 5, 5));
    button.setFocusable(false);
    tabPage1.add(button);
    tab.add(tabPage1, "tab1");
    tab.add(new CPanel(), "tab2");
}
Also used : JScrollPane(javax.swing.JScrollPane) CLabel(org.compiere.swing.CLabel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) CComboBox(org.compiere.swing.CComboBox) CTextField(org.compiere.swing.CTextField) BoxLayout(javax.swing.BoxLayout) CPanel(org.compiere.swing.CPanel) CTabbedPane(org.compiere.swing.CTabbedPane) GridLayout(java.awt.GridLayout) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) CCheckBox(org.compiere.swing.CCheckBox) JRootPane(javax.swing.JRootPane)

Example 4 with CComboBox

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

the class WFPanel method loadPanel.

//	dispose
/**
	 * 	Workflow Add & Load Panel
	 */
private void loadPanel() {
    String sql = MRole.getDefault().addAccessSQL("SELECT AD_Workflow_ID, Name FROM AD_Workflow " + (!Util.isEmpty(m_WF_whereClause, true) ? " WHERE " + m_WF_whereClause : "") + " ORDER BY 2", "AD_Workflow", MRole.SQL_NOTQUALIFIED, //	all
    MRole.SQL_RO);
    KeyNamePair[] pp = DB.getKeyNamePairs(sql, true);
    //
    workflow = new CComboBox(pp);
    AutoCompletion.enable(workflow);
    loadPanel.add(workflow);
    workflow.addActionListener(this);
    //
    loadPanel.add(bIgnore);
    bIgnore.addActionListener(this);
    loadPanel.add(bResetLayout);
    bResetLayout.addActionListener(this);
    loadPanel.add(bSaveLayout);
    bSaveLayout.addActionListener(this);
    loadPanel.add(bZoom);
    bZoom.addActionListener(this);
}
Also used : CComboBox(org.compiere.swing.CComboBox) KeyNamePair(org.compiere.util.KeyNamePair)

Example 5 with CComboBox

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

the class VAttributeGrid method init.

/**
	 * 	Init
	 *	@param WindowNo
	 *	@param frame
	 */
public void init(int WindowNo, FormFrame frame) {
    m_WindowNo = WindowNo;
    m_frame = frame;
    //	Layout
    frame.getContentPane().add(this, BorderLayout.CENTER);
    this.setLayout(new BorderLayout());
    this.add(tabbedPane, BorderLayout.CENTER);
    this.add(confirmPanel, BorderLayout.SOUTH);
    tabbedPane.addChangeListener(this);
    confirmPanel.addActionListener(this);
    //
    tabbedPane.add(selectPanel, Msg.getMsg(Env.getCtx(), "Selection"));
    selectPanel.add(attributeLabel1, new ALayoutConstraint(0, 0));
    m_attributes = MAttribute.getOfClient(Env.getCtx(), true, true);
    Vector<KeyNamePair> vector = new Vector<KeyNamePair>();
    vector.add(new KeyNamePair(0, ""));
    for (int i = 0; i < m_attributes.length; i++) vector.add(m_attributes[i].getKeyNamePair());
    attributeCombo1 = new CComboBox(vector);
    selectPanel.add(attributeCombo1, null);
    selectPanel.add(attributeLabel2, new ALayoutConstraint(1, 0));
    attributeCombo2 = new CComboBox(vector);
    selectPanel.add(attributeCombo2, null);
    //
    fillPicks();
    selectPanel.add(labelPriceList, new ALayoutConstraint(2, 0));
    selectPanel.add(pickPriceList);
    selectPanel.add(labelWarehouse, new ALayoutConstraint(3, 0));
    selectPanel.add(pickWarehouse);
    //
    selectPanel.setPreferredSize(new Dimension(300, 200));
    //
    //	Grid
    tabbedPane.add(gridPanel, "AttributeGrid");
    modePanel.add(modeLabel);
    modePanel.add(modeCombo);
    modeCombo.addActionListener(this);
}
Also used : BorderLayout(java.awt.BorderLayout) CComboBox(org.compiere.swing.CComboBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) KeyNamePair(org.compiere.util.KeyNamePair) Dimension(java.awt.Dimension) Vector(java.util.Vector) 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