Search in sources :

Example 1 with Lookup

use of org.compiere.model.Lookup in project adempiere by adempiere.

the class ADServiceImpl method getLookupData.

public WindowTabDataDocument getLookupData(int WindowNo, int TabNo, int RowNo, String columnName) throws XFireFault {
    authenticate(webServiceName, "getLookupData");
    WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
    WindowTabData wd = ret.addNewWindowTabData();
    DataSet ds = wd.addNewDataSet();
    WWindowStatus ws = WWindowStatus.get(WindowStatusMap, WindowNo, true, TabNo, true, RowNo);
    if (ws != null) {
        DataRow dr = ds.addNewDataRow();
        DataField df = dr.addNewField();
        GridField field = ws.curTab.getField(columnName);
        Lookup lookup = field.getLookup();
        df.setColumn(field.getColumnName());
        String lookupValue = null;
        if (field.getValue() != null)
            lookupValue = lookup.getDisplay(field.getValue());
        df.setLval(lookupValue);
        if (field.getValue() != null)
            df.setVal(field.getValue().toString());
        LookupValues lvs = df.addNewLookup();
        ADLookup.fillLookupValues(lvs, lookup, field);
    }
    return ret;
}
Also used : WindowTabDataDocument(pl.x3E.adInterface.WindowTabDataDocument) DataField(pl.x3E.adInterface.DataField) DataSet(pl.x3E.adInterface.DataSet) WindowTabData(pl.x3E.adInterface.WindowTabData) Lookup(org.compiere.model.Lookup) MLookup(org.compiere.model.MLookup) GridField(org.compiere.model.GridField) LookupValues(pl.x3E.adInterface.LookupValues) DataRow(pl.x3E.adInterface.DataRow)

Example 2 with Lookup

use of org.compiere.model.Lookup in project adempiere by adempiere.

the class MRelationType method getDestinationRoleDisplay.

private String getDestinationRoleDisplay() {
    checkDestinationRefId();
    final Integer colIdx;
    final String keyValue;
    if (destinationRefId == getAD_Reference_Source_ID()) {
        colIdx = this.get_ColumnIndex(COLUMNNAME_Role_Source);
        keyValue = getRole_Source();
    } else {
        colIdx = this.get_ColumnIndex(COLUMNNAME_Role_Target);
        keyValue = getRole_Target();
    }
    if (Util.isEmpty(keyValue)) {
        return "";
    }
    final Lookup lookup = this.p_info.getColumnLookup(colIdx);
    return lookup.getDisplay(keyValue);
}
Also used : Lookup(org.compiere.model.Lookup)

Example 3 with Lookup

use of org.compiere.model.Lookup in project adempiere by adempiere.

the class Process method fillParameter.

