KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > attributeType > AttributeTypeEditorOverviewPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.schemas.view.editors.attributeType;
22
23
24 import org.apache.directory.ldapstudio.schemas.Messages;
25 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
26 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
27 import org.apache.directory.ldapstudio.schemas.model.MatchingRule;
28 import org.apache.directory.ldapstudio.schemas.model.MatchingRules;
29 import org.apache.directory.ldapstudio.schemas.model.PoolListener;
30 import org.apache.directory.ldapstudio.schemas.model.Schema;
31 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
32 import org.apache.directory.ldapstudio.schemas.model.Syntax;
33 import org.apache.directory.ldapstudio.schemas.model.Syntaxes;
34 import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
35 import org.apache.directory.ldapstudio.schemas.view.dialogs.EditAliasesDialog;
36 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType;
37 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditor;
38 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput;
39 import org.apache.directory.shared.asn1.primitives.OID;
40 import org.apache.directory.shared.ldap.schema.UsageEnum;
41 import org.apache.log4j.Logger;
42 import org.eclipse.jface.viewers.ComboViewer;
43 import org.eclipse.jface.viewers.StructuredSelection;
44 import org.eclipse.jface.window.Window;
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.events.ModifyEvent;
47 import org.eclipse.swt.events.ModifyListener;
48 import org.eclipse.swt.events.SelectionAdapter;
49 import org.eclipse.swt.events.SelectionEvent;
50 import org.eclipse.swt.events.VerifyEvent;
51 import org.eclipse.swt.events.VerifyListener;
52 import org.eclipse.swt.layout.GridData;
53 import org.eclipse.swt.layout.GridLayout;
54 import org.eclipse.swt.widgets.Button;
55 import org.eclipse.swt.widgets.Combo;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Label;
58 import org.eclipse.swt.widgets.Text;
59 import org.eclipse.ui.IWorkbenchPage;
60 import org.eclipse.ui.PartInitException;
61 import org.eclipse.ui.PlatformUI;
62 import org.eclipse.ui.forms.IManagedForm;
63 import org.eclipse.ui.forms.editor.FormEditor;
64 import org.eclipse.ui.forms.editor.FormPage;
65 import org.eclipse.ui.forms.events.HyperlinkAdapter;
66 import org.eclipse.ui.forms.events.HyperlinkEvent;
67 import org.eclipse.ui.forms.widgets.FormToolkit;
68 import org.eclipse.ui.forms.widgets.Hyperlink;
69 import org.eclipse.ui.forms.widgets.ScrolledForm;
70 import org.eclipse.ui.forms.widgets.Section;
71
72
73 /**
74  * This class is the Overview Page of the Attribute Type Editor
75  */

