Search in sources :

Example 56 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class GridTabRowRenderer method setFocusToEditor.

/**
	 * set focus to first active editor
	 */
public void setFocusToEditor() {
    if (currentRow != null && currentRow.getParent() != null) {
        WEditor toFocus = null;
        WEditor firstEditor = null;
        for (WEditor editor : getEditors()) {
            if (editor.isHasFocus() && editor.isVisible() && editor.getComponent().getParent() != null) {
                toFocus = editor;
                break;
            }
            if (editor.isVisible() && editor.getComponent().getParent() != null) {
                if (toFocus == null && editor.isReadWrite()) {
                    toFocus = editor;
                }
                if (firstEditor == null)
                    firstEditor = editor;
            }
        }
        if (toFocus != null) {
            Component c = toFocus.getComponent();
            if (c instanceof EditorBox) {
                c = ((EditorBox) c).getTextbox();
            }
            Clients.response(new AuFocus(c));
        } else if (firstEditor != null) {
            Component c = firstEditor.getComponent();
            if (c instanceof EditorBox) {
                c = ((EditorBox) c).getTextbox();
            }
            Clients.response(new AuFocus(c));
        }
    }
}
Also used : WEditor(org.adempiere.webui.editor.WEditor) Component(org.zkoss.zk.ui.Component) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent) AuFocus(org.zkoss.zk.au.out.AuFocus)

Example 57 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class TokenCommand method service.

public boolean service(AuRequest request, boolean everError) {
    if (!TokenEvent.ON_USER_TOKEN.equals(request.getCommand()))
        return false;
    Map<?, ?> map = request.getData();
    String sid = (String) map.get("sid");
    String hash = (String) map.get("hash");
    final String[] data = new String[] { sid, hash };
    final Component comp = request.getComponent();
    if (comp == null)
        throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
    if (data == null || data.length < 2)
        throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
    Events.postEvent(new TokenEvent(request.getCommand(), comp, data));
    return true;
}
Also used : TokenEvent(org.adempiere.webui.event.TokenEvent) UiException(org.zkoss.zk.ui.UiException) Component(org.zkoss.zk.ui.Component)

Example 58 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class WListItemRenderer method onEvent.

/* (non-Javadoc)
	 * @see org.zkoss.zk.ui.event.EventListener#onEvent(org.zkoss.zk.ui.event.Event)
	 */
public void onEvent(Event event) throws Exception {
    int col = -1;
    int row = -1;
    Object value = null;
    TableValueChangeEvent vcEvent = null;
    WTableColumn tableColumn;
    Component source = event.getTarget();
    if (isWithinListCell(source)) {
        row = getRowPosition(source);
        col = getColumnPosition(source);
        tableColumn = m_tableColumns.get(col);
        if (source instanceof Checkbox) {
            value = Boolean.valueOf(((Checkbox) source).isChecked());
        } else if (source instanceof Decimalbox) {
            value = ((Decimalbox) source).getValue();
        } else if (source instanceof Datebox) {
            value = ((Datebox) source).getValue();
        } else if (source instanceof Textbox) {
            value = ((Textbox) source).getValue();
        }
        if (value != null) {
            vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), row, col, value, value);
            fireTableValueChange(vcEvent);
        }
    } else if (event.getTarget() instanceof WListbox && Events.ON_SELECT.equals(event.getName())) {
        WListbox table = (WListbox) event.getTarget();
        if (table.isCheckmark()) {
            int cnt = table.getRowCount();
            if (cnt == 0 || !(table.getValueAt(0, 0) instanceof IDColumn))
                return;
            //update IDColumn
            tableColumn = m_tableColumns.get(0);
            for (int i = 0; i < cnt; i++) {
                IDColumn idcolumn = (IDColumn) table.getValueAt(i, 0);
                if (idcolumn != null) {
                    Listitem item = table.getItemAtIndex(i);
                    value = item.isSelected();
                    Boolean old = idcolumn.isSelected();
                    if (!old.equals(value)) {
                        vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), i, 0, old, value);
                        fireTableValueChange(vcEvent);
                    }
                }
            }
        }
    }
    return;
}
Also used : Listitem(org.zkoss.zul.Listitem) IDColumn(org.compiere.minigrid.IDColumn) Decimalbox(org.zkoss.zul.Decimalbox) Component(org.zkoss.zk.ui.Component) TableValueChangeEvent(org.adempiere.webui.event.TableValueChangeEvent)

Example 59 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class GridTabRowRenderer method stopEditing.

