KickJava   Java API By Example, From Geeks To Geeks.

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


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.IConnection;
25 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
26 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription;
27 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription;
28 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription;
29 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
30 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
31 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
32 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
33 import org.eclipse.core.runtime.IProgressMonitor;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.custom.CTabFolder;
36 import org.eclipse.swt.custom.CTabItem;
37 import org.eclipse.swt.widgets.Composite;
38 import org.eclipse.swt.widgets.Control;
39 import org.eclipse.ui.IEditorInput;
40 import org.eclipse.ui.IEditorPart;
41 import org.eclipse.ui.IEditorSite;
42 import org.eclipse.ui.INavigationLocation;
43 import org.eclipse.ui.INavigationLocationProvider;
44 import org.eclipse.ui.IReusableEditor;
45 import org.eclipse.ui.PartInitException;
46 import org.eclipse.ui.PlatformUI;
47 import org.eclipse.ui.part.EditorPart;
48
49
50 /**
51  * The schema browser editor part.
52  *
53  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
54  * @version $Rev$, $Date$
55  */

56 public class SchemaBrowser extends EditorPart implements INavigationLocationProvider, IReusableEditor
57 {
58
59     /** The tab folder with all the schema element tabs */
60     private CTabFolder tabFolder;
61
62     /** The object class tab */
63     private CTabItem ocdTab;
64
65     /** The object class page */
66     private ObjectClassDescriptionPage ocdPage;
67
68     /** The attribute type tab */
69     private CTabItem atdTab;
70
71     /** The attribute type page */
72     private AttributeTypeDescriptionPage atdPage;
73
74     /** The matching rule tab */
75     private CTabItem mrdTab;
76
77     /** The matching rule page */
78     private MatchingRuleDescriptionPage mrdPage;
79
80     /** The matching rule use tab */
81     private CTabItem mrudTab;
82
83     /** The matching rule use page */
84     private MatchingRuleUseDescriptionPage mrudPage;
85
86     /** The syntax tab */
87     private CTabItem lsdTab;
88
89     /** The syntax page */
90     private LdapSyntaxDescriptionPage lsdPage;
91
92
93     /**
94      * Gets the ID of the schema browser.
95      *
96      * @return the ID of the schema browser
97      */

98     public static String JavaDoc getId()
99     {
100         return SchemaBrowser.class.getName();
101     }
102
103
104     /**
105      * {@inheritDoc}
106      */

107     public void init( IEditorSite site, IEditorInput input ) throws PartInitException
108     {
109         setSite( site );
110
111         // mark dummy location, necessary because the first marked
112
// location doesn't appear in history
113
setInput( new SchemaBrowserInput( null, null ) );
114         getSite().getPage().getNavigationHistory().markLocation( this );
115
116         // set real input
117
setInput( input );
118     }
119
120
121     /**
122      * {@inheritDoc}
123      */

124     public void dispose()
125     {
126         ocdPage.dispose();
127         atdPage.dispose();
128         mrdPage.dispose();
129         mrudPage.dispose();
130         lsdPage.dispose();
131         tabFolder.dispose();
132         super.dispose();
133     }
134
135
136     /**
137      * {@inheritDoc}
138      */

139     public void createPartControl( Composite parent )
140     {
141         tabFolder = new CTabFolder( parent, SWT.BOTTOM );
142
143         ocdTab = new CTabItem( tabFolder, SWT.NONE );
144         ocdTab.setText( "Object Classes" );
145         ocdTab.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_OCD ) );
146         ocdPage = new ObjectClassDescriptionPage( this );
147         Control ocdPageControl = ocdPage.createControl( tabFolder );
148         ocdTab.setControl( ocdPageControl );
149
150         atdTab = new CTabItem( tabFolder, SWT.NONE );
151         atdTab.setText( "Attribute Types" );
152         atdTab.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_ATD ) );
153         atdPage = new AttributeTypeDescriptionPage( this );
154         Control atdPageControl = atdPage.createControl( tabFolder );
155         atdTab.setControl( atdPageControl );
156
157         mrdTab = new CTabItem( tabFolder, SWT.NONE );
158         mrdTab.setText( "Matching Rules" );
159         mrdTab.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_MRD ) );
160         mrdPage = new MatchingRuleDescriptionPage( this );
161         Control mrdPageControl = mrdPage.createControl( tabFolder );
162         mrdTab.setControl( mrdPageControl );
163
164         mrudTab = new CTabItem( tabFolder, SWT.NONE );
165         mrudTab.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_MRUD ) );
166         mrudTab.setText( "Matching Rule Use" );
167         mrudPage = new MatchingRuleUseDescriptionPage( this );
168         Control mrudPageControl = mrudPage.createControl( tabFolder );
169         mrudTab.setControl( mrudPageControl );
170
171         lsdTab = new CTabItem( tabFolder, SWT.NONE );
172         lsdTab.setImage( BrowserUIPlugin.getDefault().getImage( BrowserUIConstants.IMG_LSD ) );
173         lsdTab.setText( "Syntaxes" );
174         lsdPage = new LdapSyntaxDescriptionPage( this );
175         Control lsdPageControl = lsdPage.createControl( tabFolder );
176         lsdTab.setControl( lsdPageControl );
177
178         // set default selection
179
tabFolder.setSelection( ocdTab );
180
181         // init help context
182
PlatformUI.getWorkbench().getHelpSystem().setHelp( parent,
183             BrowserUIPlugin.PLUGIN_ID + "." + "tools_schema_browser" );
184         PlatformUI.getWorkbench().getHelpSystem().setHelp( tabFolder,
185             BrowserUIPlugin.PLUGIN_ID + "." + "tools_schema_browser" );
186         PlatformUI.getWorkbench().getHelpSystem().setHelp( ocdPageControl,
187             BrowserUIPlugin.PLUGIN_ID + "." + "tools_schema_browser" );
188     }
189
190
191     /**
192      * {@inheritDoc}
193      */