//	createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
    MPInstance pInstance = new MPInstance(process, 0);
    DataField[] f = dr.getFieldArray();
    HashMap fmap = new HashMap();
    for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
    //
    MPInstancePara[] iParams = pInstance.getParameters();
    for (int pi = 0; pi < iParams.length; pi++) {
        MPInstancePara iPara = iParams[pi];
        String key = iPara.getParameterName();
        MProcessPara pPara = process.getParameter(key);
        if (pPara == null) {
            log.log(Level.SEVERE, "Parameter not found: " + key);
            continue;
        }
        int displayType = pPara.getAD_Reference_ID();
        String valueString = null;
        Object ob = fmap.get(key);
        if (ob != null)
            valueString = ob.toString();
        String valueString2 = null;
        if (pPara.isRange()) {
            ob = fmap.get(key + "_2");
            if (ob != null)
                valueString2 = ob.toString();
        }
        log.fine("fillParameter - " + key + " = " + valueString);
        Object value = valueString;
        if (valueString != null && valueString.length() == 0)
            value = null;
        if (value != null && (DisplayType.List == displayType || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
            value = null;
        //	No Value
        if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
            if (pPara.isMandatory())
                throw new Exception(" Parameter " + pPara.getName() + " is required.");
        } else {
            //	Convert to Type
            try {
                if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
                    BigDecimal bd = null;
                    if (value instanceof BigDecimal)
                        bd = (BigDecimal) value;
                    else if (value instanceof Integer)
                        bd = new BigDecimal(((Integer) value).intValue());
                    else
                        bd = new BigDecimal(value.toString());
                    iPara.setP_Number(bd);
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
                    if (pPara.isRange()) {
                        bd = null;
                        bd = new BigDecimal(valueString2.toString());
                        iPara.setP_Number_To(bd);
                    }
                } else if (DisplayType.isDate(displayType)) {
                    java.util.Date d;
                    if (displayType == DisplayType.DateTime)
                        d = m_cs.dateFormat.parse(value.toString());
                    else
                        // TODO: datetime
                        d = m_cs.dateFormat.parse(value.toString());
                    //d = m_cs.dateTimeFormat.parse(value.toString());
                    Timestamp ts = null;
                    ts = new Timestamp(d.getTime());
                    iPara.setP_Date(ts);
                    if (pPara.isRange()) {
                        if (displayType == DisplayType.DateTime)
                            d = m_cs.dateFormat.parse(valueString2);
                        else //d = m_cs.dateTimeFormat.parse(valueString2);
                        {
                            if (valueString2 == null || valueString2.length() == 0)
                                d = new java.util.Date();
                            else
                                //TODO: datetime
                                d = m_cs.dateFormat.parse(valueString2);
                        }
                        ts = new Timestamp(d.getTime());
                        iPara.setP_Date_To(ts);
                    }
                    log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
                } else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
                    String bv = "N";
                    if (value == null)
                        bv = "N";
                    else //if (value.toString().toLowerCase().charAt(0)=='t')
                    {
                        if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
                            bv = "Y";
                        else
                            bv = "N";
                    }
                    //bv ="Y";
                    iPara.setP_String(bv);
                } else {
                    iPara.setP_String(value.toString());
                }
                if (// kolec - ustawia wartosc dla parametru Lookup
                pPara.isLookup()) {
                    Lookup lok = pPara.getLookup();
                    if (lok != null) {
                        NamePair np = lok.getDirect(value, false, false);
                        if (np != null) {
                            iPara.setInfo(np.getName());
                        }
                    }
                } else {
                    if (value != null)
                        iPara.setInfo(value.toString());
                    if (valueString2 != null)
                        iPara.setInfo_To(valueString2);
                }
                //
                iPara.save();
            } catch (Exception e) {
                log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
            }
        }
    //	not null
    }
    //	instance parameter loop
    // kolec - tego chyba brakowalo
    pInstance.save();
    return pInstance;
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) HashMap(java.util.HashMap) NamePair(org.compiere.util.NamePair) MProcessPara(org.compiere.model.MProcessPara) Timestamp(java.sql.Timestamp) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) MPInstance(org.compiere.model.MPInstance) DataField(pl.x3E.adInterface.DataField) Lookup(org.compiere.model.Lookup)

Example 4 with Lookup

use of org.compiere.model.Lookup in project adempiere by adempiere.

the class Process method getProcessParams.

