KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > schemabrowser > ObjectClassDescriptionDetailsPage


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.browser.ui.editors.schemabrowser;
22
23
24 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Text;
31 import org.eclipse.ui.forms.events.ExpansionAdapter;
32 import org.eclipse.ui.forms.events.ExpansionEvent;
33 import org.eclipse.ui.forms.widgets.FormToolkit;
34 import org.eclipse.ui.forms.widgets.Hyperlink;
35 import org.eclipse.ui.forms.widgets.ScrolledForm;
36 import org.eclipse.ui.forms.widgets.Section;
37
38
39 /**
40  * The ObjectClassDescriptionDetailsPage displays the details of an
41  * object class description.
42  *
43  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
44  * @version $Rev$, $Date$
45  */

46 public class ObjectClassDescriptionDetailsPage extends SchemaDetailsPage
47 {
48
49     /** The main section, contains oid, names, desc and kind */
50     private Section mainSection;
51
52     /** The numeric oid field */
53     private Text numericOidText;
54
55     /** The names field */
56     private Text namesText;
57
58     /** The description field */
59     private Text descText;
60
61     /** The kind field */
62     private Text kindText;
63
64     /** The section with links to superior object classes */
65     private Section superclassesSection;
66
67     /** The links to superior object classes */
68     private Hyperlink[] superLinks;
69
70     /** The section with links to derived object classes */
71     private Section subclassesSection;
72
73     /** The links to derived object classes */
74     private Hyperlink[] subLinks;
75
76     /** The section with links to must attribute types */
77     private Section mustSection;
78
79     /** The links to must attribute types */
80     private Hyperlink[] mustLinks;
81
82     /** The section with links to may attribute types */
83     private Section maySection;
84
85     /** The links to may attribute types */
86     private Hyperlink[] mayLinks;
87
88
89     /**
90      * Creates a new instance of ObjectClassDescriptionDetailsPage.
91      *
92      * @param schemaPage the master schema page
93      * @param toolkit the toolkit used to create controls
94      */

95     public ObjectClassDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit )
96     {
97         super( schemaPage, toolkit );
98     }
99
100
101     /**
102      * {@inheritDoc}
103      */

104     public void createContents( final ScrolledForm detailForm )
105     {
106         this.detailForm = detailForm;
107         detailForm.getBody().setLayout( new GridLayout() );
108
109         // create main section
110
mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
111         mainSection.setText( "Details" );
112         mainSection.marginWidth = 0;
113         mainSection.marginHeight = 0;
114         mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
115         toolkit.createCompositeSeparator( mainSection );
116
117         // create must section
118
mustSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
119         mustSection.setText( "MUST Attributes" );
120         mustSection.marginWidth = 0;
121         mustSection.marginHeight = 0;
122         mustSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
123         toolkit.createCompositeSeparator( mustSection );
124         mustSection.addExpansionListener( new ExpansionAdapter()
125         {
126             public void expansionStateChanged( ExpansionEvent e )
127             {
128                 detailForm.reflow( true );
129             }
130         } );
131
132         // create may section
133
maySection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
134         maySection.setText( "MAY Attributes" );
135         maySection.marginWidth = 0;
136         maySection.marginHeight = 0;
137         maySection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
138         toolkit.createCompositeSeparator( maySection );
139         maySection.addExpansionListener( new ExpansionAdapter()
140         {
141             public void expansionStateChanged( ExpansionEvent e )
142             {
143                 detailForm.reflow( true );
144             }
145         } );
146
147         // create superior section
148
superclassesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
149         superclassesSection.setText( "Superclasses" );
150         superclassesSection.marginWidth = 0;
151         superclassesSection.marginHeight = 0;
152         superclassesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
153         toolkit.createCompositeSeparator( superclassesSection );
154         superclassesSection.addExpansionListener( new ExpansionAdapter()
155         {
156             public void expansionStateChanged( ExpansionEvent e )
157             {
158                 detailForm.reflow( true );
159             }
160         } );
161
162         // create subclasses section
163
subclassesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
164         subclassesSection.setText( "Subclasses" );
165         subclassesSection.marginWidth = 0;
166         subclassesSection.marginHeight = 0;
167         subclassesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
168         toolkit.createCompositeSeparator( subclassesSection );
169         subclassesSection.addExpansionListener( new ExpansionAdapter()
170         {
171             public void expansionStateChanged( ExpansionEvent e )
172             {
173                 detailForm.reflow( true );
174             }
175         } );
176
177         // create raw section
178
createRawSection();
179     }
180
181
182     /**
183      * {@inheritDoc}
184      */

