KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > editors > objectClass > ObjectClassEditorOverviewPage


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.objectClass;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.apache.directory.ldapstudio.schemas.Messages;
28 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
29 import org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent;
30 import org.apache.directory.ldapstudio.schemas.model.ObjectClass;
31 import org.apache.directory.ldapstudio.schemas.model.PoolListener;
32 import org.apache.directory.ldapstudio.schemas.model.Schema;
33 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
34 import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
35 import org.apache.directory.ldapstudio.schemas.view.dialogs.AttributeTypeSelectionDialog;
36 import org.apache.directory.ldapstudio.schemas.view.dialogs.EditAliasesDialog;
37 import org.apache.directory.ldapstudio.schemas.view.dialogs.ObjectClassSelectionDialog;
38 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingAttributeType;
39 import org.apache.directory.ldapstudio.schemas.view.editors.NonExistingObjectClass;
40 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor;
41 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput;
42 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditor;
43 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput;
44 import org.apache.directory.shared.asn1.primitives.OID;
45 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
46 import org.apache.log4j.Logger;
47 import org.eclipse.jface.viewers.StructuredSelection;
48 import org.eclipse.jface.viewers.TableViewer;
49 import org.eclipse.jface.window.Window;
50 import org.eclipse.swt.SWT;
51 import org.eclipse.swt.events.ModifyEvent;
52 import org.eclipse.swt.events.ModifyListener;
53 import org.eclipse.swt.events.MouseAdapter;
54 import org.eclipse.swt.events.MouseEvent;
55 import org.eclipse.swt.events.MouseListener;
56 import org.eclipse.swt.events.SelectionAdapter;
57 import org.eclipse.swt.events.SelectionEvent;
58 import org.eclipse.swt.events.VerifyEvent;
59 import org.eclipse.swt.events.VerifyListener;
60 import org.eclipse.swt.layout.GridData;
61 import org.eclipse.swt.layout.GridLayout;
62 import org.eclipse.swt.widgets.Button;
63 import org.eclipse.swt.widgets.Combo;
64 import org.eclipse.swt.widgets.Composite;
65 import org.eclipse.swt.widgets.Label;
66 import org.eclipse.swt.widgets.Table;
67 import org.eclipse.swt.widgets.Text;
68 import org.eclipse.ui.IWorkbenchPage;
69 import org.eclipse.ui.PartInitException;
70 import org.eclipse.ui.PlatformUI;
71 import org.eclipse.ui.forms.IManagedForm;
72 import org.eclipse.ui.forms.editor.FormEditor;
73 import org.eclipse.ui.forms.editor.FormPage;
74 import org.eclipse.ui.forms.events.HyperlinkAdapter;
75 import org.eclipse.ui.forms.events.HyperlinkEvent;
76 import org.eclipse.ui.forms.widgets.FormToolkit;
77 import org.eclipse.ui.forms.widgets.Hyperlink;
78 import org.eclipse.ui.forms.widgets.ScrolledForm;
79 import org.eclipse.ui.forms.widgets.Section;
80
81
82 /**
83  * This class is the Overview Page of the Object Class Editor
84  */

