KickJava   Java API By Example, From Geeks To Geeks.

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


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.MatchingRuleDescription;
26 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription;
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 public class MatchingRuleUseDescriptionDetailsPage extends SchemaDetailsPage
42 {
43
44     /** The main section, contains oid, names and desc */
45     private Section mainSection;
46
47     /** The numeric oid field */
48     private Text numericOidText;
49     
50     /** The name link */
51     private Hyperlink nameLink;
52     
53     /** The description field */
54     private Text descText;
55
56     /** The flag section, contains obsolete */
57     private Section flagSection;
58
59     /** The obsolete field */
60     private Label isObsoleteText;
61
62     /** The applies section, contains links */
63     private Section appliesSection;
64
65     /** The links to attribute types the matching rule is applicaple to */
66     private Hyperlink[] appliesLinks;
67
68
69     /**
70      * Creates a new instance of MatchingRuleUseDescriptionDetailsPage.
71      *
72      * @param schemaPage the master schema page
73      * @param toolkit the toolkit used to create controls
74      */

75     public MatchingRuleUseDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit )
76     {
77         super( schemaPage, toolkit );
78     }
79
80
81     /**
82      * {@inheritDoc}
83      */

84     public void createContents( final ScrolledForm detailForm )
85     {
86
87         this.detailForm = detailForm;
88         detailForm.getBody().setLayout( new GridLayout() );
89
90         // create main section
91
mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
92         mainSection.setText( "Details" );
93         mainSection.marginWidth = 0;
94         mainSection.marginHeight = 0;
95         mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
96         toolkit.createCompositeSeparator( mainSection );
97
98         // create flag section
99
flagSection = toolkit.createSection( detailForm.getBody(), SWT.NONE );
100         flagSection.setText( "Flags" );
101         flagSection.marginWidth = 0;
102         flagSection.marginHeight = 0;
103         flagSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
104         toolkit.createCompositeSeparator( flagSection );
105
106         // create flag content
107
Composite flagClient = toolkit.createComposite( flagSection, SWT.WRAP );
108         GridLayout flagLayout = new GridLayout();
109         flagLayout.numColumns = 1;
110         flagLayout.marginWidth = 0;
111         flagLayout.marginHeight = 0;
112         flagClient.setLayout( flagLayout );
113         flagSection.setClient( flagClient );
114
115         isObsoleteText = toolkit.createLabel( flagClient, "Obsolete", SWT.CHECK );
116         isObsoleteText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
117         isObsoleteText.setEnabled( false );
118
119         // create applies section
120
appliesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE );
121         appliesSection.setText( "Applies" );
122         appliesSection.marginWidth = 0;
123         appliesSection.marginHeight = 0;
124         appliesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
125         toolkit.createCompositeSeparator( appliesSection );
126         appliesSection.addExpansionListener( new ExpansionAdapter()
127         {
128             public void expansionStateChanged( ExpansionEvent e )
129             {
130                 detailForm.reflow( true );
131             }
132         } );
133
134         // create raw section
135
super.createRawSection();
136     }
137
138
139     /**
140      * {@inheritDoc}
141      */

142     public void setInput( Object JavaDoc input )
143     {
144         MatchingRuleUseDescription mrud = null;
145         if ( input instanceof MatchingRuleUseDescription )
146         {
147             mrud = ( MatchingRuleUseDescription ) input;
148         }
149
150         // create main content
151
this.createMainContent( mrud );
152         
153         // set flag
154
isObsoleteText.setEnabled( mrud != null && mrud.isObsolete() );
155         
156         // create contents of dynamic sections
157
this.createAppliesContents( mrud );
158         super.createRawContents( mrud );
159
160         this.detailForm.reflow( true );
161     }
162
163
164     /**
165      * Creates the content of the main section. It is newly created
166      * on every input change to ensure a proper layout of
167      * multilined descriptions.
168      *
169      * @param mrud the matching rule use description
170      */

