Search in sources :

Example 91 with GridField

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

the class VTableExcelAdapter method actionPerformed.

/**
	 * This method is activated on the Keystrokes we are listening to
	 * in this implementation. Here it listens for Copy and Paste ActionCommands.
	 * 
	 * @param e event 
	 */
public void actionPerformed(ActionEvent e) {
    // Only GridTable model is supported
    if (!(table.getModel() instanceof GridTable)) {
        if (CLogMgt.isLevelFine())
            log.fine("Not supported - " + table.getModel());
        return;
    }
    boolean isCopy = CMD_Copy.equals(e.getActionCommand());
    boolean isCopyWithHeaders = CMD_CopyWithHeaders.equals(e.getActionCommand());
    if (isCopy || isCopyWithHeaders) {
        try {
            int[] selectedRows = table.getSelectedRows();
            if (selectedRows == null || selectedRows.length == 0) {
                return;
            }
            int colscount = table.getColumnCount();
            StringBuffer sb = new StringBuffer();
            GridTable model = (GridTable) table.getModel();
            GridField[] fields = model.getFields();
            // Header
            if (isCopyWithHeaders) {
                for (int col = 0; col < colscount; col++) {
                    String value = "";
                    try {
                        GridField field = fields[col];
                        if (!field.isDisplayed(false)) {
                            continue;
                        }
                        value = field.getHeader();
                    } catch (Exception ex) {
                        log.log(Level.WARNING, "Copy-headers", ex);
                    }
                    value = fixString(value);
                    sb.append(value).append("\t");
                }
                sb.append(Env.NL);
            }
            // Selected rows
            for (int row : selectedRows) {
                for (int col = 0; col < colscount; col++) {
                    Lookup lookup = null;
                    String value = null;
                    Object key = null;
                    GridField field = null;
                    try {
                        key = table.getValueAt(row, col);
                        field = fields[col];
                        if (!field.isDisplayed(false))
                            continue;
                        if (field.isEncryptedColumn() || field.isEncryptedField()) {
                            value = "*";
                        } else if (key instanceof Boolean) {
                            value = Msg.getMsg(Env.getCtx(), ((Boolean) key).booleanValue() ? "Yes" : "No");
                        } else if (key instanceof BigDecimal) {
                            try {
                                value = sysNumberFormat.format(key != null ? key : Env.ZERO);
                            } catch (Exception ex) {
                            }
                        } else if (key instanceof Date) {
                            try {
                                value = sysDateFormat.format(key);
                            } catch (Exception ex) {
                            }
                        } else {
                            lookup = (field != null ? field.getLookup() : null);
                            value = (lookup != null && key != null ? lookup.getDisplay(key) : null);
                            if (value == null && key != null)
                                value = key.toString();
                        }
                    } catch (Exception ex) {
                        log.log(Level.WARNING, "Copy-rows", ex);
                    }
                    value = fixString(value);
                    sb.append(value).append("\t");
                    if (CLogMgt.isLevelFinest())
                        log.finest("col=" + col + ", row=" + row + ": key=" + key + " => value=" + value + ", " + field + ", " + lookup);
                }
                sb.append(Env.NL);
            }
            StringSelection stsel = new StringSelection(sb.toString());
            system = Toolkit.getDefaultToolkit().getSystemClipboard();
            system.setContents(stsel, stsel);
        } catch (Exception ex) {
            log.log(Level.WARNING, "Copy", ex);
        }
    }
}
Also used : GridTable(org.compiere.model.GridTable) GridField(org.compiere.model.GridField) BigDecimal(java.math.BigDecimal) Date(java.util.Date) StringSelection(java.awt.datatransfer.StringSelection) Lookup(org.compiere.model.Lookup)

Example 92 with GridField

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

the class WReport method doGet.

