Search in sources :

Example 71 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class WAcctViewer method actionQuery.

// sortAddItem
/**
	 *  Query
	 */
private void actionQuery() {
    //  Parameter Info
    StringBuffer para = new StringBuffer();
    //  Reset Selection Data
    m_data.C_AcctSchema_ID = 0;
    m_data.AD_Org_ID = 0;
    //  Save Selection Choices
    Listitem listitem = selAcctSchema.getSelectedItem();
    KeyNamePair kp = null;
    if (listitem != null)
        kp = (KeyNamePair) listitem.getValue();
    if (kp != null)
        m_data.C_AcctSchema_ID = kp.getKey();
    para.append("C_AcctSchema_ID=").append(m_data.C_AcctSchema_ID);
    listitem = selPostingType.getSelectedItem();
    ValueNamePair vp = null;
    if (listitem != null)
        vp = (ValueNamePair) listitem.getValue();
    else
        return;
    m_data.PostingType = vp.getValue();
    para.append(", PostingType=").append(m_data.PostingType);
    //  Document
    m_data.documentQuery = selDocument.isChecked();
    para.append(", DocumentQuery=").append(m_data.documentQuery);
    if (selDocument.isChecked()) {
        if (m_data.AD_Table_ID == 0 || m_data.Record_ID == 0)
            return;
        para.append(", AD_Table_ID=").append(m_data.AD_Table_ID).append(", Record_ID=").append(m_data.Record_ID);
    } else {
        m_data.DateFrom = selDateFrom.getValue() != null ? new Timestamp(selDateFrom.getValue().getTime()) : null;
        para.append(", DateFrom=").append(m_data.DateFrom);
        m_data.DateTo = selDateTo.getValue() != null ? new Timestamp(selDateTo.getValue().getTime()) : null;
        para.append(", DateTo=").append(m_data.DateTo);
        listitem = selOrg.getSelectedItem();
        if (listitem != null)
            kp = (KeyNamePair) listitem.getValue();
        else
            kp = null;
        if (kp != null)
            m_data.AD_Org_ID = kp.getKey();
        para.append(", AD_Org_ID=").append(m_data.AD_Org_ID);
        //
        Iterator<String> it = m_data.whereInfo.values().iterator();
        while (it.hasNext()) para.append(", ").append(it.next());
    }
    //  Save Display Choices
    m_data.displayQty = displayQty.isChecked();
    para.append(" - Display Qty=").append(m_data.displayQty);
    m_data.displaySourceAmt = displaySourceAmt.isChecked();
    para.append(", Source=").append(m_data.displaySourceAmt);
    m_data.displayDocumentInfo = displayDocumentInfo.isChecked();
    para.append(", Doc=").append(m_data.displayDocumentInfo);
    listitem = sortBy1.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy1 = vp.getValue();
            m_data.group1 = group1.isChecked();
            para.append(" - Sorting: ").append(m_data.sortBy1).append("/").append(m_data.group1);
        }
    }
    listitem = sortBy2.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy2 = vp.getValue();
            m_data.group2 = group2.isChecked();
            para.append(", ").append(m_data.sortBy2).append("/").append(m_data.group2);
        }
    }
    listitem = sortBy3.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy3 = vp.getValue();
            m_data.group3 = group3.isChecked();
            para.append(", ").append(m_data.sortBy3).append("/").append(m_data.group3);
        }
    }
    listitem = sortBy4.getSelectedItem();
    vp = null;
    if (listitem != null) {
        vp = (ValueNamePair) listitem.getValue();
        if (vp.getName() != null && vp.getName().trim().length() > 0) {
            //vp.getName();
            m_data.sortBy4 = vp.getValue();
            m_data.group4 = group4.isChecked();
            para.append(", ").append(m_data.sortBy4).append("/").append(m_data.group4);
        }
    }
    bQuery.setEnabled(false);
    statusLine.setValue(" " + Msg.getMsg(Env.getCtx(), "Processing"));
    log.config(para.toString());
    //  Switch to Result pane
    tabbedPane.setSelectedIndex(1);
    //  Set TableModel with Query
    RModel rmodel = m_data.query();
    m_queryData = rmodel.getRows();
    List<ArrayList<Object>> list = null;
    paging.setPageSize(PAGE_SIZE);
    if (m_queryData.size() > PAGE_SIZE) {
        list = m_queryData.subList(0, PAGE_SIZE);
        paging.setTotalSize(m_queryData.size());
        pagingPanel.setVisible(true);
    } else {
        list = m_queryData;
        paging.setTotalSize(m_queryData.size());
        pagingPanel.setVisible(false);
    }
    paging.setActivePage(0);
    ListModelTable listmodeltable = new ListModelTable(list);
    if (table.getListhead() == null) {
        Listhead listhead = new Listhead();
        listhead.setSizable(true);
        for (int i = 0; i < rmodel.getColumnCount(); i++) {
            // Replace user columns with the user selected names
            String displayColumnName = rmodel.getColumnName(i);
            ;
            String columnName;
            RColumn col = rmodel.getColumn(i);
            columnName = col.getColumnName();
            MAcctSchema as = MAcctSchema.get(Env.getCtx(), m_data.C_AcctSchema_ID);
            if (columnName.equals("User1_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList1);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User2_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList2);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User3_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList3);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            } else if (columnName.equals("User4_ID")) {
                MAcctSchemaElement ase = as.getAcctSchemaElement(MAcctSchemaElement.ELEMENTTYPE_UserList4);
                if (ase != null)
                    displayColumnName = Msg.translate(Env.getCtx(), ase.getName());
            }
            Listheader listheader = new Listheader(displayColumnName);
            listheader.setTooltiptext(rmodel.getColumnName(i));
            listhead.appendChild(listheader);
        }
        table.appendChild(listhead);
    } else // Elaine 2008/07/28
    {
        Listhead listhead = table.getListhead();
        // remove existing column header
        listhead.getChildren().clear();
        // add in new column header
        for (int i = 0; i < rmodel.getColumnCount(); i++) {
            Listheader listheader = new Listheader(rmodel.getColumnName(i));
            listhead.appendChild(listheader);
        }
    }
    //
    table.getItems().clear();
    table.setItemRenderer(new WListItemRenderer());
    table.setModel(listmodeltable);
    resultPanel.invalidate();
    bQuery.setEnabled(true);
    statusLine.setValue(" " + Msg.getMsg(Env.getCtx(), "ViewerOptions"));
}
Also used : WListItemRenderer(org.adempiere.webui.component.WListItemRenderer) Listheader(org.zkoss.zul.Listheader) Listhead(org.zkoss.zul.Listhead) Listitem(org.zkoss.zul.Listitem) ArrayList(java.util.ArrayList) RModel(org.compiere.report.core.RModel) ListModelTable(org.adempiere.webui.component.ListModelTable) RColumn(org.compiere.report.core.RColumn) Timestamp(java.sql.Timestamp) MAcctSchema(org.compiere.model.MAcctSchema) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 72 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class WAcctViewerData method fillTable.

