1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.searchresult; 22 23 24 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager; 25 import org.eclipse.jface.viewers.CellEditor; 26 import org.eclipse.jface.viewers.TableViewer; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.events.FocusEvent; 29 import org.eclipse.swt.events.FocusListener; 30 import org.eclipse.swt.events.KeyEvent; 31 import org.eclipse.swt.events.KeyListener; 32 import org.eclipse.swt.widgets.TableItem; 33 34 35 public abstract class AbstractOpenEditorAction extends AbstractSearchResultListenerAction implements FocusListener, 36 KeyListener 37 { 38 39 protected SearchResultEditorActionGroup actionGroup; 40 41 protected ValueEditorManager valueEditorManager; 42 43 protected TableViewer viewer; 44 45 protected SearchResultEditorCursor cursor; 46 47 protected CellEditor cellEditor; 48 49 private boolean isActive; 50 51 52 protected AbstractOpenEditorAction( TableViewer viewer, SearchResultEditorCursor cursor, 53 SearchResultEditorActionGroup actionGroup, ValueEditorManager valueEditorManager ) 54 { 55 super( cursor, "Editor", null, null ); 56 this.actionGroup = actionGroup; 57 this.viewer = viewer; 58 this.cursor = cursor; 59 this.valueEditorManager = valueEditorManager; 60 this.isActive = false; 61 } 62 63 64 public CellEditor getCellEditor() 65 { 66 return this.cellEditor; 67 } 68 69 70 public void run() 71 { 72 this.activateEditor(); 73 } 74 75 76 private void activateEditor() 77 { 78 79 Object element = cursor.getRow().getData(); 80 String property = ( String ) this.viewer.getColumnProperties()[cursor.getColumn()]; 81 82 if ( !this.viewer.isCellEditorActive() && viewer.getCellModifier().canModify( element, property ) ) 83 { 84 85 96 97 for ( int i = 0; i < this.viewer.getCellEditors().length; i++ ) 99 { 100 this.viewer.getCellEditors()[i] = this.cellEditor; 101 } 102 103 if ( this.cellEditor.getControl() != null ) 105 { 106 this.cellEditor.getControl().addFocusListener( this ); 107 this.cellEditor.getControl().addKeyListener( this ); 108 } 109 110 this.cursor.setVisible( false ); 112 113 this.actionGroup.deactivateGlobalActionHandlers(); 115 116 this.isActive = true; 118 this.viewer.editElement( element, cursor.getColumn() ); 119 120 viewer.setSelection( null, true ); 121 viewer.getTable().setSelection( new TableItem[0] ); 122 123 if ( !this.viewer.isCellEditorActive() ) 124 { 125 this.editorClosed(); 126 } 127 } 128 else 129 { 130 this.valueEditorManager.setUserSelectedValueEditor( null ); 131 } 132 } 133 134 135 private void editorClosed() 136 { 137 138 152 153 this.isActive = false; 155 156 for ( int i = 0; i < this.viewer.getCellEditors().length; i++ ) 158 { 159 this.viewer.getCellEditors()[i] = null; 160 } 161 162 if ( this.cellEditor.getControl() != null ) 164 { 165 this.cellEditor.getControl().removeFocusListener( this ); 166 this.cellEditor.getControl().removeKeyListener( this ); 167 } 168 169 this.actionGroup.activateGlobalActionHandlers(); 171 172 this.valueEditorManager.setUserSelectedValueEditor( null ); 173 174 cursor.setVisible( true ); 176 viewer.refresh(); 177 cursor.redraw(); 178 cursor.getDisplay().asyncExec( new Runnable () 179 { 180 public void run() 181 { 182 cursor.setFocus(); 183 } 184 } ); 185 186 } 187 188 189 public void focusGained( FocusEvent e ) 190 { 191 } 192 193 194 public void focusLost( FocusEvent e ) 195 { 196 this.editorClosed(); 197 } 198 199 200 public void keyPressed( KeyEvent e ) 201 { 202 if ( e.character == SWT.ESC && e.stateMask == SWT.NONE ) 203 { 204 e.doit = false; 205 } 206 } 207 208 209 public void keyReleased( KeyEvent e ) 210 { 211 } 212 213 214 public boolean isActive() 215 { 216 return isActive; 217 } 218 219 } 220 | Popular Tags |