Search in sources :

Example 26 with GridField

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

the class Find method parseUserQuery.

/**
	 * Parse delimited string into user query
	 * Old field sequence: column, operator, value, value to
	 * New field sequence: column, operator, value, value to, and/or, left brackets, right brackets
	 * @param userQuery
	 */
private void parseUserQuery(MUserQuery userQuery) {
    String code = userQuery.getCode();
    log.fine("Parse user query: " + code);
    String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR), -1);
    advancedTable.stopEditor(true);
    DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
    int cnt = model.getRowCount();
    for (int i = cnt - 1; i >= 0; i--) model.removeRow(i);
    for (int i = 0; i < segments.length; i++) {
        String[] fields = segments[i].split(Pattern.quote(FIELD_SEPARATOR));
        model.addRow(new Object[] { "", "", null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null, "" });
        String columnName = null;
        for (int j = 0; j < fields.length; j++) {
            // column
            if (j == 0) {
                for (ValueNamePair vnp : columnValueNamePairs) {
                    if (vnp.getValue().equals(fields[j])) {
                        model.setValueAt(vnp, i, INDEX_COLUMNNAME);
                        columnName = fields[j];
                        break;
                    }
                }
            } else // operator
            if (j == 1) {
                for (ValueNamePair vnp : MQuery.OPERATORS) {
                    if (vnp.getValue().equals(fields[j])) {
                        model.setValueAt(vnp, i, INDEX_OPERATOR);
                        break;
                    }
                }
            } else // value
            if (j == 2 && fields[j].length() > 0) {
                GridField field = getTargetMField(columnName);
                Object value = parseString(field, fields[j]);
                model.setValueAt(value, i, INDEX_VALUE);
            } else // value 2
            if (j == 3 && fields[j].length() > 0) {
                GridField field = getTargetMField(columnName);
                Object value = parseString(field, fields[j]);
                model.setValueAt(value, i, INDEX_VALUE2);
            } else // and/or
            if (j == 4 && fields[j].length() > 0) {
                if (i != 0)
                    model.setValueAt(fields[j], i, INDEX_ANDOR);
            } else if (j == 5 && fields[j].length() > 0) {
                model.setValueAt(fields[j], i, INDEX_LEFTBRACKET);
            } else if (j == 6 && fields[j].length() > 0) {
                model.setValueAt(fields[j], i, INDEX_RIGHTBRACKET);
            }
        }
    }
    advancedTable.invalidate();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ValueNamePair(org.compiere.util.ValueNamePair) GridField(org.compiere.model.GridField)

Example 27 with GridField

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

the class WWindow method getSR_Form.

//  getFieldValue
/**************************************************************************
	 *	Return SingleRow Form details
	 *  @param action action
	 *  @param wsc web session context
	 *  @param ws window status
	 *  @return Form
	 */
