KickJava   Java API By Example, From Geeks To Geeks.

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


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

48 public class MatchingRuleDescriptionDetailsPage extends SchemaDetailsPage
49 {
50
51     /** The main section, contains oid, names and desc */
52     private Section mainSection;
53
54     /** The numeric oid field */
55     private Text numericOidText;
56
57     /** The names field */
58     private Text namesText;
59
60     /** The description field */
61     private Text descText;
62
63     /** The flag section, contains obsolete */
64     private Section flagSection;
65
66     /** The obsolete field */
67     private Label isObsoleteText;
68
69     /** The syntax section, contains syntax description and a link to the syntax */
70     private Section syntaxSection;
71
72     /** The syntax description field */
73     private Text syntaxDescText;
74
75     /** The link to the syntax */
76     private Hyperlink syntaxLink;
77
78     /** The used from section, contains links to attribute types */
79     private Section usedFromSection;
80
81     /** The links to attribute types using the matching rule */
82     private Hyperlink[] usedFromLinks;
83
84
85     /**
86      * Creates a new instance of MatchingRuleDescriptionDetailsPage.
87      *
88      * @param schemaPage the master schema page
89      * @param toolkit the toolkit used to create controls
90      */

91     public MatchingRuleDescriptionDetailsPage( SchemaPage scheamPage, FormToolkit toolkit )
92     {
93         super( scheamPage, toolkit );
94     }
95
96
97     /**
98      * {@inheritDoc}
99      */

100     public void createContents( final ScrolledForm detailForm )
101     {
102         this.detailForm = detailForm;
103         detailForm.getBody().setLayout( new GridLayout() );
104
105         // create main section
106
mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
107         mainSection.setText( "Details" );
108         mainSection.marginWidth = 0;
109         mainSection.marginHeight = 0;
110         mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
111         toolkit.createCompositeSeparator( mainSection );
112
113         // create flag section
114
flagSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
115         flagSection.setText( "Flags" );
116         flagSection.marginWidth = 0;
117         flagSection.marginHeight = 0;
118         flagSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
119         toolkit.createCompositeSeparator( flagSection );
120
121         // create flag content
122
Composite flagClient = toolkit.createComposite( flagSection, SWT.WRAP );
123         GridLayout flagLayout = new GridLayout();
124         flagLayout.numColumns = 1;
125         flagLayout.marginWidth = 0;
126         flagLayout.marginHeight = 0;
127         flagClient.setLayout( flagLayout );
128         flagSection.setClient( flagClient );
129
130         isObsoleteText = toolkit.createLabel( flagClient, "Obsolete", SWT.CHECK );
131         isObsoleteText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
132         isObsoleteText.setEnabled( false );
133
134         // create syntax section
135
syntaxSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
136         syntaxSection.setText( "Syntax" );
137         syntaxSection.marginWidth = 0;
138         syntaxSection.marginHeight = 0;
139         syntaxSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
140         toolkit.createCompositeSeparator( syntaxSection );
141
142         // create syntax content
143
Composite syntaxClient = toolkit.createComposite( syntaxSection, SWT.WRAP );
144         GridLayout syntaxLayout = new GridLayout();
145         syntaxLayout.numColumns = 2;
146         syntaxLayout.marginWidth = 0;
147         syntaxLayout.marginHeight = 0;
148         syntaxClient.setLayout( syntaxLayout );
149         syntaxSection.setClient( syntaxClient );
150
151         toolkit.createLabel( syntaxClient, "Syntax OID:", SWT.NONE );
152         syntaxLink = toolkit.createHyperlink( syntaxClient, "", SWT.WRAP );
153         syntaxLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
154         syntaxLink.addHyperlinkListener( this );
155
156         toolkit.createLabel( syntaxClient, "Syntax Description:", SWT.NONE );
157         syntaxDescText = toolkit.createText( syntaxClient, "", SWT.NONE );
158         syntaxDescText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
159         syntaxDescText.setEditable( false );
160
161         // create used from section
162
usedFromSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
163         usedFromSection.setText( "Used from" );
164         usedFromSection.marginWidth = 0;
165         usedFromSection.marginHeight = 0;
166         usedFromSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
167         toolkit.createCompositeSeparator( usedFromSection );
168         usedFromSection.addExpansionListener( new ExpansionAdapter()
169         {
170             public void expansionStateChanged( ExpansionEvent e )
171             {
172                 detailForm.reflow( true );
173             }
174         } );
175
176         // create raw section
177
createRawSection();
178     }
179
180
181     /**
182      * {@inheritDoc}
183      */

184     public void setInput( Object JavaDoc input )
185     {
186         MatchingRuleDescription mrd = null;
187         if ( input instanceof MatchingRuleDescription )
188         {
189             mrd = ( MatchingRuleDescription ) input;
190         }
191
192         // create main content
193
createMainContent( mrd );
194
195         // set flag
196
isObsoleteText.setEnabled( mrd != null && mrd.isObsolete() );
197
198         // set syntax content
199
String JavaDoc lsdOid = null;
200         LdapSyntaxDescription lsd = null;
201         if ( mrd != null )
202         {
203             lsdOid = mrd.getSyntaxDescriptionNumericOID();
204             if ( lsdOid != null && mrd.getSchema().hasLdapSyntaxDescription( lsdOid ) )
205             {
206                 lsd = mrd.getSchema().getLdapSyntaxDescription( lsdOid );
207             }
208         }
209         syntaxLink.setText( getNonNullString( lsd != null ? lsd.getNumericOID() : lsdOid ) );
210         syntaxLink.setHref( lsd );
211         syntaxLink.setUnderlined( lsd != null );
212         syntaxLink.setEnabled( lsd != null );
213         syntaxDescText.setText( getNonNullString( lsd != null ? lsd.getDesc() : null ) );
214         syntaxSection.layout();
215
216         // create contents of dynamic sections
217
createUsedFromContents( mrd );
218         createRawContents( mrd );
219
220         detailForm.reflow( true );
221     }
222
223
224     /**
225      * Creates the content of the main section. It is newly created
226      * on every input change to ensure a proper layout of
227      * multilined descriptions.
228      *
229      * @param mrd the matching rule description
230      */

231     private void createMainContent( MatchingRuleDescription mrd )
232     {
233         // dispose old content
234
if ( mainSection.getClient() != null )
235         {
236             mainSection.getClient().dispose();
237         }
238
239         // create new client
240
Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP );
241         GridLayout mainLayout = new GridLayout( 2, false );
242         mainClient.setLayout( mainLayout );
243         mainSection.setClient( mainClient );
244
245         // create new content
246
if ( mrd != null )
247         {
248             toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE );
249             numericOidText = toolkit.createText( mainClient, getNonNullString( mrd.getNumericOID() ), SWT.NONE );
250             numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
251             numericOidText.setEditable( false );
252
253             toolkit.createLabel( mainClient, "Matching rule names:", SWT.NONE );
254             namesText = toolkit.createText( mainClient, getNonNullString( mrd.toString() ), SWT.NONE );
255             namesText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
256             namesText.setEditable( false );
257
258             toolkit.createLabel( mainClient, "Descripton:", SWT.NONE );
259             descText = toolkit.createText( mainClient, getNonNullString( mrd.getDesc() ), SWT.WRAP | SWT.MULTI );
260             GridData gd = new GridData( GridData.FILL_HORIZONTAL );
261             gd.widthHint = detailForm.getForm().getSize().x - 100 - 60;
262             descText.setLayoutData( gd );
263             descText.setEditable( false );
264         }
265
266         mainSection.layout();
267     }
268
269
270     /**
271      * Creates the content of the used from section.
272      * It is newly created on every input change because the content
273      * of this section is dynamic.
274      *
275      * @param mrd the matching rule description
276      */