85 public class ObjectClassEditorOverviewPage extends FormPage implements PoolListener
86 {
87     /** The page ID */
88     public static final String JavaDoc ID = ObjectClassEditor.ID + "overviewPage"; //$NON-NLS-1$
89

90     /** The page title*/
91     public static final String JavaDoc TITLE = Messages.getString( "ObjectClassEditorOverviewPage.Overview" ); //$NON-NLS-1$
92

93     /** The original object class */
94     private ObjectClass originalObjectClass;
95
96     /** The modified object class */
97     private ObjectClass modifiedObjectClass;
98
99     /** The Schema Pool */
100     private SchemaPool schemaPool;
101
102     // UI fields
103
private Label aliasesLabel;
104     private Button aliasesButton;
105     private Text oidText;
106     private Hyperlink schemaLink;
107     private Label schemaLabel;
108     private Text descriptionText;
109     private Table superiorsTable;
110     private TableViewer superiorsTableViewer;
111     private Button addButtonSuperiorsTable;
112     private Button removeButtonSuperiorsTable;
113     private Combo classTypeCombo;
114     private Button obsoleteCheckbox;
115     private Table mandatoryAttributesTable;
116     private TableViewer mandatoryAttributesTableViewer;
117     private Button addButtonMandatoryTable;
118     private Button removeButtonMandatoryTable;
119     private Table optionalAttributesTable;
120     private TableViewer optionalAttributesTableViewer;
121     private Button addButtonOptionalTable;
122     private Button removeButtonOptionalTable;
123
124     // Listeners
125
/** The listener for Aliases Button Widget */
126     private SelectionAdapter aliasesButtonListener = new SelectionAdapter()
127     {
128         public void widgetSelected( SelectionEvent e )
129         {
130             EditAliasesDialog editDialog = new EditAliasesDialog( modifiedObjectClass.getNames() );
131             if ( editDialog.open() != Window.OK )
132             {
133                 return;
134             }
135             if ( editDialog.isDirty() )
136             {
137                 modifiedObjectClass.setNames( editDialog.getAliases() );
138                 if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) )
139                 {
140                     aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) );
141                 }
142                 else
143                 {
144                     aliasesLabel.setText( Messages.getString( "ObjectClassEditorOverviewPage.(None)" ) ); //$NON-NLS-1$
145
}
146                 setEditorDirty();
147             }
148         }
149     };
150
151     /** The Modify listener for the OID Text Widget */
152     private ModifyListener oidTextModifyListener = new ModifyListener()
153     {
154         public void modifyText( ModifyEvent e )
155         {
156             oidText.setForeground( ViewUtils.COLOR_BLACK );
157             oidText.setToolTipText( "" ); //$NON-NLS-1$
158

159             String JavaDoc oid = oidText.getText();
160
161             if ( OID.isOID( oid ) )
162             {
163                 if ( ( originalObjectClass.getOid().equals( oid ) ) || !( schemaPool.containsSchemaElement( oid ) ) )
164                 {
165                     modifiedObjectClass.setOid( oid );
166                     setEditorDirty();
167                 }
168                 else
169                 {
170                     oidText.setForeground( ViewUtils.COLOR_RED );
171                     oidText.setToolTipText( Messages
172                         .getString( "ObjectClassEditorOverviewPage.An_element_with_same_oid_already_exists." ) ); //$NON-NLS-1$
173
}
174             }
175             else
176             {
177                 oidText.setForeground( ViewUtils.COLOR_RED );
178                 oidText.setToolTipText( Messages.getString( "ObjectClassEditorOverviewPage.Malformed_OID." ) ); //$NON-NLS-1$
179
}
180         }
181     };
182
183     /** The Verify listener for the OID Text Widget */
184     private VerifyListener oidTextVerifyListener = new VerifyListener()
185     {
186         public void verifyText( VerifyEvent e )
187         {
188             if ( !e.text.matches( "([0-9]*\\.?)*" ) ) //$NON-NLS-1$
189
{
190                 e.doit = false;
191             }
192         }
193     };
194
195     /** The listener for the Schema Hyperlink Widget*/
196     private HyperlinkAdapter schemaLinkListener = new HyperlinkAdapter()
197     {
198         public void linkActivated( HyperlinkEvent e )
199         {
200             IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
201
202             SchemaEditorInput input = new SchemaEditorInput( modifiedObjectClass.getOriginatingSchema() );
203             String JavaDoc editorId = SchemaEditor.ID;
204             try
205             {
206                 page.openEditor( input, editorId );
207             }
208             catch ( PartInitException exception )
209             {
210                 Logger.getLogger( AttributeTypeEditorInput.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
211
}
212         }
213     };
214
215     /** The listener for Description Text Widget */
216     private ModifyListener descriptionTextListener = new ModifyListener()
217     {
218         public void modifyText( ModifyEvent e )
219         {
220             int caretPosition = descriptionText.getCaretPosition();
221             modifiedObjectClass.setDescription( descriptionText.getText() );
222             descriptionText.setSelection( caretPosition );
223             setEditorDirty();
224         }
225     };
226
227     /** The listener for Class Type Widget */
228     private ModifyListener classTypeListener = new ModifyListener()
229     {
230         public void modifyText( ModifyEvent e )
231         {
232             if ( classTypeCombo.getSelectionIndex() == 0 )
233             {
234                 modifiedObjectClass.setClassType( ObjectClassTypeEnum.ABSTRACT );
235             }
236             else if ( classTypeCombo.getSelectionIndex() == 1 )
237             {
238                 modifiedObjectClass.setClassType( ObjectClassTypeEnum.AUXILIARY );
239             }
240             else if ( classTypeCombo.getSelectionIndex() == 2 )
241             {
242                 modifiedObjectClass.setClassType( ObjectClassTypeEnum.STRUCTURAL );
243             }
244             setEditorDirty();
245         }
246     };
247
248     /** The listener for Obsolete Widget */
249     private SelectionAdapter obsoleteListener = new SelectionAdapter()
250     {
251         public void widgetSelected( SelectionEvent e )
252         {
253             modifiedObjectClass.setObsolete( obsoleteCheckbox.getSelection() );
254             setEditorDirty();
255         }
256     };
257
258     /** The listener for Mandatory Attributes Table Widget */
259     private MouseListener mandatoryAttributesTableListener = new MouseListener()
260     {
261         public void mouseDoubleClick( MouseEvent e )
262         {
263             StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection();
264             if ( selection.isEmpty() )
265             {
266                 return;
267             }
268
269             Object JavaDoc selectedElement = selection.getFirstElement();
270             if ( selectedElement != null )
271             {
272                 if ( selectedElement instanceof AttributeType )
273                 {
274                     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
275                     try
276                     {
277                         page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ),
278                             AttributeTypeEditor.ID );
279                     }
280                     catch ( PartInitException exception )
281                     {
282                         Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
283
}
284                 }
285             }
286         }
287
288
289         public void mouseDown( MouseEvent e )
290         {
291         }
292
293
294         public void mouseUp( MouseEvent e )
295         {
296             if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema )
297             {
298                 removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 );
299             }
300         }
301     };
302
303     /** The listener for Add Button Widget of the Mandatory Attributes section */
304     private SelectionAdapter addButtonMandatoryTableListener = new SelectionAdapter()
305     {
306         public void widgetSelected( SelectionEvent e )
307         {
308             AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
309             List JavaDoc<AttributeType> hiddenATs = new ArrayList JavaDoc<AttributeType>();
310             for ( String JavaDoc must : modifiedObjectClass.getMust() )
311             {
312                 AttributeType at = schemaPool.getAttributeType( must );
313                 if ( at != null )
314                 {
315                     hiddenATs.add( at );
316                 }
317             }
318             for ( String JavaDoc may : modifiedObjectClass.getMay() )
319             {
320                 AttributeType at = schemaPool.getAttributeType( may );
321                 if ( at != null )
322                 {
323                     hiddenATs.add( at );
324                 }
325             }
326             dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) );
327
328             if ( dialog.open() != Window.OK )
329             {
330                 return;
331             }
332
333             AttributeType at = dialog.getSelectedAttributeType();
334             if ( at == null )
335             {
336                 return;
337             }
338
339             List JavaDoc<String JavaDoc> newMusts = new ArrayList JavaDoc<String JavaDoc>();
340             String JavaDoc[] musts = modifiedObjectClass.getMust();
341             for ( String JavaDoc must : musts )
342             {
343                 newMusts.add( must );
344             }
345             newMusts.add( at.getNames()[0] );
346             modifiedObjectClass.setMust( newMusts.toArray( new String JavaDoc[0] ) );
347
348             fillInMandatoryAttributesTable();
349             setEditorDirty();
350         }
351     };
352
353     /** The listener for Remove Button Widget of the Mandatory Attributes section */
354     private SelectionAdapter removeButtonMandatoryTableListener = new SelectionAdapter()
355     {
356         public void widgetSelected( SelectionEvent e )
357         {
358             StructuredSelection selection = ( StructuredSelection ) mandatoryAttributesTableViewer.getSelection();
359             if ( selection.isEmpty() )
360             {
361                 return;
362             }
363
364             Object JavaDoc selectedElement = selection.getFirstElement();
365             if ( selectedElement != null )
366             {
367                 List JavaDoc<String JavaDoc> newMusts = new ArrayList JavaDoc<String JavaDoc>();
368                 String JavaDoc[] musts = modifiedObjectClass.getMust();
369                 for ( String JavaDoc must : musts )
370                 {
371                     newMusts.add( must );
372                 }
373
374                 if ( selectedElement instanceof AttributeType )
375                 {
376                     for ( String JavaDoc name : ( ( AttributeType ) selectedElement ).getNames() )
377                     {
378                         newMusts.remove( name );
379                     }
380                 }
381                 else if ( selectedElement instanceof NonExistingAttributeType )
382                 {
383                     newMusts.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() );
384                 }
385
386                 modifiedObjectClass.setMust( newMusts.toArray( new String JavaDoc[0] ) );
387
388                 fillInMandatoryAttributesTable();
389                 addButtonMandatoryTable.setFocus();
390                 removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelection().length != 0 );
391                 setEditorDirty();
392             }
393         }
394     };
395
396     /** The listener for Optional Attributes Table Widget */
397     private MouseListener optionalAttributesTableListener = new MouseAdapter()
398     {
399         public void mouseDoubleClick( MouseEvent e )
400         {
401             StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection();
402             if ( selection.isEmpty() )
403             {
404                 return;
405             }
406
407             Object JavaDoc selectedElement = selection.getFirstElement();
408             if ( selectedElement != null )
409             {
410                 if ( selectedElement instanceof AttributeType )
411                 {
412                     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
413                     try
414                     {
415                         page.openEditor( new AttributeTypeEditorInput( ( AttributeType ) selectedElement ),
416                             AttributeTypeEditor.ID );
417                     }
418                     catch ( PartInitException exception )
419                     {
420                         Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
421
}
422                 }
423             }
424         }
425
426
427         public void mouseUp( MouseEvent e )
428         {
429             if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema )
430             {
431                 removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 );
432             }
433         }
434     };
435
436     /** The listener for Add Button Widget of the Optional Attributes section */
437     private SelectionAdapter addButtonOptionalTableListener = new SelectionAdapter()
438     {
439         public void widgetSelected( SelectionEvent e )
440         {
441             AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
442             List JavaDoc<AttributeType> hiddenATs = new ArrayList JavaDoc<AttributeType>();
443             for ( String JavaDoc must : modifiedObjectClass.getMust() )
444             {
445                 AttributeType at = schemaPool.getAttributeType( must );
446                 if ( at != null )
447                 {
448                     hiddenATs.add( at );
449                 }
450             }
451             for ( String JavaDoc may : modifiedObjectClass.getMay() )
452             {
453                 AttributeType at = schemaPool.getAttributeType( may );
454                 if ( at != null )
455                 {
456                     hiddenATs.add( at );
457                 }
458             }
459             dialog.setHiddenAttributeTypes( hiddenATs.toArray( new AttributeType[0] ) );
460
461             if ( dialog.open() != Window.OK )
462             {
463                 return;
464             }
465
466             AttributeType at = dialog.getSelectedAttributeType();
467             if ( at == null )
468             {
469                 return;
470             }
471
472             List JavaDoc<String JavaDoc> newMays = new ArrayList JavaDoc<String JavaDoc>();
473             String JavaDoc[] mays = modifiedObjectClass.getMay();
474             for ( String JavaDoc may : mays )
475             {
476                 newMays.add( may );
477             }
478             newMays.add( at.getNames()[0] );
479             modifiedObjectClass.setMay( newMays.toArray( new String JavaDoc[0] ) );
480
481             fillInOptionalAttributesTable();
482             setEditorDirty();
483         }
484     };
485
486     /** The listener for Remove Button Widget of the Optional Attributes section */
487     private SelectionAdapter removeButtonOptionalTableListener = new SelectionAdapter()
488     {
489         public void widgetSelected( SelectionEvent e )
490         {
491             StructuredSelection selection = ( StructuredSelection ) optionalAttributesTableViewer.getSelection();
492             if ( selection.isEmpty() )
493             {
494                 return;
495             }
496
497             Object JavaDoc selectedElement = selection.getFirstElement();
498             if ( selectedElement != null )
499             {
500                 List JavaDoc<String JavaDoc> newMays = new ArrayList JavaDoc<String JavaDoc>();
501                 String JavaDoc[] mays = modifiedObjectClass.getMay();
502                 for ( String JavaDoc may : mays )
503                 {
504                     newMays.add( may );
505                 }
506
507                 if ( selectedElement instanceof AttributeType )
508                 {
509                     for ( String JavaDoc name : ( ( AttributeType ) selectedElement ).getNames() )
510                     {
511                         newMays.remove( name );
512                     }
513                 }
514                 else if ( selectedElement instanceof NonExistingAttributeType )
515                 {
516                     newMays.remove( ( ( NonExistingAttributeType ) selectedElement ).getName() );
517                 }
518
519                 modifiedObjectClass.setMay( newMays.toArray( new String JavaDoc[0] ) );
520
521                 fillInOptionalAttributesTable();
522                 addButtonOptionalTable.setFocus();
523                 removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelection().length != 0 );
524                 setEditorDirty();
525             }
526         }
527     };
528
529     /** The listener for Superiors Table Widget */
530     private MouseListener superiorsTableListener = new MouseAdapter()
531     {
532         public void mouseDoubleClick( MouseEvent e )
533         {
534             StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection();
535             if ( selection.isEmpty() )
536             {
537                 return;
538             }
539
540             Object JavaDoc selectedElement = selection.getFirstElement();
541             if ( selectedElement != null )
542             {
543                 if ( selectedElement instanceof ObjectClass )
544                 {
545                     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
546                     try
547                     {
548                         page.openEditor( new ObjectClassEditorInput( ( ObjectClass ) selectedElement ),
549                             ObjectClassEditor.ID );
550                     }
551                     catch ( PartInitException exception )
552                     {
553                         Logger.getLogger( ObjectClassEditorOverviewPage.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
554
}
555                 }
556             }
557         }
558
559
560         public void mouseUp( MouseEvent e )
561         {
562             if ( modifiedObjectClass.getOriginatingSchema().type != Schema.SchemaType.coreSchema )
563             {
564                 removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 );
565             }
566         }
567     };
568
569     /** The listener for Add Button Widget of the Superiors Table */
570     private SelectionAdapter addButtonSuperiorsTableListener = new SelectionAdapter()
571     {
572         public void widgetSelected( SelectionEvent e )
573         {
574             ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog();
575             List JavaDoc<ObjectClass> hiddenOCs = new ArrayList JavaDoc<ObjectClass>();
576             for ( String JavaDoc sup : modifiedObjectClass.getSuperiors() )
577             {
578                 ObjectClass oc = schemaPool.getObjectClass( sup );
579                 if ( oc != null )
580                 {
581                     hiddenOCs.add( oc );
582                 }
583             }
584             hiddenOCs.add( originalObjectClass );
585             dialog.setHiddenObjectClasses( hiddenOCs.toArray( new ObjectClass[0] ) );
586
587             if ( dialog.open() != Window.OK )
588             {
589                 return;
590             }
591
592             ObjectClass oc = dialog.getSelectedObjectClass();
593             if ( oc == null )
594             {
595                 return;
596             }
597
598             List JavaDoc<String JavaDoc> superiors = new ArrayList JavaDoc<String JavaDoc>();
599             String JavaDoc[] sups = modifiedObjectClass.getSuperiors();
600             for ( String JavaDoc sup : sups )
601             {
602                 superiors.add( sup );
603             }
604             superiors.add( oc.getNames()[0] );
605             modifiedObjectClass.setSuperiors( superiors.toArray( new String JavaDoc[0] ) );
606
607             fillInSuperiorsTable();
608             setEditorDirty();
609         }
610     };
611
612     /** The listener for Remove Button Widget of the Superiors Table */
613     private SelectionAdapter removeButtonSuperiorsTableListener = new SelectionAdapter()
614     {
615         public void widgetSelected( SelectionEvent e )
616         {
617             StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection();
618             if ( selection.isEmpty() )
619             {
620                 return;
621             }
622
623             Object JavaDoc selectedElement = selection.getFirstElement();
624             if ( selectedElement != null )
625             {
626                 List JavaDoc<String JavaDoc> superiors = new ArrayList JavaDoc<String JavaDoc>();
627                 String JavaDoc[] sups = modifiedObjectClass.getSuperiors();
628                 for ( String JavaDoc sup : sups )
629                 {
630                     superiors.add( sup );
631                 }
632
633                 if ( selectedElement instanceof ObjectClass )
634                 {
635                     for ( String JavaDoc name : ( ( ObjectClass ) selectedElement ).getNames() )
636                     {
637                         superiors.remove( name );
638                     }
639                 }
640                 else if ( selectedElement instanceof NonExistingObjectClass )
641                 {
642                     superiors.remove( ( ( NonExistingObjectClass ) selectedElement ).getName() );
643                 }
644
645                 modifiedObjectClass.setSuperiors( superiors.toArray( new String JavaDoc[0] ) );
646
647                 fillInSuperiorsTable();
648                 addButtonSuperiorsTable.setFocus();
649                 removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelection().length != 0 );
650                 setEditorDirty();
651             }
652         }
653     };
654
655
656     /**
657      * Default constructor
658      * @param editor
659      * the associated editor
660      */

