Search in sources :

Example 11 with CellEditorListener

use of javax.swing.event.CellEditorListener in project JMRI by JMRI.

the class ValueEditor method fireEditingCanceled.

protected void fireEditingCanceled() {
    if (log.isDebugEnabled()) {
        log.debug("fireEditingCancelled, but we are not setting back the old value");
    }
    Vector<CellEditorListener> local;
    synchronized (listeners) {
        local = new Vector<CellEditorListener>(listeners);
    }
    ChangeEvent ce = new ChangeEvent(this);
    for (int i = local.size() - 1; i >= 0; i--) {
        local.elementAt(i).editingCanceled(ce);
    }
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) CellEditorListener(javax.swing.event.CellEditorListener)

Example 12 with CellEditorListener

use of javax.swing.event.CellEditorListener 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

CellEditorListener (javax.swing.event.CellEditorListener)12 ChangeEvent (javax.swing.event.ChangeEvent)6 EventObject (java.util.EventObject)3 TableCellRenderer (javax.swing.table.TableCellRenderer)3 Test (org.junit.Test)3 ActionEvent (java.awt.event.ActionEvent)2 TableCellEditor (javax.swing.table.TableCellEditor)2 PackageEntry (com.intellij.psi.codeStyle.PackageEntry)1 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)1 RefactoringElementListenerProvider (com.intellij.refactoring.listeners.RefactoringElementListenerProvider)1 JBTable (com.intellij.ui.table.JBTable)1 ListTreeTableModelOnColumns (com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns)1 TreeTableTree (com.intellij.ui.treeStructure.treetable.TreeTableTree)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 InputMap (javax.swing.InputMap)1