// fillPostingType
/**
	 *  Fill Table with
	 *      ValueNamePair (TableName, translatedKeyColumnName)
	 *  and tableInfo with (TableName, AD_Table_ID)
	 *  and select the entry for AD_Table_ID
	 *
	 *  @param cb Listbox to be filled
	 */
protected void fillTable(Listbox cb) {
    ValueNamePair select = null;
    String sql = "SELECT AD_Table_ID, TableName FROM AD_Table t " + "WHERE EXISTS (SELECT * FROM AD_Column c" + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" + " AND IsView='N'";
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            int id = rs.getInt(1);
            String tableName = rs.getString(2);
            String name = Msg.translate(Env.getCtx(), tableName + "_ID");
            ValueNamePair pp = new ValueNamePair(tableName, name);
            cb.appendItem(pp.getName(), pp);
            tableInfo.put(tableName, new Integer(id));
            if (id == AD_Table_ID)
                select = pp;
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    if (select != null)
        //cb.setSelectedItem(select);
        ;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ValueNamePair(org.compiere.util.ValueNamePair)

Example 73 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class FolderBrowser method getFileListing.

private void getFileListing(String dirPath) {
    File dir = new File(dirPath);
    if (!dir.exists())
        return;
    if (dir.isDirectory()) {
        listDir.removeAllItems();
        if (!dir.getParent().equals(root.getParent())) {
            ListItem li = new ListItem(dir.getName(), dir.getParent());
            li.setImage(ServletFns.resolveThemeURL("~./images/Undo16.png"));
            listDir.appendChild(li);
        }
        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                ListItem li = new ListItem(file.getName(), file.getAbsolutePath());
                li.setImage(ServletFns.resolveThemeURL("~./images/Folder16.png"));
                listDir.appendChild(li);
            }
        }
        if (!showDirOnly) {
            for (File file : files) {
                if (file.isFile()) {
                    listDir.addItem(new ValueNamePair(file.getAbsolutePath(), file.getName()));
                }
            }
        }
    }
    txtPath.setValue(dir.getAbsolutePath());
}
Also used : ValueNamePair(org.compiere.util.ValueNamePair) File(java.io.File)