public MobileDoc getSR_Form(String action, MobileSessionCtx wsc, WWindowStatus ws) {
    log.fine("Tab=" + ws.curTab.getTabNo());
    form line = new form("WWindow");
    line.addAttribute("selected", "true");
    line.setClass("panel");
    line.setMethod("post");
    line.setTitle(ws.curTab.getName());
    // line.setTarget("_self");
    fs = new fieldset();
    line.addElement(fs);
    /**********************
		 *  For all Fields
		 */
    StringBuffer scriptSrc = new StringBuffer();
    MRole role = MRole.getDefault(wsc.ctx, false);
    //
    //Modified by Rob Klein 4/29/07
    m_searchField = null;
    boolean isTabRO = ws.isReadOnlyView();
    if (ws.curTab.isDisplayed()) {
        int noFields = ws.curTab.getFieldCount();
        for (int i = 0; i < noFields; i++) {
            GridField field = ws.curTab.getField(i);
            String columnName = field.getColumnName();
            /**
				 *  Get Data and convert to String (singleRow)
				 */
            Object oData = ws.curTab.getValue(field);
            //Modified by Rob Klein 4/29/07
            /**
				 *  Get Record ID and Table ID for Processes
				 */
            int recordID = ws.curTab.getRecord_ID();
            int tableID = ws.curTab.getAD_Table_ID();
            /**
				 *  Display field
				 */
            if (field.isDisplayed(true) && field.getDisplayType() != DisplayType.Button) {
                /* todo chart support
					if ( ws.isReadOnlyView() && field.getDisplayType()== 53370 )
					{
						img chart = getChart(field.getAD_Chart_ID(), sess);
						div div = new div();
						div.setClass("row");
						if ( chart != null )
						{
							div.addElement(chart);
							fs.addElement(div);
						}
					}
					else */
                {
                    //
                    boolean hasDependents = ws.curTab.hasDependants(columnName);
                    //Modified by Rob Klein 4/29/07
                    addField(wsc, line, field, oData, hasDependents, recordID, tableID, isTabRO, i, ws.curTab, role);
                    //  Additional Values
                    String dispLogic = field.getDisplayLogic();
                    if (dispLogic != null && dispLogic.length() > 0) {
                        //  replace ' with "
                        dispLogic = dispLogic.replace('\'', '"');
                        scriptSrc.append("document.").append(FORM_NAME).append(".").append(columnName).append(".displayLogic='").append(dispLogic).append("';\n");
                    }
                }
            }
        }
    //	for all fields			
    }
    //	displayed
    /*if (scriptSrc.length() > 0)
			table.addElement(new script(scriptSrc.toString()));*/
    //  Status Line
    int rowNo = ws.curTab.getCurrentRow();
    String statusDB = String.valueOf(rowNo + 1) + " / " + ws.curTab.getRowCount();
    // return createLayout (action, new ul(), wsc, ws, ws.curTab.getDescription(), statusDB);
    if (ws.isReadOnlyView()) {
        for (int i = ws.curTab.getTabNo() + 1; i < ws.mWindow.getTabCount(); i++) {
            GridTab tab = ws.mWindow.getTab(i);
            if (tab.getTabNo() >= ws.curTab.getTabNo() && tab.getTabLevel() <= ws.curTab.getTabLevel())
                // past all children of curTab
                break;
            if (tab.getTabLevel() != ws.curTab.getTabLevel() + 1)
                // not direct child
                continue;
            if (tab.isSortTab())
                continue;
            //Modified by Rob Klein 4/29/07
            a big = new a("WWindow?tab=" + i, tab.getName());
            big.setClass("whiteButton");
            big.setTarget("_self");
            line.addElement(big);
        }
    }
    if (!ws.isReadOnlyView()) {
        a button = new a("#", "Save");
        button.addAttribute("type", "submit");
        button.setClass("redButton");
        // a.setTarget("_self");
        line.addElement(button);
    }
    MobileDoc doc = createPage(ws);
    doc.getBody().addElement(line);
    div div = new div();
    div.setClass("toolbar");
    h1 header = new h1();
    header.setID("pageTitle");
    div.addElement(header);
    a anchor = new a();
    anchor.setClass("button");
    anchor.setHref(MobileEnv.getBaseDirectory("WMenu"));
    anchor.setTarget("_self");
    anchor.addElement("Menu");
    div.addElement(anchor);
    anchor = new a("WWindow?action=list", "Back");
    anchor.setID("previousButton");
    anchor.setClass("button");
    anchor.setTarget("_self");
    div.addElement(anchor);
    doc.getBody().addElement(div);
    if (!ws.curTab.isReadOnly() && ws.isReadOnlyView()) {
        div = new div();
        div.setClass("footer");
        a a = new a("WWindow?action=edit", "Edit");
        a.setClass("redButton");
        a.setTarget("_self");
        div.addElement(a);
        doc.getBody().addElement(div);
    }
    return doc;
}
Also used : org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) MRole(org.compiere.model.MRole) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) GridTab(org.compiere.model.GridTab)

Example 28 with GridField

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

the class WLocation method doGet.

