Search in sources :

Example 56 with ValueNamePair

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

the class VLookupAutoCompleter method fetchUserObject.

@Override
protected Object fetchUserObject(ResultSet rs) throws SQLException {
    final boolean isNumber = lookup.getColumnName().endsWith("_ID");
    String name = rs.getString(3);
    if (isNumber) {
        int key = rs.getInt(1);
        KeyNamePair p = new KeyNamePair(key, name);
        return p;
    } else {
        String value = rs.getString(2);
        ValueNamePair p = new ValueNamePair(value, name);
        return p;
    }
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

Example 57 with ValueNamePair

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

the class VLookup method actionZoom.

//	actionBPartner
/**
	 *	Action - Zoom
	 *	@param selectedItem item
	 */
private void actionZoom(Object selectedItem) {
    if (m_lookup == null)
        return;
    //
    MQuery zoomQuery = m_lookup.getZoomQuery();
    Object value = getValue();
    if (value == null)
        value = selectedItem;
    //	If not already exist or exact value
    if (zoomQuery == null || value != null) {
        //	ColumnName might be changed in MTab.validateQuery
        zoomQuery = new MQuery();
        String keyTableName = null;
        String keyColumnName = null;
        //	Check if it is a Table Reference
        if (m_lookup != null && m_lookup instanceof MLookup) {
            int AD_Reference_ID = ((MLookup) m_lookup).getAD_Reference_Value_ID();
            if (DisplayType.List == m_lookup.getDisplayType()) {
                keyColumnName = "AD_Ref_List_ID";
                keyTableName = "AD_Ref_List";
                value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
            } else {
                if (AD_Reference_ID != 0) {
                    String query = "SELECT kc.ColumnName, kt.TableName" + " FROM AD_Ref_Table rt" + " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" + " INNER JOIN AD_Table kt ON (rt.AD_Table_ID=kt.AD_Table_ID)" + " WHERE rt.AD_Reference_ID=?";
                    PreparedStatement pstmt = null;
                    ResultSet rs = null;
                    try {
                        pstmt = DB.prepareStatement(query, null);
                        pstmt.setInt(1, AD_Reference_ID);
                        rs = pstmt.executeQuery();
                        if (rs.next()) {
                            keyColumnName = rs.getString(1);
                            keyTableName = rs.getString(2);
                        }
                    } catch (Exception e) {
                        log.log(Level.SEVERE, query, e);
                    } finally {
                        DB.close(rs, pstmt);
                        rs = null;
                        pstmt = null;
                    }
                }
            //	Table Reference
            }
        }
        if (keyColumnName != null && keyColumnName.length() != 0) {
            zoomQuery.addRestriction(keyColumnName, MQuery.EQUAL, value);
            zoomQuery.setZoomColumnName(keyColumnName);
            zoomQuery.setZoomTableName(keyTableName);
        } else {
            zoomQuery.addRestriction(m_columnName, MQuery.EQUAL, value);
            if (m_columnName.indexOf(".") > 0) {
                zoomQuery.setZoomColumnName(m_columnName.substring(m_columnName.indexOf(".") + 1));
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.indexOf(".")));
            } else {
                zoomQuery.setZoomColumnName(m_columnName);
                //remove _ID to get table name
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.length() - 3));
            }
        }
        zoomQuery.setZoomValue(value);
        //	guess
        zoomQuery.setRecordCount(1);
    }
    int AD_Window_ID = m_lookup.getZoom(zoomQuery);
    //
    log.info(m_columnName + " - AD_Window_ID=" + AD_Window_ID + " - Query=" + zoomQuery + " - Value=" + value);
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    //
    AWindow frame = new AWindow(getGraphicsConfiguration());
    if (!frame.initWindow(AD_Window_ID, zoomQuery, false)) {
        setCursor(Cursor.getDefaultCursor());
        ValueNamePair pp = CLogger.retrieveError();
        String msg = pp == null ? "AccessTableNoView" : pp.getValue();
        ADialog.error(m_lookup.getWindowNo(), this, msg, pp == null ? "" : pp.getName());
    } else {
        AEnv.addToWindowManager(frame);
        if (Ini.isPropertyBool(Ini.P_OPEN_WINDOW_MAXIMIZED)) {
            AEnv.showMaximized(frame);
        } else {
            AEnv.showCenterScreen(frame);
        }
    }
    //  async window - not able to get feedback
    frame = null;
    //
    setCursor(Cursor.getDefaultCursor());
}
Also used : AWindow(org.compiere.apps.AWindow) MLookup(org.compiere.model.MLookup) ResultSet(java.sql.ResultSet) MQuery(org.compiere.model.MQuery) PreparedStatement(java.sql.PreparedStatement) ValueNamePair(org.compiere.util.ValueNamePair) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 58 with ValueNamePair

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

