Search in sources :

Example 1 with Column

use of org.zkoss.zul.Column in project adempiere by adempiere.

the class GridPanel method setupColumns.

private void setupColumns() {
    if (init)
        return;
    Columns columns = new Columns();
    //	listbox.appendChild(columns);			// moved to end
    columns.setSizable(true);
    columns.setMenupopup("auto");
    columns.setColumnsgroup(false);
    Map<Integer, String> colnames = new HashMap<Integer, String>();
    int index = 0;
    for (int i = 0; i < numColumns; i++) {
        if (gridField[i].isDisplayed()) {
            colnames.put(index, gridField[i].getHeader());
            index++;
            org.zkoss.zul.Column column = new Column();
            column.setSortAscending(new SortComparator(i, true, Env.getLanguage(Env.getCtx())));
            column.setSortDescending(new SortComparator(i, false, Env.getLanguage(Env.getCtx())));
            column.setLabel(gridField[i].getHeader());
            int displayLength = gridField[i].getPreferredWidthInListView() > 0 ? gridField[i].getPreferredWidthInListView() : gridField[i].getDisplayLength() * 9;
            int l = DisplayType.isNumeric(gridField[i].getDisplayType()) ? 120 : displayLength;
            if (gridField[i].getHeader().length() * 9 > l)
                l = gridField[i].getHeader().length() * 9;
            if (l > MAX_COLUMN_WIDTH)
                l = MAX_COLUMN_WIDTH;
            else if (l < MIN_COLUMN_WIDTH && gridField[i].getPreferredWidthInListView() <= 0)
                l = MIN_COLUMN_WIDTH;
            if (gridField[i].getDisplayType() == DisplayType.Table || gridField[i].getDisplayType() == DisplayType.TableDir) {
                if (l < MIN_COMBOBOX_WIDTH)
                    l = MIN_COMBOBOX_WIDTH;
            } else if (DisplayType.isNumeric(gridField[i].getDisplayType())) {
                if (l < MIN_NUMERIC_COL_WIDTH)
                    l = MIN_NUMERIC_COL_WIDTH;
            }
            column.setWidth(Integer.toString(l) + "px");
            // FR 3051618 - Hide in list view
            if (!gridField[i].isDisplayedGrid()) {
                column.setVisible(false);
            }
            columns.appendChild(column);
            listbox.appendChild(columns);
        }
    }
}
Also used : HashMap(java.util.HashMap) Column(org.zkoss.zul.Column) SortComparator(org.adempiere.webui.util.SortComparator) Column(org.zkoss.zul.Column)

Example 2 with Column

use of org.zkoss.zul.Column in project adempiere by adempiere.

the class DynamicDashBoard method prepareSelectQuery.

/**
	 * 
	 * @return String<br>
	 * 
	 *         This method builds the sql query to generate Result set. It creates Columns and labels as well.
	 * 
	 * 
	 */