/**
	 * Process the HTTP Get request - initial Start
	 * Needs to have parameters FormName and ColumnName
	 *
	 * @param request request
	 * @param response response
	 * @throws ServletException
	 * @throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.fine("");
    HttpSession sess = request.getSession();
    WWindowStatus ws = WWindowStatus.get(request);
    if (ws == null) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = MobileUtil.getParameter(request, "ColumnName");
    log.info("ColumnName=" + columnName + " - " + ws.toString());
    //
    GridField mField = ws.curTab.getField(columnName);
    log.config("ColumnName=" + columnName + ", MField=" + mField);
    if (mField == null || columnName == null || columnName.equals("")) {
        MobileUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
        return;
    }
    MLocation location = null;
    Object value = mField.getValue();
    if (value != null && value instanceof Integer)
        location = new MLocation(ws.ctx, ((Integer) value).intValue(), null);
    else
        location = new MLocation(ws.ctx, 0, null);
    //String targetBase = "parent.WWindow." + WWindow.FORM_NAME + "." + columnName;
    String targetBase = "opener.WWindow." + WWindow.FORM_NAME + "." + columnName;
    String action = request.getRequestURI();
    //  Create Document
    MobileDoc doc = MobileDoc.createPopup(mField.getHeader());
    boolean hasDependents = ws.curTab.hasDependants(columnName);
    boolean hasCallout = mField.getCallout().length() > 0;
    //  Reset
    button reset = new button();
    //  translate
    reset.addElement("Reset");
    String script = targetBase + "D.value='';" + targetBase + "F.value='';closePopup();";
    if (hasDependents || hasCallout)
        script += "startUpdate(" + targetBase + "F);";
    reset.setOnClick(script);
    //
    div div = new div();
    div.setClass("toolbar");
    h1 header = new h1();
    header.setID("pageTitle");
    div.addElement(header);
    a anchor = new a();
    anchor.setID("backButton");
    anchor.setClass("button");
    div.addElement(anchor);
    doc.getBody().addElement(fillForm(ws, action, location, targetBase, hasDependents || hasCallout)).addElement(reset).addElement(div);
    //
    //	log.trace(log.l6_Database, doc.toString());
    MobileUtil.createResponse(request, response, this, null, doc, true);
}
Also used : org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) HttpSession(javax.servlet.http.HttpSession) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.button(org.apache.ecs.xhtml.button) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) MLocation(org.compiere.model.MLocation)

Example 29 with GridField

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

the class WWindow method getSR_Form.

//  getFieldValue
/**************************************************************************
	 *	Return SingleRow Form details
	 *  @param action action
	 *  @param wsc web session context
	 *  @param ws window status
	 *  @return Form
	 */
