1 20 21 package org.apache.directory.ldapstudio.schemas.view.dialogs; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.schemas.Activator; 28 import org.apache.directory.ldapstudio.schemas.Messages; 29 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 30 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 31 import org.apache.directory.ldapstudio.schemas.view.views.TableDecoratingLabelProvider; 32 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper; 33 import org.eclipse.jface.dialogs.Dialog; 34 import org.eclipse.jface.dialogs.IDialogConstants; 35 import org.eclipse.jface.dialogs.MessageDialog; 36 import org.eclipse.jface.viewers.StructuredSelection; 37 import org.eclipse.jface.viewers.TableViewer; 38 import org.eclipse.swt.SWT; 39 import org.eclipse.swt.events.KeyAdapter; 40 import org.eclipse.swt.events.KeyEvent; 41 import org.eclipse.swt.events.ModifyEvent; 42 import org.eclipse.swt.events.ModifyListener; 43 import org.eclipse.swt.events.MouseAdapter; 44 import org.eclipse.swt.events.MouseEvent; 45 import org.eclipse.swt.layout.GridData; 46 import org.eclipse.swt.layout.GridLayout; 47 import org.eclipse.swt.widgets.Composite; 48 import org.eclipse.swt.widgets.Control; 49 import org.eclipse.swt.widgets.Label; 50 import org.eclipse.swt.widgets.Shell; 51 import org.eclipse.swt.widgets.Table; 52 import org.eclipse.swt.widgets.Text; 53 import org.eclipse.ui.PlatformUI; 54 55 56 62 public class ObjectClassSelectionDialog extends Dialog 63 { 64 65 private ObjectClass selectedObjectClass; 66 67 68 private SchemaPool schemaPool; 69 70 71 private List <ObjectClass> hiddenObjectClasses; 72 73 private Text searchText; 75 private Table objectClassesTable; 76 private TableViewer tableViewer; 77 78 79 82 public ObjectClassSelectionDialog() 83 { 84 super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() ); 85 schemaPool = SchemaPool.getInstance(); 86 } 87 88 89 92 protected void configureShell( Shell newShell ) 93 { 94 super.configureShell( newShell ); 95 newShell.setText( Messages.getString( "ObjectClassSelectionDialog.Object_Class_Selection" ) ); } 97 98 99 102 protected Control createDialogArea( Composite parent ) 103 { 104 Composite composite = new Composite( parent, SWT.NONE ); 105 GridLayout layout = new GridLayout( 1, false ); 106 composite.setLayout( layout ); 107 108 Label chooseLabel = new Label( composite, SWT.NONE ); 109 chooseLabel.setText( Messages.getString( "ObjectClassSelectionDialog.Choose_an_object_class" ) ); chooseLabel.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) ); 111 112 searchText = new Text( composite, SWT.BORDER ); 113 searchText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) ); 114 searchText.addModifyListener( new ModifyListener() 115 { 116 public void modifyText( ModifyEvent e ) 117 { 118 tableViewer.setInput( searchText.getText() ); 119 objectClassesTable.select( 0 ); 120 } 121 } ); 122 searchText.addKeyListener( new KeyAdapter() 123 { 124 public void keyPressed( KeyEvent e ) 125 { 126 if ( e.keyCode == SWT.ARROW_DOWN ) 127 { 128 objectClassesTable.setFocus(); 129 } 130 } 131 } ); 132 133 Label matchingLabel = new Label( composite, SWT.NONE ); 134 matchingLabel.setText( Messages.getString( "ObjectClassSelectionDialog.Matching_object_class(es)" ) ); matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) ); 136 137 objectClassesTable = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL 138 | SWT.FULL_SELECTION | SWT.HIDE_SELECTION ); 139 GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true ); 140 gridData.heightHint = 148; 141 gridData.minimumHeight = 148; 142 gridData.widthHint = 350; 143 gridData.minimumWidth = 350; 144 objectClassesTable.setLayoutData( gridData ); 145 objectClassesTable.addMouseListener( new MouseAdapter() 146 { 147 public void mouseDoubleClick( MouseEvent e ) 148 { 149 if ( objectClassesTable.getSelectionIndex() != -1 ) 150 { 151 okPressed(); 152 } 153 } 154 } ); 155 156 tableViewer = new TableViewer( objectClassesTable ); 157 tableViewer.setUseHashlookup( true ); 158 159 tableViewer.setContentProvider( new ObjectClassSelectionDialogContentProvider( hiddenObjectClasses ) ); 160 tableViewer.setLabelProvider( new TableDecoratingLabelProvider( new ObjectClassSelectionDialogLabelProvider(), 161 Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator() ) ); 162 163 tableViewer.setInput( "" ); objectClassesTable.select( 0 ); 167 168 return composite; 169 } 170 171 172 175 protected void createButtonsForButtonBar( Composite parent ) 176 { 177 createButton( parent, IDialogConstants.OK_ID, Messages.getString( "ObjectClassSelectionDialog.Add" ), true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); 179 } 180 181 182 185 protected void okPressed() 186 { 187 StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection(); 188 189 if ( selection.isEmpty() ) 190 { 191 MessageDialog 192 .openError( 193 getShell(), 194 Messages.getString( "ObjectClassSelectionDialog.Invalid_Selection" ), Messages.getString( "ObjectClassSelectionDialog.You_have_to_choose_an_object_class" ) ); return; 196 } 197 198 ObjectClassWrapper ocw = ( ObjectClassWrapper ) selection.getFirstElement(); 199 if ( ocw != null ) 200 { 201 selectedObjectClass = ocw.getMyObjectClass(); 202 } 203 204 super.okPressed(); 205 } 206 207 208 214 public ObjectClass getSelectedObjectClass() 215 { 216 return selectedObjectClass; 217 } 218 219 220 226 public void setHiddenObjectClasses( List <ObjectClass> list ) 227 { 228 hiddenObjectClasses = list; 229 } 230 231 232 238 public void setHiddenObjectClasses( ObjectClass[] objectClasses ) 239 { 240 hiddenObjectClasses = new ArrayList <ObjectClass>(); 241 242 for ( ObjectClass objectClass : objectClasses ) 243 { 244 hiddenObjectClasses.add( objectClass ); 245 } 246 } 247 248 249 255 public void setHiddenObjectClasses( String [] names ) 256 { 257 hiddenObjectClasses = new ArrayList <ObjectClass>(); 258 259 for ( String name : names ) 260 { 261 ObjectClass oc = schemaPool.getObjectClass( name ); 262 if ( oc != null ) 263 { 264 hiddenObjectClasses.add( oc ); 265 } 266 } 267 } 268 } 269 | Popular Tags |