Search in sources :

Example 1 with CellEditor

use of javax.swing.CellEditor in project CCDD by nasa.

the class CcddKeyboardHandler method getActiveUndoManager.

/**
 ********************************************************************************************
 * Get the active component's undo manager
 *
 * @return The active undo manager; null if no undo manager is active or no editor has focus
 ********************************************************************************************
 */
private CcddUndoManager getActiveUndoManager() {
    CellEditor cellEditor = null;
    CcddUndoManager undoManager = null;
    editPnlHandler = null;
    // Check if a modal dialog is active
    if (modalUndoManager != null) {
        // Set the undo manager to the modal dialog's undo manager
        undoManager = modalUndoManager;
        // Check if a modal table is active
        if (modalTable != null) {
            // Get the cell editor for the modal table
            cellEditor = modalTable.getCellEditor();
        }
        // Get a reference to the group manager dialog to shorten subsequent calls
        CcddGroupManagerDialog groupManager = ccddMain.getGroupManager();
        // Check if the group manager is open and has focus
        if (groupManager != null && groupManager.isFocused()) {
            // Get the group manager's editor panel handler
            editPnlHandler = groupManager.getEditorPanelHandler();
        }
    } else // No modal undo manager is active
    {
        // Step through each open table editor dialog
        for (CcddTableEditorDialog editorDialog : ccddMain.getTableEditorDialogs()) {
            // Check if this editor dialog has the keyboard focus
            if (editorDialog.isFocused()) {
                // Get the undo manager, cell editor, and editor panel handler for the active
                // table editor
                undoManager = editorDialog.getTableEditor().getFieldPanelUndoManager();
                cellEditor = editorDialog.getTableEditor().getTable().getCellEditor();
                editPnlHandler = editorDialog.getTableEditor().getInputFieldPanelHandler();
            }
            // Check if an undo manager is active
            if (undoManager != null) {
                // Stop searching
                break;
            }
        }
        // Get a reference to the type editor dialog to shorten subsequent calls
        CcddTableTypeEditorDialog editorDialog = ccddMain.getTableTypeEditor();
        // Check if no table undo manager is applicable and the table type editor is open
        if (undoManager == null && editorDialog != null) {
            // Check if the table type editor has the keyboard focus
            if (editorDialog.isFocused()) {
                // Get the undo manager, cell editor, and editor panel handler for the active
                // table type editor
                undoManager = editorDialog.getTypeEditor().getFieldPanelUndoManager();
                cellEditor = editorDialog.getTypeEditor().getTable().getCellEditor();
                editPnlHandler = editorDialog.getTypeEditor().getInputFieldPanelHandler();
            }
        }
        // Get a reference to the data field table editor dialog to shorten subsequent calls
        CcddFieldTableEditorDialog fieldEditor = ccddMain.getFieldTableEditor();
        // editor is open, and the editor has focus
        if (undoManager == null && fieldEditor != null && fieldEditor.isFocused()) {
            // Get the undo manager and cell editor for the data field table editor
            undoManager = fieldEditor.getTable().getUndoManager();
            cellEditor = fieldEditor.getTable().getCellEditor();
        }
        // Get a reference to the script manager dialog to shorten subsequent calls
        CcddScriptManagerDialog scriptManager = ccddMain.getScriptManager();
        // open, and the editor has focus
        if (undoManager == null && scriptManager != null && scriptManager.isFocused()) {
            // Get the undo manager and cell editor for the script manager
            undoManager = ccddMain.getScriptHandler().getAssociationsTable().getUndoManager();
            cellEditor = ccddMain.getScriptHandler().getAssociationsTable().getCellEditor();
        }
    }
    // Check if a table cell is actively being edited
    if (cellEditor != null) {
        // Incorporate any cell changes and terminate editing
        cellEditor.stopCellEditing();
    } else // No table cell is being edited
    {
        // Get the current owner of the keyboard focus
        Component focusOwner = focusManager.getFocusOwner();
        // Check if the focus is in an edit panel's description or data field
        if (focusOwner != null && (focusOwner instanceof UndoableTextField || focusOwner instanceof UndoableTextArea || focusOwner instanceof UndoableCheckBox)) {
            // Check if the focus owner is a text field data field
            if (focusOwner instanceof UndoableTextField) {
                // Force the text to update so that an undo command starts with this field
                ((JTextField) focusOwner).setText(((JTextField) focusOwner).getText());
            }
            // Clear the keyboard focus so that the current data field value is registered as
            // an edit
            focusManager.clearGlobalFocusOwner();
        }
    }
    return undoManager;
}
Also used : UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) CellEditor(javax.swing.CellEditor) UndoableTextArea(CCDD.CcddUndoHandler.UndoableTextArea) UndoableTextField(CCDD.CcddUndoHandler.UndoableTextField) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) JTextField(javax.swing.JTextField)

Example 2 with CellEditor

use of javax.swing.CellEditor in project jmeter by apache.

the class TableEditor method focusLost.

@Override
public void focusLost(FocusEvent e) {
    final int editingRow = table.getEditingRow();
    final int editingColumn = table.getEditingColumn();
    CellEditor ce = null;
    if (editingRow != -1 && editingColumn != -1) {
        ce = table.getCellEditor(editingRow, editingColumn);
    }
    Component editor = table.getEditorComponent();
    if (ce != null && (editor == null || editor != e.getOppositeComponent())) {
        ce.stopCellEditing();
    } else if (editor != null) {
        editor.addFocusListener(this);
    }
    this.firePropertyChange();
}
Also used : CellEditor(javax.swing.CellEditor) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

Component (java.awt.Component)2 CellEditor (javax.swing.CellEditor)2 UndoableCheckBox (CCDD.CcddUndoHandler.UndoableCheckBox)1 UndoableTextArea (CCDD.CcddUndoHandler.UndoableTextArea)1 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)1 JComponent (javax.swing.JComponent)1 JTextField (javax.swing.JTextField)1 JTextComponent (javax.swing.text.JTextComponent)1