the class WCollectDetail method loadCreditPanel.

/**
	 * Load Credit Panel
	 * @return void
	 */
public void loadCreditPanel() {
    v_CreditPanel = GridFactory.newGridLayout();
    v_CreditPanel.setWidth("100%");
    v_CreditPanel.setHeight("175px");
    Rows rows = v_CreditPanel.newRows();
    Row row = rows.newRow();
    row.setStyle("303px");
    //C_Payment_v.TenderType
    int AD_Column_ID = 8374;
    MLookup cardlookup = MLookupFactory.get(Env.getCtx(), 0, 0, AD_Column_ID, DisplayType.List);
    ArrayList<Object> cards = cardlookup.getData(true, false, true, true);
    row = rows.newRow();
    fCCardType = ListboxFactory.newDropdownListbox();
    row.appendChild(fCCardType);
    fCCardType.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    fCCardType.setValue(Msg.translate(p_ctx, "CreditCardType"));
    fCCardType.addActionListener(this);
    /**
		 *	Load Credit Cards
		 */
    for (Object obj : cards) {
        if (obj instanceof ValueNamePair) {
            ValueNamePair key = (ValueNamePair) obj;
            fCCardType.appendItem(key.getName(), key.getID());
        }
    }
    row.setSpans("1,2");
    fCCardNo = new WPOSTextField(Msg.translate(p_ctx, "CreditCardNumber"), keyboard);
    fCCardNo.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    row.appendChild(fCCardNo);
    fCCardNo.addEventListener("onFocus", this);
    fCCardName = new WPOSTextField(Msg.translate(p_ctx, "Name"), keyboard);
    row = rows.newRow();
    row.appendChild(fCCardName);
    fCCardName.setStyle(HEIGHT + WIDTH + FONT_SIZE);
    fCCardName.addEventListener("onFocus", this);
    //	For Card Month
    fCreditCardExpMM = ListboxFactory.newDropdownListbox();
    ValueNamePair[] data = getCCMonths();
    for (ValueNamePair pp : data) {
        fCreditCardExpMM.appendItem(String.valueOf(pp.getName()), pp.getID());
        fCreditCardExpMM.setName(String.valueOf(pp.getID()));
    }
    fCreditCardExpMM.setName("CreditCardExpMM");
    fCreditCardExpMM.addActionListener(this);
    fCreditCardExpMM.setStyle(HEIGHT + "width:" + 75 + "px;" + FONT_SIZE);
    //	For Card Year
    fCreditCardExpYY = ListboxFactory.newDropdownListbox();
    data = getCCYears();
    for (ValueNamePair pp : data) {
        fCreditCardExpYY.appendItem(String.valueOf(pp.getName()), pp.getID());
        fCreditCardExpYY.setName(String.valueOf(pp.getID()));
    }
    fCreditCardExpYY.setName("CreditCardExpYY");
    fCreditCardExpYY.addActionListener(this);
    fCreditCardExpYY.setStyle("margin: 0px 50px 0px 0px;" + HEIGHT + "width:" + 60 + "px;" + FONT_SIZE);
    //	For Card VV
    row.appendChild(fCreditCardExpMM);
    row.appendChild(fCreditCardExpYY);
    fCCardVC = new WPOSTextField(Msg.translate(p_ctx, "CVC"), keyboard);
    row = rows.newRow();
    row.appendChild(fCCardVC);
    fCCardVC.addEventListener("onFocus", this);
    fCCardVC.setStyle(HEIGHT + WIDTH + FONT_SIZE);
}
Also used : MLookup(org.compiere.model.MLookup) Row(org.adempiere.webui.component.Row) ValueNamePair(org.compiere.util.ValueNamePair) Rows(org.adempiere.webui.component.Rows)