76 public class AttributeTypeEditorOverviewPage extends FormPage implements PoolListener
77 {
78     /** The page ID*/
79     public static final String JavaDoc ID = AttributeTypeEditor.ID + ".overviewPage"; //$NON-NLS-1$
80

81     /** The page title */
82     public static String JavaDoc TITLE = Messages.getString( "AttributeTypeEditorOverviewPage.Overview" ); //$NON-NLS-1$
83

84     /** The original object class */
85     private AttributeType originalAttributeType;
86
87     /** The modified object class */
88     private AttributeType modifiedAttributeType;
89
90     /** The Schema Pool */
91     private SchemaPool schemaPool;
92
93     // UI Fields
94
private Label aliasesLabel;
95     private Button aliasesButton;
96     private Text oidText;
97     private Hyperlink schemaLink;
98     private Label schemaLabel;
99     private Text descriptionText;
100     private Hyperlink supLabel;
101     private Combo supCombo;
102     private ComboViewer supComboViewer;
103     private Combo usageCombo;
104     private Combo syntaxCombo;
105     private ComboViewer syntaxComboViewer;
106     private Text syntaxLengthText;
107     private Button obsoleteCheckbox;
108     private Button singleValueCheckbox;
109     private Button collectiveCheckbox;
110     private Button noUserModificationCheckbox;
111     private Combo equalityCombo;
112     private ComboViewer equalityComboViewer;
113     private Combo orderingCombo;
114     private ComboViewer orderingComboViewer;
115     private Combo substringCombo;
116     private ComboViewer substringComboViewer;
117
118     // Listeners
119
/** The listener for the Edit Aliases Button Widget */
120     private SelectionAdapter aliasesButtonListener = new SelectionAdapter()
121     {
122         public void widgetSelected( SelectionEvent e )
123         {
124             EditAliasesDialog editDialog = new EditAliasesDialog( modifiedAttributeType.getNames() );
125             if ( editDialog.open() != Window.OK )
126             {
127                 return;
128             }
129             if ( editDialog.isDirty() )
130             {
131                 modifiedAttributeType.setNames( editDialog.getAliases() );
132                 if ( ( modifiedAttributeType.getNames() != null ) && ( modifiedAttributeType.getNames().length != 0 ) )
133                 {
134                     aliasesLabel.setText( ViewUtils.concateAliases( modifiedAttributeType.getNames() ) );
135                 }
136                 else
137                 {
138                     aliasesLabel.setText( Messages.getString( "AttributeTypeEditorOverviewPage.(None)" ) ); //$NON-NLS-1$
139
}
140                 setEditorDirty();
141             }
142         }
143     };
144
145     /** The Modify listener for the OID Text Widget */
146     private ModifyListener oidTextModifyListener = new ModifyListener()
147     {
148         public void modifyText( ModifyEvent e )
149         {
150             oidText.setForeground( ViewUtils.COLOR_BLACK );
151             oidText.setToolTipText( "" ); //$NON-NLS-1$
152

153             String JavaDoc oid = oidText.getText();
154
155             if ( OID.isOID( oid ) )
156             {
157                 if ( ( originalAttributeType.getOid().equals( oid ) ) || !( schemaPool.containsSchemaElement( oid ) ) )
158                 {
159                     modifiedAttributeType.setOid( oid );
160                     setEditorDirty();
161                 }
162                 else
163                 {
164                     oidText.setForeground( ViewUtils.COLOR_RED );
165                     oidText.setToolTipText( Messages
166                         .getString( "AttributeTypeEditorOverviewPage.An_element_with_same_oid_already_exists." ) ); //$NON-NLS-1$
167
}
168             }
169             else
170             {
171                 oidText.setForeground( ViewUtils.COLOR_RED );
172                 oidText.setToolTipText( Messages.getString( "AttributeTypeEditorOverviewPage.Malformed_OID." ) ); //$NON-NLS-1$
173
}
174         }
175     };
176
177     /** The Verify listener for the OID Text Widget */
178     private VerifyListener oidTextVerifyListener = new VerifyListener()
179     {
180         public void verifyText( VerifyEvent e )
181         {
182             if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$
183
{
184                 e.doit = false;
185             }
186         }
187     };
188
189     /** The listener for the Schema Hyperlink Widget*/
190     private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter()
191     {
192         public void linkActivated( HyperlinkEvent e )
193         {
194             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
195
196             SchemaEditorInput input = new SchemaEditorInput( modifiedAttributeType.getOriginatingSchema() );
197             String JavaDoc editorId = SchemaEditor.ID;
198             try
199             {
200                 page.openEditor( input, editorId );
201             }
202             catch ( PartInitException exception )
203             {
204                 Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
205
}
206         }
207     };
208
209     /** The listener for the Description Text Widget */
210     private ModifyListener descriptionTextListener = new ModifyListener()
211     {
212         public void modifyText( ModifyEvent e )
213         {
214             int caretPosition = descriptionText.getCaretPosition();
215             modifiedAttributeType.setDescription( descriptionText.getText() );
216             descriptionText.setSelection( caretPosition );
217             setEditorDirty();
218         }
219     };
220
221     /** The listener for the Sup Label Widget*/
222     private HyperlinkAdapter supLabelListener = new HyperlinkAdapter()
223     {
224         public void linkActivated( HyperlinkEvent e )
225         {
226             Object JavaDoc selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement();
227
228             if ( selectedItem instanceof AttributeType )
229             {
230                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
231
232                 AttributeTypeEditorInput input = new AttributeTypeEditorInput( ( AttributeType ) selectedItem );
233                 try
234                 {
235                     page.openEditor( input, AttributeTypeEditor.ID );
236                 }
237                 catch ( PartInitException exception )
238                 {
239                     Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
240
}
241             }
242         }
243     };
244
245     /** The listener for the Sup Combo Widget */
246     private ModifyListener supComboListener = new ModifyListener()
247     {
248         public void modifyText( ModifyEvent e )
249         {
250             Object JavaDoc selectedItem = ( ( StructuredSelection ) supComboViewer.getSelection() ).getFirstElement();
251
252             if ( selectedItem instanceof AttributeType )
253             {
254                 modifiedAttributeType.setSuperior( ( ( AttributeType ) selectedItem ).getNames()[0] );
255             }
256             else if ( selectedItem instanceof NonExistingAttributeType )
257             {
258                 NonExistingAttributeType neat = ( NonExistingAttributeType ) selectedItem;
259
260                 if ( NonExistingAttributeType.NONE.equals( neat.getName() ) )
261                 {
262                     modifiedAttributeType.setSuperior( null );
263                 }
264                 else
265                 {
266                     modifiedAttributeType.setSuperior( ( ( NonExistingAttributeType ) selectedItem ).getName() );
267                 }
268             }
269             setEditorDirty();
270         }
271     };
272
273     /** The listener for the Usage Combo Widget */
274     private ModifyListener usageComboListener = new ModifyListener()
275     {
276         public void modifyText( ModifyEvent e )
277         {
278             if ( usageCombo.getSelectionIndex() == 0 )
279             {
280                 modifiedAttributeType.setUsage( UsageEnum.DIRECTORY_OPERATION );
281             }
282             else if ( usageCombo.getSelectionIndex() == 1 )
283             {
284                 modifiedAttributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
285             }
286             else if ( usageCombo.getSelectionIndex() == 2 )
287             {
288                 modifiedAttributeType.setUsage( UsageEnum.DSA_OPERATION );
289             }
290             else if ( usageCombo.getSelectionIndex() == 3 )
291             {
292                 modifiedAttributeType.setUsage( UsageEnum.USER_APPLICATIONS );
293             }
294             setEditorDirty();
295         }
296     };
297
298     /** The listener for the Syntax Combo Widget */
299     private ModifyListener syntaxComboListener = new ModifyListener()
300     {
301         public void modifyText( ModifyEvent e )
302         {
303             Object JavaDoc selectedItem = ( ( StructuredSelection ) syntaxComboViewer.getSelection() ).getFirstElement();
304
305             if ( selectedItem instanceof Syntax )
306             {
307                 modifiedAttributeType.setSyntax( ( ( Syntax ) selectedItem ).getOid() );
308             }
309             else if ( selectedItem instanceof NonExistingSyntax )
310             {
311                 NonExistingSyntax nes = ( NonExistingSyntax ) selectedItem;
312
313                 if ( NonExistingMatchingRule.NONE.equals( nes.getName() ) )
314                 {
315                     modifiedAttributeType.setSyntax( null );
316                 }
317                 else
318                 {
319                     modifiedAttributeType.setSyntax( ( ( NonExistingSyntax ) selectedItem ).getName() );
320                 }
321             }
322             setEditorDirty();
323         }
324     };
325
326     /** The Modify listener for the Syntax Length Text Widget */
327     private ModifyListener syntaxLengthTextModifyListener = new ModifyListener()
328     {
329         public void modifyText( ModifyEvent e )
330         {
331             if ( syntaxLengthText.getText().length() == 0 )
332             {
333                 modifiedAttributeType.setLength( -1 );
334             }
335             else
336             {
337                 modifiedAttributeType.setLength( Integer.parseInt( syntaxLengthText.getText() ) );
338             }
339             setEditorDirty();
340         }
341     };
342
343     /** The Verify listener for the Syntax Length Text Widget */
344     private VerifyListener syntaxLengthTextVerifyListener = new VerifyListener()
345     {
346         public void verifyText( VerifyEvent e )
347         {
348             if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
349
{
350                 e.doit = false;
351             }
352         }
353     };
354
355     /** The listener for the Obsolete Checbox Widget */
356     private SelectionAdapter obsoleteCheckboxListener = new SelectionAdapter()
357     {
358         public void widgetSelected( SelectionEvent e )
359         {
360             modifiedAttributeType.setObsolete( obsoleteCheckbox.getSelection() );
361             setEditorDirty();
362         }
363     };
364
365     /** The listener for the Single-Value Checkbox Widget */
366     private SelectionAdapter singleValueCheckboxListener = new SelectionAdapter()
367     {
368         public void widgetSelected( SelectionEvent e )
369         {
370             modifiedAttributeType.setSingleValue( singleValueCheckbox.getSelection() );
371             setEditorDirty();
372         }
373     };
374
375     /** The listener for the Collective Checkbox Widget */
376     private SelectionAdapter collectiveCheckboxListener = new SelectionAdapter()
377     {
378         public void widgetSelected( SelectionEvent e )
379         {
380             modifiedAttributeType.setCollective( collectiveCheckbox.getSelection() );
381             setEditorDirty();
382         }
383     };
384
385     /** The listener for the No-User-Modification Widget */
386     private SelectionAdapter noUserModificationCheckboxListener = new SelectionAdapter()
387     {
388         public void widgetSelected( SelectionEvent e )
389         {
390             modifiedAttributeType.setNoUserModification( noUserModificationCheckbox.getSelection() );
391             setEditorDirty();
392         }
393     };
394
395     /** The listener for the Equality Combo Widget */
396     private ModifyListener equalityComboListener = new ModifyListener()
397     {
398         public void modifyText( ModifyEvent e )
399         {
400             Object JavaDoc selectedItem = ( ( StructuredSelection ) equalityComboViewer.getSelection() ).getFirstElement();
401
402             if ( selectedItem instanceof MatchingRule )
403             {
404                 modifiedAttributeType.setEquality( ( ( MatchingRule ) selectedItem ).getName() );
405             }
406             else if ( selectedItem instanceof NonExistingMatchingRule )
407             {
408                 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem;
409
410                 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) )
411                 {
412                     modifiedAttributeType.setEquality( null );
413                 }
414                 else
415                 {
416                     modifiedAttributeType.setEquality( ( ( NonExistingMatchingRule ) selectedItem ).getName() );
417                 }
418             }
419             setEditorDirty();
420         }
421     };
422
423     /** The listener for the Ordering Combo Widget */
424     private ModifyListener orderingComboListener = new ModifyListener()
425     {
426         public void modifyText( ModifyEvent e )
427         {
428             Object JavaDoc selectedItem = ( ( StructuredSelection ) orderingComboViewer.getSelection() ).getFirstElement();
429
430             if ( selectedItem instanceof MatchingRule )
431             {
432                 modifiedAttributeType.setOrdering( ( ( MatchingRule ) selectedItem ).getName() );
433             }
434             else if ( selectedItem instanceof NonExistingMatchingRule )
435             {
436                 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem;
437
438                 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) )
439                 {
440                     modifiedAttributeType.setOrdering( null );
441                 }
442                 else
443                 {
444                     modifiedAttributeType.setOrdering( ( ( NonExistingMatchingRule ) selectedItem ).getName() );
445                 }
446             }
447             setEditorDirty();
448         }
449     };
450
451     /** The listener for the Substring Combo Widget */
452     private ModifyListener substringComboListener = new ModifyListener()
453     {
454         public void modifyText( ModifyEvent e )
455         {
456             Object JavaDoc selectedItem = ( ( StructuredSelection ) substringComboViewer.getSelection() ).getFirstElement();
457
458             if ( selectedItem instanceof MatchingRule )
459             {
460                 modifiedAttributeType.setSubstr( ( ( MatchingRule ) selectedItem ).getName() );
461             }
462             else if ( selectedItem instanceof NonExistingMatchingRule )
463             {
464                 NonExistingMatchingRule nemr = ( NonExistingMatchingRule ) selectedItem;
465
466                 if ( NonExistingMatchingRule.NONE.equals( nemr.getName() ) )
467                 {
468                     modifiedAttributeType.setSubstr( null );
469                 }
470                 else
471                 {
472                     modifiedAttributeType.setSubstr( ( ( NonExistingMatchingRule ) selectedItem ).getName() );
473                 }
474             }
475             setEditorDirty();
476         }
477     };
478
479
480     /**
481      * Default constructor.
482      *
483      * @param editor
484      * the associated editor
485      */