661     public ObjectClassEditorOverviewPage( FormEditor editor )
662     {
663         super( editor, ID, TITLE );
664         schemaPool = SchemaPool.getInstance();
665         schemaPool.addListener( this );
666     }
667
668
669     /* (non-Javadoc)
670      * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
671      */

672     protected void createFormContent( IManagedForm managedForm )
673     {
674         // Getting the original and modified object classes
675
modifiedObjectClass = ( ( ObjectClassEditor ) getEditor() ).getModifiedObjectClass();
676         originalObjectClass = ( ( ObjectClassEditor ) getEditor() ).getOriginalObjectClass();
677
678         // Creating the base UI
679
ScrolledForm form = managedForm.getForm();
680         FormToolkit toolkit = managedForm.getToolkit();
681         form.getBody().setLayout( new GridLayout() );
682
683         // General Information Section
684
createGeneralInformationSection( form.getBody(), toolkit );
685
686         Composite bottomComposite = toolkit.createComposite( form.getBody() );
687         bottomComposite.setLayout( new GridLayout( 2, true ) );
688         bottomComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
689
690         // Mandatory Attributes Section
691
createMandatoryAttributesSection( bottomComposite, toolkit );
692
693         // Optionnal Attributes Section
694
createOptionalAttributesSection( bottomComposite, toolkit );
695
696         // Enabling or disabling the fields
697
setFieldsEditableState();
698
699         // Filling the UI with values from the object class
700
fillInUiFields();
701
702         // Listeners initialization
703
addListeners();
704     }
705
706
707     /**
708      * Creates the General Information Section.
709      *
710      * @param parent
711      * the parent composite
712      * @param toolkit
713      * the FormToolKit to use
714      */

