KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > actions > OpenSchemaBrowserAction


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.actions;
22
23
24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction;
25 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
26 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
27 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
28 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription;
29 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
30 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
31 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
32 import org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser.SchemaBrowserManager;
33 import org.eclipse.jface.resource.ImageDescriptor;
34
35
36 /**
37  * This Action opens the Schema Browser
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class OpenSchemaBrowserAction extends BrowserAction
43 {
44     /**
45      * None Mode
46      */

47     public static final int MODE_NONE = 0;
48
49     /**
50      * Object Class Mode
51      */

52     public static final int MODE_OBJECTCLASS = 10;
53
54     /**
55      * Attribute Type Mode
56      */

57     public static final int MODE_ATTRIBUTETYPE = 20;
58
59     /**
60      * Equality Matching Rule Mode
61      */

62     public static final int MODE_EQUALITYMATCHINGRULE = 30;
63
64     /**
65      * Substring Matching Rule Mode
66      */

67     public static final int MODE_SUBSTRINGMATCHINGRULE = 31;
68
69     /**
70      * Ordering Matching Rule Mode
71      */

72     public static final int MODE_ORDERINGMATCHINGRULE = 32;
73
74     /**
75      * Syntax Mode
76      */

77     public static final int MODE_SYNTAX = 40;
78
79     protected int mode;
80
81
82     /**
83      * Creates a new instance of OpenSchemaBrowserAction.
84      */

85     public OpenSchemaBrowserAction()
86     {
87         super();
88         this.mode = MODE_NONE;
89     }
90
91
92     /**
93      * Creates a new instance of OpenSchemaBrowserAction.
94      *
95      * @param mode
96      * the display mode
97      */

98     public OpenSchemaBrowserAction( int mode )
99     {
100         super();
101         this.mode = mode;
102     }
103
104
105     /**
106      * {@inheritDoc}
107      */

108     public void run()
109     {
110         if ( mode == MODE_NONE )
111         {
112             SchemaBrowserManager.setInput( getConnection(), null );
113         }
114         else if ( mode == MODE_OBJECTCLASS )
115         {
116             SchemaBrowserManager.setInput( getConnection(), getOcd() );
117         }
118         else if ( mode == MODE_ATTRIBUTETYPE )
119         {
120             SchemaBrowserManager.setInput( getConnection(), getAtd() );
121         }
122         else if ( mode == MODE_EQUALITYMATCHINGRULE )
123         {
124             SchemaBrowserManager.setInput( getConnection(), getEmrd() );
125         }
126         else if ( mode == MODE_SUBSTRINGMATCHINGRULE )
127         {
128             SchemaBrowserManager.setInput( getConnection(), getSmrd() );
129         }
130         else if ( mode == MODE_ORDERINGMATCHINGRULE )
131         {
132             SchemaBrowserManager.setInput( getConnection(), getOmrd() );
133         }
134         else if ( mode == MODE_SYNTAX )
135         {
136             SchemaBrowserManager.setInput( getConnection(), getLsd() );
137         }
138         else
139         {
140             SchemaBrowserManager.setInput( getConnection(), null );
141         }
142     }
143
144
145     /**
146      * {@inheritDoc}
147      */

148     public String JavaDoc getText()
149     {
150         if ( mode == MODE_NONE )
151         {
152             return "Open Schema Browser";
153         }
154         else if ( mode == MODE_OBJECTCLASS )
155         {
156             return "Object Class Description";
157         }
158         else if ( mode == MODE_ATTRIBUTETYPE )
159         {
160             return "Attribute Type Description";
161         }
162         else if ( mode == MODE_EQUALITYMATCHINGRULE )
163         {
164             return "Equality Matching Rule Description";
165         }
166         else if ( mode == MODE_SUBSTRINGMATCHINGRULE )
167         {
168             return "Substring Matching Rule Description";
169         }
170         else if ( mode == MODE_ORDERINGMATCHINGRULE )
171         {
172             return "Ordering Matching Rule Description";
173         }
174         else if ( mode == MODE_SYNTAX )
175         {
176             return "Syntax Description";
177         }
178         else
179         {
180             return "Open Schema Browser";
181         }
182     }
183
184
185     /**
186      * {@inheritDoc}
187      */