public WebDoc getSR_Form(String action, WebSessionCtx wsc, WWindowStatus ws) {
    log.fine("Tab=" + ws.curTab.getTabNo());
    /**********************
		 *  For all Fields
		 */
    //Modified by Rob Klein 4/29/07
    //table table = new table()
    //	.setAlign(AlignType.CENTER);
    table table = new table();
    table.setClass("centerTable");
    StringBuffer scriptSrc = new StringBuffer();
    MRole role = MRole.getDefault(wsc.ctx, false);
    //
    tr line = new tr();
    //Modified by Rob Klein 4/29/07
    m_searchField = null;
    boolean isTabRO = ws.curTab.isReadOnly();
    if (ws.curTab.isDisplayed()) {
        int noFields = ws.curTab.getFieldCount();
        for (int i = 0; i < noFields; i++) {
            GridField field = ws.curTab.getField(i);
            String columnName = field.getColumnName();
            /**
				 *  Get Data and convert to String (singleRow)
				 */
            Object oData = ws.curTab.getValue(field);
            //Modified by Rob Klein 4/29/07
            /**
				 *  Get Record ID and Table ID for Processes
				 */
            int recordID = ws.curTab.getRecord_ID();
            int tableID = ws.curTab.getAD_Table_ID();
            /**
				 *  Display field
				 */
            if (field.isDisplayed(true)) {
                if (!field.isSameLine())
                    line = new tr();
                //
                boolean hasDependents = ws.curTab.hasDependants(columnName);
                //Modified by Rob Klein 4/29/07
                addField(wsc, line, field, oData, hasDependents, recordID, tableID, isTabRO, i, ws.curTab, role);
                //addField(wsc, line, field, oData, hasDependents);
                table.addElement(line);
                //  Additional Values
                String dispLogic = field.getDisplayLogic();
                if (dispLogic != null && dispLogic.length() > 0) {
                    //  replace ' with "
                    dispLogic = dispLogic.replace('\'', '"');
                    scriptSrc.append("document.").append(FORM_NAME).append(".").append(columnName).append(".displayLogic='").append(dispLogic).append("';\n");
                }
                if (m_searchField == null)
                    if (columnName.equals("Description"))
                        m_searchField = columnName;
                    else if (columnName.equals("Name"))
                        m_searchField = columnName;
                    else if (columnName.equals("DocumentNo"))
                        m_searchField = columnName;
                    else if (columnName.equals("Value"))
                        m_searchField = columnName;
            }
        }
    //	for all fields
    }
    //	displayed
    if (scriptSrc.length() > 0)
        table.addElement(new script(scriptSrc.toString()));
    //  Status Line
    int rowNo = ws.curTab.getCurrentRow();
    String statusDB = String.valueOf(rowNo + 1) + " / " + ws.curTab.getRowCount();
    //
    return createLayout(action, table, wsc, ws, ws.curTab.getDescription(), statusDB);
}
Also used : MRole(org.compiere.model.MRole) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.script(org.apache.ecs.xhtml.script)

Example 30 with GridField

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

the class WWindow method getMR_Form.

//	getSR_Form
/**************************************************************************
	 *	Return MultiRow Form details
	 *  @param action action
	 *  @param wsc session context
	 *  @param ws window status
	 *  @return Form
	 */
