Search in sources :

Example 36 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class FindWindow method codeUserQuery.

//	cmd_save
/**
     * Code the query parameters entered in the table into a string that can be saved in the database.
     * This is the counterpart to {@link #parseUserQuery()}. Also updates the {@link #m_query} variable with 
     * the current query information.
     * @return a StringBuffer containing the coded query information.
     */
private StringBuffer codeUserQuery() {
    m_query = new MQuery(m_tableName);
    StringBuffer code = new StringBuffer();
    int openBrackets = 0;
    List<?> rowList = advancedPanel.getChildren();
    for (int rowIndex = 1; rowIndex < rowList.size(); rowIndex++) {
        //  Column
        ListItem row = (ListItem) rowList.get(rowIndex);
        Listbox column = (Listbox) row.getFellow("listColumn" + row.getId());
        if (column == null)
            continue;
        String ColumnName = column.getSelectedItem().getValue().toString();
        String infoName = column.toString();
        //
        GridField field = getTargetMField(ColumnName);
        if (field == null)
            // Elaine 2008/07/29
            continue;
        boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
        String ColumnSQL = field.getColumnSQL(false);
        // Left brackets
        Listbox listLeftBracket = (Listbox) row.getFellow("listLeftBracket" + row.getId());
        String lBrackets = listLeftBracket.getSelectedItem().getValue().toString();
        if (lBrackets != null)
            openBrackets += lBrackets.length();
        // Right brackets
        Listbox listRightBracket = (Listbox) row.getFellow("listRightBracket" + row.getId());
        String rBrackets = listRightBracket.getSelectedItem().getValue().toString();
        if (rBrackets != null)
            openBrackets -= rBrackets.length();
        // And Or
        Listbox listAndOr = (Listbox) row.getFellow("listAndOr" + row.getId());
        String andOr = listAndOr.getSelectedItem().getValue().toString();
        boolean and = true;
        if (rowIndex > 1) {
            and = !"OR".equals(andOr);
        }
        //  Op
        Listbox op = (Listbox) row.getFellow("listOperator" + row.getId());
        if (op == null)
            continue;
        String Operator = op.getSelectedItem().getValue().toString();
        //  Value   ******
        ListCell cellQueryFrom = (ListCell) row.getFellow("cellQueryFrom" + row.getId());
        Object value = cellQueryFrom.getAttribute("value");
        ListCell cellQueryTo = (ListCell) row.getFellow("cellQueryTo" + row.getId());
        Object value2 = cellQueryTo.getAttribute("value");
        if (value == null) {
            // Capture the case "is null" ?
            if (MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op)) {
                m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets);
            } else {
                continue;
            }
        } else {
            // Value has a value - check for range too.
            Object parsedValue = parseValue(field, value);
            if (parsedValue == null)
                continue;
            //TODO - verify compatibility with find.java
            if (field.isEncryptedColumn()) {
                value = SecureEngine.encrypt(value);
            }
            String infoDisplay = value.toString();
            if (field.isLookup())
                infoDisplay = field.getLookup().getDisplay(value);
            else if (field.getDisplayType() == DisplayType.YesNo)
                infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay);
            //  Value2  ******
            if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op.getSelectedItem().toValueNamePair())) {
                if (value2 == null)
                    continue;
                Object parsedValue2 = parseValue(field, value2);
                String infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                //encrypt the value if we are searching an encrypted column.
                if (field.isEncryptedColumn()) {
                    value2 = SecureEngine.encrypt(value2);
                }
                m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, infoName, infoDisplay, infoDisplay_to, and, openBrackets);
            } else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
                if (!(parsedValue instanceof Integer)) {
                    continue;
                }
                m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
            } else
                m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets);
        }
        if (code.length() > 0)
            code.append(SEGMENT_SEPARATOR);
        code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append(value.toString()).append(FIELD_SEPARATOR).append(value2 != null ? value2.toString() : "").append(FIELD_SEPARATOR).append(andOr).append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
    }
    return code;
}
Also used : ListCell(org.adempiere.webui.component.ListCell) MQuery(org.compiere.model.MQuery) ListItem(org.adempiere.webui.component.ListItem) GridField(org.compiere.model.GridField) Listbox(org.adempiere.webui.component.Listbox)

Example 37 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class InfoSchedule method fillResource.

