Search in sources :

Example 1 with MUserQuery

use of org.compiere.model.MUserQuery in project adempiere by adempiere.

the class FindWindow method cmd_save.

//	parseValue
/**
	 * Save the advanced query in the database using the query name. If the query name is set,
	 * the query will be updated or a new query saved.
	 * @param saveQuery	Save the query as the Last Query.  Set to true when running the query.
	 * Set to false to only save using the query name.
	 */
private void cmd_save(boolean saveQuery) {
    //
    StringBuffer code = codeUserQuery();
    //  Save the query
    //  Every query is saved automatically as ** Last Query ** when run.
    //  Queries run without a name will not be saved.
    String name = fQueryName.getValue();
    if (name == null) {
        return;
    }
    if (name.equals(m_sNew) || name.equals(m_sLast) || name.equals(m_sTipText) || Util.isEmpty(name, true)) {
    // No name to save to.  Just run the query.
    } else // Save the query in the database.
    {
        MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name);
        if (code.length() > 0) {
            // New or updated
            if (// Create a new record
            uq == null) {
                uq = new MUserQuery(Env.getCtx(), 0, null);
                uq.setName(name);
                uq.setAD_Table_ID(m_AD_Table_ID);
                //red1 UserQuery [ 1798539 ] taking in new field from Compiere
                uq.setAD_Tab_ID(m_AD_Tab_ID);
                //red1 - [ 1798539 ] missing in Compiere delayed source :-)
                uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
            }
            // Update the query code
            uq.setCode(code.toString());
        } else if (// Delete the query
        code.length() <= 0) {
            if (uq.delete(true)) {
                FDialog.info(m_targetWindowNo, this, "Deleted", name);
                refreshUserQueries();
            } else
                FDialog.warn(m_targetWindowNo, this, "DeleteError", name);
            return;
        }
        //
        if (uq.save()) {
            //FDialog.info (m_targetWindowNo, this, "Saved", name);
            refreshUserQueries();
        } else
            FDialog.warn(m_targetWindowNo, this, "SaveError", name);
    }
    //  Save the query as the Last Query.
    if (saveQuery) {
        MUserQuery last = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, m_sLast);
        if (code.length() > 0) {
            // New or update				
            if (// Create a new record
            last == null) {
                last = new MUserQuery(Env.getCtx(), 0, null);
                last.setName(m_sLast);
                last.setAD_Table_ID(m_AD_Table_ID);
                last.setAD_Tab_ID(m_AD_Tab_ID);
                last.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
            }
            // Update the query code
            last.setCode(code.toString());
        } else if (code.length() <= 0) {
            // Delete the query
            if (last != null && !last.delete(true))
                FDialog.warn(m_targetWindowNo, this, "DeleteError", name);
            return;
        }
        if (!last.save())
            FDialog.warn(m_targetWindowNo, this, "SaveError", name);
    }
}
Also used : MUserQuery(org.compiere.model.MUserQuery)

Example 2 with MUserQuery

use of org.compiere.model.MUserQuery in project adempiere by adempiere.

the class FindWindow method cmd_delete.

//  onEvent
/**
	 * 
	 */
private void cmd_delete() {
    int index = advancedPanel.getSelectedIndex();
    if (index < 0) {
        int index0 = fQueryName.getSelectedIndex();
        if (index0 < 0)
            return;
        MUserQuery uq = userQueries[index0];
        uq.delete(true);
        userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
        for (int i = 0; i < userQueries.length; i++) fQueryName.appendItem(userQueries[i].getName());
        fQueryName.setValue("");
    } else {
        advancedPanel.getSelectedItem().detach();
        advancedPanel.setSelectedIndex(--index);
    //refreshUserQueries();
    }
}
Also used : MUserQuery(org.compiere.model.MUserQuery)

Example 3 with MUserQuery

use of org.compiere.model.MUserQuery in project lar_361 by comitsrl.

the class Find method cmd_save.

// cmd_new
/**
 *	Save (Advanced)
 */
