Search in sources :

Example 11 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WFEditor method onEvent.

@Override
public void onEvent(Event event) throws Exception {
    if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
        this.detach();
    else if (event.getTarget().getId().equals(ConfirmPanel.A_OK))
        this.detach();
    else if (event.getTarget() == workflowList) {
        ListItem item = workflowList.getSelectedItem();
        KeyNamePair knp = item != null ? item.toKeyNamePair() : null;
        if (knp != null && knp.getKey() > 0) {
            load(knp.getKey());
        } else {
            Image dummy = null;
            imageMap.setContent(dummy);
        }
    }
}
Also used : ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) AImage(org.zkoss.image.AImage) BufferedImage(java.awt.image.BufferedImage) Image(org.zkoss.image.Image)

Example 12 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WPAttributeDialog method initAttributes.

//	init
/**
	 *	Dyanmic Init.
	 *  @return true if initialized
	 */
private boolean initAttributes() {
    Rows rows = new Rows();
    rows.setParent(centerLayout);
    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) {
        FDialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
        return false;
    }
    //  always read/write.  The two are exclusive and can't co-exists.  
    if (//	Set Instance Attributes and dialog controls
    !m_productWindow || !m_productASI) {
        if (// Instance attributes possible.  Set up controls.
        !m_productASI) {
            Row row = new Row();
            //	New/Edit - Selection
            if (//	new
            m_M_AttributeSetInstance_ID == 0)
                cbNewEdit.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "NewRecord")));
            else
                cbNewEdit.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "EditRecord")));
            cbNewEdit.addEventListener(Events.ON_CHECK, this);
            row.appendChild(cbNewEdit);
            bSelect.setLabel(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "SelectExisting")));
            bSelect.setImage(ServletFns.resolveThemeURL("~./images/PAttribute16.png"));
            bSelect.addEventListener(Events.ON_CLICK, this);
            row.appendChild(bSelect);
            rows.appendChild(row);
        }
        //	Add the Instance Attributes if any.  If its a product attribute set
        //  this will do nothing.
        // True = Instances
        MAttribute[] attributes = as.getMAttributes(true);
        log.fine("Instance Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(rows, attributes[i], false, false);
    }
    //  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 = products
    MAttribute[] attributes = as.getMAttributes(false);
    log.fine("Product Attributes=" + attributes.length);
    for (int i = 0; i < attributes.length; i++) addAttributeLine(rows, attributes[i], true, !m_productWindow);
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "Lot")));
        row.appendChild(label);
        row.appendChild(fieldLotString);
        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 Listbox();
        fieldLot.setMold("select");
        KeyNamePair[] keyNamePairs = DB.getKeyNamePairs(sql, true);
        for (KeyNamePair pair : keyNamePairs) {
            fieldLot.appendItem(pair.getName(), pair.getKey());
        }
        label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "M_Lot_ID")));
        row = new Row();
        row.setParent(rows);
        m_row++;
        row.appendChild(label);
        row.appendChild(fieldLot);
        if (m_masi.getM_Lot_ID() != 0) {
            for (int i = 1; i < fieldLot.getItemCount(); i++) {
                ListItem pp = fieldLot.getItemAtIndex(i);
                if ((Integer) pp.getValue() == m_masi.getM_Lot_ID()) {
                    fieldLot.setSelectedIndex(i);
                    fieldLotString.setReadonly(true);
                    break;
                }
            }
        }
        fieldLot.addEventListener(Events.ON_SELECT, this);
        //	New Lot Button
        if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0) {
            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))) {
                row = new Row();
                row.setParent(rows);
                m_row++;
                row.appendChild(bLot);
                bLot.addEventListener(Events.ON_CLICK, this);
            }
        }
        //	Popup 
        //			fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));    //  popup
        mZoom = new Menuitem(Msg.getMsg(Env.getCtx(), "Zoom"), ServletFns.resolveThemeURL("~./images/Zoom16.png"));
        mZoom.addEventListener(Events.ON_CLICK, this);
        popupMenu.appendChild(mZoom);
        this.appendChild(popupMenu);
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "SerNo")));
        row.appendChild(label);
        row.appendChild(fieldSerNo);
        fieldSerNo.setText(m_masi.getSerNo());
        //	New SerNo Button
        if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0) {
            if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                row = new Row();
                row.setParent(rows);
                m_row++;
                row.appendChild(bSerNo);
                bSerNo.addEventListener(Events.ON_CLICK, this);
            }
        }
    }
    //	GuaranteeDate
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        Row row = new Row();
        row.setParent(rows);
        m_row++;
        Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "GuaranteeDate")));
        if (m_M_AttributeSetInstance_ID == 0)
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
        else
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
        row.appendChild(label);
        row.appendChild(fieldGuaranteeDate);
    }
    if (m_row == 0) {
        FDialog.error(m_WindowNo, this, "PAttributeNoInfo");
        return false;
    }
    //	New/Edit Window
    if (!m_productWindow) {
        cbNewEdit.setChecked(m_M_AttributeSetInstance_ID == 0);
        cmd_newEdit();
    }
    //	Attrribute Set Instance Description
    Label label = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "Description")));
    //		label.setLabelFor(fieldDescription);
    fieldDescription.setText(m_masi.getDescription());
    fieldDescription.setReadonly(true);
    Row row = new Row();
    row.setParent(rows);
    row.appendChild(label);
    row.appendChild(fieldDescription);
    return true;
}
Also used : Label(org.adempiere.webui.component.Label) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MAttributeSet(org.compiere.model.MAttributeSet) Menuitem(org.zkoss.zul.Menuitem) Row(org.adempiere.webui.component.Row) KeyNamePair(org.compiere.util.KeyNamePair) ListItem(org.adempiere.webui.component.ListItem) Listbox(org.adempiere.webui.component.Listbox) Rows(org.adempiere.webui.component.Rows) MAttribute(org.compiere.model.MAttribute)

