Search in sources :

Example 81 with ValueNamePair

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

the class Find method codeUserQuery.

//	actionPerformed
/**
     * Code the query parameters entered in the table into a string that can be saved in the database.
     * This is the counterpart to {@link #parseUserQuery()}. 
     * @return a StringBuffer containing the coded query information.
     */
private StringBuffer codeUserQuery() {
    advancedTable.stopEditor(true);
    m_query = new MQuery(m_tableName);
    m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
    StringBuffer code = new StringBuffer();
    int openBrackets = 0;
    for (int row = 0; row < advancedTable.getRowCount(); row++) {
        //	Column
        Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME);
        if (column == null)
            continue;
        String ColumnName = column instanceof ValueNamePair ? ((ValueNamePair) column).getValue() : column.toString();
        String infoName = column.toString();
        //
        GridField field = getTargetMField(ColumnName);
        if (field == null)
            continue;
        boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
        String ColumnSQL = field.getColumnSQL(false);
        String lBrackets = (String) advancedTable.getValueAt(row, INDEX_LEFTBRACKET);
        if (lBrackets != null)
            openBrackets += lBrackets.length();
        String rBrackets = (String) advancedTable.getValueAt(row, INDEX_RIGHTBRACKET);
        if (rBrackets != null)
            openBrackets -= rBrackets.length();
        boolean and = true;
        if (row > 0)
            and = !"OR".equals((String) advancedTable.getValueAt(row, INDEX_ANDOR));
        //	Op
        Object op = advancedTable.getValueAt(row, INDEX_OPERATOR);
        if (op == null)
            continue;
        String Operator = ((ValueNamePair) op).getValue();
        //	Value	******
        Object value = advancedTable.getValueAt(row, INDEX_VALUE);
        if (value == null) {
            if (MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op)) {
                m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets);
                if (code.length() > 0)
                    code.append(SEGMENT_SEPARATOR);
                code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
            } else {
                continue;
            }
        } else {
            Object parsedValue = parseValue(field, value);
            if (parsedValue == null)
                continue;
            String infoDisplay = value.toString();
            if (field.isLookup())
                infoDisplay = field.getLookup().getDisplay(value);
            else if (field.getDisplayType() == DisplayType.YesNo)
                infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay);
            //	Value2	******
            Object value2 = null;
            if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op)) {
                value2 = advancedTable.getValueAt(row, INDEX_VALUE2);
                if (value2 == null)
                    continue;
                Object parsedValue2 = parseValue(field, value2);
                String infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, infoName, infoDisplay, infoDisplay_to, and, openBrackets);
            } else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
                if (!(parsedValue instanceof Integer)) {
                    continue;
                }
                m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
            } else
                m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets);
            if (code.length() > 0)
                code.append(SEGMENT_SEPARATOR);
            code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append(value.toString()).append(FIELD_SEPARATOR).append(value2 != null ? value2.toString() : "").append(FIELD_SEPARATOR).append(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
        }
    }
    return code;
}
Also used : MQuery(org.compiere.model.MQuery) ValueNamePair(org.compiere.util.ValueNamePair) GridField(org.compiere.model.GridField)

Example 82 with ValueNamePair

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

the class VTranslationDialog method actionPerformed.

//	dispose
/**************************************************************************
	 * 	Action Listener
	 * 	@param e event
	 */