486     public AttributeTypeEditorOverviewPage( FormEditor editor )
487     {
488         super( editor, ID, TITLE );
489         schemaPool = SchemaPool.getInstance();
490         schemaPool.addListener( this );
491     }
492
493
494     /* (non-Javadoc)
495      * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
496      */

497     protected void createFormContent( IManagedForm managedForm )
498     {
499         // Getting the original and modified attribute types
500
modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
501         originalAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getOriginalAttributeType();
502
503         // Creating the base UI
504
ScrolledForm form = managedForm.getForm();
505         FormToolkit toolkit = managedForm.getToolkit();
506         GridLayout layout = new GridLayout();
507         form.getBody().setLayout( layout );
508
509         // General Information Section
510
createGeneralInformationSection( form.getBody(), toolkit );
511
512         // Matching Rules Section
513
createMatchingRulesSection( form.getBody(), toolkit );
514
515         // Enabling or disabling the fields
516
setFieldsEditableState();
517
518         // Filling the UI with values from the attribute type
519
fillInUiFields();
520
521         // Listeners initialization
522
addListeners();
523     }
524
525
526     /**
527      * Creates the General Information Section.
528      *
529      * @param parent
530      * the parent composite
531      * @param toolkit
532      * the FormToolKit to use
533      */

534     private void createGeneralInformationSection( Composite parent, FormToolkit toolkit )
535     {
536         // General Information Section
537
Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
538             | Section.TITLE_BAR );
539         section_general_information.setDescription( Messages
540             .getString( "AttributeTypeEditorOverviewPage.General_Section_Description" ) ); //$NON-NLS-1$
541
section_general_information.setText( Messages
542             .getString( "AttributeTypeEditorOverviewPage.General_Section_Text" ) ); //$NON-NLS-1$
543