Example 13 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WPAttributeDialog method onEvent.

//	dispose
public void onEvent(Event e) throws Exception {
    //	Select Instance
    if (e.getTarget() == bSelect) {
        if (cmd_select())
            dispose();
    } else //	New/Edit
    if (e.getTarget() == cbNewEdit) {
        cmd_newEdit();
    } else //	Select Lot from existing
    if (e.getTarget() == fieldLot) {
        ListItem pp = fieldLot.getSelectedItem();
        if (pp != null && (Integer) pp.getValue() != -1) {
            fieldLotString.setText(pp.getLabel());
            fieldLotString.setReadonly(true);
            m_masi.setM_Lot_ID((Integer) pp.getValue());
        } else {
            fieldLotString.setReadonly(false);
            m_masi.setM_Lot_ID(0);
        }
    } else //	Create New Lot
    if (e.getTarget() == bLot) {
        KeyNamePair pp = m_masi.createLot(m_M_Product_ID);
        if (pp != null) {
            ListItem item = new ListItem(pp.getName(), pp.getKey());
            fieldLot.appendChild(item);
            fieldLot.setSelectedItem(item);
            fieldLotString.setText(m_masi.getLot());
            fieldLotString.setReadonly(true);
        }
    } else //	Create New SerNo
    if (e.getTarget() == bSerNo) {
        fieldSerNo.setText(m_masi.getSerNo(true));
    } else //	OK
    if (e.getTarget().getId().equals("Ok")) {
        if (saveSelection())
            dispose();
    } else //	Cancel
    if (e.getTarget().getId().equals("Cancel")) {
        //  in the product window.
        if (m_productWindow || !m_productASI) {
            m_changed = m_M_AttributeSetInstance_ID != 0;
            m_M_AttributeSetInstance_ID = 0;
            m_M_Locator_ID = 0;
        }
        dispose();
    } else //	Zoom M_Lot
    if (e.getTarget() == mZoom) {
        cmd_zoom();
    } else
        log.log(Level.SEVERE, "not found - " + e);
}
Also used : ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair)

Example 14 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WPAttributeInstance method enableButtons.

//	actionPerformed
/**
	 * 	Enable/Set Buttons and set ID
	 */
private void enableButtons() {
    m_M_AttributeSetInstance_ID = -1;
    m_M_AttributeSetInstanceName = null;
    m_M_Locator_ID = 0;
    int row = m_table.getSelectedRow();
    boolean enabled = row != -1;
    if (enabled) {
        Integer ID = m_table.getSelectedRowKey();
        if (ID != null) {
            m_M_AttributeSetInstance_ID = ID.intValue();
            m_M_AttributeSetInstanceName = (String) m_table.getValueAt(row, 1);
            //
            Object oo = m_table.getValueAt(row, 5);
            if (oo instanceof KeyNamePair) {
                KeyNamePair pp = (KeyNamePair) oo;
                m_M_Locator_ID = pp.getKey();
            }
        }
    }
    confirmPanel.getButton("Ok").setEnabled(enabled);
    log.fine("M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + " - " + m_M_AttributeSetInstanceName + "; M_Locator_ID=" + m_M_Locator_ID);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 15 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WAssignmentDialog method onEvent.

//	getResources
public void onEvent(Event e) throws Exception {
    if (m_setting)
        return;
    //	Update Assignment
    ListItem listItem = fResource.getSelectedItem();
    KeyNamePair resource = listItem != null ? new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel()) : null;
    if (resource != null) {
        int S_Resource_ID = resource.getKey();
        m_mAssignment.setS_Resource_ID(S_Resource_ID);
    }
    Calendar date = new GregorianCalendar();
    getDateAndTimeFrom(date);
    Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis());
    if (assignDateFrom != null)
        m_mAssignment.setAssignDateFrom(assignDateFrom);
    if (fQty.getValue() != null) {
        BigDecimal qty = fQty.getValue();
        m_mAssignment.setQty(qty);
    }
    m_mAssignment.setName((String) fName.getValue());
    m_mAssignment.setDescription((String) fDescription.getValue());
    //	Resource - Look up UOM
    if (e.getTarget() == fResource) {
        Object o = m_lookup.get(resource);
        if (o == null)
            lUOM.setValue(" ? ");
        else
            lUOM.setValue(o.toString());
    } else //	Zoom - InfoResource
    if (e.getTarget().getId().equals("Zoom")) {
        InfoSchedule is = new InfoSchedule(m_mAssignment, true);
        if (is.getMResourceAssignment() != null) {
            m_mAssignment = is.getMResourceAssignment();
            //	setDisplay();
            detach();
        }
        is = null;
    } else //	cancel - return
    if (e.getTarget().getId().equals("Cancel")) {
        m_cancel = true;
        detach();
    } else //	delete - delete and return
    if (e.getTarget().getId().equals("Delete")) {
        if (m_mAssignment.delete(true)) {
            m_mAssignment = null;
            detach();
        } else
            FDialog.error(0, this, "ResourceAssignmentNotDeleted");
    } else //	OK - Save
    if (e.getTarget().getId().equals("Ok")) {
        if (cmd_save())
            detach();
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7