171     private void createMainContent( MatchingRuleUseDescription mrud )
172     {
173         // dispose old content
174
if ( mainSection.getClient() != null )
175         {
176             mainSection.getClient().dispose();
177         }
178
179         // create new client
180
Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP );
181         GridLayout mainLayout = new GridLayout( 2, false );
182         mainClient.setLayout( mainLayout );
183         mainSection.setClient( mainClient );
184
185         // create new content
186
if ( mrud != null )
187         {
188             toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE );
189             numericOidText = toolkit.createText( mainClient, getNonNullString( mrud.getNumericOID() ), SWT.NONE );
190             numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
191             numericOidText.setEditable( false );
192
193             toolkit.createLabel( mainClient, "Matching rule names:", SWT.NONE );
194             nameLink = toolkit.createHyperlink( mainClient, "", SWT.WRAP );
195             nameLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
196             nameLink.addHyperlinkListener( this );
197
198             MatchingRuleDescription mrd = mrud.getSchema().hasMatchingRuleDescription( mrud.getNumericOID() ) ? mrud
199                 .getSchema().getMatchingRuleDescription( mrud.getNumericOID() ) : null;
200             nameLink.setText( getNonNullString( mrd != null ? mrd.toString() : mrud.toString() ) );
201             nameLink.setHref( mrd );
202             nameLink.setUnderlined( mrd != null );
203             nameLink.setEnabled( mrd != null );
204
205             toolkit.createLabel( mainClient, "Descripton:", SWT.NONE );
206             descText = toolkit.createText( mainClient, getNonNullString( mrud.getDesc() ), SWT.WRAP | SWT.MULTI );
207             GridData gd = new GridData( GridData.FILL_HORIZONTAL );
208             gd.widthHint = detailForm.getForm().getSize().x - 100 - 60;
209             descText.setLayoutData( gd );
210             descText.setEditable( false );
211         }
212
213         mainSection.layout();
214     }
215
216
217     /**
218      * Creates the content of the applies section.
219      * It is newly created on every input change because the content
220      * of this section is dynamic.
221      *
222      * @param mrud the matching rule use description
223      */

224     private void createAppliesContents( MatchingRuleUseDescription mrud )
225     {
226         // dispose old content
227
if ( appliesSection.getClient() != null )
228         {
229             appliesSection.getClient().dispose();
230         }
231
232         // create new client
233
Composite appliesClient = toolkit.createComposite( appliesSection, SWT.WRAP );
234         appliesClient.setLayout( new GridLayout() );
235         appliesSection.setClient( appliesClient );
236
237         // create content
238
if ( mrud != null )
239         {
240             String JavaDoc[] names = mrud.getAppliesAttributeTypeDescriptionOIDs();
241             if ( names != null && names.length > 0 )
242             {
243                 appliesSection.setText( "Applies (" + names.length + ")" );
244                 appliesLinks = new Hyperlink[names.length];
245                 for ( int i = 0; i < names.length; i++ )
246                 {
247                     if ( mrud.getSchema().hasAttributeTypeDescription( names[i] ) )
248                     {
249                         AttributeTypeDescription appliesAtd = mrud.getSchema().getAttributeTypeDescription( names[i] );
250                         appliesLinks[i] = toolkit.createHyperlink( appliesClient, appliesAtd.toString(), SWT.WRAP );
251                         appliesLinks[i].setHref( appliesAtd );
252                         appliesLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
253                         appliesLinks[i].setUnderlined( true );
254                         appliesLinks[i].setEnabled( true );
255                         appliesLinks[i].addHyperlinkListener( this );
256                     }
257                     else
258                     {
259                         appliesLinks[i] = toolkit.createHyperlink( appliesClient, names[i], SWT.WRAP );
260                         appliesLinks[i].setHref( null );
261                         appliesLinks[i].setUnderlined( false );
262                         appliesLinks[i].setEnabled( false );
263                     }
264                 }
265             }
266             else
267             {
268                 appliesSection.setText( "Applies (0)" );
269                 appliesLinks = new Hyperlink[0];
270                 Text usedFromText = toolkit.createText( appliesClient, getNonNullString( null ), SWT.NONE );
271                 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
272                 usedFromText.setEditable( false );
273             }
274         }
275         else
276         {
277             appliesSection.setText( "Applies" );
278         }
279
280         appliesSection.layout();
281     }
282
283 }
284
Popular Tags