185     public void setInput( Object JavaDoc input )
186     {
187         ObjectClassDescription ocd = null;
188         if ( input instanceof ObjectClassDescription )
189         {
190             ocd = ( ObjectClassDescription ) input;
191         }
192
193         // create main content
194
this.createMainContent( ocd );
195
196         // create contents of dynamic sections
197
this.createSuperclassContents( ocd );
198         this.createSubclassContents( ocd );
199         this.createMustContents( ocd );
200         this.createMayContents( ocd );
201         super.createRawContents( ocd );
202
203         this.detailForm.reflow( true );
204     }
205
206
207     /**
208      * Creates the content of the main section. It is newly created
209      * on every input change to ensure a proper layout of
210      * multilined descriptions.
211      *
212      * @param ocd the object class description
213      */

214     private void createMainContent( ObjectClassDescription ocd )
215     {
216         // dispose old content
217
if ( mainSection.getClient() != null )
218         {
219             mainSection.getClient().dispose();
220         }
221
222         // create new client
223
Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP );
224         GridLayout mainLayout = new GridLayout( 2, false );
225         mainClient.setLayout( mainLayout );
226         mainSection.setClient( mainClient );
227
228         // create new content
229
if ( ocd != null )
230         {
231             toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE );
232             numericOidText = toolkit.createText( mainClient, getNonNullString( ocd.getNumericOID() ), SWT.NONE );
233             numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
234             numericOidText.setEditable( false );
235
236             toolkit.createLabel( mainClient, "Objectclass names:", SWT.NONE );
237             namesText = toolkit.createText( mainClient, getNonNullString( ocd.toString() ), SWT.NONE );
238             namesText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
239             namesText.setEditable( false );
240
241             toolkit.createLabel( mainClient, "Descripton:", SWT.NONE );
242             descText = toolkit.createText( mainClient, getNonNullString( ocd.getDesc() ), SWT.WRAP | SWT.MULTI );
243             GridData gd = new GridData( GridData.FILL_HORIZONTAL );
244             gd.widthHint = detailForm.getForm().getSize().x - 100 - 60;
245             descText.setLayoutData( gd );
246             descText.setEditable( false );
247
248             String JavaDoc kind = "";
249             if ( ocd.isStructural() )
250             {
251                 kind = "structural";
252             }
253             else if ( ocd.isAbstract() )
254             {
255                 kind = "abstract";
256             }
257             else if ( ocd.isAuxiliary() )
258             {
259                 kind = "auxiliary";
260             }
261             if ( ocd.isObsolete() )
262             {
263                 kind += " (obsolete)";
264             }
265             toolkit.createLabel( mainClient, "Objectclass kind:", SWT.NONE );
266             kindText = toolkit.createText( mainClient, getNonNullString( kind ), SWT.NONE );
267             kindText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
268             kindText.setEditable( false );
269         }
270
271         mainSection.layout();
272     }
273
274
275     /**
276      * Creates the content of the must section.
277      * It is newly created on every input change because the content
278      * of this section is dynamic.
279      *
280      * @param ocd the object class description
281      */

