KickJava   Java API By Example, From Geeks To Geeks.

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


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.BrowserCorePlugin;
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.MatchingRuleUseDescription;
30 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
31 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart;
32 import org.eclipse.ui.IEditorPart;
33 import org.eclipse.ui.IMemento;
34 import org.eclipse.ui.INavigationLocation;
35 import org.eclipse.ui.NavigationLocation;
36
37
38 /**
39  * This class is used to mark the schema browser input to the navigation history.
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class SchemaBrowserNavigationLocation extends NavigationLocation
45 {
46
47     /**
48      * Creates a new instance of SchemaBrowserNavigationLocation.
49      *
50      * @param schemaBrowser the schema browser
51      */

52     SchemaBrowserNavigationLocation( SchemaBrowser schemaBrowser )
53     {
54         super( schemaBrowser );
55     }
56
57
58     /**
59      * {@inheritDoc}
60      */

61     public String JavaDoc getText()
62     {
63         SchemaPart schemaElement = getSchemElement();
64         if ( schemaElement != null )
65         {
66             if(schemaElement instanceof ObjectClassDescription)
67             {
68                 return "Object Class " + schemaElement.toString();
69             }
70             else if(schemaElement instanceof AttributeTypeDescription )
71             {
72                 return "Attribute Type " + schemaElement.toString();
73             }
74             else if(schemaElement instanceof LdapSyntaxDescription )
75             {
76                 return "Syntax " + schemaElement.toString();
77             }
78             else if(schemaElement instanceof MatchingRuleDescription)
79             {
80                 return "Matching Rule " + schemaElement.toString();
81             }
82             else if(schemaElement instanceof MatchingRuleUseDescription )
83             {
84                 return "Matching Rule Use " + schemaElement.toString();
85             }
86             else
87             {
88                 return schemaElement.getNumericOID();
89             }
90         }
91         else
92         {
93             return super.getText();
94         }
95     }
96
97
98     /**
99      * {@inheritDoc}
100      */

101     public void saveState( IMemento memento )
102     {
103         IConnection connection = getConnection();
104         SchemaPart schemaElement = getSchemElement();
105         memento.putString( "CONNECTION", connection.getName() );
106         memento.putString( "SCHEMAELEMENTYPE", schemaElement.getClass().getName() );
107         memento.putString( "SCHEMAELEMENTOID", schemaElement.getNumericOID() );
108     }
109
110
111     /**
112      * {@inheritDoc}
113      */

114     public void restoreState( IMemento memento )
115     {
116         IConnection connection = BrowserCorePlugin.getDefault().getConnectionManager().getConnection(
117             memento.getString( "CONNECTION" ) );
118         String JavaDoc schemaElementType = memento.getString( "SCHEMAELEMENTYPE" );
119         String JavaDoc schemaElementOid = memento.getString( "SCHEMAELEMENTOID" );
120         SchemaPart schemaElement = null;
121         if(ObjectClassDescription.class.getName().equals( schemaElementType ) )
122         {
123             schemaElement = connection.getSchema().getObjectClassDescription( schemaElementOid );
124         }
125         else if(AttributeTypeDescription.class.getName().equals( schemaElementType ) )
126         {
127             schemaElement = connection.getSchema().getAttributeTypeDescription( schemaElementOid );
128         }
129         else if(LdapSyntaxDescription.class.getName().equals( schemaElementType ) )
130         {
131             schemaElement = connection.getSchema().getLdapSyntaxDescription( schemaElementOid );
132         }
133         else if(MatchingRuleDescription.class.getName().equals( schemaElementType ) )
134         {
135             schemaElement = connection.getSchema().getMatchingRuleDescription( schemaElementOid );
136         }
137         else if(MatchingRuleUseDescription.class.getName().equals( schemaElementType ) )
138         {
139             schemaElement = connection.getSchema().getMatchingRuleUseDescription( schemaElementOid );
140         }
141         
142         super.setInput( new SchemaBrowserInput( connection, schemaElement ) );
143     }
144
145
146     /**
147      * {@inheritDoc}
148      */

149     public void restoreLocation()
150     {
151         IEditorPart editorPart = getEditorPart();
152         if ( editorPart != null && editorPart instanceof SchemaBrowser )
153         {
154             SchemaBrowser schemaBrowser = ( SchemaBrowser ) editorPart;
155             Object JavaDoc input = getInput();
156             if(input != null && input instanceof SchemaBrowserInput)
157             {
158                 SchemaBrowserInput sbi = (SchemaBrowserInput)input;
159                 if(sbi.getConnection() != null && sbi.getSchemaElement() != null)
160                 {
161                     schemaBrowser.setInput( sbi );
162                 }
163             }
164         }
165     }
166
167
168     /**
169      * {@inheritDoc}
170      */

171     public boolean mergeInto( INavigationLocation currentLocation )
172     {
173         if ( currentLocation == null )
174         {
175             return false;
176         }
177
178         if ( getClass() != currentLocation.getClass() )
179         {
180             return false;
181         }
182
183         SchemaBrowserNavigationLocation location = ( SchemaBrowserNavigationLocation ) currentLocation;
184         SchemaPart other = location.getSchemElement();
185         SchemaPart element = getSchemElement();
186
187         if ( other == null && element == null )
188         {
189             return true;
190         }
191         else if ( other == null || element == null )
192         {
193             return false;
194         }
195         else
196         {
197             return element.equals( other );
198         }
199     }
200
201
202     /**
203      * {@inheritDoc}
204      */

205     public void update()
206     {
207     }
208
209
210     /**
211      * Gets the schema element.
212      *
213      * @return the schema element
214      */

215     private SchemaPart getSchemElement()
216     {
217
218         Object JavaDoc editorInput = getInput();
219         if ( editorInput != null && editorInput instanceof SchemaBrowserInput )
220         {
221             SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput;
222             SchemaPart schemaElement = schemaBrowserInput.getSchemaElement();
223             if ( schemaElement != null )
224             {
225                 return schemaElement;
226             }
227         }
228
229         return null;
230     }
231
232
233     /**
234      * Gets the connection.
235      *
236      * @return the connection
237      */

238     private IConnection getConnection()
239     {
240         
241         Object JavaDoc editorInput = getInput();
242         if ( editorInput != null && editorInput instanceof SchemaBrowserInput )
243         {
244             SchemaBrowserInput schemaBrowserInput = ( SchemaBrowserInput ) editorInput;
245             return schemaBrowserInput.getConnection();
246         }
247         
248         return null;
249     }
250     
251     
252     /**
253      * {@inheritDoc}
254      */

255     public String JavaDoc toString()
256     {
257         return "" + getSchemElement();
258     }
259
260 }
261
Popular Tags