715     private void createGeneralInformationSection( Composite parent, FormToolkit toolkit )
716     {
717         // General Information Section
718
Section section_general_information = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
719         section_general_information.setDescription( Messages
720             .getString( "ObjectClassEditorOverviewPage.General_Information_Section_Description" ) ); //$NON-NLS-1$
721
section_general_information.setText( Messages
722             .getString( "ObjectClassEditorOverviewPage.General_Information_Section_Text" ) ); //$NON-NLS-1$
723
section_general_information.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, true ) );
724
725         // Creating the layout of the section
726
Composite client_general_information = toolkit.createComposite( section_general_information );
727         client_general_information.setLayout( new GridLayout( 3, false ) );
728         toolkit.paintBordersFor( client_general_information );
729         section_general_information.setClient( client_general_information );
730
731         // ALIASES Button
732
toolkit.createLabel( client_general_information, Messages.getString( "ObjectClassEditorOverviewPage.Aliases" ) ); //$NON-NLS-1$
733
aliasesLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
734
aliasesLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
735         toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
736
aliasesButton = toolkit.createButton( client_general_information, Messages
737             .getString( "ObjectClassEditorOverviewPage.Edit_Aliases" ), SWT.PUSH ); //$NON-NLS-1$
738
aliasesButton.setLayoutData( new GridData( SWT.NONE, SWT.NONE, false, false, 2, 1 ) );
739
740         // OID Field
741
toolkit.createLabel( client_general_information, Messages.getString( "ObjectClassEditorOverviewPage.OID" ) ); //$NON-NLS-1$
742
oidText = toolkit.createText( client_general_information, "" ); //$NON-NLS-1$
743
oidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
744
745         // SCHEMA Field
746
schemaLink = toolkit.createHyperlink( client_general_information, Messages
747             .getString( "ObjectClassEditorOverviewPage.Schema" ), SWT.WRAP ); //$NON-NLS-1$
748
schemaLabel = toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
749
schemaLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
750
751         // DESCRIPTION Field
752
toolkit.createLabel( client_general_information, Messages
753             .getString( "ObjectClassEditorOverviewPage.Description" ) ); //$NON-NLS-1$
754
descriptionText = toolkit.createText( client_general_information, "", SWT.MULTI | SWT.V_SCROLL ); //$NON-NLS-1$
755
GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 );
756         descriptionGridData.heightHint = 42;
757         descriptionText.setLayoutData( descriptionGridData );
758
759         // SUPERIORS Table
760
toolkit.createLabel( client_general_information, Messages
761             .getString( "ObjectClassEditorOverviewPage.Superior_classes" ) ); //$NON-NLS-1$
762
superiorsTable = toolkit.createTable( client_general_information, SWT.SINGLE | SWT.V_SCROLL );
763         GridData gridData = new GridData( SWT.FILL, SWT.NONE, true, false );
764         gridData.heightHint = 45;
765         gridData.minimumHeight = 45;
766         superiorsTable.setLayoutData( gridData );
767         superiorsTableViewer = new TableViewer( superiorsTable );
768         superiorsTableViewer.setContentProvider( new ObjectClassEditorSuperiorsTableContentProvider() );
769         superiorsTableViewer.setLabelProvider( new ObjectClassEditorSuperiorsTableLabelProvider() );
770         Composite superiorsButtonComposite = toolkit.createComposite( client_general_information );
771         superiorsButtonComposite.setLayout( new GridLayout() );
772         addButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, Messages
773             .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); //$NON-NLS-1$
774
addButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
775         removeButtonSuperiorsTable = toolkit.createButton( superiorsButtonComposite, Messages
776             .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); //$NON-NLS-1$
777
removeButtonSuperiorsTable.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
778
779         // CLASS TYPE Combo
780
toolkit.createLabel( client_general_information, Messages
781             .getString( "ObjectClassEditorOverviewPage.Class_type" ) ); //$NON-NLS-1$
782
classTypeCombo = new Combo( client_general_information, SWT.READ_ONLY | SWT.SINGLE );
783         classTypeCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
784         initClassTypeCombo();
785
786         // OBSOLETE Checkbox
787
toolkit.createLabel( client_general_information, "" ); //$NON-NLS-1$
788
obsoleteCheckbox = toolkit.createButton( client_general_information, Messages
789             .getString( "ObjectClassEditorOverviewPage.Obsolete" ), SWT.CHECK ); //$NON-NLS-1$
790
obsoleteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
791     }
792
793
794     /**
795      * Creates the Mandatory Attributes Section.
796      *
797      * @param parent
798      * the parent composite
799      * @param toolkit
800      * the FormToolKit to use
801      */

