Search in sources :

Example 96 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)

Example 97 with ValueNamePair

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

the class Find method actionPerformed.

//	dispose
/**************************************************************************
	 *	Action Listener
	 *  @param e ActionEvent
	 */
public void actionPerformed(ActionEvent e) {
    log.info(e.getActionCommand());
    //
    if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
        cmd_cancel();
    else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH))
        cmd_refresh();
    else //
    if (e.getActionCommand().equals(ConfirmPanel.A_NEW)) {
        m_query = MQuery.getNoRecordQuery(m_tableName, true);
        m_total = 0;
        dispose();
    } else //
    if (e.getSource() == bIgnore)
        cmd_ignore();
    else if (e.getSource() == bNew)
        cmd_new();
    else if (e.getSource() == bSave)
        cmd_save(true);
    else if (e.getSource() == bDelete)
        cmd_delete();
    else //
    if (e.getSource() == columns) {
        String columnName = null;
        Object selected = columns.getSelectedItem();
        if (selected != null) {
            if (selected instanceof ValueNamePair) {
                ValueNamePair column = (ValueNamePair) selected;
                columnName = column.getValue();
            } else {
                columnName = selected.toString();
            }
        }
        if (columnName != null) {
            log.config("Column: " + columnName);
            if (columnName.endsWith("_ID") || columnName.endsWith("_Acct"))
                operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_ID));
            else if (columnName.startsWith("Is"))
                operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_YN));
            else
                operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS));
        }
    } else if (e.getSource() == fQueryName) {
        // fQueryName has changed.
        int index = fQueryName.getSelectedIndex();
        if (index < 0) {
            if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                return;
            }
        } else if (index == 0) {
            // no query - wipe and start over.
            advancedTable.stopEditor(false);
            DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
            int cnt = model.getRowCount();
            if (cnt > 0) {
                for (int i = cnt - 1; i >= 0; i--) {
                    model.removeRow(i);
                }
                // No row - create one.
                cmd_new();
            }
            fQueryName.setSelectedIndex(-1);
            fQueryName.setSelectedItem(m_sTipText);
            advancedTable.requestFocusInWindow();
        } else
            parseUserQuery(userQueries[index - 1]);
    } else // ConfirmPanel.A_OK and enter in fields
    {
        if (e.getSource() == confirmPanelA.getOKButton())
            cmd_ok_Advanced();
        else if (e.getSource() == confirmPanelS.getOKButton())
            cmd_ok_Simple();
        else if (e.getSource() instanceof JTextField && tabbedPane.getSelectedIndex() == 0)
            cmd_ok_Simple();
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ValueNamePair(org.compiere.util.ValueNamePair) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTextField(javax.swing.JTextField)

Example 98 with ValueNamePair

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

the class FindValueEditor method getTableCellEditorComponent.

//	getCellEditorValue
/**
	 *	Get Editor
	 *
	 *  @param table Table
	 *  @param value Value
	 *  @param isSelected cell is selected
	 *  @param row row
	 *  @param col column
	 *  @return Editor component
	 */
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
    //	log.config( "FindValueEditor.getTableCellEditorComponent", "r=" + row + ", c=" + col);
    //	Between - enables valueToColumn
    m_between = false;
    Object betweenValue = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
    if (m_valueToColumn && betweenValue != null && betweenValue.equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX]))
        m_between = true;
    boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
    log.config("(" + value + ") - Enabled=" + enabled);
    if (enabled) {
        String columnName = null;
        Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
        if (column != null)
            columnName = ((ValueNamePair) column).getValue();
        //  Create Editor
        GridField field = m_find.getTargetMField(columnName);
        //	log.fine( "Field=" + field.toStringX());
        if (field.isKey())
            m_editor = new VNumber(columnName, false, false, true, DisplayType.Integer, columnName);
        else
            m_editor = VEditorFactory.getEditor(field, true);
        if (m_editor == null)
            m_editor = new VString();
        m_editor.setValue(value);
        m_editor.setReadWrite(enabled);
        m_editor.setBorder(null);
    } else {
        m_editor = null;
    }
    //
    return (Component) m_editor;
}
Also used : VString(org.compiere.grid.ed.VString) EventObject(java.util.EventObject) VNumber(org.compiere.grid.ed.VNumber) VString(org.compiere.grid.ed.VString) ValueNamePair(org.compiere.util.ValueNamePair) GridField(org.compiere.model.GridField) Component(java.awt.Component)

Example 99 with ValueNamePair

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

the class FindValueRenderer method getTableCellRendererComponent.