544         // Creating the layout of the section
545
Composite client_general_information = toolkit.createComposite( section_general_information );
546         GridLayout layout_general_information = new GridLayout();
547         layout_general_information.numColumns = 3;
548         client_general_information.setLayout( layout_general_information );
549         toolkit.paintBordersFor( client_general_information );
550         section_general_information.setClient( client_general_information );
551         section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
552
553         // Adding elements to the section
554
// ALIASES Button
555
toolkit
556             .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Aliases" ) ); //$NON-NLS-1$
557
aliasesLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
558
aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false, 2, 1 ) );
559         toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
560
aliasesButton = toolkit.createButton( client_general_information, Messages
561             .getString( "AttributeTypeEditorOverviewPage.Edit_Aliases" ), SWT.PUSH ); //$NON-NLS-1$
562
aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) );
563
564         // OID Field
565
toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.OID" ) ); //$NON-NLS-1$
566
oidText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$
567
oidText.setLayoutData( new GridData( SWT.FILL, 0, true, false, 2, 1 ) );
568
569         // DESCRIPTION Field
570
toolkit.createLabel( client_general_information, Messages
571             .getString( "AttributeTypeEditorOverviewPage.Description" ) ); //$NON-NLS-1$
572
descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); //$NON-NLS-1$
573
GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 );
574         descriptionGridData.heightHint = 42;
575         descriptionText.setLayoutData( descriptionGridData );
576
577         // SCHEMA Field
578
schemaLink = toolkit.createHyperlink( client_general_information, Messages
579             .getString( "AttributeTypeEditorOverviewPage.Schema" ), SWT.WRAP ); //$NON-NLS-1$
580
schemaLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
581
schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
582
583         // SUP Combo
584
supLabel = toolkit.createHyperlink( client_general_information, Messages
585             .getString( "AttributeTypeEditorOverviewPage.Superior_type" ), SWT.WRAP ); //$NON-NLS-1$
586
supCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE );
587         supCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
588         supComboViewer = new ComboViewer( supCombo );
589         supComboViewer.setContentProvider( new ATESuperiorComboContentProvider() );
590         supComboViewer.setLabelProvider( new ATESuperiorComboLabelProvider() );
591
592         // USAGE Combo
593
toolkit.createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Usage" ) ); //$NON-NLS-1$
594
usageCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE );
595         usageCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
596         initUsageCombo();
597
598         // SYNTAX Combo
599
toolkit
600             .createLabel( client_general_information, Messages.getString( "AttributeTypeEditorOverviewPage.Synatx" ) ); //$NON-NLS-1$
601
syntaxCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE );
602         syntaxCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
603         syntaxComboViewer = new ComboViewer( syntaxCombo );
604         syntaxComboViewer.setContentProvider( new ATESyntaxComboContentProvider() );
605         syntaxComboViewer.setLabelProvider( new ATESyntaxComboLabelProvider() );
606
607         // SYNTAX LENGTH Field
608
toolkit.createLabel( client_general_information, Messages
609             .getString( "AttributeTypeEditorOverviewPage.Syntax_length" ) ); //$NON-NLS-1$
610
syntaxLengthText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$
611
syntaxLengthText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
612
613         // OBSOLETE Checkbox
614
toolkit.createLabel( client_general_information, "" ); // Filling the first column //$NON-NLS-1$
615
obsoleteCheckbox = toolkit.createButton( client_general_information, Messages
616             .getString( "AttributeTypeEditorOverviewPage.Obsolete" ), SWT.CHECK ); //$NON-NLS-1$
617
obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
618
619         // SINGLE-VALUE Checkbox
620
singleValueCheckbox = toolkit.createButton( client_general_information, Messages
621             .getString( "AttributeTypeEditorOverviewPage.Single-Value" ), SWT.CHECK ); //$NON-NLS-1$
622
singleValueCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
623
624         // COLLECTIVE Checkbox
625
toolkit.createLabel( client_general_information, "" ); // Filling the first column //$NON-NLS-1$
626
collectiveCheckbox = toolkit.createButton( client_general_information, Messages
627             .getString( "AttributeTypeEditorOverviewPage.Collective" ), SWT.CHECK ); //$NON-NLS-1$
628
collectiveCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
629
630         // NO-USER-MODIFICATION Checkbox
631
noUserModificationCheckbox = toolkit.createButton( client_general_information, Messages
632             .getString( "AttributeTypeEditorOverviewPage.No-User-Modification" ), SWT.CHECK ); //$NON-NLS-1$
633
noUserModificationCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
634     }
635
636
637     /**
638      * Creates the Matching Rules Section.
639      *
640      * @param parent
641      * the parent composite
642      * @param toolkit
643      * the FormToolKit to use
644      */