802     private void createMandatoryAttributesSection( Composite parent, FormToolkit toolkit )
803     {
804         // MANDATORY ATTRIBUTES Section
805
Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
806         section.setText( Messages.getString( "ObjectClassEditorOverviewPage.Mandatory_Attribute_Section_Text" ) ); //$NON-NLS-1$
807
section.setDescription( Messages
808             .getString( "ObjectClassEditorOverviewPage.Mandatory_Attribute_Section_Description" ) ); //$NON-NLS-1$
809
section.setExpanded( true );
810         Composite client = toolkit.createComposite( section );
811         section.setClient( client );
812         GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false );
813         section.setLayoutData( gd );
814         toolkit.paintBordersFor( client );
815
816         GridLayout layout = new GridLayout();
817         layout.numColumns = 2;
818         client.setLayout( layout );
819
820         mandatoryAttributesTable = toolkit.createTable( client, SWT.NULL );
821         gd = new GridData( SWT.FILL, SWT.NONE, true, false );
822         gd.verticalSpan = 2;
823         gd.heightHint = 108;
824         mandatoryAttributesTable.setLayoutData( gd );
825         mandatoryAttributesTableViewer = new TableViewer( mandatoryAttributesTable );
826         mandatoryAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() );
827         mandatoryAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() );
828
829         addButtonMandatoryTable = toolkit.createButton( client, Messages
830             .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); //$NON-NLS-1$
831
removeButtonMandatoryTable = toolkit.createButton( client, Messages
832             .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); //$NON-NLS-1$
833
gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING );
834         addButtonMandatoryTable.setLayoutData( gd );
835         removeButtonMandatoryTable.setLayoutData( gd );
836
837         // By default, no element is selected
838
removeButtonMandatoryTable.setEnabled( false );
839     }
840
841
842     /**
843      * Creates the Optional Attributes Section.
844      *
845      * @param parent
846      * the parent composite
847      * @param toolkit
848      * the FormToolKit to use
849      */

