Search in sources :

Example 16 with MBrowseField

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

the class Browser method deleteSelection.

/**
	 * Delete a Selection
	 * @param browseTable
	 * @return
	 */
protected int deleteSelection(IBrowserTable browseTable) {
    MTable table = null;
    MBrowseField fieldKey = m_Browse.getFieldKey();
    if (fieldKey != null)
        if (fieldKey.getAD_View_Column().getAD_Column_ID() > 0)
            table = (MTable) fieldKey.getAD_View_Column().getAD_Column().getAD_Table();
    int records = 0;
    for (int id : getSelectedRowKeys(browseTable)) {
        if (table != null) {
            table.getPO(id, null).deleteEx(true);
            records++;
        }
    }
    return records;
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MTable(org.compiere.model.MTable)

Example 17 with MBrowseField

use of org.adempiere.model.MBrowseField 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 18 with MBrowseField

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

the class VBrowserTable method addTotals.

/**
     * Adding a new row with the totals
     */
public void addTotals() {
    if (getRowCount() == 0 || this.browserRows.getNoViewColumns() == 0)
        return;
    Object[] total = new Object[this.browserRows.getNoViewColumns()];
    for (int row = 0; row < getRowCount(); row++) {
        for (int col = 0; col < this.browserRows.getNoViewColumns(); col++) {
            Object data = getModel().getValueAt(row, col);
            //Class<?> c = layout[col].getColClass();
            int ReferenceType = this.browserRows.getBrowserField(this.browserRows.getTableIndex(col)).getAD_Reference_ID();
            //if (c == BigDecimal.class)
            if (DisplayType.isNumeric(ReferenceType)) {
                BigDecimal subtotal = Env.ZERO;
                if (total[col] != null) {
                    if (total[col] instanceof BigDecimal)
                        subtotal = (BigDecimal) (total[col]);
                    if (total[col] instanceof Integer)
                        subtotal = new BigDecimal((Integer) total[col]);
                }
                BigDecimal amt = Env.ZERO;
                if (data == null)
                    amt = Env.ZERO;
                if (data instanceof BigDecimal)
                    amt = (BigDecimal) data;
                if (data instanceof Integer)
                    amt = new BigDecimal((Integer) data);
                if (subtotal == null)
                    subtotal = Env.ZERO;
                total[col] = subtotal.add(amt);
            }
        }
    }
    //adding total row
    int row = getRowCount() + 1;
    boolean markerSet = false;
    setRowCount(row);
    for (int col = 0; col < this.browserRows.getNoViewColumns(); col++) {
        MBrowseField field = this.browserRows.getBrowserField(this.browserRows.getTableIndex(col));
        GridField gridField = MBrowseField.createGridFieldVO(field, browser.getWindowNo());
        if (DisplayType.isNumeric(field.getAD_Reference_ID())) {
            gridField.setValue(total[col], true);
            setValueAt(row - 1, col, gridField);
        } else {
            if (DisplayType.isText(field.getAD_Reference_ID()) && !markerSet) {
                gridField.setValue(" Σ ", true);
                //setValueAt(" Σ ", row - 1, col);
                setValueAt(row - 1, col, gridField);
                markerSet = true;
            } else {
                gridField.setValue(null, true);
                setValueAt(row - 1, col, gridField);
            }
        }
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) GridField(org.compiere.model.GridField) BigDecimal(java.math.BigDecimal)

Example 19 with MBrowseField

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

the class WBrowserListItemRenderer method getCellComponent.

/**
	 * Generate the cell for the given <code>field</code>.
	 *
	 * @param table 	The table into which the cell will be placed.
	 * @param field		The data field for which the cell is to be created.
	 * @param rowIndex	The row in which the cell is to be placed.
	 * @param columnIndex	The column in which the cell is to be placed.
	 * @return	The list cell component.
	 */
private Listcell getCellComponent(WBrowserTable table, Object field, int rowIndex, int columnIndex) {
    ListCell listcell = new ListCell();
    if (table == null)
        return listcell;
    BrowserRow browserRows = table.getData();
    //	BR [ 257 ]
    MBrowseField browseField = browserRows.getBrowserField(browserRows.getTableIndex(columnIndex));
    if (browseField == null)
        return listcell;
    //	
    GridField gridField = table.getGridFieldAt(rowIndex, columnIndex);
    boolean isColumnVisible = true;
    if (!m_tableColumns.isEmpty())
        isColumnVisible = isColumnVisible(getColumn(columnIndex));
    // are assigned to Table Columns
    if (isColumnVisible && gridField != null) {
        //	Set Read Only
        boolean isCellEditable = table.isCellEditable(rowIndex, columnIndex);
        //	
        if (DisplayType.YesNo == browseField.getAD_Reference_ID()) {
            //	BR [ 347 ]
            boolean selected = false;
            if (field != null) {
                selected = Boolean.valueOf(field.toString());
            }
            listcell.setValue(selected);
            if (columnIndex == 0)
                table.setCheckmark(false);
            Checkbox checkbox = new Checkbox();
            checkbox.setChecked(selected);
            if (isCellEditable) {
                checkbox.setEnabled(true);
                checkbox.addEventListener(Events.ON_CHECK, this);
            } else {
                checkbox.setEnabled(false);
            }
            listcell.appendChild(checkbox);
            ZkCssHelper.appendStyle(listcell, "text-align:center");
        } else if ((DisplayType.isNumeric(browseField.getAD_Reference_ID())) && !browseField.isKey()) {
            DecimalFormat format = field instanceof BigDecimal ? DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx())) : DisplayType.getNumberFormat(DisplayType.Integer, AEnv.getLanguage(Env.getCtx()));
            // set cell value to allow sorting
            listcell.setValue((field == null ? "0" : field.toString()));
            if (isCellEditable) {
                NumberBox numberbox = new NumberBox(false);
                numberbox.setFormat(format);
                numberbox.setValue(field);
                numberbox.setWidth("100px");
                numberbox.setStyle("text-align:right; " + listcell.getStyle());
                numberbox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(numberbox);
                numberbox.setEnabled(true);
            } else {
                listcell.setLabel(format.format(((Number) (field == null ? Env.ZERO : field)).doubleValue()));
                ZkCssHelper.appendStyle(listcell, "text-align:right");
            }
        } else if (DisplayType.Date == browseField.getAD_Reference_ID() || DisplayType.DateTime == browseField.getAD_Reference_ID()) {
            if (field != null) {
                SimpleDateFormat dateFormat = DisplayType.getDateFormat(browseField.getAD_Reference_ID(), AEnv.getLanguage(Env.getCtx()));
                //	BR [ 270 ]
                listcell.setValue(dateFormat.format(field));
                if (isCellEditable) {
                    Datebox datebox = new Datebox();
                    datebox.setFormat(dateFormat.toPattern());
                    //	
                    datebox.setValue((Date) field);
                    datebox.addEventListener(Events.ON_CHANGE, this);
                    listcell.appendChild(datebox);
                } else {
                    listcell.setLabel(dateFormat.format(field));
                }
            }
        } else //	Add support to other String
        if (browseField.getAD_Reference_ID() == DisplayType.String || browseField.getAD_Reference_ID() == DisplayType.PrinterName || browseField.getAD_Reference_ID() == DisplayType.Text || browseField.getAD_Reference_ID() == DisplayType.TextLong) {
            listcell.setValue((field == null ? "" : field.toString()));
            if (isCellEditable) {
                Textbox textbox = new Textbox();
                textbox.setValue((field == null ? "" : field.toString()));
                textbox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(textbox);
            } else {
                listcell.setLabel((field == null ? "" : field.toString()));
            }
        } else if (field instanceof org.adempiere.webui.component.Combobox) {
            listcell.setValue(field);
            if (isCellEditable) {
                Combobox combobox = (Combobox) field;
                combobox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(combobox);
            } else {
                Combobox combobox = (Combobox) field;
                if (combobox != null && combobox.getItemCount() > 0) {
                    if (combobox.getSelectedIndex() >= 0)
                        listcell.setLabel((String) combobox.getItemAtIndex(combobox.getSelectedIndex()).getLabel());
                    else
                        listcell.setLabel("");
                }
            }
        } else if (field instanceof org.adempiere.webui.component.Button) {
            listcell.setValue(field);
            if (isCellEditable) {
                Button button = (Button) field;
                button.addEventListener(Events.ON_CLICK, this);
                listcell.appendChild(button);
            } else {
                Button button = (Button) field;
                if (button != null) {
                    listcell.setLabel("");
                }
            }
        } else // if ID column make it invisible
        if (field instanceof IDColumn && browseField.isKey()) {
            IDColumn id = (IDColumn) field;
            if (id != null && id.getRecord_ID() != null) {
                listcell.setValue(id.getRecord_ID());
                if (!table.isCheckmark()) {
                    table.setCheckmark(true);
                    table.removeEventListener(Events.ON_SELECT, this);
                    table.addEventListener(Events.ON_SELECT, this);
                }
            }
        } else if ((DisplayType.isLookup(browseField.getAD_Reference_ID()) || DisplayType.ID == browseField.getAD_Reference_ID()) && !browseField.isKey()) {
            if (isCellEditable) {
                WEditor editor = WebEditorFactory.getEditor(gridField, true);
                editor.addValueChangeListener(this);
                editor.dynamicDisplay();
                editor.setReadWrite(true);
                editor.fillHorizontal();
                gridField.addPropertyChangeListener(editor);
                listcell.appendChild(editor.getComponent());
            } else {
                Component component;
                if (gridField.getDisplayType() == DisplayType.YesNo) {
                    component = createReadonlyCheckbox(field);
                } else {
                    String text = getDisplayText(field, gridField);
                    Label label = new Label();
                    setLabelText(text, label);
                    component = label;
                }
                listcell.appendChild(component);
            }
        } else {
            listcell.setLabel((field == null ? null : field.toString()));
            listcell.setValue((field == null ? null : field.toString()));
        }
    } else {
        listcell.setLabel("");
        listcell.setValue("");
    }
    listcell.setAttribute("zk_component_ID", "ListItem_Cell_" + rowIndex + "_" + columnIndex);
    return listcell;
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) Datebox(org.adempiere.webui.component.Datebox) Button(org.adempiere.webui.component.Button) Combobox(org.adempiere.webui.component.Combobox) ListCell(org.adempiere.webui.component.ListCell) DecimalFormat(java.text.DecimalFormat) Textbox(org.adempiere.webui.component.Textbox) Label(org.zkoss.zhtml.Label) GridField(org.compiere.model.GridField) NumberBox(org.adempiere.webui.component.NumberBox) WEditor(org.adempiere.webui.editor.WEditor) BigDecimal(java.math.BigDecimal) IDColumn(org.compiere.minigrid.IDColumn) Button(org.adempiere.webui.component.Button) Checkbox(org.adempiere.webui.component.Checkbox) Component(org.zkoss.zk.ui.Component) SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with MBrowseField

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

