Search in sources :

Example 71 with GridField

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

the class FindWindow method getEditorComponent.

//  addOperators
/**
     *  Get Editor
     *  @param row row
     *  @return Editor component
    **/
public Component getEditorComponent(ListItem row, boolean to) {
    String columnName = getColumnName(row);
    boolean between = false;
    Listbox listOp = (Listbox) row.getFellow("listOperator" + row.getId());
    String betweenValue = listOp.getSelectedItem().getValue().toString();
    String opValue = MQuery.OPERATORS[MQuery.BETWEEN_INDEX].getValue();
    if (to && betweenValue != null && betweenValue.equals(opValue))
        between = true;
    boolean enabled = !to || (to && between);
    //  Create Editor
    GridField field = getTargetMField(columnName);
    if (field == null)
        return new Label("");
    WEditor editor = null;
    if (field.isKey())
        editor = new WNumberEditor(field);
    else
        editor = WebEditorFactory.getEditor(field, true);
    if (editor == null)
        editor = new WStringEditor(field);
    field.addPropertyChangeListener(editor);
    editor.addValueChangeListener(this);
    editor.setValue(null);
    editor.setReadWrite(enabled);
    editor.setVisible(enabled);
    editor.dynamicDisplay();
    // So we have to do this after setting the ReadWrite
    if (enabled && editor instanceof WTableDirEditor) {
        ((WTableDirEditor) editor).actionRefresh();
    }
    //
    return editor.getComponent();
}
Also used : WTableDirEditor(org.adempiere.webui.editor.WTableDirEditor) Label(org.adempiere.webui.component.Label) GridField(org.compiere.model.GridField) WEditor(org.adempiere.webui.editor.WEditor) Listbox(org.adempiere.webui.component.Listbox) WNumberEditor(org.adempiere.webui.editor.WNumberEditor) WStringEditor(org.adempiere.webui.editor.WStringEditor)

Example 72 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 73 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 74 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 75 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)

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