public void actionPerformed(ActionEvent e) {
    ValueNamePair AD_Language = (ValueNamePair) cbLanguage.getSelectedItem();
    if (AD_Language == null) {
        statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "LanguageSetupError"), true);
        return;
    }
    ValueNamePair AD_Table = (ValueNamePair) cbTable.getSelectedItem();
    if (AD_Table == null)
        return;
    boolean imp = (e.getSource() == bImport);
    KeyNamePair AD_Client = (KeyNamePair) cbClient.getSelectedItem();
    int AD_Client_ID = -1;
    if (AD_Client != null)
        AD_Client_ID = AD_Client.getKey();
    String startDir = Ini.getAdempiereHome() + File.separator + "data";
    JFileChooser chooser = new JFileChooser(startDir);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnVal = imp ? chooser.showOpenDialog(panel) : chooser.showSaveDialog(panel);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    String directory = chooser.getSelectedFile().getAbsolutePath();
    //
    statusBar.setStatusLine(directory);
    panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    Translation t = new Translation(Env.getCtx());
    String msg = t.validateLanguage(AD_Language.getValue());
    if (msg.length() > 0) {
        ADialog.error(m_WindowNo, panel, "LanguageSetupError", msg);
        return;
    }
    //	All Tables
    if (AD_Table.getValue().equals("")) {
        msg = null;
        for (int i = 1; i < cbTable.getItemCount(); i++) {
            AD_Table = (ValueNamePair) cbTable.getItemAt(i);
            msg = imp ? t.importTrl(directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()) : t.exportTrl(directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
        }
        if (msg == null || msg.length() == 0)
            msg = (imp ? "Import" : "Export") + " Successful. [" + directory + "]";
        statusBar.setStatusLine(directory);
    } else //	single table
    {
        msg = null;
        msg = imp ? t.importTrl(directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue()) : t.exportTrl(directory, AD_Client_ID, AD_Language.getValue(), AD_Table.getValue());
        if (msg == null || msg.length() == 0)
            msg = (imp ? "Import" : "Export") + " Successful. [" + directory + "]";
        statusBar.setStatusLine(msg);
    }
    //
    panel.setCursor(Cursor.getDefaultCursor());
}
Also used : JFileChooser(javax.swing.JFileChooser) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair)

Example 83 with ValueNamePair

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

the class CollectDetail method getCCMonths.

/**
	 * Get Months for Credit Card
	 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com
	 * @return
	 * @return ValueNamePair[]
	 */
protected ValueNamePair[] getCCMonths() {
    //	Populate Month
    ArrayList<ValueNamePair> m_Months = new ArrayList<ValueNamePair>();
    Locale locale = Language.getLoginLanguage().getLocale();
    Calendar cal = Calendar.getInstance();
    for (int i = Calendar.JANUARY; i <= Calendar.DECEMBER; i++) {
        cal.set(1, i, 1);
        String displayName = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale);
        String value = String.format("%02d", i + 1);
        m_Months.add(new ValueNamePair(value, displayName + "-" + value));
    }
    //	Convert to Array
    ValueNamePair[] values = new ValueNamePair[m_Months.size()];
    m_Months.toArray(values);
    //	Return Values
    return values;
}
Also used : Locale(java.util.Locale) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ValueNamePair(org.compiere.util.ValueNamePair)

Example 84 with ValueNamePair

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

the class CollectDetail method getCCYears.

/**
	 * Get Year for Credit Card
	 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com
	 * @return
	 * @return ValueNamePair[]
	 */
protected ValueNamePair[] getCCYears() {
    //	Populate Month
    ArrayList<ValueNamePair> m_Years = new ArrayList<ValueNamePair>();
    Locale locale = Language.getLoginLanguage().getLocale();
    Calendar cal = Calendar.getInstance(locale);
    for (int i = 0; i < 10; i++) {
        //	Seek in new year
        String year = String.valueOf(cal.get(Calendar.YEAR));
        String shortYear = year.substring(2);
        m_Years.add(new ValueNamePair(shortYear, year));
        cal.add(Calendar.YEAR, 1);
    }
    //	Convert to Array
    ValueNamePair[] values = new ValueNamePair[m_Years.size()];
    m_Years.toArray(values);
    //	Return Values
    return values;
}
Also used : Locale(java.util.Locale) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ValueNamePair(org.compiere.util.ValueNamePair)

Example 85 with ValueNamePair

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

the class ADLookup method fillLookupValues.

public static void fillLookupValues(LookupValues lvs, Lookup lookup, boolean isMandatory, boolean isReadOnly) {
    if (lookup.getSize() == 0)
        lookup.refresh();
    Object[] list = lookup.getData(isMandatory, true, !isReadOnly, false).toArray();
    for (int i = 0; i < list.length; i++) {
        boolean isNumber = list[0] instanceof KeyNamePair;
        LookupValue lv = lvs.addNewLv();
        if (isNumber) {
            KeyNamePair p = (KeyNamePair) list[i];
            lv.setKey(Integer.toString(p.getKey()));
            lv.setVal(p.getName());
        } else {
            ValueNamePair p = (ValueNamePair) list[i];
            lv.setKey(p.getValue());
            lv.setVal(p.getName());
        }
    }
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) LookupValue(pl.x3E.adInterface.LookupValue)

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