KickJava   Java API By Example, From Geeks To Geeks.

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


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.LdapSyntaxDescription;
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 LdapSyntaxDescriptionDetailsPage displays the details of an
41  * syntax description.
42  *
43  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
44  * @version $Rev$, $Date$
45  */

46 public class LdapSyntaxDescriptionDetailsPage extends SchemaDetailsPage
47 {
48
49     /** The main section, contains oid and desc */
50     private Section mainSection;
51
52     /** The numeric oid field */
53     private Text numericOidText;
54
55     /** The description field */
56     private Text descText;
57
58     /** The used from section, contains links to attribute types */
59     private Section usedFromSection;
60
61     /** The links to attributes using the syntax */
62     private Hyperlink[] usedFromLinks;
63
64
65     /**
66      * Creates a new instance of LdapSyntaxDescriptionDetailsPage.
67      *
68      * @param schemaPage the master schema page
69      * @param toolkit the toolkit used to create controls
70      */

71     public LdapSyntaxDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit )
72     {
73         super( schemaPage, toolkit );
74     }
75
76
77     /**
78      * {@inheritDoc}
79      */

80     public void createContents( final ScrolledForm detailForm )
81     {
82
83         this.detailForm = detailForm;
84         detailForm.getBody().setLayout( new GridLayout() );
85
86         // create main section
87
mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
88         mainSection.setText( "Details" );
89         mainSection.marginWidth = 0;
90         mainSection.marginHeight = 0;
91         mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
92         toolkit.createCompositeSeparator( mainSection );
93
94         // create used from section
95
usedFromSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
96         usedFromSection.setText( "Used from" );
97         usedFromSection.marginWidth = 0;
98         usedFromSection.marginHeight = 0;
99         usedFromSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
100         toolkit.createCompositeSeparator( usedFromSection );
101         usedFromSection.addExpansionListener( new ExpansionAdapter()
102         {
103             public void expansionStateChanged( ExpansionEvent e )
104             {
105                 detailForm.reflow( true );
106             }
107         } );
108
109         // create raw aection
110
createRawSection();
111     }
112
113
114     /**
115      * {@inheritDoc}
116      */

117     public void setInput( Object JavaDoc input )
118     {
119         LdapSyntaxDescription lsd = null;
120         if ( input instanceof LdapSyntaxDescription )
121         {
122             lsd = ( LdapSyntaxDescription ) input;
123         }
124
125         createMainContent( lsd );
126         createUsedFromContents( lsd );
127         createRawContents( lsd );
128
129         detailForm.reflow( true );
130     }
131
132
133     /**
134      * Creates the content of the main section. It is newly created
135      * on every input change to ensure a proper layout of
136      * multilined descriptions.
137      *
138      * @param lsd the syntax description
139      */

140     private void createMainContent( LdapSyntaxDescription lsd )
141     {
142         // dispose old content
143
if ( mainSection.getClient() != null )
144         {
145             mainSection.getClient().dispose();
146         }
147
148         // create new client
149
Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP );
150         GridLayout mainLayout = new GridLayout( 2, false );
151         mainClient.setLayout( mainLayout );
152         mainSection.setClient( mainClient );
153
154         // create new content
155
if ( lsd != null )
156         {
157             toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE );
158             numericOidText = toolkit.createText( mainClient, getNonNullString( lsd.getNumericOID() ), SWT.NONE );
159             numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
160             numericOidText.setEditable( false );
161
162             toolkit.createLabel( mainClient, "Descripton:", SWT.NONE );
163             descText = toolkit.createText( mainClient, getNonNullString( lsd.getDesc() ), SWT.WRAP | SWT.MULTI );
164             GridData gd = new GridData( GridData.FILL_HORIZONTAL );
165             gd.widthHint = detailForm.getForm().getSize().x - 100 - 60;
166             descText.setLayoutData( gd );
167             descText.setEditable( false );
168         }
169
170         mainSection.layout();
171     }
172
173
174     /**
175      * Creates the content of the used from section.
176      * It is newly created on every input change because the content
177      * of this section is dynamic.
178      *
179      * @param lsd the syntax description
180      */

181     private void createUsedFromContents( LdapSyntaxDescription lsd )
182     {
183         // dispose old content
184
if ( usedFromSection.getClient() != null && !usedFromSection.getClient().isDisposed() )
185         {
186             usedFromSection.getClient().dispose();
187         }
188
189         // create new client
190
Composite usedFromClient = toolkit.createComposite( usedFromSection, SWT.WRAP );
191         usedFromClient.setLayout( new GridLayout() );
192         usedFromSection.setClient( usedFromClient );
193
194         // create content
195
if ( lsd != null )
196         {
197             AttributeTypeDescription[] usedFromATDs = lsd.getUsedFromAttributeTypeDescription();
198             if ( usedFromATDs != null && usedFromATDs.length > 0 )
199             {
200                 usedFromSection.setText( "Used from (" + usedFromATDs.length + ")" );
201                 usedFromLinks = new Hyperlink[usedFromATDs.length];
202                 for ( int i = 0; i < usedFromATDs.length; i++ )
203                 {
204                     usedFromLinks[i] = toolkit.createHyperlink( usedFromClient, usedFromATDs[i].toString(), SWT.WRAP );
205                     usedFromLinks[i].setHref( usedFromATDs[i] );
206                     usedFromLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
207                     usedFromLinks[i].setUnderlined( true );
208                     usedFromLinks[i].setEnabled( true );
209                     usedFromLinks[i].addHyperlinkListener( this );
210                 }
211             }
212             else
213             {
214                 usedFromSection.setText( "Used from (0)" );
215                 usedFromLinks = new Hyperlink[0];
216                 Text usedFromText = toolkit.createText( usedFromClient, getNonNullString( null ), SWT.NONE );
217                 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
218                 usedFromText.setEditable( false );
219             }
220         }
221         else
222         {
223             usedFromSection.setText( "Used from" );
224         }
225
226         usedFromSection.layout();
227     }
228
229 }
230
Popular Tags