194     public void setInput( IEditorInput input )
195     {
196         super.setInput( input );
197
198         if ( input instanceof SchemaBrowserInput && tabFolder != null )
199         {
200             SchemaBrowserInput sbi = ( SchemaBrowserInput ) input;
201
202             // set connection;
203
IConnection connection = sbi.getConnection();
204             setConnection( connection );
205
206             // set schema element and activate tab
207
SchemaPart schemaElement = sbi.getSchemaElement();
208             if ( schemaElement instanceof ObjectClassDescription )
209             {
210                 ocdPage.select( schemaElement );
211                 tabFolder.setSelection( ocdTab );
212             }
213             else if ( schemaElement instanceof AttributeTypeDescription )
214             {
215                 atdPage.select( schemaElement );
216                 tabFolder.setSelection( atdTab );
217             }
218             else if ( schemaElement instanceof MatchingRuleDescription )
219             {
220                 mrdPage.select( schemaElement );
221                 tabFolder.setSelection( mrdTab );
222             }
223             else if ( schemaElement instanceof MatchingRuleUseDescription )
224             {
225                 mrudPage.select( schemaElement );
226                 tabFolder.setSelection( mrudTab );
227             }
228             else if ( schemaElement instanceof LdapSyntaxDescription )
229             {
230                 lsdPage.select( schemaElement );
231                 tabFolder.setSelection( lsdTab );
232             }
233
234             if ( connection != null && schemaElement != null )
235             {
236                 // enable one instance hack before fireing the input change event
237
// otherwise the navigation history is cleared.
238
SchemaBrowserInput.enableOneInstanceHack( true );
239                 firePropertyChange( IEditorPart.PROP_INPUT );
240
241                 // disable one instance hack for marking the location
242
SchemaBrowserInput.enableOneInstanceHack( false );
243                 getSite().getPage().getNavigationHistory().markLocation( this );
244             }
245
246             // finally enable the one instance hack
247
SchemaBrowserInput.enableOneInstanceHack( true );
248         }
249     }
250
251
252     /**
253      * Refreshes all pages.
254      */

255     public void refresh()
256     {
257         ocdPage.refresh();
258         atdPage.refresh();
259         mrdPage.refresh();
260         mrudPage.refresh();
261         lsdPage.refresh();
262     }
263
264
265     /**
266      * Sets the show defauls schema flag to all pages.
267      *
268      * @param b the default schema flag
269      */

270     public void setShowDefaultSchema( boolean b )
271     {
272         ocdPage.setShowDefaultSchema( b );
273         atdPage.setShowDefaultSchema( b );
274         mrdPage.setShowDefaultSchema( b );
275         mrudPage.setShowDefaultSchema( b );
276         lsdPage.setShowDefaultSchema( b );
277     }
278
279
280     /**
281      * Sets the connection.
282      *
283      * @param connection the connection
284      */

285     public void setConnection( IConnection connection )
286     {
287         ocdPage.setConnection( connection );
288         atdPage.setConnection( connection );
289         mrdPage.setConnection( connection );
290         mrudPage.setConnection( connection );
291         lsdPage.setConnection( connection );
292     }
293
294
295     /**
296      * {@inheritDoc}
297      */

298     public void setFocus()
299     {
300     }
301
302
303     /**
304      * {@inheritDoc}
305      */

306     public void doSave( IProgressMonitor monitor )
307     {
308     }
309
310
311     /**
312      * {@inheritDoc}
313      */

314     public void doSaveAs()
315     {
316     }
317
318
319     /**
320      * {@inheritDoc}
321      */

322     public boolean isDirty()
323     {
324         return false;
325     }
326
327
328     /**
329      * {@inheritDoc}
330      */

331     public boolean isSaveAsAllowed()
332     {
333         return false;
334     }
335
336
337     /**
338      * {@inheritDoc}
339      */

340     public INavigationLocation createEmptyNavigationLocation()
341     {
342         return null;
343     }
344
345
346     /**
347      * {@inheritDoc}
348      */

349     public INavigationLocation createNavigationLocation()
350     {
351         return new SchemaBrowserNavigationLocation( this );
352     }
353
354 }
355
Popular Tags