Example 74 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class T_InventoryValue_Create method raiseError.

//	doIt
private void raiseError(String string, String sql) throws Exception {
    DB.rollback(false, get_TrxName());
    String msg = string;
    ValueNamePair pp = CLogger.retrieveError();
    if (pp != null)
        msg = pp.getName() + " - ";
    msg += sql;
    throw new AdempiereUserError(msg);
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) ValueNamePair(org.compiere.util.ValueNamePair)

Example 75 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class Find method initFindAdvanced.

//	addSelectionColumn
/**
	 *  Init Find GridController
	 */
private void initFindAdvanced() {
    log.config("");
    advancedTable.setModel(new DefaultTableModel(0, 7));
    advancedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    advancedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    TableCellRenderer renderer = new ProxyRenderer(advancedTable.getDefaultRenderer(Object.class));
    advancedTable.setDefaultRenderer(Object.class, renderer);
    InputMap im = advancedTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final Action tabAction = advancedTable.getActionMap().get(im.get(tab));
    Action tabActionWrapper = new AbstractAction() {

        private static final long serialVersionUID = -6868476640719619801L;

        public void actionPerformed(ActionEvent e) {
            tabAction.actionPerformed(e);
            JTable table = (JTable) e.getSource();
            table.requestFocusInWindow();
        }
    };
    advancedTable.getActionMap().put(im.get(tab), tabActionWrapper);
    KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
    final Action shiftTabAction = advancedTable.getActionMap().get(im.get(shiftTab));
    Action shiftTabActionWrapper = new AbstractAction() {

        private static final long serialVersionUID = 5493691483070046620L;

        public void actionPerformed(ActionEvent e) {
            shiftTabAction.actionPerformed(e);
            JTable table = (JTable) e.getSource();
            table.requestFocusInWindow();
        }
    };
    advancedTable.getActionMap().put(im.get(shiftTab), shiftTabActionWrapper);
    //	0 = Columns
    ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
    for (int c = 0; c < m_findFields.length; c++) {
        GridField field = m_findFields[c];
        String columnName = field.getColumnName();
        String header = field.getHeader();
        if (header == null || header.length() == 0) {
            header = Msg.translate(Env.getCtx(), columnName);
            if (header == null || header.length() == 0)
                continue;
        }
        if (field.isKey())
            header += (" (ID)");
        ValueNamePair pp = new ValueNamePair(columnName, header);
        //	System.out.println(pp + " = " + field);
        items.add(pp);
    }
    columnValueNamePairs = new ValueNamePair[items.size()];
    items.toArray(columnValueNamePairs);
    //	sort alpha
    Arrays.sort(columnValueNamePairs);
    columns = new CComboBox(columnValueNamePairs);
    columns.addActionListener(this);
    TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME);
    tc.setPreferredWidth(120);
    FindCellEditor dce = new FindCellEditor(columns);
    dce.addCellEditorListener(new CellEditorListener() {

        public void editingCanceled(ChangeEvent ce) {
        }

        public void editingStopped(ChangeEvent ce) {
            int col = advancedTable.getSelectedColumn();
            int row = advancedTable.getSelectedRow();
            if (col == INDEX_COLUMNNAME && row >= 0) {
                advancedTable.setValueAt(null, row, INDEX_VALUE);
                advancedTable.setValueAt(null, row, INDEX_VALUE2);
            }
        }
    });
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.translate(Env.getCtx(), "AD_Column_ID"));
    // 0 = And/Or
    andOr = new CComboBox(new String[] { "", Msg.getMsg(Env.getCtx(), "AND"), Msg.getMsg(Env.getCtx(), "OR") });
    tc = advancedTable.getColumnModel().getColumn(INDEX_ANDOR);
    tc.setPreferredWidth(45);
    dce = new FindCellEditor(andOr);
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "And/Or"));
    // 1 = Left Bracket
    leftBrackets = new CComboBox(new String[] { "", "(", "((", "(((" });
    tc = advancedTable.getColumnModel().getColumn(INDEX_LEFTBRACKET);
    tc.setPreferredWidth(25);
    dce = new FindCellEditor(leftBrackets);
    tc.setCellEditor(dce);
    tc.setHeaderValue("(");
    //	3 = Operators
    operators = new CComboBox(MQuery.OPERATORS);
    tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR);
    tc.setPreferredWidth(55);
    dce = new FindCellEditor(operators);
    tc.setCellEditor(dce);
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator"));
    // 	4 = QueryValue
    tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE);
    FindValueEditor fve = new FindValueEditor(this, false);
    tc.setCellEditor(fve);
    tc.setPreferredWidth(120);
    tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue"));
    // 	5 = QueryValue2
    tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2);
    tc.setPreferredWidth(120);
    fve = new FindValueEditor(this, true);
    tc.setCellEditor(fve);
    tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
    tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2"));
    // 6 = Right Bracket
    rightBrackets = new CComboBox(new String[] { "", ")", "))", ")))" });
    tc = advancedTable.getColumnModel().getColumn(INDEX_RIGHTBRACKET);
    tc.setPreferredWidth(25);
    dce = new FindCellEditor(rightBrackets);
    tc.setCellEditor(dce);
    tc.setHeaderValue(")");
    // phib: disabled auto-completion as it causes date fields to have to be entered twice
    //AutoCompletion.enable(columns);
    //AutoCompletion.enable(operators);
    //user query
    refreshUserQueries();
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) CComboBox(org.compiere.swing.CComboBox) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) CellEditorListener(javax.swing.event.CellEditorListener) GridField(org.compiere.model.GridField) TableColumn(javax.swing.table.TableColumn) ChangeEvent(javax.swing.event.ChangeEvent) JTable(javax.swing.JTable) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) ValueNamePair(org.compiere.util.ValueNamePair) AbstractAction(javax.swing.AbstractAction)

Aggregations

ValueNamePair (org.compiere.util.ValueNamePair)109 KeyNamePair (org.compiere.util.KeyNamePair)35 SQLException (java.sql.SQLException)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)19 Timestamp (java.sql.Timestamp)9 GridField (org.compiere.model.GridField)7 BigDecimal (java.math.BigDecimal)5 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)5 MetalTheme (javax.swing.plaf.metal.MetalTheme)5 MInvoice (org.compiere.model.MInvoice)5 MLookup (org.compiere.model.MLookup)5 MLookupInfo (org.compiere.model.MLookupInfo)5 HRPayPrint (org.eevolution.service.HRPayPrint)5 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)4 ListItem (org.adempiere.webui.component.ListItem)4 MCashLine (org.compiere.model.MCashLine)4 AdempiereUserError (org.compiere.util.AdempiereUserError)4 NamePair (org.compiere.util.NamePair)4