Search in sources :

Example 46 with GridField

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

the class WLookup method doGet.

//  init
/**
	 * Process the HTTP Get request - initial Start
	 * Needs to have parameters FormName and ColumnName
	 *
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    WebEnv.dump(request);
    WebEnv.dump(request.getSession());
    //Modified by Rob Klein 4/29/07
    //
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        WebUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = WebUtil.getParameter(request, "ColumnName");
    //Lookup called from a process
    //Modified by Rob Klein 4/29/07
    int AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
    //Lookup modified to include paging
    //Modified by Rob Klein 07/07/07
    int page = WebUtil.getParameterAsInt(request, "page");
    log.info("This is the page on original call" + page);
    if (AD_Process_ID > 0) {
        if (AD_Process_ID < 1 || columnName == null || columnName.equals("")) {
            WebUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
            return;
        }
        String targetBase = "'" + columnName;
        MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
        MProcessPara para = null;
        MProcessPara[] parameter = process.getParameters();
        for (int i = 0; i < parameter.length; i++) {
            para = parameter[i];
            if (para.getColumnName().equals(columnName))
                i = parameter.length;
        }
        //  Create Document
        WebDoc doc = WebDoc.createPopup(para.getColumnName());
        div panel = new div();
        panel.setStyle("height: 330px;overflow: scroll;overflow: auto;");
        panel.addElement(fillTable(wsc, para.getColumnName(), para.getAD_Reference_Value_ID(), request.getRequestURI(), targetBase, false, page));
        //tr tr = new tr().addElement(panel);
        //  Reset
        String text = "Reset";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Reset");
        input resetbtn = new input("button", text, "  " + text);
        resetbtn.setID(text);
        resetbtn.setClass("resetbtn");
        String script = targetBase + "F.value='';" + targetBase + "D.value='';closePopup();";
        resetbtn.setOnClick(script);
        //
        //			
        //First Page
        text = "First";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Next Page");		
        input firstpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        firstpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", 1);return false;");
        firstpgbtn.setID(text);
        firstpgbtn.setClass("firstpgbtn");
        //Previous Page
        text = "Prior";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Prior Page");		
        input prevpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int prevpage = (page == 1) ? 1 : page - 1;
        prevpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + prevpage + ");return false;");
        prevpgbtn.setID(text);
        prevpgbtn.setClass("prevpgbtn");
        //Next Page
        text = "Next";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Next Page");		
        input nextpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int nextpage = (page + 1);
        nextpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + nextpage + ");return false;");
        nextpgbtn.setID(text);
        nextpgbtn.setClass("nextpgbtn");
        //Last Page
        text = "Next";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Next Page");		
        input lastpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int lastpage = m_recordCount / MAX_LINES + 1;
        lastpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + lastpage + ");return false;");
        lastpgbtn.setID(text);
        lastpgbtn.setClass("lastpgbtn");
        int index1 = (page - 1) * MAX_LINES + 1;
        int index2 = (page) * MAX_LINES < m_recordCount ? (page) * MAX_LINES : m_recordCount;
        doc.getTable().addElement(new tr(new td(panel).setColSpan(2)));
        doc.addPopupClose(ws.ctx)[0].addElement("&nbsp;#&nbsp;" + index1 + "-" + index2 + " / " + m_recordCount).addElement(resetbtn).addElement(firstpgbtn).addElement(prevpgbtn).addElement(nextpgbtn).addElement(lastpgbtn);
        WebUtil.createResponse(request, response, this, null, doc, false);
    } else //Lookup called from a window
    {
        //	Modified by Rob Klein 7/01/07
        if (ws == null) {
            WebUtil.createTimeoutPage(request, response, this, null);
            return;
        }
        GridField mField = ws.curTab.getField(columnName);
        log.config("ColumnName=" + columnName + ", MField=" + mField);
        if (mField == null || columnName == null || columnName.equals("")) {
            WebUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
            return;
        }
        //	parent = framesetWindow
        //	Label - Dtata - Field - Button
        String targetBase = "'" + columnName;
        //  Create Document
        WebDoc doc = WebDoc.createPopup(mField.getHeader());
        boolean hasDependents = ws.curTab.hasDependants(columnName);
        boolean hasCallout = mField.getCallout().length() > 0;
        div panel = new div();
        panel.setStyle("height: 330px;overflow: scroll;overflow: auto;");
        panel.addElement(fillTable(wsc, mField.getColumnName(), mField.getAD_Reference_Value_ID(), request.getRequestURI(), targetBase, hasDependents || hasCallout, page));
        //tr tr = new tr().addElement(panel);
        //  Reset
        String text = "Reset";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Reset");		
        input resetbtn = new input(input.TYPE_RESET, text, "  " + text);
        resetbtn.setID(text);
        resetbtn.setClass("resetbtn");
        String script = targetBase + "F.value='';" + targetBase + "D.value='';self.close();";
        if (hasDependents || hasCallout)
            script += "startUpdate(" + targetBase + "F);";
        resetbtn.setOnClick(script);
        //First Page
        text = "First";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "First");		
        input firstpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        firstpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", 1);return false;");
        firstpgbtn.setID(text);
        firstpgbtn.setClass("firstpgbtn");
        //Previous Page
        text = "Prior";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Prior");		
        input prevpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int prevpage = (page == 1) ? 1 : page - 1;
        prevpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + prevpage + ");return false;");
        prevpgbtn.setID(text);
        prevpgbtn.setClass("prevpgbtn");
        //Next Page
        text = "Next";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Next");		
        input nextpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int nextpage = (page + 1);
        nextpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + nextpage + ");return false;");
        nextpgbtn.setID(text);
        nextpgbtn.setClass("nextpgbtn");
        //Last Page
        text = "Last";
        //if (wsc.ctx != null)
        //	text = Msg.getMsg (wsc.ctx, "Last");		
        input lastpgbtn = new input(input.TYPE_BUTTON, text, "  " + text);
        int lastpage = m_recordCount / MAX_LINES + 1;
        lastpgbtn.setOnClick("startLookup('" + columnName + "', " + AD_Process_ID + ", " + lastpage + ");return false;");
        lastpgbtn.setID(text);
        lastpgbtn.setClass("lastpgbtn");
        int index1 = (page - 1) * MAX_LINES + 1;
        int index2 = (page) * MAX_LINES < m_recordCount ? (page) * MAX_LINES : m_recordCount;
        doc.getTable().addElement(new tr(new td(panel).setColSpan(2)));
        doc.addPopupClose(ws.ctx)[0].addElement("&nbsp;#&nbsp;" + index1 + "-" + index2 + " / " + m_recordCount).addElement(resetbtn).addElement(firstpgbtn).addElement(prevpgbtn).addElement(nextpgbtn).addElement(lastpgbtn);
        WebUtil.createResponse(request, response, this, null, doc, false);
    }
}
Also used : MProcess(org.compiere.model.MProcess) MProcessPara(org.compiere.model.MProcessPara) GridField(org.compiere.model.GridField) WebSessionCtx(org.compiere.util.WebSessionCtx) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) WebDoc(org.compiere.util.WebDoc) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr)

Example 47 with GridField

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

the class WWindow method executeSave.

//  executeCommand
/**
	 *  Execute Save
	 *  @param request request
	 *  @param wsc web session
	 *  @param ws
	 */