645     private void createMatchingRulesSection( Composite parent, FormToolkit toolkit )
646     {
647         // Matching Rules Section
648
Section section_matching_rules = toolkit.createSection( parent, Section.DESCRIPTION | Section.EXPANDED
649             | Section.TITLE_BAR );
650         section_matching_rules.setDescription( Messages
651             .getString( "AttributeTypeEditorOverviewPage.Specify_matching_rules" ) ); //$NON-NLS-1$
652
section_matching_rules.setText( Messages.getString( "AttributeTypeEditorOverviewPage.Matching_Rules" ) ); //$NON-NLS-1$
653

654         // Creating the layout of the section
655
Composite client_matching_rules = toolkit.createComposite( section_matching_rules );
656         GridLayout layout_matching_rules = new GridLayout();
657         layout_matching_rules.numColumns = 2;
658         client_matching_rules.setLayout( layout_matching_rules );
659         toolkit.paintBordersFor( client_matching_rules );
660         section_matching_rules.setClient( client_matching_rules );
661         section_matching_rules.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
662
663         // EQUALITY Combo
664
toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Equility" ) ); //$NON-NLS-1$
665
equalityCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE );
666         equalityCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
667         equalityComboViewer = new ComboViewer( equalityCombo );
668         equalityComboViewer.setContentProvider( new ATEEqualityComboContentProvider() );
669         equalityComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() );
670
671         // ORDERING Combo
672
toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Ordering" ) ); //$NON-NLS-1$
673
orderingCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE );
674         orderingCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
675         orderingComboViewer = new ComboViewer( orderingCombo );
676         orderingComboViewer.setContentProvider( new ATEOrderingComboContentProvider() );
677         orderingComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() );
678
679         // SUBSTRING Combo
680
toolkit.createLabel( client_matching_rules, Messages.getString( "AttributeTypeEditorOverviewPage.Substring" ) ); //$NON-NLS-1$
681
substringCombo = new Combo( client_matching_rules, SWT.READ_ONLY | SWT.SINGLE );
682         substringCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
683         substringComboViewer = new ComboViewer( substringCombo );
684         substringComboViewer.setContentProvider( new ATESubstringComboContentProvider() );
685         substringComboViewer.setLabelProvider( new ATEMatchingRulesComboLabelProvider() );
686     }
687
688
689     /**
690      * Initializes the Usage Combo.
691      */