public static ProcessParamsDocument getProcessParams(CompiereService cs, GetProcessParamsDocument req) throws XFireFault {
    ProcessParamsDocument res = ProcessParamsDocument.Factory.newInstance();
    ProcessParams params = res.addNewProcessParams();
    ProcessParamList PL = params.addNewParams();
    int AD_Menu_ID = req.getGetProcessParams().getADMenuID();
    int AD_Process_ID = req.getGetProcessParams().getADProcessID();
    MProcess process = null;
    if (AD_Menu_ID > 0 && AD_Process_ID == 0)
        process = MProcess.getFromMenu(cs.getM_ctx(), AD_Menu_ID);
    else if (AD_Menu_ID == 0 && AD_Process_ID > 0)
        process = new MProcess(cs.getM_ctx(), AD_Process_ID, null);
    if (process != null) {
        params.setDescription(process.getDescription());
        params.setHelp(process.getHelp());
        params.setName(process.getName());
        params.setADProcessID(process.getAD_Process_ID());
        MProcessPara[] parameter = process.getParameters();
        for (int i = 0; i < parameter.length; i++) {
            MProcessPara para = parameter[i];
            ProcessParam p = PL.addNewParam();
            p.setName(para.getName());
            p.setDescription(para.getDescription());
            p.setDisplayType(para.getAD_Reference_ID());
            p.setIsMandatory(para.isMandatory());
            p.setFieldLength(para.getFieldLength());
            p.setIsRange(para.isRange());
            p.setColumnName(para.getColumnName());
            p.setDefaultValue(para.getDefaultValue());
            p.setDefaultValue2(para.getDefaultValue2());
            if (para.getDefaultValue() != null) {
                if (DisplayType.isDate(para.getAD_Reference_ID())) {
                    if (para.getDefaultValue().indexOf("@#Date@") >= 0) {
                        //Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
                        //String t = Env.getContext( cs.getM_ctx(), "#Date" );
                        String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
                        //cs.dateFormat.format( t ));
                        p.setDefaultValue(t);
                    }
                } else if (DisplayType.YesNo == para.getAD_Reference_ID()) {
                    if ("Y".equalsIgnoreCase(para.getDefaultValue()))
                        p.setDefaultValue("true");
                    else
                        p.setDefaultValue("false");
                }
            } else {
                if (DisplayType.YesNo == para.getAD_Reference_ID())
                    p.setDefaultValue("false");
            }
            if (para.getDefaultValue2() != null) {
                if (DisplayType.isDate(para.getAD_Reference_ID())) {
                    if (para.getDefaultValue2().indexOf("@#Date@") >= 0) {
                        //Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
                        //String t = Env.getContext( cs.getM_ctx(), "#Date" );
                        String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
                        //cs.dateFormat.format( t ) );
                        p.setDefaultValue2(t);
                    }
                }
            }
            if (para.isLookup()) {
                LookupValues lvs = p.addNewLookup();
                Lookup lookup = para.getLookup();
                try {
                    ADLookup.fillLookupValues(lvs, lookup, para.isMandatory(), false);
                } catch (Exception ex) {
                    System.out.println("getProcessParams exception: " + ex.getMessage());
                    ex.printStackTrace();
                }
            }
        }
    }
    return res;
}
Also used : MProcess(org.compiere.model.MProcess) ProcessParams(pl.x3E.adInterface.ProcessParams) GetProcessParamsDocument(pl.x3E.adInterface.GetProcessParamsDocument) ProcessParamsDocument(pl.x3E.adInterface.ProcessParamsDocument) ProcessParamList(pl.x3E.adInterface.ProcessParamList) MProcessPara(org.compiere.model.MProcessPara) Lookup(org.compiere.model.Lookup) LookupValues(pl.x3E.adInterface.LookupValues) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ProcessParam(pl.x3E.adInterface.ProcessParam) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 5 with Lookup

use of org.compiere.model.Lookup in project adempiere by adempiere.

the class DeleteSelectionController method getValue.

/**
	 * Get value from index
	 * @param index
	 * @return
	 */
private String getValue(int index) {
    StringBuffer displayValue = new StringBuffer();
    if (keyColumnName.trim().length() == 0) {
        ArrayList<String> parentColumnNames = currentTab.getParentColumnNames();
        for (Iterator<String> iter = parentColumnNames.iterator(); iter.hasNext(); ) {
            String columnName = iter.next();
            GridField field = currentTab.getField(columnName);
            if (field.isLookup()) {
                Lookup lookup = field.getLookup();
                if (lookup != null) {
                    displayValue = displayValue.append(lookup.getDisplay(currentTab.getValue(index, columnName))).append(" | ");
                } else {
                    displayValue = displayValue.append(currentTab.getValue(index, columnName)).append(" | ");
                }
            } else {
                displayValue = displayValue.append(currentTab.getValue(index, columnName)).append(" | ");
            }
        }
    } else {
        final int id = currentTab.getKeyID(index);
        String value = DB.getSQLValueStringEx(null, sql, id);
        if (value != null)
            value = value.replace(" - ", " | ");
        displayValue.append(value);
        // Append ID
        if (displayValue.length() == 0 || CLogMgt.isLevelFine()) {
            if (displayValue.length() > 0)
                displayValue.append(" | ");
            displayValue.append("<").append(id).append(">");
        }
    }
    //	Return
    return displayValue.toString();
}
Also used : Lookup(org.compiere.model.Lookup) GridField(org.compiere.model.GridField)

Aggregations

Lookup (org.compiere.model.Lookup)15 GridField (org.compiere.model.GridField)8 MLookup (org.compiere.model.MLookup)5 LookupValues (pl.x3E.adInterface.LookupValues)4 DataField (pl.x3E.adInterface.DataField)3 PropertyVetoException (java.beans.PropertyVetoException)2 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 SQLException (java.sql.SQLException)2 JasperPrint (net.sf.jasperreports.engine.JasperPrint)2 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)2 MProcessPara (org.compiere.model.MProcessPara)2 KeyNamePair (org.compiere.util.KeyNamePair)2 StringSelection (java.awt.datatransfer.StringSelection)1 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Label (org.adempiere.webui.component.Label)1