private void executeSave(HttpServletRequest request, WebSessionCtx wsc, WWindowStatus ws) {
    log.info("");
    boolean error = updateFields(request, wsc, ws);
    //  Check Mandatory
    log.fine("Mandatory check");
    int size = ws.curTab.getFieldCount();
    for (int i = 0; i < size; i++) {
        GridField field = ws.curTab.getField(i);
        if (//  context check
        field.isMandatory(true)) {
            Object value = field.getValue();
            if (value == null || value.toString().length() == 0) {
                //  set editable otherwise deadlock
                field.setInserting(true);
                field.setError(true);
                field.setErrorValue(value == null ? null : value.toString());
                if (!error)
                    error = true;
                log.info("Mandatory Error: " + field.getColumnName());
            } else
                field.setError(false);
        }
    }
    if (error)
        return;
    //  save it - of errors ignore changes
    if (!ws.curTab.dataSave(true))
        ws.curTab.dataIgnore();
    log.fine("done");
}
Also used : GridField(org.compiere.model.GridField)

Example 48 with GridField

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

the class WWindow method updateFields.

//  executeSave
/**
	 * 	Update Field Values from Parameter
	 *	@param request request
	 *	@param wsc session context
	 *	@param ws window status
	 *	@return true if error
	 */
private boolean updateFields(HttpServletRequest request, WebSessionCtx wsc, WWindowStatus ws) {
    boolean error = false;
    try {
        String enc = request.getCharacterEncoding();
        if (enc == null)
            request.setCharacterEncoding(WebEnv.ENCODING);
    } catch (Exception e) {
        log.log(Level.SEVERE, "Set CharacterEndocung=" + WebEnv.ENCODING, e);
    }
    //  loop through parameters
    Enumeration en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        //  ignore hidden commands
        if (key.equals(P_Command) || key.equals(P_ChangedColumn) || key.equals(P_MR_RowNo) || key.equals(P_Tab))
            continue;
        GridField mField = ws.curTab.getField(key);
        //  we found a writable field
        if (mField != null && mField.isEditable(true)) {
            String oldValue = WebUtil.getParameter(request, key);
            String newValue = WebUtil.getParameter(request, key + "F");
            String value = null;
            if (newValue != null) {
                Object val = lookupValue(newValue, mField.getLookup());
                if (val != null)
                    value = val.toString();
            }
            if (value == null)
                value = oldValue;
            Object dbValue = mField.getValue();
            boolean fieldError = false;
            String columnName = mField.getColumnName();
            log.finest(columnName + ": " + (dbValue == null ? "null" : dbValue.toString()) + " -> " + (value == null ? "null" : value.toString()));
            //  same = both null
            if (dbValue == null && value == null)
                continue;
            else //   new value null
            if (dbValue != null && value == null)
                ws.curTab.setValue(mField, null);
            else //  from null to new value
            if (dbValue == null && value != null)
                fieldError = !setFieldValue(wsc, ws, mField, value);
            else //  same
            if (dbValue.equals(value))
                continue;
            else
                fieldError = !setFieldValue(wsc, ws, mField, value);
            //
            if (!error && fieldError) {
                log.info("Error: " + mField.getColumnName());
                error = true;
            }
        }
    }
    /*String columnName = WebUtil.getParameter (request, P_ChangedColumn);
		if (columnName != null && columnName.length() > 0)
		{
			GridField mField = ws.curTab.getField(columnName);
			if (mField != null)
			{
				String value = WebUtil.getParameter(request, columnName);
				Object newValue = getFieldValue (wsc, mField, value);
				if (!ERROR.equals(newValue))
				{
					//	De-Selected Check Boxes are null 
					if (newValue == null && mField.getDisplayType() == DisplayType.YesNo)
						newValue = "N";
					log.fine("ChangedColumn: " + columnName + "=" + newValue);
					ws.curTab.setValue(mField, newValue);
				}
			}
		}*/
    return error;
}
Also used : Enumeration(java.util.Enumeration) GridField(org.compiere.model.GridField) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 49 with GridField

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