692     private void initUsageCombo()
693     {
694         usageCombo.add( "directoryOperation", 0 ); //$NON-NLS-1$
695
usageCombo.add( "distributedOperation", 1 ); //$NON-NLS-1$
696
usageCombo.add( "DSAOperation", 2 ); //$NON-NLS-1$
697
usageCombo.add( "userApplications", 3 ); //$NON-NLS-1$
698
}
699
700
701     /**
702      * Fills in the User Interface fields.
703      */

704     private void fillInUiFields()
705     {
706         // ALIASES Label
707
if ( ( modifiedAttributeType.getNames() != null ) && ( modifiedAttributeType.getNames().length != 0 ) )
708         {
709             aliasesLabel.setText( ViewUtils.concateAliases( modifiedAttributeType.getNames() ) );
710         }
711         else
712         {
713             aliasesLabel.setText( Messages.getString( "AttributeTypeEditorOverviewPage.(None)" ) ); //$NON-NLS-1$
714
}
715
716         // OID Field
717
if ( modifiedAttributeType.getOid() != null )
718         {
719             this.oidText.setText( modifiedAttributeType.getOid() );
720         }
721
722         // SCHEMA Field
723
if ( modifiedAttributeType.getOriginatingSchema() != null )
724         {
725             this.schemaLabel.setText( modifiedAttributeType.getOriginatingSchema().getName() );
726         }
727
728         // DESCRIPTION Field
729
if ( modifiedAttributeType.getDescription() != null )
730         {
731             this.descriptionText.setText( modifiedAttributeType.getDescription() );
732         }
733
734         // SUP Combo
735
fillSupCombo();
736
737         // USAGE Combo
738
fillInUsageCombo();
739
740         // SYNTAX Combo
741
fillSyntaxCombo();
742
743         // SYNTAX LENGTH Field
744
if ( modifiedAttributeType.getLength() != -1 )
745         {
746             this.syntaxLengthText.setText( modifiedAttributeType.getLength() + "" ); //$NON-NLS-1$
747
}
748
749         // OBSOLETE Checkbox
750
this.obsoleteCheckbox.setSelection( modifiedAttributeType.isObsolete() );
751
752         // SINGLE-VALUE Checkbox
753
this.singleValueCheckbox.setSelection( modifiedAttributeType.isSingleValue() );
754
755         // COLLECTIVE Checkbox
756
this.collectiveCheckbox.setSelection( modifiedAttributeType.isCollective() );
757
758         // NO-USER-MODIFICATION Checkbox
759
this.noUserModificationCheckbox.setSelection( modifiedAttributeType.isNoUserModification() );
760
761         // EQUALITY Combo
762
fillEqualityCombo();
763
764         // ORDERING Combo
765
fillOrderingCombo();
766
767         // SUBSTRING Combo
768
fillSubstringCombo();
769     }
770
771
772     /**
773      * Fills the the Sup Combo with the correct value.
774      */

775     private void fillSupCombo()
776     {
777         supComboViewer.setInput( new ATESuperiorComboInput( originalAttributeType ) );
778
779         if ( modifiedAttributeType.getSuperior() == null )
780         {
781             supComboViewer.setSelection( new StructuredSelection( new NonExistingAttributeType(
782                 NonExistingAttributeType.NONE ) ), true );
783         }
784         else
785         {
786             String JavaDoc supAtName = modifiedAttributeType.getSuperior();
787
788             AttributeType supAT = schemaPool.getAttributeType( supAtName );
789             if ( supAT != null )
790             {
791                 supComboViewer.setSelection( new StructuredSelection( supAT ), true );
792             }
793             else
794             {
795                 ATESuperiorComboInput input = ( ATESuperiorComboInput ) supComboViewer.getInput();
796                 NonExistingAttributeType neat = new NonExistingAttributeType( supAtName );
797                 if ( !input.getChildren().contains( neat ) )
798                 {
799                     input.addChild( neat );
800                 }
801                 supComboViewer.refresh();
802                 supComboViewer.setSelection( new StructuredSelection( neat ), true );
803             }
804         }
805     }
806
807
808     /**
809      * Fills the Usage Combo from the attribute type value
810      */