/**
	 * Detach all editor and optionally set the current value of the editor as cell label.
	 * @param updateCellLabel
	 */
public void stopEditing(boolean updateCellLabel) {
    if (!editing) {
        return;
    } else {
        editing = false;
    }
    Row row = null;
    for (Entry<GridField, WEditor> entry : editors.entrySet()) {
        if (entry.getValue().getComponent().getParent() != null) {
            Component child = entry.getValue().getComponent();
            Div div = null;
            while (div == null && child != null) {
                Component parent = child.getParent();
                if (parent instanceof Div && parent.getParent() instanceof Row)
                    div = (Div) parent;
                else
                    child = parent;
            }
            Component component = div.getFirstChild();
            if (updateCellLabel) {
                if (component instanceof Label) {
                    Label label = (Label) component;
                    label.getChildren().clear();
                    String text = getDisplayText(entry.getValue().getValue(), entry.getValue().getGridField());
                    setLabelText(text, label);
                } else if (component instanceof Checkbox) {
                    Checkbox checkBox = (Checkbox) component;
                    Object value = entry.getValue().getValue();
                    if (value != null && "true".equalsIgnoreCase(value.toString()))
                        checkBox.setChecked(true);
                    else
                        checkBox.setChecked(false);
                }
            }
            component.setVisible(true);
            if (row == null)
                row = ((Row) div.getParent());
            entry.getValue().getComponent().detach();
            entry.getKey().removePropertyChangeListener(entry.getValue());
            entry.getValue().removeValuechangeListener(dataBinder);
        }
    }
    GridTableListModel model = (GridTableListModel) grid.getModel();
    model.setEditing(false);
}
Also used : Div(org.zkoss.zul.Div) Label(org.zkoss.zhtml.Label) Row(org.zkoss.zul.Row) GridField(org.compiere.model.GridField) WEditor(org.adempiere.webui.editor.WEditor) Component(org.zkoss.zk.ui.Component) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent)

Example 60 with Component

use of org.zkoss.zk.ui.Component in project adempiere by adempiere.

the class InfoPAttributePanel method createQuery.

//	actionPerformed
/**
	 * 	Create Query
	 *  <code>
	 * 	Available synonyms:
	 *		M_Product p
	 *		M_ProductPrice pr
	 *		M_AttributeSet pa
	 *	</code>
	 *	@return query
	 */