//	getCheck
/*************************************************************************
	 *	Get TableCell RendererComponent
	 *  @param table table
	 *  @param value value
	 *  @param isSelected selected
	 *  @param hasFocus focus
	 *  @param row row
	 *  @param col col
	 *  @return renderer component (Label or CheckBox)
	 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    //	log.config( "FindValueRenderer.getTableCellRendererComponent", "r=" + row + ", c=" + col );
    //	Column
    m_columnName = null;
    Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
    if (column != null) {
        if (column instanceof ValueNamePair)
            m_columnName = ((ValueNamePair) column).getValue();
        else
            m_columnName = column.toString();
    }
    //	Between - enables valueToColumn
    m_between = false;
    Object betweenValue = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
    if (m_valueToColumn && betweenValue != null && betweenValue.equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX]))
        m_between = true;
    boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
    //	set Background
    if (enabled)
        setBackground(AdempierePLAF.getFieldBackground_Normal());
    else
        setBackground(AdempierePLAF.getFieldBackground_Inactive());
    //	log.config( "FindValueRenderer.getTableCellRendererComponent - (" + value + ") - Enabled=" + enabled);
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    if (value == null || (m_valueToColumn && !m_between))
        return c;
    //
    GridField field = getMField();
    if (field != null && field.getDisplayType() == DisplayType.YesNo) {
        JCheckBox cb = getCheck();
        if (value instanceof Boolean)
            cb.setSelected(((Boolean) value).booleanValue());
        else
            cb.setSelected(value.toString().indexOf('Y') != -1);
        return cb;
    }
    return c;
}
Also used : JCheckBox(javax.swing.JCheckBox) ValueNamePair(org.compiere.util.ValueNamePair) GridField(org.compiere.model.GridField) Component(java.awt.Component)

Example 100 with ValueNamePair

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

the class VPayPrint method cmd_print.

//  cmd_EFT
/**
	 *  Print Checks and/or Remittance
	 */
private void cmd_print() {
    ValueNamePair valueNamePair = (ValueNamePair) fPaymentRule.getSelectedItem();
    if (valueNamePair == null)
        return;
    String paymentRule = valueNamePair.getValue();
    log.info(paymentRule);
    if (!getChecks(paymentRule))
        return;
    panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    AtomicBoolean somethingPrinted = new AtomicBoolean(false);
    boolean directPrint = !Ini.isPropertyBool(Ini.P_PRINTPREVIEW);
    //	for all checks
    paySelectionChecks.stream().filter(paySelectionCheck -> paySelectionCheck != null).forEach(paySelectionCheck -> {
        boolean ok = ReportCtl.startDocumentPrint(ReportEngine.CHECK, paySelectionCheck.get_ID(), null, Env.getWindowNo(panel), directPrint);
        if (!somethingPrinted.get() && ok)
            somethingPrinted.set(true);
    });
    //	Confirm Print and Update BankAccountDoc
    if (somethingPrinted.get() && ADialog.ask(windowNo, panel, "VPayPrintSuccess?")) {
        int lastDocumentNo = MPaySelectionCheck.confirmPrint(paySelectionChecks, paymentBatch);
        if (lastDocumentNo != 0) {
            StringBuffer sb = new StringBuffer();
            sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo).append(" WHERE C_BankAccount_ID=").append(bankAccountId).append(" AND PaymentRule='").append(paymentRule).append("'");
            DB.executeUpdate(sb.toString(), null);
        }
    }
    if (ADialog.ask(windowNo, panel, "VPayPrintPrintRemittance")) {
        paySelectionChecks.stream().filter(paySelectionCheck -> paySelectionCheck != null).forEach(paySelectionCheck -> {
            ReportCtl.startDocumentPrint(ReportEngine.REMITTANCE, paySelectionCheck.get_ID(), null, Env.getWindowNo(panel), directPrint);
        });
    }
    //	remittance
    panel.setCursor(Cursor.getDefaultCursor());
    dispose();
}
Also used : Insets(java.awt.Insets) ADialog(org.compiere.apps.ADialog) ActionListener(java.awt.event.ActionListener) ReportCtl(org.compiere.print.ReportCtl) Cursor(java.awt.Cursor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Env(org.compiere.util.Env) MLookupFactory(org.compiere.model.MLookupFactory) ValueNamePair(org.compiere.util.ValueNamePair) ConfirmPanel(org.compiere.apps.ConfirmPanel) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PropertyVetoException(java.beans.PropertyVetoException) MLookupInfo(org.compiere.model.MLookupInfo) DB(org.compiere.util.DB) Msg(org.compiere.util.Msg) VetoableChangeListener(java.beans.VetoableChangeListener) DisplayType(org.compiere.util.DisplayType) CComboBox(org.compiere.swing.CComboBox) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) PropertyChangeEvent(java.beans.PropertyChangeEvent) PaymentExportList(org.compiere.util.PaymentExportList) FlowLayout(java.awt.FlowLayout) MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) JButton(javax.swing.JButton) MPaymentBatch(org.compiere.model.MPaymentBatch) VLookup(org.compiere.grid.ed.VLookup) GridBagConstraints(java.awt.GridBagConstraints) ActionEvent(java.awt.event.ActionEvent) MLookup(org.compiere.model.MLookup) CompiereColor(org.compiere.plaf.CompiereColor) VNumber(org.compiere.grid.ed.VNumber) ReportEngine(org.compiere.print.ReportEngine) Ini(org.compiere.util.Ini) CLabel(org.compiere.swing.CLabel) CPanel(org.compiere.swing.CPanel) PaymentExport(org.compiere.util.PaymentExport) GridBagLayout(java.awt.GridBagLayout) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ValueNamePair(org.compiere.util.ValueNamePair)

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