Search in sources :

Example 11 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class BrowseFieldElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    String elementValue = element.getElementValue();
    Attributes atts = element.attributes;
    log.info(elementValue + " " + atts.getValue("Name"));
    String entitytype = atts.getValue("EntityType");
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.getElementValue().equals("browse") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String browsename = atts.getValue("ADBrowseNameID");
        String colviewname = atts.getValue("ADViewColumnNameID");
        String viewName = atts.getValue("ADViewNameID");
        int viewid = get_IDWithColumn(ctx, "AD_View", "Name", viewName);
        if (viewid <= 0) {
            element.defer = true;
            return;
        }
        int viewcolumnid = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", colviewname, "AD_View", viewid);
        if (viewcolumnid <= 0) {
            element.defer = true;
            return;
        }
        int browseid = 0;
        if (element.parent != null && element.parent.getElementValue().equals("browse") && element.parent.recordId > 0) {
            browseid = element.parent.recordId;
        } else {
            StringBuffer sqlB = new StringBuffer("SELECT AD_Browse_ID from AD_Browse WHERE AD_Browse_ID = " + browseid).append(" and Name = '" + browsename + "'").append(" and AD_View_ID = ?");
            browseid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), viewid);
            if (element.parent != null && element.parent.getElementValue().equals("browse") && browseid > 0) {
                element.parent.recordId = browseid;
            }
        }
        if (browseid > 0) {
            StringBuffer sqlB = new StringBuffer("SELECT AD_Browse_Field_ID from AD_Browse_Field where AD_View_Column_ID = ").append(viewcolumnid).append(" and AD_Browse_ID = ?");
            int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), browseid);
            final MBrowseField m_BrowseField = new MBrowseField(ctx, id, getTrxName(ctx));
            if (id <= 0 && atts.getValue("AD_Browse_Field_ID") != null && Integer.parseInt(atts.getValue("AD_Browse_Field_ID")) <= PackOut.MAX_OFFICIAL_ID)
                m_BrowseField.setAD_Browse_Field_ID(Integer.parseInt(atts.getValue("AD_Browse_Field_ID")));
            int AD_Backup_ID = -1;
            String Object_Status = null;
            if (id > 0) {
                AD_Backup_ID = copyRecord(ctx, "AD_Browse_Field", m_BrowseField);
                Object_Status = "Update";
            } else {
                Object_Status = "New";
                AD_Backup_ID = 0;
            }
            m_BrowseField.setName(atts.getValue("Name"));
            m_BrowseField.setAD_View_Column_ID(viewcolumnid);
            m_BrowseField.setAD_Browse_ID(browseid);
            m_BrowseField.setEntityType(atts.getValue("EntityType"));
            m_BrowseField.setIsCentrallyMaintained(Boolean.valueOf(atts.getValue("isCentrallyMaintained")).booleanValue());
            m_BrowseField.setIsMandatory(Boolean.valueOf(atts.getValue("isMandatory")).booleanValue());
            m_BrowseField.setIsDisplayed(Boolean.valueOf(atts.getValue("Displayed")).booleanValue());
            m_BrowseField.setIsReadOnly(Boolean.valueOf(atts.getValue("isReadOnly")).booleanValue());
            m_BrowseField.setDefaultValue(atts.getValue("DefaultValue"));
            m_BrowseField.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass"));
            m_BrowseField.setDefaultValue2(atts.getValue("DefaultValue2"));
            m_BrowseField.setReadOnlyLogic(atts.getValue("ReadOnlyLogic"));
            m_BrowseField.setDisplayLogic(atts.getValue("DisplayLogic"));
            m_BrowseField.setVFormat(atts.getValue("VFormat"));
            m_BrowseField.setFieldLength(Integer.parseInt(atts.getValue("FieldLength")));
            m_BrowseField.setValueMin(atts.getValue("ValueMin"));
            m_BrowseField.setValueMin(atts.getValue("ValueMax"));
            String Name = atts.getValue("ADValRuleNameID");
            id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
            m_BrowseField.setAD_Val_Rule_ID(id);
            m_BrowseField.setSeqNo(Integer.parseInt(atts.getValue("SeqNo")));
            m_BrowseField.setSeqNoGrid(Integer.parseInt(atts.getValue("SeqNoGrid")));
            //	Is Information Only #556
            m_BrowseField.setIsInfoOnly(Boolean.valueOf(atts.getValue("IsInfoOnly")).booleanValue());
            m_BrowseField.setSortNo(Integer.parseInt(atts.getValue("SortNo")));
            m_BrowseField.setIsOrderBy(Boolean.valueOf(atts.getValue("IsOrderBy")).booleanValue());
            m_BrowseField.setDescription(getStringValue(atts, "Description"));
            m_BrowseField.setHelp(getStringValue(atts, "Help"));
            m_BrowseField.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
            m_BrowseField.setIsRange(atts.getValue("isRange") != null ? Boolean.valueOf(atts.getValue("isRange")).booleanValue() : true);
            m_BrowseField.setIsKey(atts.getValue("isKey") != null ? Boolean.valueOf(atts.getValue("isKey")).booleanValue() : true);
            m_BrowseField.setIsQueryCriteria(atts.getValue("isQueryCriteria") != null ? Boolean.valueOf(atts.getValue("isQueryCriteria")).booleanValue() : true);
            m_BrowseField.setIsIdentifier(atts.getValue("isIdentifier") != null ? Boolean.valueOf(atts.getValue("isIdentifier")).booleanValue() : true);
            Name = atts.getValue("ADReferenceNameID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_BrowseField.setAD_Reference_ID(id);
            // Name = atts.getValue("ADValRuleNameID");
            // id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name);
            // m_BrowseField.setAD_Val_Rule_ID(id);
            Name = atts.getValue("ADReferenceNameValueID");
            id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name);
            m_BrowseField.setAD_Reference_Value_ID(id);
            Name = atts.getValue("ADAxisViewColumnNameID");
            id = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", Name, "AD_View", viewid);
            m_BrowseField.setAxis_Column_ID(id);
            Name = atts.getValue("ADAxisParentViewColumnNameID");
            id = get_IDWithMasterAndColumn(ctx, "AD_View_Column", "ColumnName", Name, "AD_View", viewid);
            m_BrowseField.setAxis_Parent_Column_ID(id);
            // Setup Element.
            Name = atts.getValue("ADElementNameID");
            id = get_IDWithColumn(ctx, "AD_Element", "ColumnName", Name);
            X_AD_Element adElement = new X_AD_Element(ctx, id, getTrxName(ctx));
            String Object_Status_col = Object_Status;
            if (adElement.getAD_Element_ID() == 0) {
                // Object_Status = "New";
                adElement.setColumnName(m_BrowseField.getAD_View_Column().getAD_Column().getColumnName());
                adElement.setEntityType(m_BrowseField.getEntityType());
                adElement.setPrintName(m_BrowseField.getName());
                adElement.setName(m_BrowseField.getName());
                if (adElement.save(getTrxName(ctx)) == true) {
                    record_log(ctx, 1, m_BrowseField.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
                } else {
                    record_log(ctx, 0, m_BrowseField.getName(), "Element", adElement.getAD_Element_ID(), AD_Backup_ID, "New", "AD_Element", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Element"));
                }
            }
            Object_Status = Object_Status_col;
            m_BrowseField.setAD_Element_ID(adElement.getAD_Element_ID());
            if (m_BrowseField.save(getTrxName(ctx)) == true) {
                record_log(ctx, 1, m_BrowseField.getName(), "BrowseField", m_BrowseField.get_ID(), AD_Backup_ID, Object_Status, "AD_Browse_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Browse_Field"));
                element.recordId = m_BrowseField.getAD_Browse_Field_ID();
            } else {
                record_log(ctx, 0, m_BrowseField.getName(), "BrowseField", m_BrowseField.get_ID(), AD_Backup_ID, Object_Status, "AD_Browse_Field", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Browse_Field"));
                throw new POSaveFailedException("Failed to save field definition.");
            }
        } else {
            element.defer = true;
            return;
        }
    } else {
        element.skip = true;
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) X_AD_Element(org.compiere.model.X_AD_Element)