850     private void createOptionalAttributesSection( Composite parent, FormToolkit toolkit )
851     {
852         // OPTIONAL ATTRIBUTES Section
853
Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
854         section.setText( Messages.getString( "ObjectClassEditorOverviewPage.Optionnal_Attributes_Section_Text" ) ); //$NON-NLS-1$
855
section.setDescription( Messages
856             .getString( "ObjectClassEditorOverviewPage.Optionnal_Attributes_Section_Description" ) ); //$NON-NLS-1$
857
section.setExpanded( true );
858         Composite client = toolkit.createComposite( section );
859         section.setClient( client );
860         GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false );
861         section.setLayoutData( gd );
862         toolkit.paintBordersFor( client );
863
864         GridLayout layout = new GridLayout();
865         layout.numColumns = 2;
866         client.setLayout( layout );
867
868         optionalAttributesTable = toolkit.createTable( client, SWT.SINGLE | SWT.V_SCROLL );
869         gd = new GridData( SWT.FILL, SWT.NONE, true, false );
870         gd.verticalSpan = 2;
871         gd.heightHint = 108;
872         optionalAttributesTable.setLayoutData( gd );
873         optionalAttributesTableViewer = new TableViewer( optionalAttributesTable );
874         optionalAttributesTableViewer.setContentProvider( new ObjectClassEditorAttributesTableContentProvider() );
875         optionalAttributesTableViewer.setLabelProvider( new ObjectClassEditorAttributesTableLabelProvider() );
876
877         addButtonOptionalTable = toolkit.createButton( client, Messages
878             .getString( "ObjectClassEditorOverviewPage.Add..." ), SWT.PUSH ); //$NON-NLS-1$
879
removeButtonOptionalTable = toolkit.createButton( client, Messages
880             .getString( "ObjectClassEditorOverviewPage.Remove" ), SWT.PUSH ); //$NON-NLS-1$
881
gd = new GridData( GridData.VERTICAL_ALIGN_BEGINNING );
882         addButtonOptionalTable.setLayoutData( gd );
883         removeButtonOptionalTable.setLayoutData( gd );
884
885         // By default, no element is selected
886
removeButtonOptionalTable.setEnabled( false );
887     }
888
889
890     /**
891      * Initializes the UI fields from the input.
892      */

