Search in sources :

Example 6 with MViewColumn

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

the class ViewColumnElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    int AD_View_Column_ID = Env.getContextAsInt(ctx, X_AD_View_Column.COLUMNNAME_AD_View_Column_ID);
    MViewColumn m_ColumnView = new MViewColumn(ctx, AD_View_Column_ID, null);
    AttributesImpl atts = new AttributesImpl();
    createViewColumnBinding(atts, m_ColumnView);
    PackOut packOut = (PackOut) ctx.get("PackOutProcess");
    document.startElement("", "", "viewcolumn", atts);
    document.endElement("", "", "viewcolumn");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) PackOut(org.adempiere.pipo.PackOut) MViewColumn(org.adempiere.model.MViewColumn)

Example 7 with MViewColumn

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

the class ViewColumnElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    PackIn packIn = (PackIn) ctx.get("PackInProcess");
    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("viewdefinition") && element.parent.defer) {
            element.defer = true;
            return;
        }
        String name = atts.getValue("Name");
        String viewdenitionname = atts.getValue("ADViewDefinitionNameID");
        String colname = atts.getValue("ADColumnNameID");
        String viewColumnName = atts.getValue("ADViewColumnNameID");
        String tableName = atts.getValue("ADTableNameID");
        int tableid = packIn.getTableId(tableName);
        if (tableid <= 0) {
            tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName);
            if (tableid > 0)
                packIn.addTable(tableName, tableid);
        }
        if (tableid <= 0 && tableName.length() > 0) {
            element.defer = true;
            return;
        }
        int viewid = get_ID(ctx, "AD_View", atts.getValue("ADViewNameID"));
        if (viewid <= 0) {
            element.defer = true;
            return;
        }
        int columnid = packIn.getColumnId(tableName, colname);
        if (columnid <= 0) {
            columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", "ColumnName", colname, "AD_Table", tableid);
            if (columnid > 0)
                packIn.addColumn(tableName, colname, columnid);
        }
        if (columnid <= 0 && colname.length() > 0) {
            element.defer = true;
            return;
        }
        int viewdefinitionid = 0;
        if (element.parent != null && element.parent.getElementValue().equals("viewdefinition") && element.parent.recordId > 0) {
            viewdefinitionid = element.parent.recordId;
        } else {
            StringBuffer sqlB = new StringBuffer("select AD_View_Definition_ID from AD_View_Definition where AD_View_ID = " + viewid).append(" and TableAlias = '" + viewdenitionname + "'").append(" and AD_Table_ID = ?");
            viewdefinitionid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tableid);
            if (element.parent != null && element.parent.getElementValue().equals("viewdefinition") && viewdefinitionid > 0) {
                element.parent.recordId = viewdefinitionid;
            }
        }
        if (viewdefinitionid > 0) {
            StringBuilder sqlB = new StringBuilder("SELECT AD_View_Column_ID from AD_View_Column WHERE ColumnName=?").append(" AND AD_View_Definition_ID=?");
            int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), viewColumnName, viewdefinitionid);
            final MViewColumn m_ColumnView = new MViewColumn(ctx, id, getTrxName(ctx));
            if (id <= 0 && atts.getValue("AD_View_Column_ID") != null && Integer.parseInt(atts.getValue("AD_View_Column_ID")) <= PackOut.MAX_OFFICIAL_ID)
                m_ColumnView.setAD_View_Column_ID(Integer.parseInt(atts.getValue("AD_View_Column_ID")));
            int AD_Backup_ID = -1;
            String Object_Status = null;
            if (id > 0) {
                AD_Backup_ID = copyRecord(ctx, "AD_View_Column_ID", m_ColumnView);
                Object_Status = "Update";
            } else {
                Object_Status = "New";
                AD_Backup_ID = 0;
            }
            m_ColumnView.setName(atts.getValue("Name"));
            m_ColumnView.setAD_View_ID(viewid);
            if (columnid > 0)
                m_ColumnView.setAD_Column_ID(columnid);
            m_ColumnView.setAD_View_Definition_ID(viewdefinitionid);
            m_ColumnView.setEntityType(atts.getValue("EntityType"));
            m_ColumnView.setColumnSQL(atts.getValue("ColumnSQL"));
            m_ColumnView.setColumnName(viewColumnName);
            // m_ColumnView.setIsReadOnly(Boolean.valueOf(
            // atts.getValue("isReadOnly")).booleanValue());
            m_ColumnView.setDescription(getStringValue(atts, "Description"));
            m_ColumnView.setHelp(getStringValue(atts, "Help"));
            m_ColumnView.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
            if (m_ColumnView.save(getTrxName(ctx)) == true) {
                record_log(ctx, 1, m_ColumnView.getName(), "ViewColumn", m_ColumnView.get_ID(), AD_Backup_ID, Object_Status, "ViewColumn", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View_Column"));
                element.recordId = m_ColumnView.getAD_View_Column_ID();
            } else {
                record_log(ctx, 0, m_ColumnView.getName(), "ViewColumn", m_ColumnView.get_ID(), AD_Backup_ID, Object_Status, "AD_View_Column", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_View_Column"));
                throw new POSaveFailedException("Failed to save view column definition.");
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : PackIn(org.adempiere.pipo.PackIn) Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) MViewColumn(org.adempiere.model.MViewColumn)

Example 8 with MViewColumn

use of org.adempiere.model.MViewColumn 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 9 with MViewColumn

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

the class Browser method initBrowserData.

//	copyWinContext
/**
	 * Initialize data of browser
	 * @return
	 */
public void initBrowserData() {
    browserFields = new ArrayList<MBrowseField>();
    MBrowseField fieldKey = m_Browse.getFieldKey();
    if (fieldKey != null) {
        browserFields.add(fieldKey);
    } else {
        MViewColumn column = new MViewColumn(m_Browse.getCtx(), 0, m_Browse.get_TrxName());
        column.setName("Row");
        column.setColumnSQL("'Row' AS \"Row\"");
        MBrowseField browseField = new MBrowseField(m_Browse, column);
        browseField.setAD_Reference_ID(DisplayType.ID);
        browseField.setIsKey(true);
        browseField.setIsReadOnly(false);
    }
    //	
    for (MBrowseField field : m_Browse.getDisplayFields()) {
        //	
        if (field.isQueryCriteria()) {
            m_queryColumns.add(field.getName());
        }
        m_queryColumnsSql.add(field.getAD_View_Column().getColumnSQL());
        if (field.isKey())
            continue;
        // Defines Field as Y-Axis
        if (field.getAxis_Column_ID() > 0) {
            for (MBrowseField fieldAxis : getInfoColumnForAxisField(field)) {
                browserFields.add(fieldAxis);
            }
            continue;
        }
        browserFields.add(field);
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MViewColumn(org.adempiere.model.MViewColumn)

Example 10 with MViewColumn

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

the class ViewCopyFrom method doIt.

/**
	 * Copy view from other view
	 * 
	 * @return result string
	 */
@SuppressWarnings("unchecked")
protected String doIt() throws Exception {
    MView viewFrom = new MView(getCtx(), p_AD_View_ID, get_TrxName());
    MView viewTo = new MView(getCtx(), p_Record_ID, get_TrxName());
    String name = viewTo.getName();
    String value = viewTo.getValue();
    viewTo.copyValues(viewFrom, viewTo);
    viewTo.setName(name);
    viewTo.setValue(value);
    viewTo.saveEx();
    for (MViewDefinition viewDefinitionFrom : viewFrom.getViewDefinitions()) {
        MViewDefinition viewDefinitionTo = new MViewDefinition(getCtx(), 0, get_TrxName());
        viewDefinitionTo.copyValues(viewDefinitionFrom, viewDefinitionTo);
        viewDefinitionTo.setAD_View_ID(viewTo.getAD_View_ID());
        viewDefinitionTo.saveEx();
        for (MViewColumn viewColumnFrom : viewDefinitionFrom.getADViewColumns()) {
            MViewColumn viewColumnTo = new MViewColumn(getCtx(), 0, get_TrxName());
            viewColumnTo.copyValues(viewColumnFrom, viewColumnTo);
            viewColumnTo.setAD_View_Definition_ID(viewDefinitionTo.getAD_View_Definition_ID());
            viewColumnTo.saveEx();
        }
    }
    return "@Ok@";
}
Also used : MView(org.adempiere.model.MView) MViewDefinition(org.adempiere.model.MViewDefinition) MViewColumn(org.adempiere.model.MViewColumn)

Aggregations

MViewColumn (org.adempiere.model.MViewColumn)11 MBrowseField (org.adempiere.model.MBrowseField)6 MViewDefinition (org.adempiere.model.MViewDefinition)4 MBrowse (org.adempiere.model.MBrowse)3 I_AD_View_Column (org.adempiere.model.I_AD_View_Column)2 MView (org.adempiere.model.MView)2 PackOut (org.adempiere.pipo.PackOut)2 MColumn (org.compiere.model.MColumn)2 Query (org.compiere.model.Query)2 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 DBException (org.adempiere.exceptions.DBException)1 PackIn (org.adempiere.pipo.PackIn)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 MLookup (org.compiere.model.MLookup)1 MQuery (org.compiere.model.MQuery)1 MTable (org.compiere.model.MTable)1