the class SmallViewController method dynamicDisplay.

//	vetoableChange
/** 
	 *  This is a semi-recursive function to set field default values based on changes in other fields
	 *  or the context.  It cycles through all fields and changes the value to the updated defaults where
	 *  it makes sense to do so.  For read/write enabled fields, user input or initial default values will
	 *  not be overridden.  The recursive part of the function occurs when events are fired as a result of 
	 *  the change in default values which cause other fields to call this function again.<br>
	 *  <br>
	 *  There is a chance of an infinite loop if two or more read-only fields have defaults based on
	 *  the values of each other and the values are not stable.  
	 *
	 */
protected void dynamicDisplay() {
    for (int index = 0; index < fields.size(); index++) {
        GridField field = getField(index);
        if (field != null) {
            // r/w - check if field is Editable
            boolean rw = !field.isReadOnly();
            if (field.isDisplayed(true)) {
                // check context
                // visibility
                setComponentVisibility(index, true, field.isRange());
                rw = field.isEditablePara(true);
                setEditor_RW(index, rw);
                Boolean valueSet = false;
                Object value = field.getValue();
                // If the field is null, test the defaults again
                if (// If the field is not set 
                value == null || value.toString().length() == 0 || // or we are initializing
                !m_IsLoaded || !rw) {
                    // or the field is read only, then ...
                    // Try to reset the default value - could be null
                    // Don't want to overwrite a user input, so if the field is rw and has
                    // a value, don't change it.
                    Object defaultValue = field.getDefault();
                    if (defaultValue != null && field.getOldValue() == null && (value == null || !value.equals(defaultValue))) {
                        // Set the context and fire events if there is a change in value.
                        // Setting the field value to null fires events even if the field is
                        // already null so don't set null if the value is already null.
                        // Not inserting - overwriting the current value
                        field.setValue(defaultValue, false);
                        // The property change events fired will call this function recursively so
                        // we can bail out of this loop as it will be completed by the subsequent calls
                        valueSet = true;
                        // Check for valid values, mandatory (similar to GridController)
                        boolean manMissing = false;
                        boolean noValue = false;
                        noValue = field.getValue() == null || field.getValue().toString().length() == 0;
                        if (//  check context
                        noValue && field.isEditable(true) && field.isMandatory(true))
                            manMissing = true;
                        CEditor editor = getEditor(index);
                        if (editor != null)
                            editor.setBackground(manMissing || field.isError());
                    }
                    if (field.isRange() && getFieldTo(index) != null) {
                        GridField fieldTo = getFieldTo(index);
                        rw = fieldTo.isEditablePara(true);
                        setEditorTo_RW(index, rw);
                        Object valueTo = fieldTo.getValue();
                        if (valueTo == null || valueTo.toString().length() == 0 || !m_IsLoaded || (!rw && DisplayType.isNumeric(fieldTo.getVO().displayType))) {
                            Object defaultValueTo = fieldTo.getDefault();
                            if (defaultValueTo != null && fieldTo.getOldValue() == null && (valueTo == null || !valueTo.equals(defaultValueTo))) {
                                // Not inserting - overwriting the current value
                                fieldTo.setValue(defaultValueTo, false);
                                valueSet = true;
                                // Check for valid values, mandatory (similar to GridController)
                                boolean manMissing = false;
                                boolean noValue = false;
                                noValue = fieldTo.getValue() == null || fieldTo.getValue().toString().length() == 0;
                                if (//  check context
                                noValue && fieldTo.isEditable(true) && fieldTo.isMandatory(true))
                                    manMissing = true;
                                CEditor editorTo = getEditorTo(index);
                                if (editorTo != null)
                                    editorTo.setBackground(manMissing || fieldTo.isError());
                            }
                        }
                    }
                    if (valueSet)
                        break;
                }
            } else {
                // visibility
                setComponentVisibility(index, false, field.isRange());
            }
        }
    }
}
Also used : CEditor(org.compiere.swing.CEditor) GridField(org.compiere.model.GridField)

Example 50 with GridField

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

the class SmallViewController method propertyChange.

/** 
	 * This function responds to PropertyChangeEvents that are fired by GridFields when the value is set.
	 * The editors and the SmallViewController are both listeners.  The SmallViewController uses
	 * the property events to change the value in dependent fields and set default values were 
	 * necessary.
	 */
public void propertyChange(PropertyChangeEvent evt) {
    GridField changedField = null;
    //	Set GridField
    if (evt.getSource() instanceof GridField) {
        changedField = ((GridField) evt.getSource());
    } else
        return;
    //	Change Dependents
    fieldChange(changedField, evt.getNewValue(), evt.getPropertyName());
}
Also used : GridField(org.compiere.model.GridField)

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