893     private void fillInUiFields()
894     {
895         // ALIASES Label
896
if ( ( modifiedObjectClass.getNames() != null ) && ( modifiedObjectClass.getNames().length != 0 ) )
897         {
898             aliasesLabel.setText( ViewUtils.concateAliases( modifiedObjectClass.getNames() ) );
899         }
900         else
901         {
902             aliasesLabel.setText( Messages.getString( "ObjectClassEditorOverviewPage.(None)" ) ); //$NON-NLS-1$
903
}
904
905         // OID Field
906
if ( modifiedObjectClass.getOid() != null )
907         {
908             oidText.setText( modifiedObjectClass.getOid() );
909         }
910
911         // SCHEMAS Field
912
if ( modifiedObjectClass.getOriginatingSchema() != null )
913         {
914             this.schemaLabel.setText( modifiedObjectClass.getOriginatingSchema().getName() );
915         }
916
917         // DESCRIPTION Field
918
if ( modifiedObjectClass.getDescription() != null )
919         {
920             descriptionText.setText( modifiedObjectClass.getDescription() );
921         }
922
923         // SUPERIORS Table
924
fillInSuperiorsTable();
925
926         // CLASS TYPE Combo
927
fillInClassType();
928
929         // OBSOLETE Checkbox
930
obsoleteCheckbox.setSelection( modifiedObjectClass.isObsolete() );
931
932         // MANDATORY ATTRIBUTES Table
933
fillInMandatoryAttributesTable();
934
935         // OPTIONNAL ATTRIBUTES Table
936
fillInOptionalAttributesTable();
937     }
938
939
940     /**
941      * Fills in the Superiors Table.
942      */

943     private void fillInSuperiorsTable()
944     {
945         superiorsTableViewer.setInput( modifiedObjectClass.getSuperiors() );
946     }
947
948
949     /**
950      * Initializes the Class Type Combo
951      */

952     private void initClassTypeCombo()
953     {
954         classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Abstract" ), 0 ); //$NON-NLS-1$
955
classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Auxiliary" ), 1 ); //$NON-NLS-1$
956
classTypeCombo.add( Messages.getString( "ObjectClassEditorOverviewPage.Structural" ), 2 ); //$NON-NLS-1$
957
}
958
959
960     /**
961      * Fills in the Class Type Combo
962      */

963     private void fillInClassType()
964     {
965         if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.ABSTRACT )
966         {
967             classTypeCombo.select( 0 );
968         }
969         else if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.AUXILIARY )
970         {
971             classTypeCombo.select( 1 );
972         }
973         else if ( modifiedObjectClass.getClassType() == ObjectClassTypeEnum.STRUCTURAL )
974         {
975             classTypeCombo.select( 2 );
976         }
977     }
978
979
980     /**
981      * Initializes the Mandatory Attributes Table
982      */

983     private void fillInMandatoryAttributesTable()
984     {
985         mandatoryAttributesTableViewer.setInput( modifiedObjectClass.getMust() );
986     }
987
988
989     /**
990      * Initializes the Optional Attributes Table
991      */

992     private void fillInOptionalAttributesTable()
993     {
994         optionalAttributesTableViewer.setInput( modifiedObjectClass.getMay() );
995     }
996
997
998     /**
999      * Enalbes/Disables the UI fields
1000     */

1001    private void setFieldsEditableState()
1002    {
1003        if ( modifiedObjectClass.getOriginatingSchema().type == Schema.SchemaType.coreSchema )
1004        {
1005            // If the object class is in a core-schema file, we disable editing
1006
aliasesButton.setEnabled( false );
1007            oidText.setEditable( false );
1008            descriptionText.setEditable( false );
1009            addButtonSuperiorsTable.setEnabled( false );
1010            removeButtonSuperiorsTable.setEnabled( false );
1011            classTypeCombo.setEnabled( false );
1012            obsoleteCheckbox.setEnabled( false );
1013            addButtonMandatoryTable.setEnabled( false );
1014            removeButtonMandatoryTable.setEnabled( false );
1015            addButtonOptionalTable.setEnabled( false );
1016            removeButtonOptionalTable.setEnabled( false );
1017        }
1018        else
1019        {
1020            removeButtonSuperiorsTable.setEnabled( superiorsTable.getSelectionIndex() != -1 );
1021            removeButtonMandatoryTable.setEnabled( mandatoryAttributesTable.getSelectionIndex() != -1 );
1022            removeButtonOptionalTable.setEnabled( optionalAttributesTable.getSelectionIndex() != -1 );
1023        }
1024    }
1025
1026
1027    /**
1028     * Adds listeners to UI fields
1029     */