//  init
/**
	 * Process the HTTP Get request
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.fine("doGet");
    log.info(response.toString());
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    m_curTab = ws.curTab;
    //
    WebDoc doc = null;
    File file = null;
    if (ws == null) {
        doc = WebDoc.createPopup("No Context");
        doc.addPopupClose(wsc.ctx);
    } else /**else if (fileName!=null)
		{			
			int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
			File file = new File (fileName);
			String error = WebUtil.streamFile(response, file);
			if (error == null)
				return;
			doc = WebDoc.createWindow(error);
		}**/
    {
        log.info("");
        if (!MRole.getDefault().isCanReport(ws.curTab.getAD_Table_ID())) {
            doc = WebDoc.createPopup("Access Cannot Report");
            doc.addPopupClose(wsc.ctx);
        }
        //	Query
        MQuery query = new MQuery(m_curTab.getTableName());
        //	Link for detail records
        String queryColumn = m_curTab.getLinkColumnName();
        //	Current row otherwise
        if (queryColumn.length() == 0)
            queryColumn = m_curTab.getKeyColumnName();
        //	Find display
        String infoName = null;
        String infoDisplay = null;
        for (int i = 0; i < m_curTab.getFieldCount(); i++) {
            GridField field = m_curTab.getField(i);
            if (field.isKey())
                infoName = field.getHeader();
            if ((field.getColumnName().equals("Name") || field.getColumnName().equals("DocumentNo")) && field.getValue() != null)
                infoDisplay = field.getValue().toString();
            if (infoName != null && infoDisplay != null)
                break;
        }
        if (queryColumn.length() != 0) {
            if (queryColumn.endsWith("_ID"))
                query.addRestriction(queryColumn, MQuery.EQUAL, new Integer(Env.getContextAsInt(wsc.ctx, m_curTab.getWindowNo(), queryColumn)), infoName, infoDisplay);
            else
                query.addRestriction(queryColumn, MQuery.EQUAL, Env.getContext(wsc.ctx, m_curTab.getWindowNo(), queryColumn), infoName, infoDisplay);
        }
        file = getPrintFormats(m_curTab.getAD_Table_ID(), request, m_curTab, query);
        String error = WebUtil.streamFile(response, file);
        if (error == null)
            return;
        doc = WebDoc.createWindow(error);
    }
    //
    WebUtil.createResponse(request, response, this, null, doc, false);
}
Also used : WebDoc(org.compiere.util.WebDoc) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 93 with GridField

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

the class WFindAdv method createPageFindAdv.

//  createFields
private form createPageFindAdv(HttpServletRequest request, HttpServletResponse response, WWindowStatus ws) throws ServletException, IOException {
    form myForm = new form(MobileEnv.getBaseDirectory("/WWindow"), form.METHOD_POST, form.ENC_DEFAULT);
    myForm.setName("WForm");
    myForm.setOnSubmit("this.target=window.opener.name");
    myForm.addElement(createTabs("FindAdv"));
    table table = new table();
    //table.setClass("centerTable");
    tr line = new tr();
    line.addElement(new td().addElement("Field"));
    line.addElement(new td().addElement("Operator"));
    line.addElement(new td().addElement("Value"));
    line.addElement(new td().addElement("To Value"));
    table.addElement(line);
    select select = new select("cboField");
    int size = ws.curTab.getFieldCount();
    for (int i = 0; i < size; i++) {
        GridField mField = ws.curTab.getField(i);
        if (mField.isDisplayed()) {
            select.addElement(new option(mField.getColumnSQL(false)).addElement(mField.getColumnSQL(false)));
        }
    }
    line = new tr();
    line.addElement(new td().addElement(select));
    select = new select("cboOperator", new option[] { new option(LIKE).addElement(LIKE), new option(NOT_LIKE).addElement(NOT_LIKE), new option(EQUAL).addElement(EQUAL), new option(NOT_EQUAL).addElement(NOT_EQUAL), new option(GREATER).addElement(GREATER), new option(GREATER_EQUAL).addElement(GREATER_EQUAL), new option(LESS).addElement(LESS), new option(LESS_EQUAL).addElement(LESS_EQUAL), new option(BETWEEN).addElement(BETWEEN) });
    line.addElement(new td().addElement(select));
    line.addElement(new td().addElement(new input("text", "txtValue", "%")));
    line.addElement(new td().addElement(new input("text", "txtToValue", "")));
    table.addElement(line);
    line = new tr();
    input cmd = new input("button", "cmdAdd", "Add Clause");
    cmd.setOnClick("txtSQL.value+=cboField.value + ' ' + cboOperator.value + ' \\'' + txtValue.value + '\\'\\n'");
    line.addElement(new td().addElement(cmd));
    cmd = new input("button", "cmdAnd", "AND");
    cmd.setOnClick("txtSQL.value+='AND' + '\\n'");
    line.addElement(new td().addElement(cmd));
    table.addElement(line);
    cmd = new input("button", "cmdOr", "OR");
    cmd.setOnClick("txtSQL.value+='OR' + '\\n'");
    line.addElement(new td().addElement(cmd));
    table.addElement(line);
    line = new tr();
    line.addElement(new td().addElement("SQL Clause"));
    table.addElement(line);
    line = new tr();
    line.addElement(new td().addElement(new textarea().setName("txtSQL").setStyle("width:100%")).setColSpan(4));
    table.addElement(line);
    myForm.addElement(table);
    myForm.addElement(new br());
    myForm.addElement(new input("hidden", "PCommand", "FindAdv"));
    myForm.addElement("&nbsp;&nbsp;");
    myForm.addElement(new input("Reset", "", "  Reset").setClass("resetbtn"));
    myForm.addElement("&nbsp;");
    cmd = new input("Submit", "", "  Submit");
    cmd.setClass("submitbtn");
    cmd.setOnClick("if (txtSQL.value.length==0) {alert('Input SQL clause before submit');return false}");
    myForm.addElement(cmd);
    myForm.addElement("&nbsp;");
    cmd = new input("button", "", "  Close");
    cmd.setClass("closebtn");
    cmd.setOnClick("window.close()");
    myForm.addElement(cmd);
    return myForm;
}
Also used : org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.br(org.apache.ecs.xhtml.br) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) org.apache.ecs.xhtml.textarea(org.apache.ecs.xhtml.textarea) 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.option(org.apache.ecs.xhtml.option)