811     private void fillInUsageCombo()
812     {
813         if ( modifiedAttributeType.getUsage() == UsageEnum.DIRECTORY_OPERATION )
814         {
815             usageCombo.select( 0 );
816         }
817         else if ( modifiedAttributeType.getUsage() == UsageEnum.DISTRIBUTED_OPERATION )
818         {
819             usageCombo.select( 1 );
820         }
821         else if ( modifiedAttributeType.getUsage() == UsageEnum.DSA_OPERATION )
822         {
823             usageCombo.select( 2 );
824         }
825         else if ( modifiedAttributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
826         {
827             usageCombo.select( 3 );
828         }
829     }
830
831
832     /**
833      * Fills the the Syntax Combo with the correct value.
834      */

835     private void fillSyntaxCombo()
836     {
837         syntaxComboViewer.setInput( new ATESyntaxComboInput() );
838
839         if ( modifiedAttributeType.getSyntax() == null )
840         {
841             syntaxComboViewer.setSelection( new StructuredSelection( new NonExistingSyntax( NonExistingSyntax.NONE ) ),
842                 true );
843         }
844         else
845         {
846             String JavaDoc syntaxOID = modifiedAttributeType.getSyntax();
847
848             Syntax syntax = Syntaxes.getSyntaxFromOid( syntaxOID );
849             if ( syntax != null )
850             {
851                 syntaxComboViewer.setSelection( new StructuredSelection( syntax ), true );
852             }
853             else
854             {
855                 ATESyntaxComboInput input = ( ATESyntaxComboInput ) syntaxComboViewer.getInput();
856                 NonExistingSyntax nes = new NonExistingSyntax( syntaxOID );
857                 if ( !input.getChildren().contains( nes ) )
858                 {
859                     input.addChild( nes );
860                 }
861                 syntaxComboViewer.refresh();
862                 syntaxComboViewer.setSelection( new StructuredSelection( nes ), true );
863             }
864         }
865     }
866
867
868     /**
869      * Fills the the Equality Combo with the correct value.
870      */

871     private void fillEqualityCombo()
872     {
873         equalityComboViewer.setInput( new ATEMatchingRulesComboInput() );
874
875         if ( modifiedAttributeType.getEquality() == null )
876         {
877             equalityComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule(
878                 NonExistingMatchingRule.NONE ) ), true );
879         }
880         else
881         {
882             String JavaDoc equalityName = modifiedAttributeType.getEquality();
883
884             MatchingRule matchingRule = MatchingRules.getMatchingRule( equalityName );
885             if ( matchingRule != null )
886             {
887                 equalityComboViewer.setSelection( new StructuredSelection( matchingRule ), true );
888             }
889             else
890             {
891                 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) equalityComboViewer.getInput();
892                 NonExistingMatchingRule nemr = new NonExistingMatchingRule( equalityName );
893                 if ( !input.getChildren().contains( nemr ) )
894                 {
895                     input.addChild( nemr );
896                 }
897                 equalityComboViewer.refresh();
898                 equalityComboViewer.setSelection( new StructuredSelection( nemr ), true );
899             }
900         }
901     }
902
903
904     /**
905      * Fills the the Ordering Combo with the correct value.
906      */

907     private void fillOrderingCombo()
908     {
909         orderingComboViewer.setInput( new ATEMatchingRulesComboInput() );
910
911         if ( modifiedAttributeType.getOrdering() == null )
912         {
913             orderingComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule(
914                 NonExistingMatchingRule.NONE ) ), true );
915         }
916         else
917         {
918             String JavaDoc orderingName = modifiedAttributeType.getOrdering();
919
920             MatchingRule matchingRule = MatchingRules.getMatchingRule( orderingName );
921             if ( matchingRule != null )
922             {
923                 orderingComboViewer.setSelection( new StructuredSelection( matchingRule ), true );
924             }
925             else
926             {
927                 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) orderingComboViewer.getInput();
928                 NonExistingMatchingRule nemr = new NonExistingMatchingRule( orderingName );
929                 if ( !input.getChildren().contains( nemr ) )
930                 {
931                     input.addChild( nemr );
932                 }
933                 orderingComboViewer.refresh();
934                 orderingComboViewer.setSelection( new StructuredSelection( nemr ), true );
935             }
936         }
937
938     }
939
940
941     /**
942      * Fills the the Substring Combo with the correct value.
943      */

944     private void fillSubstringCombo()
945     {
946         substringComboViewer.setInput( new ATEMatchingRulesComboInput() );
947
948         if ( modifiedAttributeType.getSubstr() == null )
949         {
950             substringComboViewer.setSelection( new StructuredSelection( new NonExistingMatchingRule(
951                 NonExistingMatchingRule.NONE ) ), true );
952         }
953         else
954         {
955             String JavaDoc substringName = modifiedAttributeType.getSubstr();
956
957             MatchingRule matchingRule = MatchingRules.getMatchingRule( substringName );
958             if ( matchingRule != null )
959             {
960                 substringComboViewer.setSelection( new StructuredSelection( matchingRule ), true );
961             }
962             else
963             {
964                 ATEMatchingRulesComboInput input = ( ATEMatchingRulesComboInput ) substringComboViewer.getInput();
965                 NonExistingMatchingRule nemr = new NonExistingMatchingRule( substringName );
966                 if ( !input.getChildren().contains( nemr ) )
967                 {
968                     input.addChild( nemr );
969                 }
970                 substringComboViewer.refresh();
971                 substringComboViewer.setSelection( new StructuredSelection( nemr ), true );
972             }
973         }
974     }
975
976
977     /**
978      * Enalbes/Disables the UI fields
979      */