188     public ImageDescriptor getImageDescriptor()
189     {
190         if ( mode == MODE_NONE )
191         {
192             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
193         }
194         else if ( mode == MODE_OBJECTCLASS )
195         {
196             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_OCD );
197         }
198         else if ( mode == MODE_ATTRIBUTETYPE )
199         {
200             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_ATD );
201         }
202         else if ( mode == MODE_EQUALITYMATCHINGRULE )
203         {
204             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_EQUALITY );
205         }
206         else if ( mode == MODE_SUBSTRINGMATCHINGRULE )
207         {
208             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_SUBSTRING );
209         }
210         else if ( mode == MODE_ORDERINGMATCHINGRULE )
211         {
212             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_ORDERING );
213         }
214         else if ( mode == MODE_SYNTAX )
215         {
216             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_LSD );
217         }
218         else
219         {
220             return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR );
221         }
222     }
223
224
225     /**
226      * {@inheritDoc}
227      */

228     public String JavaDoc getCommandId()
229     {
230         return null;
231     }
232
233
234     /**
235      * {@inheritDoc}
236      */

237     public boolean isEnabled()
238     {
239
240         if ( mode == MODE_NONE )
241         {
242             return true;
243         }
244         else if ( mode == MODE_OBJECTCLASS )
245         {
246             return getOcd() != null;
247         }
248         else if ( mode == MODE_ATTRIBUTETYPE )
249         {
250             return getAtd() != null;
251         }
252         else if ( mode == MODE_EQUALITYMATCHINGRULE )
253         {
254             return getEmrd() != null;
255         }
256         else if ( mode == MODE_SUBSTRINGMATCHINGRULE )
257         {
258             return getSmrd() != null;
259         }
260         else if ( mode == MODE_ORDERINGMATCHINGRULE )
261         {
262             return getOmrd() != null;
263         }
264         else if ( mode == MODE_SYNTAX )
265         {
266             return getLsd() != null;
267         }
268         else
269         {
270             return false;
271         }
272     }
273
274
275     /**
276      * Gets the LDAP Syntax Description.
277      *
278      * @return
279      * the LDAP Syntax Description
280      */

281     private LdapSyntaxDescription getLsd()
282     {
283         AttributeTypeDescription atd = getAtd();
284
285         if ( atd != null && atd.getSyntaxDescriptionNumericOIDTransitive() != null
286             && atd.getSchema().hasLdapSyntaxDescription( atd.getSyntaxDescriptionNumericOIDTransitive() ) )
287         {
288             return atd.getSchema().getLdapSyntaxDescription( atd.getSyntaxDescriptionNumericOIDTransitive() );
289         }
290
291         return null;
292     }
293
294
295     /**
296      * Gets the Object Class Description.
297      *
298      * @return
299      * the Object Class Drescription
300      */

301     private ObjectClassDescription getOcd()
302     {
303         if ( getSelectedAttributes().length == 0 && getSelectedValues().length == 1
304             && getSelectedValues()[0].getAttribute().isObjectClassAttribute() )
305         {
306             String JavaDoc ocdName = getSelectedValues()[0].getStringValue();
307             if ( ocdName != null
308                 && getSelectedValues()[0].getAttribute().getEntry().getConnection().getSchema()
309                     .hasObjectClassDescription( ocdName ) )
310             {
311                 return getSelectedValues()[0].getAttribute().getEntry().getConnection().getSchema()
312                     .getObjectClassDescription( ocdName );
313             }
314         }
315
316         return null;
317     }
318
319
320     /**
321      * Gets the Attribute Type Description.
322      *
323      * @return
324      * the Attribute Type Description
325      */