//	fillResourceType
/**
	 * 	Fill Resource Pick from Resource Type
	 */
private void fillResource() {
    ListItem listItem = fieldResourceType.getSelectedItem();
    if (listItem == null)
        return;
    //	Get Resource Type
    KeyNamePair pp = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
    int S_ResourceType_ID = pp.getKey();
    KeyNamePair defaultValue = null;
    //	Load Resources
    m_loading = true;
    fieldResource.getChildren().clear();
    String sql = "SELECT S_Resource_ID, Name FROM S_Resource WHERE S_ResourceType_ID=? ORDER BY 2";
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, S_ResourceType_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            if (m_mAssignment.getS_Resource_ID() == pp.getKey())
                defaultValue = pp;
            fieldResource.appendItem(pp.getName(), pp.getKey());
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    if (defaultValue != null) {
        int cnt = fieldResource.getItemCount();
        for (int i = 0; i < cnt; i++) {
            ListItem li = fieldResource.getItemAtIndex(i);
            Integer key = (Integer) li.getValue();
            if (key.intValue() == defaultValue.getKey()) {
                fieldResource.setSelectedItem(li);
                break;
            }
        }
    } else if (fieldResource.getItemCount() > 0) {
        fieldResource.setSelectedIndex(0);
    }
    m_loading = false;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair)

Example 38 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class ADSortTab method init.

/**
	 * 	Static Layout
	 * 	@throws Exception
	 */
private void init() throws Exception {
    this.setStyle("height: 100%; width: 100%;");
    //
    noLabel.setValue("No");
    yesLabel.setValue("Yes");
    //yesList.setHeight("100%");
    //noList.setHeight("100%");
    yesList.setVflex(true);
    noList.setVflex(true);
    EventListener mouseListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            if (Events.ON_DOUBLE_CLICK.equals(event.getName())) {
                migrateValueAcrossLists(event);
            }
        }
    };
    yesList.addDoubleClickListener(mouseListener);
    noList.addDoubleClickListener(mouseListener);
    //
    EventListener actionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            migrateValueAcrossLists(event);
        }
    };
    yesList.setSeltype("multiple");
    noList.setSeltype("multiple");
    bAdd.setImage(ServletFns.resolveThemeURL("~./images/Detail24.png"));
    bAdd.addEventListener(Events.ON_CLICK, actionListener);
    bRemove.setImage(ServletFns.resolveThemeURL("~./images/Parent24.png"));
    bRemove.addEventListener(Events.ON_CLICK, actionListener);
    EventListener crossListMouseListener = new DragListener();
    yesList.addOnDropListener(crossListMouseListener);
    noList.addOnDropListener(crossListMouseListener);
    yesList.setItemDraggable(true);
    noList.setItemDraggable(true);
    actionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            migrateValueWithinYesList(event);
        }
    };
    bUp.setImage(ServletFns.resolveThemeURL("~./images/Previous24.png"));
    bUp.addEventListener(Events.ON_CLICK, actionListener);
    bDown.setImage(ServletFns.resolveThemeURL("~./images/Next24.png"));
    bDown.addEventListener(Events.ON_CLICK, actionListener);
    EventListener yesListMouseMotionListener = new EventListener() {

        public void onEvent(Event event) throws Exception {
            if (event instanceof DropEvent) {
                DropEvent me = (DropEvent) event;
                ListItem startItem = (ListItem) me.getDragged();
                ListItem endItem = (ListItem) me.getTarget();
                if (startItem.getListbox() == endItem.getListbox() && startItem.getListbox() == yesList) {
                    int startIndex = yesList.getIndexOfItem(startItem);
                    int endIndex = yesList.getIndexOfItem(endItem);
                    Object endElement = yesModel.getElementAt(endIndex);
                    Object element = yesModel.getElementAt(startIndex);
                    yesModel.removeElement(element);
                    endIndex = yesModel.indexOf(endElement);
                    yesModel.add(endIndex, element);
                    yesList.setSelectedIndex(endIndex);
                    if (yesList.getSelectedItem() != null) {
                        AuFocus focus = new AuFocus(yesList.getSelectedItem());
                        Clients.response(focus);
                    }
                    setIsChanged(true);
                }
            }
        }
    };
    yesList.addOnDropListener(yesListMouseMotionListener);
    ListHead listHead = new ListHead();
    listHead.setParent(yesList);
    ListHeader listHeader = new ListHeader();
    listHeader.appendChild(yesLabel);
    listHeader.setParent(listHead);
    listHead = new ListHead();
    listHead.setParent(noList);
    listHeader = new ListHeader();
    listHeader.appendChild(noLabel);
    listHeader.setParent(listHead);
    Span span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 40%;");
    span.appendChild(noList);
    Vbox vbox = new Vbox();
    vbox.appendChild(bAdd);
    vbox.appendChild(bRemove);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 46px");
    span.appendChild(vbox);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 40%");
    span.appendChild(yesList);
    vbox = new Vbox();
    vbox.appendChild(bUp);
    vbox.appendChild(bDown);
    span = new Span();
    span.setParent(this);
    span.setStyle("height: 99%; display: inline-block; width: 46px");
    span.appendChild(vbox);
}
Also used : DropEvent(org.zkoss.zk.ui.event.DropEvent) Span(org.zkoss.zhtml.Span) SQLException(java.sql.SQLException) AuFocus(org.zkoss.zk.au.out.AuFocus) ListHead(org.adempiere.webui.component.ListHead) ListDataEvent(org.zkoss.zul.event.ListDataEvent) Event(org.zkoss.zk.ui.event.Event) DropEvent(org.zkoss.zk.ui.event.DropEvent) ListHeader(org.adempiere.webui.component.ListHeader) EventListener(org.zkoss.zk.ui.event.EventListener) ListItem(org.adempiere.webui.component.ListItem) Vbox(org.zkoss.zul.Vbox)