277     private void createUsedFromContents( MatchingRuleDescription mrd )
278     {
279         // dispose old content
280
if ( usedFromSection.getClient() != null )
281         {
282             usedFromSection.getClient().dispose();
283         }
284
285         // create new client
286
Composite usedFromClient = toolkit.createComposite( usedFromSection, SWT.WRAP );
287         usedFromClient.setLayout( new GridLayout() );
288         usedFromSection.setClient( usedFromClient );
289
290         // create new content
291
if ( mrd != null )
292         {
293             AttributeTypeDescription[] usedFromATDs = mrd.getUsedFromAttributeTypeDescriptions();
294             if ( usedFromATDs != null && usedFromATDs.length > 0 )
295             {
296                 usedFromSection.setText( "Used from (" + usedFromATDs.length + ")" );
297                 usedFromLinks = new Hyperlink[usedFromATDs.length];
298                 for ( int i = 0; i < usedFromATDs.length; i++ )
299                 {
300                     usedFromLinks[i] = toolkit.createHyperlink( usedFromClient, usedFromATDs[i].toString(), SWT.WRAP );
301                     usedFromLinks[i].setHref( usedFromATDs[i] );
302                     usedFromLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
303                     usedFromLinks[i].setUnderlined( true );
304                     usedFromLinks[i].setEnabled( true );
305                     usedFromLinks[i].addHyperlinkListener( this );
306                 }
307             }
308             else
309             {
310                 usedFromSection.setText( "Used from (0)" );
311                 usedFromLinks = new Hyperlink[0];
312                 Text usedFromText = toolkit.createText( usedFromClient, getNonNullString( null ), SWT.NONE );
313                 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
314                 usedFromText.setEditable( false );
315             }
316         }
317         else
318         {
319             usedFromSection.setText( "Used from" );
320         }
321
322         usedFromSection.layout();
323     }
324
325 }
326
Popular Tags