Example 59 with ValueNamePair

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

the class WWFActivity method display.

//	resetDisplay
/**
	 * 	Display.
	 * 	Fill Editors
	 */
public void display(int index) {
    log.fine("Index=" + index);
    //
    m_activity = resetDisplay(index);
    //	Nothing to show
    if (m_activity == null) {
        return;
    }
    //	Display Activity
    fNode.setText(m_activity.getNodeName());
    fDescription.setValue(m_activity.getNodeDescription());
    fHelp.setValue(m_activity.getNodeHelp());
    //
    fHistory.setContent(HISTORY_DIV_START_TAG + m_activity.getHistoryHTML() + "</div>");
    //	User Actions
    MWFNode node = m_activity.getNode();
    if (MWFNode.ACTION_UserChoice.equals(node.getAction())) {
        if (m_column == null)
            m_column = node.getColumn();
        if (m_column != null && m_column.get_ID() != 0) {
            fAnswerList.removeAllItems();
            int dt = m_column.getAD_Reference_ID();
            if (dt == DisplayType.YesNo) {
                //	_YesNo
                ValueNamePair[] values = MRefList.getList(Env.getCtx(), 319, false);
                for (int i = 0; i < values.length; i++) {
                    fAnswerList.appendItem(values[i].getName(), values[i].getValue());
                }
                fAnswerList.setVisible(true);
            } else if (dt == DisplayType.List) {
                ValueNamePair[] values = MRefList.getList(Env.getCtx(), m_column.getAD_Reference_Value_ID(), false);
                for (int i = 0; i < values.length; i++) {
                    fAnswerList.appendItem(values[i].getName(), values[i].getValue());
                }
                fAnswerList.setVisible(true);
            } else //	other display types come here
            {
                fAnswerText.setText("");
                fAnswerText.setVisible(true);
            }
        }
    } else //	--
    if (MWFNode.ACTION_UserWindow.equals(node.getAction()) || MWFNode.ACTION_UserForm.equals(node.getAction())) {
        fAnswerButton.setLabel(node.getName());
        fAnswerButton.setTooltiptext(node.getDescription());
        fAnswerButton.setVisible(true);
    } else
        log.log(Level.SEVERE, "Unknown Node Action: " + node.getAction());
    statusBar.setStatusDB((m_index + 1) + "/" + m_activities.length);
    statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "WFActivities"));
}
Also used : MWFNode(org.compiere.wf.MWFNode) ValueNamePair(org.compiere.util.ValueNamePair)

Example 60 with ValueNamePair

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

the class PP_Product_BOM_Check method raiseError.

// doIt
private void raiseError(String string, String hint) throws Exception {
    DB.rollback(false, get_TrxName());
    // parent
    MProduct xp = new MProduct(getCtx(), p_Record_ID, null);
    // set BOM not verified
    xp.setIsVerified(false);
    xp.saveEx();
    String msg = string;
    ValueNamePair pp = CLogger.retrieveError();
    if (pp != null)
        msg = pp.getName() + " - ";
    msg += hint;
    throw new AdempiereUserError(msg);
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereUserError(org.compiere.util.AdempiereUserError) ValueNamePair(org.compiere.util.ValueNamePair)

Aggregations

ValueNamePair (org.compiere.util.ValueNamePair)109 KeyNamePair (org.compiere.util.KeyNamePair)35 SQLException (java.sql.SQLException)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)19 Timestamp (java.sql.Timestamp)9 GridField (org.compiere.model.GridField)7 BigDecimal (java.math.BigDecimal)5 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)5 MetalTheme (javax.swing.plaf.metal.MetalTheme)5 MInvoice (org.compiere.model.MInvoice)5 MLookup (org.compiere.model.MLookup)5 MLookupInfo (org.compiere.model.MLookupInfo)5 HRPayPrint (org.eevolution.service.HRPayPrint)5 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)4 ListItem (org.adempiere.webui.component.ListItem)4 MCashLine (org.compiere.model.MCashLine)4 AdempiereUserError (org.compiere.util.AdempiereUserError)4 NamePair (org.compiere.util.NamePair)4