the class WBrowserTable method loadTable.

@Override
public int loadTable(ResultSet rs) {
    int no = 0;
    int row = 0;
    //	
    clearTable();
    try {
        while (rs.next()) {
            no++;
            setRowCount(row + 1);
            int colOffset = 1;
            int col = 0;
            //	BR [ 257 ]
            for (MBrowseField field : getFields()) {
                Object value = null;
                if (field.isKey() && DisplayType.isID(field.getAD_Reference_ID()) && !field.getAD_View_Column().getColumnSQL().equals("'Row' AS \"Row\""))
                    value = new IDColumn(rs.getInt(col + colOffset));
                else if (field.isKey() && DisplayType.isNumeric(field.getAD_Reference_ID()) && field.getAD_View_Column().getColumnSQL().equals("'Row' AS \"Row\""))
                    value = new IDColumn(no);
                else if (DisplayType.isID(field.getAD_Reference_ID()) || field.getAD_Reference_ID() == DisplayType.Integer) {
                    Integer id = rs.getInt(col + colOffset);
                    value = id != 0 ? id : null;
                } else if (DisplayType.isNumeric(field.getAD_Reference_ID()))
                    value = rs.getBigDecimal(col + colOffset);
                else if (DisplayType.isDate(field.getAD_Reference_ID()))
                    value = rs.getTimestamp(col + colOffset);
                else if (DisplayType.YesNo == field.getAD_Reference_ID()) {
                    value = rs.getString(col + colOffset);
                    if (value != null)
                        value = value.equals("Y");
                } else
                    value = rs.getObject(col + colOffset);
                GridField gridField = MBrowseField.createGridFieldVO(field, browser.getWindowNo());
                gridField.setValue(value, true);
                //	Set Value
                setValueAnyColumn(row, col, gridField);
                col++;
            }
            row++;
        }
    } catch (SQLException exception) {
        logger.log(Level.SEVERE, "", exception);
    }
    autoSize();
    if (isShowTotals())
        addTotals();
    // repaint the table
    this.repaint();
    logger.config("Row(rs)=" + getRowCount());
    //	Return Row No
    return no;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) MBrowseField(org.adempiere.model.MBrowseField) SQLException(java.sql.SQLException) GridField(org.compiere.model.GridField)

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