1030    private void addListeners()
1031    {
1032        if ( modifiedObjectClass.getOriginatingSchema().type == Schema.SchemaType.userSchema )
1033        {
1034            aliasesButton.addSelectionListener( aliasesButtonListener );
1035            oidText.addModifyListener( oidTextModifyListener );
1036            oidText.addVerifyListener( oidTextVerifyListener );
1037            descriptionText.addModifyListener( descriptionTextListener );
1038            addButtonSuperiorsTable.addSelectionListener( addButtonSuperiorsTableListener );
1039            removeButtonSuperiorsTable.addSelectionListener( removeButtonSuperiorsTableListener );
1040            classTypeCombo.addModifyListener( classTypeListener );
1041            obsoleteCheckbox.addSelectionListener( obsoleteListener );
1042            addButtonMandatoryTable.addSelectionListener( addButtonMandatoryTableListener );
1043            removeButtonMandatoryTable.addSelectionListener( removeButtonMandatoryTableListener );
1044            addButtonOptionalTable.addSelectionListener( addButtonOptionalTableListener );
1045            removeButtonOptionalTable.addSelectionListener( removeButtonOptionalTableListener );
1046        }
1047
1048        schemaLink.addHyperlinkListener( schemaLinkListener );
1049
1050        // This listener needs to be outside of the 'if' so that attribute type editor can be opened from any object class (in a core or a user schema)
1051
superiorsTable.addMouseListener( superiorsTableListener );
1052
1053        // This listener needs to be outside of the 'if' so that attribute type editor can be opened from any object class (in a core or a user schema)
1054
mandatoryAttributesTable.addMouseListener( mandatoryAttributesTableListener );
1055
1056        // This listener needs to be outside of the 'if' so that attribute type editor can be opened from any object class (in a core or a user schema)
1057
optionalAttributesTable.addMouseListener( optionalAttributesTableListener );
1058    }
1059
1060
1061    /**
1062     * Removes listeners from UI fields
1063     */

1064    private void removeListeners()
1065    {
1066        aliasesButton.removeSelectionListener( aliasesButtonListener );
1067        oidText.removeModifyListener( oidTextModifyListener );
1068        oidText.removeVerifyListener( oidTextVerifyListener );
1069        schemaLink.removeHyperlinkListener( schemaLinkListener );
1070        descriptionText.removeModifyListener( descriptionTextListener );
1071        superiorsTable.removeMouseListener( superiorsTableListener );
1072        addButtonSuperiorsTable.removeSelectionListener( addButtonSuperiorsTableListener );
1073        removeButtonSuperiorsTable.removeSelectionListener( removeButtonSuperiorsTableListener );
1074        classTypeCombo.removeModifyListener( classTypeListener );
1075        obsoleteCheckbox.removeSelectionListener( obsoleteListener );
1076        mandatoryAttributesTable.removeMouseListener( mandatoryAttributesTableListener );
1077        addButtonMandatoryTable.removeSelectionListener( addButtonMandatoryTableListener );
1078        removeButtonMandatoryTable.removeSelectionListener( removeButtonMandatoryTableListener );
1079        optionalAttributesTable.removeMouseListener( optionalAttributesTableListener );
1080        addButtonOptionalTable.removeSelectionListener( addButtonOptionalTableListener );
1081        removeButtonOptionalTable.removeSelectionListener( removeButtonOptionalTableListener );
1082    }
1083
1084
1085    /**
1086     * Sets the editor as dirty
1087     */

1088    private void setEditorDirty()
1089    {
1090        ( ( ObjectClassEditor ) getEditor() ).setDirty( true );
1091    }
1092
1093
1094    /**
1095     * Refreshes the UI.
1096     */

1097    public void refreshUI()
1098    {
1099        removeListeners();
1100        fillInUiFields();
1101        addListeners();
1102        setFieldsEditableState();
1103    }
1104
1105
1106    /* (non-Javadoc)
1107     * @see org.apache.directory.ldapstudio.schemas.model.PoolListener#poolChanged(org.apache.directory.ldapstudio.schemas.model.SchemaPool, org.apache.directory.ldapstudio.schemas.model.LDAPModelEvent)
1108     */

1109    public void poolChanged( SchemaPool p, LDAPModelEvent e )
1110    {
1111        removeListeners();
1112        fillInSuperiorsTable();
1113        fillInMandatoryAttributesTable();
1114        fillInOptionalAttributesTable();
1115        addListeners();
1116        setFieldsEditableState();
1117    }
1118
1119
1120    /* (non-Javadoc)
1121     * @see org.eclipse.ui.forms.editor.FormPage#dispose()
1122     */

1123    public void dispose()
1124    {
1125        schemaPool.removeListener( this );
1126        removeListeners();
1127
1128        super.dispose();
1129    }
1130}
1131
Popular Tags