public String prepareSelectQuery() {
    // Getting isDisplayed fields based on the Browse ID
    StringBuffer whereClause = new StringBuffer(X_AD_Browse.COLUMNNAME_AD_Browse_ID + " = " + browseId + " AND isDisplayed = 'Y'");
    List<MBrowseField> fieldList = new Query(Env.getCtx(), I_AD_Browse_Field.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).setOrderBy(X_AD_Browse_Field.COLUMNNAME_SeqNo).list();
    if (fieldList != null && !fieldList.isEmpty()) {
        lable = new Label[fieldList.size()];
        column = new Column[fieldList.size()];
        sqlQuery = sqlQuery.append(" SELECT ");
        if (zoomWindowId > 0 && zoomTabId > 0) {
            MBrowseField zoomField = new MBrowseField(Env.getCtx(), zoomFieldId, null);
            if (!fieldList.contains(zoomField)) {
                StringBuffer columnWhereClause = new StringBuffer("AD_View_Column_ID = " + zoomField.getAD_View_Column_ID());
                MViewColumn viewColumn = new Query(Env.getCtx(), I_AD_View_Column.Table_Name, columnWhereClause.toString(), null).setOnlyActiveRecords(true).first();
                sqlQuery = sqlQuery.append(viewColumn.getColumnSQL() + ", ");
            } else {
                displayZoomCol = Boolean.TRUE;
            }
            whereClause = new StringBuffer("AD_Tab_ID= " + zoomTabId);
            zoomTab = new Query(Env.getCtx(), I_AD_Tab.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
            if (zoomTab != null) {
                // Getting Zoom table based on the zoom tab
                whereClause = new StringBuffer("AD_Table_ID= " + zoomTab.getAD_Table_ID());
                zoomTable = new Query(Env.getCtx(), I_AD_Table.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
                if (zoomTable != null) {
                    // table or view? based on suffix "_v". It assumed that
                    // created view is having this suffix
                    //@The View Name must be Actual Table Name and It must ends with one of above suffixes @
                    //If this view combination of multiple tables, the view name must be prefix with any one of Joining Tables
                    //And That table should have primary key::: Eg: AD_USer_v, here AD_User_ID is Primary key of AD_User
                    zoomTableName = zoomTable.getTableName();
                    if (zoomTable.isView()) {
                        if (zoomTableName.endsWith("_vt")) {
                            zoomTableColumnName = zoomTableName.replace("_vt", "_ID");
                            sqlQuery = sqlQuery.append(zoomTableColumnName + ", ");
                        } else // if view ends with _v only
                        if (zoomTableName.endsWith("_v")) {
                            zoomTableColumnName = zoomTableName.replace("_v", "_ID");
                            sqlQuery = sqlQuery.append(zoomTableColumnName + ", ");
                        }
                    } else {
                        zoomTableColumnName = zoomTable.getTableName() + "_ID";
                    }
                }
            }
        }
        int i = 0;
        for (MBrowseField field : fieldList) {
            if (i != 0) {
                sqlQuery = sqlQuery.append(", ");
            }
            // creating column and preparing sql query with db column names
            column[i] = new Column(field.getName(), null, null);
            StringBuffer columnWhereClause = new StringBuffer("AD_View_Column_ID = " + field.getAD_View_Column_ID());
            MViewColumn viewColumn = new Query(Env.getCtx(), I_AD_View_Column.Table_Name, columnWhereClause.toString(), null).setOnlyActiveRecords(true).first();
            sqlQuery = sqlQuery.append(viewColumn.getColumnName().replaceFirst("_", "."));
            i = i + 1;
        }
    }
    whereClause = new StringBuffer("AD_Browse_ID= " + browseId);
    MBrowse browse = new Query(Env.getCtx(), I_AD_Browse.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
    if (browse != null) {
        whereClause = new StringBuffer("AD_View_ID= " + browse.getAD_View_ID());
        List<MViewDefinition> list = new Query(Env.getCtx(), I_AD_View_Definition.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).list();
        whereClause = new StringBuffer(X_AD_View_Definition.COLUMNNAME_AD_Table_ID + " = " + list.get(0).getAD_Table_ID());
        table = new Query(Env.getCtx(), I_AD_Table.Table_Name, whereClause.toString(), null).setOnlyActiveRecords(true).first();
        StringBuffer joinClause = new StringBuffer();
        for (MViewDefinition viewDefinition : list) {
            if (viewDefinition.getJoinClause() == null)
                joinClause.append(" " + viewDefinition.getTableAlias());
            else
                joinClause.append(" " + viewDefinition.getJoinClause());
        }
        // Associating sql query with table name 
        sqlQuery.append(" FROM " + table.getTableName()).append(joinClause.toString());
        //get where clause of this Smart Browse
        String where = browse.getWhereClause();
        if (where != null) {
            boolean success = true;
            do {
                int index = where.indexOf("@");
                int index2 = where.indexOf("@", index + 1);
                boolean integer = false;
                int replacedValue = 0;
                String replacedString = null;
                if (index > 0 || index2 > 0) {
                    String subString1 = where.substring(index + 1, index2);
                    if (subString1.contains("#")) {
                        if (subString1.endsWith("_ID")) {
                            replacedValue = Env.getContextAsInt(ctx, subString1);
                            integer = true;
                        } else {
                            replacedString = Env.getContext(ctx, subString1);
                        }
                        if (integer) {
                            where = where.replaceAll(where.substring(index, index2 + 1), String.valueOf(replacedValue));
                        } else {
                            where = where.replaceAll(where.substring(index, index2 + 1), "'" + replacedString + "'");
                        }
                    } else {
                        where = where.replaceAll(where.substring(index, index2 + 1), where.substring(index + 1, index2));
                    }
                    success = true;
                } else {
                    success = false;
                }
            } while (success);
            sqlQuery.append(" Where " + where);
        }
    }
    return sqlQuery.toString();
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MQuery(org.compiere.model.MQuery) Query(org.compiere.model.Query) I_AD_View_Column(org.adempiere.model.I_AD_View_Column) MViewColumn(org.adempiere.model.MViewColumn) Column(org.zkoss.zul.Column) MViewDefinition(org.adempiere.model.MViewDefinition) MBrowse(org.adempiere.model.MBrowse) MViewColumn(org.adempiere.model.MViewColumn)

Aggregations

Column (org.zkoss.zul.Column)2 HashMap (java.util.HashMap)1 I_AD_View_Column (org.adempiere.model.I_AD_View_Column)1 MBrowse (org.adempiere.model.MBrowse)1 MBrowseField (org.adempiere.model.MBrowseField)1 MViewColumn (org.adempiere.model.MViewColumn)1 MViewDefinition (org.adempiere.model.MViewDefinition)1 SortComparator (org.adempiere.webui.util.SortComparator)1 MQuery (org.compiere.model.MQuery)1 Query (org.compiere.model.Query)1