Example 94 with GridField

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

the class WFindAdv method createPageFind.

private form createPageFind(HttpServletRequest request, HttpServletResponse response, WWindowStatus ws) throws ServletException, IOException {
    boolean hasValue = false;
    boolean hasName = false;
    boolean hasDocNo = false;
    boolean hasDescription = false;
    if (ws.curTab == null)
        return new form();
    //Get Info from target Tab
    int size = ws.curTab.getFieldCount();
    for (int i = 0; i < size; i++) {
        GridField mField = ws.curTab.getField(i);
        String columnName = mField.getColumnName();
        if (mField.isDisplayed()) {
            if (columnName.equals("Value"))
                hasValue = true;
            else if (columnName.equals("Name"))
                hasName = true;
            else if (columnName.equals("DocumentNo"))
                hasDocNo = true;
            else if (columnName.equals("Description"))
                hasDescription = true;
        }
    }
    form myForm = new form("WWindow", form.METHOD_GET);
    myForm.setName("WFind");
    myForm.setID("WFind");
    myForm.setClass("dialog");
    myForm.addAttribute("selected", "true");
    myForm.setTarget("_self");
    //myForm.addElement(createTabs("Find"));
    fieldset fields = new fieldset();
    //table.setClass("centerTable");
    h1 h = new h1("Find");
    fields.addElement(h);
    a a = new a("#", "Cancel");
    a.addAttribute("type", "cancel");
    a.setClass("button leftButton");
    fields.addElement(a);
    a = new a("javascript:void(1);", "Search");
    a.addAttribute("type", "submit");
    // iui bug workaround http://code.google.com/p/iui/issues/detail?id=80
    a.addAttribute("onclick", "(function(event) {return true;})()");
    a.setClass("button");
    fields.addElement(a);
    input line = null;
    if (hasValue) {
        line = new input(input.TYPE_TEXT, "txtValue", "");
        line.setID("txtValue");
        line.addAttribute("placeholder", Msg.translate(ws.ctx, "Value"));
        fields.addElement(line);
    }
    if (hasDocNo) {
        line = new input(input.TYPE_TEXT, "txtDocumentNo", "");
        line.addAttribute("placeholder", Msg.translate(ws.ctx, "DocumentNo"));
        line.setID("txtDocumentNo");
        fields.addElement(line);
    }
    if (hasName) {
        line = new input(input.TYPE_TEXT, "txtName", "");
        line.addAttribute("placeholder", Msg.translate(ws.ctx, "Name"));
        line.setID("txtName");
        fields.addElement(line);
    }
    if (hasDescription) {
        line = new input(input.TYPE_TEXT, "txtDescription", "");
        line.addAttribute("placeholder", Msg.translate(ws.ctx, "Description"));
        line.setID("txtDescription");
        fields.addElement(line);
    }
    if (!hasDescription && !hasDocNo && !hasName && !hasValue) {
        fields.addElement(new h2("N/A!"));
    }
    fields.addElement(new input("hidden", "txtSQL", "FIND").setID("txtSQL"));
    myForm.addElement(fields);
    return myForm;
}
Also used : org.apache.ecs.xhtml.textarea(org.apache.ecs.xhtml.textarea) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) org.apache.ecs.xhtml.h2(org.apache.ecs.xhtml.h2) GridField(org.compiere.model.GridField)

