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.AttributeType; 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.AttributeTypeWrapper; 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 AttributeTypeSelectionDialog extends Dialog 63 { 64 65 private AttributeType selectedAttributeType; 66 67 68 private SchemaPool schemaPool; 69 70 71 private List <AttributeType> hiddenAttributeTypes; 72 73 private Text searchText; 75 private Table attributeTypesTable; 76 private TableViewer tableViewer; 77 78 79 82 public AttributeTypeSelectionDialog() 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( "AttributeTypeSelectionDialog.Attribute_Type_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( "AttributeTypeSelectionDialog.Choose_an_attribute_type" ) ); 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 attributeTypesTable.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 attributeTypesTable.setFocus(); 129 } 130 } 131 } ); 132 133 Label matchingLabel = new Label( composite, SWT.NONE ); 134 matchingLabel.setText( Messages.getString( "AttributeTypeSelectionDialog.Matching_attribute_type(s)" ) ); matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) ); 136 137 attributeTypesTable = 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 attributeTypesTable.setLayoutData( gridData ); 145 attributeTypesTable.addMouseListener( new MouseAdapter() 146 { 147 public void mouseDoubleClick( MouseEvent e ) 148 { 149 if ( attributeTypesTable.getSelectionIndex() != -1 ) 150 { 151 okPressed(); 152 } 153 } 154 } ); 155 156 tableViewer = new TableViewer( attributeTypesTable ); 157 tableViewer.setUseHashlookup( true ); 158 159 tableViewer.setContentProvider( new AttributeTypeSelectionDialogContentProvider( hiddenAttributeTypes ) ); 160 tableViewer.setLabelProvider( new TableDecoratingLabelProvider( 161 new AttributeTypeSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench() 162 .getDecoratorManager().getLabelDecorator() ) ); 163 164 tableViewer.setInput( "" ); attributeTypesTable.select( 0 ); 168 169 return composite; 170 } 171 172 173 176 protected void createButtonsForButtonBar( Composite parent ) 177 { 178 createButton( parent, IDialogConstants.OK_ID, Messages.getString( "AttributeTypeSelectionDialog.Add" ), true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); 180 181 } 182 183 184 187 protected void okPressed() 188 { 189 StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection(); 190 191 if ( selection.isEmpty() ) 192 { 193 MessageDialog 194 .openError( 195 getShell(), 196 Messages.getString( "AttributeTypeSelectionDialog.Invalid_Selection" ), Messages.getString( "AttributeTypeSelectionDialog.You_have_to_choose_an_attribute_type" ) ); return; 198 } 199 200 AttributeTypeWrapper atw = ( AttributeTypeWrapper ) selection.getFirstElement(); 201 if ( atw != null ) 202 { 203 selectedAttributeType = atw.getMyAttributeType(); 204 } 205 206 super.okPressed(); 207 } 208 209 210 216 public AttributeType getSelectedAttributeType() 217 { 218 return selectedAttributeType; 219 } 220 221 222 228 public void setHiddenAttributeTypes( List <AttributeType> list ) 229 { 230 hiddenAttributeTypes = list; 231 } 232 233 234 240 public void setHiddenAttributeTypes( AttributeType[] attributeTypes ) 241 { 242 hiddenAttributeTypes = new ArrayList <AttributeType>(); 243 244 for ( AttributeType objectClass : attributeTypes ) 245 { 246 hiddenAttributeTypes.add( objectClass ); 247 } 248 } 249 250 251 257 public void setHiddenAttributeTypes( String [] names ) 258 { 259 hiddenAttributeTypes = new ArrayList <AttributeType>(); 260 261 for ( String name : names ) 262 { 263 AttributeType at = schemaPool.getAttributeType( name ); 264 if ( at != null ) 265 { 266 hiddenAttributeTypes.add( at ); 267 } 268 } 269 } 270 } 271 | Popular Tags |