282     private void createMustContents( ObjectClassDescription ocd )
283     {
284         // dispose old content
285
if ( mustSection.getClient() != null )
286         {
287             mustSection.getClient().dispose();
288         }
289
290         // create new client
291
Composite mustClient = toolkit.createComposite( mustSection, SWT.WRAP );
292         mustClient.setLayout( new GridLayout() );
293         mustSection.setClient( mustClient );
294
295         // create new content
296
if ( ocd != null )
297         {
298             String JavaDoc[] names = ocd.getMustAttributeTypeDescriptionNamesTransitive();
299             if ( names != null && names.length > 0 )
300             {
301                 mustSection.setText( "MUST Attributes (" + names.length + ")" );
302                 mustLinks = new Hyperlink[names.length];
303                 for ( int i = 0; i < names.length; i++ )
304                 {
305                     if ( ocd.getSchema().hasAttributeTypeDescription( names[i] ) )
306                     {
307                         AttributeTypeDescription mustAtd = ocd.getSchema().getAttributeTypeDescription( names[i] );
308                         mustLinks[i] = toolkit.createHyperlink( mustClient, mustAtd.toString(), SWT.WRAP );
309                         mustLinks[i].setHref( mustAtd );
310                         mustLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
311                         mustLinks[i].setUnderlined( true );
312                         mustLinks[i].setEnabled( true );
313                         mustLinks[i].addHyperlinkListener( this );
314                     }
315                     else
316                     {
317                         mustLinks[i] = toolkit.createHyperlink( mustClient, names[i], SWT.WRAP );
318                         mustLinks[i].setHref( null );
319                         mustLinks[i].setUnderlined( false );
320                         mustLinks[i].setEnabled( false );
321                     }
322                 }
323             }
324             else
325             {
326                 mustSection.setText( "MUST Attributes (0)" );
327                 mustLinks = new Hyperlink[0];
328                 Text mustText = toolkit.createText( mustClient, getNonNullString( null ), SWT.NONE );
329                 mustText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
330                 mustText.setEditable( false );
331             }
332         }
333         else
334         {
335             mustSection.setText( "MUST Attributes" );
336         }
337
338         mustSection.layout();
339     }
340
341
342     /**
343      * Creates the content of the may section.
344      * It is newly created on every input change because the content
345      * of this section is dynamic.
346      *
347      * @param ocd the object class description
348      */

349     private void createMayContents( ObjectClassDescription ocd )
350     {
351         // dispose old content
352
if ( maySection.getClient() != null )
353         {
354             maySection.getClient().dispose();
355         }
356
357         // create new client
358
Composite mayClient = toolkit.createComposite( maySection, SWT.WRAP );
359         mayClient.setLayout( new GridLayout() );
360         maySection.setClient( mayClient );
361
362         // create new content
363
if ( ocd != null )
364         {
365             String JavaDoc[] names = ocd.getMayAttributeTypeDescriptionNamesTransitive();
366             if ( names != null && names.length > 0 )
367             {
368                 maySection.setText( "MAY Attributes (" + names.length + ")" );
369                 mayLinks = new Hyperlink[names.length];
370                 for ( int i = 0; i < names.length; i++ )
371                 {
372                     if ( ocd.getSchema().hasAttributeTypeDescription( names[i] ) )
373                     {
374                         AttributeTypeDescription mayAtd = ocd.getSchema().getAttributeTypeDescription( names[i] );
375                         mayLinks[i] = toolkit.createHyperlink( mayClient, mayAtd.toString(), SWT.WRAP );
376                         mayLinks[i].setHref( mayAtd );
377                         mayLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
378                         mayLinks[i].setUnderlined( true );
379                         mayLinks[i].setEnabled( true );
380                         mayLinks[i].addHyperlinkListener( this );
381                     }
382                     else
383                     {
384                         mayLinks[i] = toolkit.createHyperlink( mayClient, names[i], SWT.WRAP );
385                         mayLinks[i].setHref( null );
386                         mayLinks[i].setUnderlined( false );
387                         mayLinks[i].setEnabled( false );
388                     }
389                 }
390             }
391             else
392             {
393                 maySection.setText( "MAY Attributes (0)" );
394                 mayLinks = new Hyperlink[0];
395                 Text mayText = toolkit.createText( mayClient, getNonNullString( null ), SWT.NONE );
396                 mayText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
397                 mayText.setEditable( false );
398             }
399         }
400         else
401         {
402             maySection.setText( "MAY Attributes" );
403         }
404         maySection.layout();
405     }
406
407
408     /**
409      * Creates the content of the must section.
410      * It is newly created on every input change because the content
411      * of this section is dynamic.
412      *
413      * @param ocd the object class description
414      */