Example 95 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 {
    MobileEnv.dump(request);
    MobileEnv.dump(request.getSession());
    //Modified by Rob Klein 4/29/07
    //
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        MobileUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    //  Get Mandatory Parameters
    String columnName = MobileUtil.getParameter(request, "ColumnName");
    //Lookup called from a process
    //Modified by Rob Klein 4/29/07
    int AD_Process_ID = MobileUtil.getParameterAsInt(request, "AD_Process_ID");
    //Lookup modified to include paging
    //Modified by Rob Klein 07/07/07
    int page = MobileUtil.getParameterAsInt(request, "page");
    int refValueId = 0;
    boolean startUpdate = false;
    String targetBase = "'" + columnName;
    String header = null;
    if (AD_Process_ID > 0) {
        if (AD_Process_ID < 1 || columnName == null || columnName.equals("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing"));
            return;
        }
        MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
        MProcessPara para = null;
        MProcessPara[] parameters = process.getParameters();
        for (int i = 0; i < parameters.length; i++) {
            if (para.getColumnName().equals(columnName))
                para = parameters[i];
        }
        if (para != null)
            refValueId = para.getAD_Reference_Value_ID();
        header = para.getColumnName();
    } else //Lookup called from a window
    {
        //	Modified by Rob Klein 7/01/07
        if (ws == null) {
            MobileUtil.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("")) {
            MobileUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing"));
            return;
        }
        header = mField.getHeader();
        boolean hasDependents = ws.curTab.hasDependants(columnName);
        boolean hasCallout = mField.getCallout().length() > 0;
        startUpdate = hasDependents || hasCallout;
        refValueId = mField.getAD_Reference_Value_ID();
    }
    if (m_searchFields == null || m_searchFields.length == 0) {
        getSearchFields(columnName, refValueId);
    }
    String search = MobileUtil.getParameter(request, "search");
    if (Util.isEmpty(MobileUtil.getParameter(request, "search"))) {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        form panel = new form();
        panel.setMethod("post");
        panel.setClass("dialog");
        panel.setID("WLookup1");
        panel.setAction("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID);
        panel.addAttribute("selected", "true");
        fieldset set = new fieldset();
        h1 h = new h1(header);
        set.addElement(h);
        a a = new a("#", "Cancel");
        a.addAttribute("type", "cancel");
        a.setClass("button leftButton");
        set.addElement(a);
        a = new a("WLookup?ColumnName=" + columnName + "&AD_Process_ID=" + AD_Process_ID, "Search");
        a.addAttribute("type", "submit");
        a.setClass("button");
        set.addElement(a);
        panel.addElement(set);
        for (int i = 0; i < m_searchFields.length; i++) {
            /*
				label l = new label();
				l.addElement(m_searchLabels[i]);
				set.addElement(l)*/
            input f = new input(input.TYPE_TEXT, m_searchFields[i], "");
            f.setID(m_searchFields[i]);
            f.addAttribute("placeholder", m_searchLabels[i]);
            set.addElement(f).addElement(new br());
        }
        input hidden = new input(input.TYPE_HIDDEN, "search", "true");
        set.addElement(hidden);
        doc.getBody().addElement(panel);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    } else {
        //  Create Document
        MobileDoc doc = MobileDoc.createPopup(header);
        StringBuffer where = new StringBuffer();
        for (String column : m_searchFields) {
            String value = request.getParameter(column);
            if (!Util.isEmpty(value)) {
                value = "%" + value + "%";
                where.append(" AND UPPER(").append(column).append(") LIKE UPPER(").append(DB.TO_STRING(value)).append(") ");
            }
        }
        div panel = new div();
        panel.setClass("dialog");
        panel.addAttribute("selected", "true");
        panel.setID("WLookup2");
        fieldset set = new fieldset();
        panel.addElement(set);
        set.addElement(fillTable(wsc, columnName, refValueId, request.getRequestURI(), targetBase, startUpdate, page, where.toString()));
        //  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 (startUpdate)
            script += "startUpdate(" + targetBase + "F);";
        resetbtn.setOnClick(script);
        doc.getBody().addElement(panel);
        doc.getBody().addElement(resetbtn);
        MobileUtil.createResponseFragment(request, response, this, null, doc);
    }
}
Also used : MobileSessionCtx(org.compiere.mobile.MobileSessionCtx) MProcessPara(org.compiere.model.MProcessPara) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.fieldset(org.apache.ecs.xhtml.fieldset) org.apache.ecs.xhtml.h1(org.apache.ecs.xhtml.h1) MProcessPara(org.compiere.model.MProcessPara) GridField(org.compiere.model.GridField) org.apache.ecs.xhtml.br(org.apache.ecs.xhtml.br) org.apache.ecs.xhtml.div(org.apache.ecs.xhtml.div) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form)

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