private String createQuery() {
    /** Base Query
		SELECT *
		FROM M_Product p
 		 INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)
 		 LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)
		WHERE
		**/
    /***	Instance Attributes		*/
    StringBuffer sb = new StringBuffer();
    //	Serial No
    String s = serNoField.getComponent().getText();
    if (s != null && s.length() > 0) {
        sb.append(" AND asi.SerNo");
        if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
            sb.append("=");
        else
            sb.append(" LIKE ");
        sb.append(DB.TO_STRING(s));
    }
    //	Lot Number
    s = lotField.getComponent().getText();
    if (s != null && s.length() > 0) {
        sb.append(" AND asi.Lot");
        if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
            sb.append("=");
        else
            sb.append(" LIKE ");
        sb.append(DB.TO_STRING(s));
    }
    //	Lot ID
    ListItem li = lotSelection.getSelectedItem();
    if (li != null && li.getValue() != null) {
        KeyNamePair pp = (KeyNamePair) li.getValue();
        if (pp != null && pp.getKey() != -1) {
            int ID = pp.getKey();
            sb.append(" AND asi.M_Lot_ID=").append(ID);
        }
    }
    //	Guarantee Date
    Timestamp ts = (Timestamp) guaranteeDateField.getValue();
    if (ts != null) {
        sb.append(" AND TRUNC(asi.GuaranteeDate, 'DD')");
        //	 < = >
        int index = guaranteeDateSelection.getSelectedIndex();
        if (index == 0)
            sb.append("<");
        else if (index == 1)
            sb.append("=");
        else
            sb.append(">");
        sb.append(DB.TO_DATE(ts, true));
    }
    //	Instance Editors
    for (int i = 0; i < m_instanceEditors.size(); i++) {
        StringBuffer iAttr = new StringBuffer();
        Component c = (Component) m_instanceEditors.get(i);
        Component cTo = (Component) m_instanceEditorsTo.get(i);
        int M_Attribute_ID = Integer.parseInt(c.getId());
        if (c instanceof Listbox) {
            Listbox field = (Listbox) c;
            li = field.getSelectedItem();
            if (li != null && li.getValue() != null) {
                KeyNamePair pp = (KeyNamePair) li.getValue();
                if (pp != null && pp.getKey() != -1) {
                    iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
                }
            }
        } else if (c instanceof NumberBox) {
            NumberBox field = (NumberBox) c;
            BigDecimal value = (BigDecimal) field.getValue();
            NumberBox fieldTo = (NumberBox) cTo;
            BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
            if (value != null || valueTo != null) {
                iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
                if (value != null && valueTo == null)
                    iAttr.append("=").append(value);
                else if (value == null && valueTo != null)
                    iAttr.append("<=").append(valueTo);
                else if (value != null && valueTo != null)
                    iAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
            }
        } else {
            Textbox field = (Textbox) c;
            String value = field.getText();
            if (value != null && value.length() > 0) {
                iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
                if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
                    iAttr.append("=");
                else
                    iAttr.append(" LIKE ");
                iAttr.append(DB.TO_STRING(value));
            }
        }
        //	Add to where
        if (iAttr.length() > 0)
            sb.append(" AND asi.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance " + "WHERE ").append(iAttr).append(")");
    }
    //	finish Instance Attributes
    if (sb.length() > 0) {
        sb.insert(0, " AND EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) " + "WHERE s.M_Product_ID=p.M_Product_ID");
        sb.append(")");
    }
    //	Product Attributes 
    for (int i = 0; i < m_productEditors.size(); i++) {
        StringBuffer pAttr = new StringBuffer();
        Component c = (Component) m_productEditors.get(i);
        Component cTo = (Component) m_productEditorsTo.get(i);
        int M_Attribute_ID = Integer.parseInt(c.getId());
        if (c instanceof Listbox) {
            Listbox field = (Listbox) c;
            li = field.getSelectedItem();
            if (li != null && li.getValue() != null) {
                KeyNamePair pp = (KeyNamePair) li.getValue();
                if (pp != null && pp.getKey() != -1) {
                    pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
                }
            }
        } else if (c instanceof NumberBox) {
            NumberBox field = (NumberBox) c;
            BigDecimal value = (BigDecimal) field.getValue();
            NumberBox fieldTo = (NumberBox) cTo;
            BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
            if (value != null || valueTo != null) {
                pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
                if (value != null && valueTo == null)
                    pAttr.append("=").append(value);
                else if (value == null && valueTo != null)
                    pAttr.append("<=").append(valueTo);
                else if (value != null && valueTo != null)
                    pAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
            }
        } else {
            Textbox field = (Textbox) c;
            String value = field.getText();
            if (value != null && value.length() > 0) {
                pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
                if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
                    pAttr.append("=");
                else
                    pAttr.append(" LIKE ");
                pAttr.append(DB.TO_STRING(value));
            }
        }
        //	Add to Where
        if (pAttr.length() > 0)
            sb.append(" AND p.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID " + "FROM M_AttributeInstance WHERE ").append(pAttr).append(")");
    }
    //
    m_query = null;
    if (sb.length() > 0)
        m_query = sb.toString();
    log.config(m_query);
    return m_query;
}
Also used : Textbox(org.zkoss.zul.Textbox) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) NumberBox(org.adempiere.webui.component.NumberBox) Component(org.zkoss.zk.ui.Component) Listbox(org.adempiere.webui.component.Listbox) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Aggregations

Component (org.zkoss.zk.ui.Component)70 IOException (java.io.IOException)8 HtmlBasedComponent (org.zkoss.zk.ui.HtmlBasedComponent)8 Checkbox (org.adempiere.webui.component.Checkbox)7 ToolBarButton (org.adempiere.webui.component.ToolBarButton)7 Div (org.zkoss.zul.Div)7 Listitem (org.zkoss.zul.Listitem)7 MapLayer (au.org.emii.portal.menu.MapLayer)6 Button (org.adempiere.webui.component.Button)6 Tabpanel (org.adempiere.webui.component.Tabpanel)6 WEditor (org.adempiere.webui.editor.WEditor)6 ParseException (org.json.simple.parser.ParseException)6 Event (org.zkoss.zk.ui.event.Event)6 MapComposer (au.org.emii.portal.composer.MapComposer)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 DashboardPanel (org.adempiere.webui.dashboard.DashboardPanel)5 HeaderPanel (org.adempiere.webui.panel.HeaderPanel)5 SidePanel (org.adempiere.webui.panel.SidePanel)5 UiException (org.zkoss.zk.ui.UiException)5