980     private void setFieldsEditableState()
981     {
982         if ( modifiedAttributeType.getOriginatingSchema().type == Schema.SchemaType.coreSchema )
983         {
984             // If the attribute type is in a core-schema file, we disable editing
985
aliasesButton.setEnabled( false );
986             oidText.setEditable( false );
987             descriptionText.setEditable( false );
988             supCombo.setEnabled( false );
989             usageCombo.setEnabled( false );
990             syntaxCombo.setEnabled( false );
991             syntaxLengthText.setEditable( false );
992             obsoleteCheckbox.setEnabled( false );
993             singleValueCheckbox.setEnabled( false );
994             collectiveCheckbox.setEnabled( false );
995             noUserModificationCheckbox.setEnabled( false );
996             equalityCombo.setEnabled( false );
997             orderingCombo.setEnabled( false );
998             substringCombo.setEnabled( false );
999         }
1000    }
1001
1002
1003    /**
1004     * Adds listeners to UI fields
1005     */

1006    private void addListeners()
1007    {
1008        if ( modifiedAttributeType.getOriginatingSchema().type == Schema.SchemaType.userSchema )
1009        {
1010            aliasesButton.addSelectionListener( aliasesButtonListener );
1011            oidText.addModifyListener( oidTextModifyListener );
1012            oidText.addVerifyListener( oidTextVerifyListener );
1013            descriptionText.addModifyListener( descriptionTextListener );
1014            supLabel.addHyperlinkListener( supLabelListener );
1015            supCombo.addModifyListener( supComboListener );
1016            usageCombo.addModifyListener( usageComboListener );
1017            syntaxCombo.addModifyListener( syntaxComboListener );
1018            syntaxLengthText.addModifyListener( syntaxLengthTextModifyListener );
1019            syntaxLengthText.addVerifyListener( syntaxLengthTextVerifyListener );
1020            obsoleteCheckbox.addSelectionListener( obsoleteCheckboxListener );
1021            singleValueCheckbox.addSelectionListener( singleValueCheckboxListener );
1022            collectiveCheckbox.addSelectionListener( collectiveCheckboxListener );
1023            noUserModificationCheckbox.addSelectionListener( noUserModificationCheckboxListener );
1024            equalityCombo.addModifyListener( equalityComboListener );
1025            orderingCombo.addModifyListener( orderingComboListener );
1026            substringCombo.addModifyListener( substringComboListener );
1027        }
1028
1029        schemaLink.addHyperlinkListener( schemaLinkListener );
1030        supLabel.addHyperlinkListener( supLabelListener );
1031    }
1032
1033
1034    /**
1035     * Removes listeners from UI fields
1036     */

1037    private void removeListeners()
1038    {
1039        oidText.removeModifyListener( oidTextModifyListener );
1040        oidText.removeVerifyListener( oidTextVerifyListener );
1041        aliasesButton.removeSelectionListener( aliasesButtonListener );
1042        schemaLink.removeHyperlinkListener( schemaLinkListener );
1043        descriptionText.removeModifyListener( descriptionTextListener );
1044        supLabel.removeHyperlinkListener( supLabelListener );
1045        supCombo.removeModifyListener( supComboListener );
1046        usageCombo.removeModifyListener( usageComboListener );
1047        syntaxCombo.removeModifyListener( syntaxComboListener );
1048        syntaxLengthText.removeModifyListener( syntaxLengthTextModifyListener );
1049        syntaxLengthText.removeVerifyListener( syntaxLengthTextVerifyListener );
1050        obsoleteCheckbox.removeSelectionListener( obsoleteCheckboxListener );
1051        singleValueCheckbox.removeSelectionListener( singleValueCheckboxListener );
1052        collectiveCheckbox.removeSelectionListener( collectiveCheckboxListener );
1053        noUserModificationCheckbox.removeSelectionListener( noUserModificationCheckboxListener );
1054        equalityCombo.removeModifyListener( equalityComboListener );
1055        orderingCombo.removeModifyListener( orderingComboListener );
1056        substringCombo.removeModifyListener( substringComboListener );
1057    }
1058
1059
1060    /**
1061     * Sets the dirty state of the editor to dirty
1062     */

1063    private void setEditorDirty()
1064    {
1065        ( ( AttributeTypeEditor ) getEditor() ).setDirty( true );
1066    }
1067
1068
1069    /**
1070     * Refreshes the UI.
1071     */

1072    public void refreshUI()
1073    {
1074        removeListeners();
1075        fillInUiFields();
1076        addListeners();
1077    }
1078
1079
1080    /* (non-Javadoc)
1081     * @see org.apache.directory.ldapstudio.schemas.model.PoolListener#poolChanged(org.apache.directory.ldapstudio.schemas.model.SchemaPool, org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent)
1082     */

1083    public void poolChanged( SchemaPool p, LDAPModelEvent e )
1084    {
1085        removeListeners();
1086        supComboViewer.setInput( new ATESuperiorComboInput( originalAttributeType ) );
1087        fillSupCombo();
1088        addListeners();
1089    }
1090
1091
1092    /* (non-Javadoc)
1093     * @see org.eclipse.ui.forms.editor.FormPage#dispose()
1094     */

1095    public void dispose()
1096    {
1097        schemaPool.removeListener( this );
1098        removeListeners();
1099        super.dispose();
1100    }
1101}
1102
Popular Tags