1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.entryeditor; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 25 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager; 26 import org.eclipse.jface.viewers.CellEditor; 27 import org.eclipse.jface.viewers.TreeViewer; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.events.FocusEvent; 30 import org.eclipse.swt.events.FocusListener; 31 import org.eclipse.swt.events.KeyEvent; 32 import org.eclipse.swt.events.KeyListener; 33 34 35 42 public abstract class AbstractOpenEditorAction extends BrowserAction implements FocusListener, KeyListener 43 { 44 45 46 protected EntryEditorWidgetActionGroup actionGroup; 47 48 49 protected ValueEditorManager valueEditorManager; 50 51 52 protected TreeViewer viewer; 53 54 55 protected CellEditor cellEditor; 56 57 58 65 protected AbstractOpenEditorAction( TreeViewer viewer, EntryEditorWidgetActionGroup actionGroup, 66 ValueEditorManager valueEditorManager ) 67 { 68 this.viewer = viewer; 69 this.actionGroup = actionGroup; 70 this.valueEditorManager = valueEditorManager; 71 } 72 73 74 77 public void dispose() 78 { 79 valueEditorManager = null; 80 actionGroup = null; 81 viewer = null; 82 cellEditor = null; 83 super.dispose(); 84 } 85 86 87 92 public CellEditor getCellEditor() 93 { 94 return cellEditor; 95 } 96 97 98 101 public void run() 102 { 103 activateEditor(); 104 } 105 106 107 110 private void activateEditor() 111 { 112 113 if ( !viewer.isCellEditorActive() 114 && getSelectedValues().length == 1 115 && getSelectedAttributes().length == 0 116 && viewer.getCellModifier().canModify( getSelectedValues()[0], 117 EntryEditorWidgetTableMetadata.VALUE_COLUMN_NAME ) ) 118 { 119 120 viewer.getCellEditors()[EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX] = cellEditor; 122 123 if ( cellEditor.getControl() != null ) 125 { 126 cellEditor.getControl().addFocusListener( this ); 127 cellEditor.getControl().addKeyListener( this ); 128 } 129 130 if ( actionGroup != null ) 132 { 133 actionGroup.deactivateGlobalActionHandlers(); 134 } 135 136 viewer.editElement( getSelectedValues()[0], EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX ); 138 139 if ( !viewer.isCellEditorActive() ) 140 { 141 editorClosed(); 142 } 143 } 144 else 145 { 146 valueEditorManager.setUserSelectedValueEditor( null ); 147 } 148 } 149 150 151 154 private void editorClosed() 155 { 156 157 for ( int i = 0; i < viewer.getCellEditors().length; i++ ) 159 { 160 viewer.getCellEditors()[i] = null; 161 } 162 163 if ( cellEditor.getControl() != null ) 165 { 166 cellEditor.getControl().removeFocusListener( this ); 167 cellEditor.getControl().removeKeyListener( this ); 168 } 169 170 if ( actionGroup != null ) 172 { 173 actionGroup.activateGlobalActionHandlers(); 174 } 175 176 valueEditorManager.setUserSelectedValueEditor( null ); 179 viewer.setSelection( viewer.getSelection() ); 180 } 181 182 183 186 public void focusGained( FocusEvent e ) 187 { 188 } 189 190 191 194 public void focusLost( FocusEvent e ) 195 { 196 editorClosed(); 197 } 198 199 200 203 public void keyPressed( KeyEvent e ) 204 { 205 if ( e.character == SWT.ESC && e.stateMask == SWT.NONE ) 206 { 207 e.doit = false; 208 } 209 } 210 211 212 215 public void keyReleased( KeyEvent e ) 216 { 217 } 218 219 } 220 | Popular Tags |