private void cmd_save(boolean saveQuery) {
    advancedTable.stopEditor(true);
    // 
    m_query = new MQuery(m_tableName);
    m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
    StringBuffer code = new StringBuffer();
    int openBrackets = 0;
    for (int row = 0; row < advancedTable.getRowCount(); row++) {
        // Column
        Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME);
        if (column == null)
            continue;
        String ColumnName = column instanceof ValueNamePair ? ((ValueNamePair) column).getValue() : column.toString();
        String infoName = column.toString();
        // 
        GridField field = getTargetMField(ColumnName);
        if (field == null)
            continue;
        boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
        String ColumnSQL = field.getColumnSQL(false);
        String lBrackets = (String) advancedTable.getValueAt(row, INDEX_LEFTBRACKET);
        if (lBrackets != null)
            openBrackets += lBrackets.length();
        String rBrackets = (String) advancedTable.getValueAt(row, INDEX_RIGHTBRACKET);
        if (rBrackets != null)
            openBrackets -= rBrackets.length();
        boolean and = true;
        if (row > 0)
            and = !"OR".equals((String) advancedTable.getValueAt(row, INDEX_ANDOR));
        // Op
        Object op = advancedTable.getValueAt(row, INDEX_OPERATOR);
        if (op == null)
            continue;
        String Operator = ((ValueNamePair) op).getValue();
        // Value	******
        Object value = advancedTable.getValueAt(row, INDEX_VALUE);
        if (value == 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);
                if (code.length() > 0)
                    code.append(SEGMENT_SEPARATOR);
                code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
            } else {
                continue;
            }
        } else {
            Object parsedValue = parseValue(field, value);
            if (parsedValue == null)
                continue;
            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	******
            Object value2 = null;
            if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op)) {
                value2 = advancedTable.getValueAt(row, INDEX_VALUE2);
                if (value2 == null)
                    continue;
                Object parsedValue2 = parseValue(field, value2);
                String infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                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(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
        }
    }
    Object selected = fQueryName.getSelectedItem();
    if (selected != null && saveQuery) {
        String name = selected.toString();
        if (Util.isEmpty(name, true)) {
            ADialog.warn(m_targetWindowNo, this, "FillMandatory", Msg.translate(Env.getCtx(), "Name"));
            return;
        }
        MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name);
        if (uq == null && code.length() > 0) {
            uq = new MUserQuery(Env.getCtx(), 0, null);
            uq.setName(name);
            // red1 UserQuery [ 1798539 ] taking in new field from Compiere
            uq.setAD_Tab_ID(m_AD_Tab_ID);
            // red1 - [ 1798539 ] missing in Compiere delayed source :-)
            uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
        } else if (uq != null && code.length() == 0) {
            if (uq.delete(true)) {
                ADialog.info(m_targetWindowNo, this, "Deleted", name);
                refreshUserQueries();
            } else
                ADialog.warn(m_targetWindowNo, this, "DeleteError", name);
            return;
        }
        uq.setCode(code.toString());
        uq.setAD_Table_ID(m_AD_Table_ID);
        // 
        if (uq.save()) {
            ADialog.info(m_targetWindowNo, this, "Saved", name);
            refreshUserQueries();
        } else
            ADialog.warn(m_targetWindowNo, this, "SaveError", name);
    }
}
Also used : MUserQuery(org.compiere.model.MUserQuery) MQuery(org.compiere.model.MQuery) ValueNamePair(org.compiere.util.ValueNamePair) GridField(org.compiere.model.GridField)

Example 4 with MUserQuery

use of org.compiere.model.MUserQuery in project adempiere by adempiere.

the class WSearch method fillPopup.

/**
	 * Find the search targets and load the pop-up menu.  If there are no saved
	 * searches, the FindWindow will open.
	 */
private void fillPopup() {
    MUserQuery[] search = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
    if (search.length == 0) {
        // No queries to add to the popup. Just return;
        return;
    }
    //  There are saved queries, so create the pop-up menu.
    //  The first item is "Search" which will open the FindWindow
    Menuitem menuItem = new Menuitem(Msg.getMsg(Env.getCtx(), "Search"));
    menuItem.addEventListener(Events.ON_CLICK, new EventListener() {

        @Override
        public void onEvent(Event event) throws Exception {
            // Just open the find window
            find();
        }
    });
    m_popup.appendChild(menuItem);
    for (final MUserQuery query : search) {
        menuItem = new Menuitem(query.getName());
        menuItem.addEventListener(Events.ON_CLICK, new EventListener() {

            @Override
            public void onEvent(Event event) throws Exception {
                // Set the query
                m_query = query.getQuery(m_AD_Table_ID, m_targetWindowNo, m_findFields);
                m_panel.onFindCallback(m_query);
            }
        });
        m_popup.appendChild(menuItem);
    }
}
Also used : MUserQuery(org.compiere.model.MUserQuery) Menuitem(org.zkoss.zul.Menuitem) Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 5 with MUserQuery

use of org.compiere.model.MUserQuery in project adempiere by adempiere.

the class ASearch method getSearchTargets.

/**
	 * 	Get the UserQuery for the table.
	 *  Fill the list and the popup menu
	 */
private void getSearchTargets() {
    MUserQuery[] search = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
    KeyNamePair pp = null;
    if (search.length == 0) {
        find();
        return;
    } else {
        pp = new KeyNamePair(0, Msg.getMsg(Env.getCtx(), "Search"));
        m_list.add(pp);
        m_popup.add(pp.toString()).addActionListener(this);
    }
    for (MUserQuery query : search) {
        pp = new KeyNamePair(query.getAD_UserQuery_ID(), query.getName());
        m_list.add(pp);
        m_popup.add(pp.toString()).addActionListener(this);
    }
    if (m_invoker.isShowing() && m_list.size() > 1) {
        m_popup.show(m_invoker, 0, m_invoker.getHeight());
    } else {
        launchSearch(pp);
    }
}
Also used : MUserQuery(org.compiere.model.MUserQuery) KeyNamePair(org.compiere.util.KeyNamePair)

Aggregations

MUserQuery (org.compiere.model.MUserQuery)8 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1 GridField (org.compiere.model.GridField)1 MQuery (org.compiere.model.MQuery)1 KeyNamePair (org.compiere.util.KeyNamePair)1 ValueNamePair (org.compiere.util.ValueNamePair)1 Event (org.zkoss.zk.ui.event.Event)1 EventListener (org.zkoss.zk.ui.event.EventListener)1 Menuitem (org.zkoss.zul.Menuitem)1