Example 39 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WRecordAccessDialog method setLine.

//	setLine
/**
	 * 	Set Selection
	 *	@param ra record access
	 */
private void setLine(MRecordAccess ra) {
    int AD_Role_ID = 0;
    boolean active = true;
    boolean exclude = true;
    boolean readonly = false;
    boolean dependent = false;
    //
    if (ra != null) {
        AD_Role_ID = ra.getAD_Role_ID();
        active = ra.isActive();
        exclude = ra.isExclude();
        readonly = ra.isReadOnly();
        dependent = ra.isDependentEntities();
    }
    cbActive.setSelected(active);
    cbExclude.setSelected(exclude);
    cbReadOnly.setSelected(readonly);
    cbDependent.setSelected(dependent);
    bDelete.setDisabled(ra == null);
    //
    ListItem selection = null;
    for (int i = 0; i < roleField.getItemCount(); i++) {
        ListItem pp = roleField.getItemAtIndex(i);
        if (pp != null && (Integer) pp.getValue() != null) {
            if (((Integer) pp.getValue()).intValue() == AD_Role_ID)
                selection = pp;
        }
    }
    if (selection != null && ra != null) {
        roleField.setSelectedItem(selection);
        m_currentData = ra;
        log.fine("" + ra);
    } else
        m_currentData = null;
}
Also used : ListItem(org.adempiere.webui.component.ListItem)

Example 40 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WLocationDialog method setCountry.

private void setCountry() {
    List<?> listCountry = lstCountry.getChildren();
    Iterator<?> iter = listCountry.iterator();
    while (iter.hasNext()) {
        ListItem listitem = (ListItem) iter.next();
        if (m_location.getCountry().equals(listitem.getValue())) {
            lstCountry.setSelectedItem(listitem);
        }
    }
}
Also used : ListItem(org.adempiere.webui.component.ListItem)

Aggregations

ListItem (org.adempiere.webui.component.ListItem)52 KeyNamePair (org.compiere.util.KeyNamePair)22 Timestamp (java.sql.Timestamp)8 Listbox (org.adempiere.webui.component.Listbox)8 SQLException (java.sql.SQLException)7 BigDecimal (java.math.BigDecimal)6 Label (org.adempiere.webui.component.Label)5 ResultSet (java.sql.ResultSet)4 Date (java.util.Date)4 MLocator (org.compiere.model.MLocator)4 ValueNamePair (org.compiere.util.ValueNamePair)4 Charset (java.nio.charset.Charset)3 PreparedStatement (java.sql.PreparedStatement)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 NumberBox (org.adempiere.webui.component.NumberBox)3 Row (org.adempiere.webui.component.Row)3 Textbox (org.adempiere.webui.component.Textbox)3 MAttributeValue (org.compiere.model.MAttributeValue)3 BufferedImage (java.awt.image.BufferedImage)2