415     private void createSubclassContents( ObjectClassDescription ocd )
416     {
417         // dispose old content
418
if ( subclassesSection.getClient() != null )
419         {
420             subclassesSection.getClient().dispose();
421         }
422
423         // create new client
424
Composite subClient = toolkit.createComposite( subclassesSection, SWT.WRAP );
425         subClient.setLayout( new GridLayout() );
426         subclassesSection.setClient( subClient );
427
428         // create new content
429
if ( ocd != null )
430         {
431             ObjectClassDescription[] subOCDs = ocd.getSubObjectClassDescriptions();
432             if ( subOCDs != null && subOCDs.length > 0 )
433             {
434                 subclassesSection.setText( "Subclasses (" + subOCDs.length + ")" );
435                 subLinks = new Hyperlink[subOCDs.length];
436                 for ( int i = 0; i < subOCDs.length; i++ )
437                 {
438                     subLinks[i] = toolkit.createHyperlink( subClient, subOCDs[i].toString(), SWT.WRAP );
439                     subLinks[i].setHref( subOCDs[i] );
440                     subLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
441                     subLinks[i].setUnderlined( true );
442                     subLinks[i].setEnabled( true );
443                     subLinks[i].addHyperlinkListener( this );
444                 }
445             }
446             else
447             {
448                 subclassesSection.setText( "Subclasses (0)" );
449                 subLinks = new Hyperlink[0];
450                 Text derivedText = toolkit.createText( subClient, getNonNullString( null ), SWT.NONE );
451                 derivedText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
452                 derivedText.setEditable( false );
453             }
454         }
455         else
456         {
457             subclassesSection.setText( "Subclasses" );
458         }
459
460         subclassesSection.layout();
461     }
462
463
464     /**
465      * Creates the content of the must section.
466      * It is newly created on every input change because the content
467      * of this section is dynamic.
468      *
469      * @param ocd the object class description
470      */

471     private void createSuperclassContents( ObjectClassDescription ocd )
472     {
473         // dispose old content
474
if ( superclassesSection.getClient() != null )
475         {
476             superclassesSection.getClient().dispose();
477         }
478
479         // create new client
480
Composite superClient = toolkit.createComposite( superclassesSection, SWT.WRAP );
481         superClient.setLayout( new GridLayout() );
482         superclassesSection.setClient( superClient );
483
484         // craete new content
485
if ( ocd != null )
486         {
487             String JavaDoc[] names = ocd.getSuperiorObjectClassDescriptionNames();
488             if ( names != null && names.length > 0 )
489             {
490                 superclassesSection.setText( "Superclasses (" + names.length + ")" );
491                 Composite supClient = toolkit.createComposite( superClient, SWT.WRAP );
492                 GridLayout gl = new GridLayout();
493                 gl.marginWidth = 0;
494                 gl.marginHeight = 0;
495                 supClient.setLayout( gl );
496                 superLinks = new Hyperlink[names.length];
497                 for ( int i = 0; i < names.length; i++ )
498                 {
499                     if ( ocd.getSchema().hasObjectClassDescription( names[i] ) )
500                     {
501                         ObjectClassDescription supOcd = ocd.getSchema().getObjectClassDescription( names[i] );
502                         superLinks[i] = toolkit.createHyperlink( supClient, supOcd.toString(), SWT.WRAP );
503                         superLinks[i].setHref( supOcd );
504                         superLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
505                         superLinks[i].setUnderlined( true );
506                         superLinks[i].setEnabled( true );
507                         superLinks[i].addHyperlinkListener( this );
508                     }
509                     else
510                     {
511                         superLinks[i] = toolkit.createHyperlink( supClient, names[i], SWT.WRAP );
512                         superLinks[i].setHref( null );
513                         superLinks[i].setUnderlined( false );
514                         superLinks[i].setEnabled( false );
515                     }
516                 }
517             }
518             else
519             {
520                 superclassesSection.setText( "Superlasses (0)" );
521                 superLinks = new Hyperlink[0];
522                 Text superText = toolkit.createText( superClient, getNonNullString( null ), SWT.NONE );
523                 superText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
524                 superText.setEditable( false );
525             }
526         }
527         else
528         {
529             superclassesSection.setText( "Superclasses" );
530         }
531
532         superclassesSection.layout();
533     }
534
535 }
536
Popular Tags