public WebDoc getMR_Form(String action, WebSessionCtx wsc, WWindowStatus ws) {
    log.fine("Tab=" + ws.curTab.getTabNo());
    int initRowNo = ws.curTab.getCurrentRow();
    /**
		 *  Table Header
		 */
    table table = new table().setAlign(AlignType.CENTER);
    //Modified by Rob Klein 4/29/07
    table.setClass("MultiRow table-autofilter table-filterable table-autosort table-autostripe table-stripeclass:alternate");
    //.setClass("MultiRow");
    table.setBorder(1);
    table.setCellSpacing(1);
    tr line = new tr();
    //  First Column
    //Modified by Rob Klein 4/29/07
    m_searchField = null;
    line.addElement(new th().addElement(" "));
    //	Tab not displayed
    if (!ws.curTab.isDisplayed())
        return createLayout(action, table, wsc, ws, "The table is not displayed", "-");
    int noFields = ws.curTab.getFieldCount();
    //  for all (header) columns
    for (int colNo = 0; colNo < noFields; colNo++) {
        GridField field = ws.curTab.getField(colNo);
        String columnName = field.getColumnName();
        if (field.isDisplayed(false)) {
            th th = new th();
            //Modified by Rob Klein 4/29/07 with Autofilter
            th.addElement(field.getHeader()).setClass("table-filterable table-filtered table-sortable:default");
            //th.addElement(field.getHeader()); 
            th.setAbbr(field.getDescription());
            line.addElement(th);
            if (m_searchField == null)
                if (columnName.equals("Description"))
                    m_searchField = columnName;
                else if (columnName.equals("Name"))
                    m_searchField = columnName;
                else if (columnName.equals("DocumentNo"))
                    m_searchField = columnName;
                else if (columnName.equals("Value"))
                    m_searchField = columnName;
        }
    }
    //  for all columns
    //	Modified by Rob Klein Client Side Filter Manual Filter 6/1/07
    //tr line2 = new tr();
    //th th = new th();
    //input filter = new input (input.TYPE_TEXT, "  filter", "");
    //filter.setOnKeyUp("Table.filter(this,this)");
    //th.addElement(" ");
    //line2.addElement(th);
    //input filter = null;
    //for (int colNo = 0; colNo < noFields; colNo++)
    //{
    //	GridField field = ws.curTab.getField(colNo);
    //	if (field.isDisplayed(false))
    //	{
    //		th = new th();
    //		filter = new input (input.TYPE_TEXT, field.getHeader()+"filter", "");
    //		filter.setOnKeyUp("Table.filter(this,this)");
    //		th.addElement(filter);				
    //		line2.addElement(th);				
    //line.addElement(th);
    //	}
    //}   //  for all columns
    //Modified by Rob Klein 4/29/07
    table.addElement(new thead().addElement(line));
    //Modified by Rob Klein 4/29/07
    table.addElement("<TBODY>");
    /**
		 *  Table Lines
		 */
    int lastRow = initRowNo + MAX_LINES;
    lastRow = Math.min(lastRow, ws.curTab.getRowCount());
    for (int lineNo = initRowNo; lineNo < lastRow; lineNo++) {
        //  Row
        ws.curTab.navigate(lineNo);
        line = new tr();
        //  Selector
        button selector = new button();
        //  displays ">"
        selector.addElement("&gt;");
        selector.setOnClick("document." + FORM_NAME + "." + P_MR_RowNo + ".value='" + lineNo + "'; submit();");
        line.addElement(new td().addElement(selector));
        //  for all columns
        for (int colNo = 0; colNo < noFields; colNo++) {
            td td = new td();
            //
            GridField field = ws.curTab.getField(colNo);
            if (!field.isDisplayed(false))
                continue;
            //  Get Data - turn to string
            Object data = ws.curTab.getValue(field.getColumnName());
            String info = null;
            //
            if (data == null)
                info = "";
            else {
                int dt = field.getDisplayType();
                switch(dt) {
                    case DisplayType.Date:
                        info = wsc.dateFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.DateTime:
                        info = wsc.dateTimeFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.Amount:
                        info = wsc.amountFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.Number:
                    case DisplayType.CostPrice:
                        info = wsc.numberFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.Quantity:
                        info = wsc.quantityFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.Integer:
                        info = wsc.integerFormat.format(data);
                        td.setAlign("right");
                        break;
                    case DisplayType.YesNo:
                        info = Msg.getMsg(ws.ctx, data.toString());
                        break;
                    /** @todo output formatting 2 */
                    default:
                        if (DisplayType.isLookup(dt))
                            info = field.getLookup().getDisplay(data);
                        else
                            info = data.toString();
                }
            }
            //  Empty info
            if (info == null || info.length() == 0)
                //  Space
                info = "&nbsp;";
            //
            td.addElement(info);
            line.addElement(td);
        }
        //  for all columns
        table.addElement(line);
    }
    //  for all table lines
    //Modified by Rob Klein 4/29/07
    table.addElement("</TBODY>");
    //  Status Line
    String statusDB = String.valueOf(initRowNo + 1) + "-" + String.valueOf(lastRow) + " / " + ws.curTab.getRowCount();
    return createLayout(action, table, wsc, ws, ws.curTab.getDescription(), statusDB);
}
Also used : org.apache.ecs.xhtml.button(org.apache.ecs.xhtml.button) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) org.apache.ecs.xhtml.thead(org.apache.ecs.xhtml.thead) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr)

Aggregations

GridField (org.compiere.model.GridField)114 MQuery (org.compiere.model.MQuery)15 WEditor (org.adempiere.webui.editor.WEditor)11 GridFieldVO (org.compiere.model.GridFieldVO)10 GridTab (org.compiere.model.GridTab)10 Lookup (org.compiere.model.Lookup)9 org.apache.ecs.xhtml.tr (org.apache.ecs.xhtml.tr)8 MLookup (org.compiere.model.MLookup)8 Component (java.awt.Component)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)7 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)7 ValueNamePair (org.compiere.util.ValueNamePair)7 SQLException (java.sql.SQLException)6 MBrowseField (org.adempiere.model.MBrowseField)6 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)6 VEditor (org.compiere.grid.ed.VEditor)6 Point (java.awt.Point)5 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)5 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)5