Example 12 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class BrowseCopyFrom method doIt.

/**
	 * Copy Browse
	 * 
	 * @return info
	 */
@SuppressWarnings("unchecked")
protected String doIt() throws Exception {
    MBrowse browseFrom = new MBrowse(getCtx(), p_AD_Browse_ID, get_TrxName());
    MBrowse browseTo = new MBrowse(getCtx(), p_Record_ID, get_TrxName());
    String name = browseTo.getName();
    String value = browseTo.getValue();
    browseTo.copyValues(browseFrom, browseTo);
    browseTo.setName(name);
    browseTo.setValue(value);
    browseTo.saveEx();
    for (MBrowseField fieldFrom : browseFrom.getFields()) {
        MBrowseField fieldTo = new MBrowseField(getCtx(), 0, get_TrxName());
        fieldTo.copyValues(fieldFrom, fieldTo);
        fieldTo.setAD_Browse_ID(browseTo.getAD_Browse_ID());
        fieldTo.saveEx();
    }
    return "@Ok@";
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MBrowse(org.adempiere.model.MBrowse)

Example 13 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class CreateBrowseField method doIt.

/**
	 * Process - Generate Export Format
	 * 
	 * @return info
	 */
@SuppressWarnings("unchecked")
protected String doIt() throws Exception {
    MBrowse browse = new MBrowse(getCtx(), p_Record_ID, get_TrxName());
    MView view = browse.getAD_View();
    int seq = 10;
    for (MViewColumn column : view.getViewColumns()) {
        if (column.getAD_Column_ID() <= 0)
            continue;
        MBrowseField field = MBrowseField.get(browse, column);
        if (field != null)
            continue;
        field = new MBrowseField(browse, column);
        field.setAD_Browse_ID(browse.get_ID());
        field.setEntityType(browse.getEntityType());
        field.setIsDisplayed(false);
        field.setIsMandatory(false);
        field.setSeqNo(seq);
        field.saveEx();
        seq++;
        addLog(column.getColumnName());
    }
    return "@Ok@";
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MView(org.adempiere.model.MView) MBrowse(org.adempiere.model.MBrowse) MViewColumn(org.adempiere.model.MViewColumn)

Example 14 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class Browser method getMQuery.

/**
	 * Get Query from Record Identifier
	 * @return
	 */
public MQuery getMQuery(IBrowserTable browseTable) {
    Integer record_ID = getSelectedRowKey(browseTable);
    if (record_ID == null)
        return null;
    MBrowseField fieldKey = getFieldKey();
    if (fieldKey == null)
        return null;
    MColumn column = fieldKey.getAD_View_Column().getAD_Column();
    String keyColumn = MQuery.getZoomColumnName(column.getColumnName());
    String tableName = column.getAD_Table().getTableName();
    MQuery query = new MQuery(tableName);
    query.addRestriction(keyColumn, MQuery.EQUAL, record_ID);
    return query;
}
Also used : MColumn(org.compiere.model.MColumn) MBrowseField(org.adempiere.model.MBrowseField) MQuery(org.compiere.model.MQuery)

Example 15 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class BrowserSearch method loadData.

/**
	 *	Read Fields to display
	 *  @return true if loaded OK
	 */
public boolean loadData() {
    log.config("");
    //	Create Fields
    MBrowse browse = MBrowse.get(Env.getCtx(), m_AD_Browse_ID);
    //	Valid null
    if (browse == null)
        return false;
    //	
    List<MBrowseField> fields = browse.getCriteriaFields();
    if (fields == null || fields.size() == 0)
        return false;
    //	Add fields
    for (MBrowseField field : fields) {
        createField(field, m_WindowNo);
    }
    //	
    return true;
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MBrowse(org.adempiere.model.MBrowse)

Aggregations

MBrowseField (org.adempiere.model.MBrowseField)21 MBrowse (org.adempiere.model.MBrowse)6 MViewColumn (org.adempiere.model.MViewColumn)6 GridField (org.compiere.model.GridField)6 IDColumn (org.compiere.minigrid.IDColumn)4 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 I_AD_View_Column (org.adempiere.model.I_AD_View_Column)2 PackOut (org.adempiere.pipo.PackOut)2 MColumn (org.compiere.model.MColumn)2 MQuery (org.compiere.model.MQuery)2 MTable (org.compiere.model.MTable)2 Query (org.compiere.model.Query)2 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1