326     private AttributeTypeDescription getAtd()
327     {
328         if ( ( getSelectedValues().length + getSelectedAttributes().length ) + getSelectedAttributeHierarchies().length == 1 )
329         {
330             AttributeTypeDescription atd = null;
331             if ( getSelectedValues().length == 1 )
332             {
333                 atd = getSelectedValues()[0].getAttribute().getAttributeTypeDescription();
334             }
335             else if ( getSelectedAttributes().length == 1 )
336             {
337                 atd = getSelectedAttributes()[0].getAttributeTypeDescription();
338             }
339             else if ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 )
340             {
341                 atd = getSelectedAttributeHierarchies()[0].getAttribute().getAttributeTypeDescription();
342             }
343
344             return atd;
345         }
346
347         return null;
348     }
349
350
351     /**
352      * Gets the connection.
353      *
354      * @return the connection
355      */

356     private IConnection getConnection()
357     {
358         if ( ( getSelectedValues().length + getSelectedAttributes().length ) + getSelectedAttributeHierarchies().length == 1 )
359         {
360             IConnection connection = null;
361             if ( getSelectedValues().length == 1 )
362             {
363                 connection = getSelectedValues()[0].getAttribute().getEntry().getConnection();
364             }
365             else if ( getSelectedAttributes().length == 1 )
366             {
367                 connection = getSelectedAttributes()[0].getEntry().getConnection();
368             }
369             else if ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 )
370             {
371                 connection = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getConnection();
372             }
373
374             return connection;
375         }
376         else if ( getSelectedConnections().length == 1 )
377         {
378             return getSelectedConnections()[0];
379         }
380         else if ( getSelectedEntries().length == 1 )
381         {
382             return getSelectedEntries()[0].getConnection();
383         }
384         else if ( getSelectedSearchResults().length == 1 )
385         {
386             return getSelectedSearchResults()[0].getEntry().getConnection();
387         }
388         else if ( getSelectedBookmarks().length == 1 )
389         {
390             return getSelectedBookmarks()[0].getConnection();
391         }
392         else if ( getSelectedSearches().length == 1 )
393         {
394             return getSelectedSearches()[0].getConnection();
395         }
396
397         return null;
398     }
399
400
401     /**
402      * Gets the Equality Matching Rule Description.
403      *
404      * @return
405      * the Equality Matching Rule Description
406      */

407     private MatchingRuleDescription getEmrd()
408     {
409         AttributeTypeDescription atd = getAtd();
410
411         if ( atd != null && atd.getEqualityMatchingRuleDescriptionOIDTransitive() != null
412             && atd.getSchema().hasMatchingRuleDescription( atd.getEqualityMatchingRuleDescriptionOIDTransitive() ) )
413         {
414             return atd.getSchema().getMatchingRuleDescription( atd.getEqualityMatchingRuleDescriptionOIDTransitive() );
415         }
416
417         return null;
418     }
419
420
421     /**
422      * Gets the Substring Matching Rule Description.
423      *
424      * @return
425      * the Substring Matching Rule Description
426      */

427     private MatchingRuleDescription getSmrd()
428     {
429         AttributeTypeDescription atd = getAtd();
430
431         if ( atd != null && atd.getSubstringMatchingRuleDescriptionOIDTransitive() != null
432             && atd.getSchema().hasMatchingRuleDescription( atd.getSubstringMatchingRuleDescriptionOIDTransitive() ) )
433         {
434             return atd.getSchema().getMatchingRuleDescription( atd.getSubstringMatchingRuleDescriptionOIDTransitive() );
435         }
436
437         return null;
438     }
439
440
441     /**
442      * Gets the Ordering Matching Rule Description.
443      *
444      * @return
445      * the Ordering Matching Rule Description
446      */

447     private MatchingRuleDescription getOmrd()
448     {
449         AttributeTypeDescription atd = getAtd();
450
451         if ( atd != null && atd.getOrderingMatchingRuleDescriptionOIDTransitive() != null
452             && atd.getSchema().hasMatchingRuleDescription( atd.getOrderingMatchingRuleDescriptionOIDTransitive() ) )
453         {
454             return atd.getSchema().getMatchingRuleDescription( atd.getOrderingMatchingRuleDescriptionOIDTransitive() );
455         }
456
457         return null;
458     }
459 }
460
Popular Tags