KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > Activator


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.schemas;
22
23
24 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
25 import org.apache.directory.ldapstudio.schemas.view.views.SchemaCodeScanner;
26 import org.apache.directory.ldapstudio.schemas.view.views.SchemaTextAttributeProvider;
27 import org.eclipse.jface.text.rules.ITokenScanner;
28 import org.eclipse.jface.util.IPropertyChangeListener;
29 import org.eclipse.jface.util.PropertyChangeEvent;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31 import org.osgi.framework.BundleContext;
32
33
34 /**
35  * The activator class controls the plug-in life cycle
36  */

37 public class Activator extends AbstractUIPlugin
38 {
39
40     /** The plug-in ID */
41     public static final String JavaDoc PLUGIN_ID = "org.apache.directory.ldapstudio.schemas"; //$NON-NLS-1$
42

43     /** The shared instance */
44     private static Activator plugin;
45
46     /** the Schema Code Scanner */
47     private static ITokenScanner schemaCodeScanner;
48
49     /** The Schema Text Attribute Provider */
50     private static SchemaTextAttributeProvider schemaTextAttributeProvider;
51
52     /** The Schema Pool */
53     private SchemaPool schemaPool;
54
55
56     /**
57      * The constructor
58      */

59     public Activator()
60     {
61         plugin = this;
62     }
63
64
65     /*
66      * (non-Javadoc)
67      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
68      */

69     public void start( BundleContext context ) throws Exception JavaDoc
70     {
71         super.start( context );
72
73         // Loading the Schema Pool
74
schemaPool = SchemaPool.getInstance();
75
76         // Initialiazing the Preferences Listener
77
initPreferencesListener();
78
79     }
80
81
82     /*
83      * (non-Javadoc)
84      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
85      */

86     public void stop( BundleContext context ) throws Exception JavaDoc
87     {
88         // Saving workspace configuration
89
schemaPool.saveUserSchemasPaths();
90
91         plugin = null;
92         super.stop( context );
93     }
94
95
96     /**
97      * Returns the shared instance
98      *
99      * @return the shared instance
100      */

101     public static Activator getDefault()
102     {
103         return plugin;
104     }
105
106
107     /**
108      * Returns the Schema Code Scanner.
109      *
110      * @return
111      * the Schema Code Scanner
112      */

113     public static ITokenScanner getSchemaCodeScanner()
114     {
115         if ( schemaCodeScanner == null )
116         {
117             schemaCodeScanner = new SchemaCodeScanner( getSchemaTextAttributeProvider() );
118         }
119
120         return schemaCodeScanner;
121     }
122
123
124     /**
125      * Returns the Schema Text Attribute Provider.
126      *
127      * @return
128      * the Schema Text Attribute Provider
129      */

130     private static SchemaTextAttributeProvider getSchemaTextAttributeProvider()
131     {
132         if ( schemaTextAttributeProvider == null )
133         {
134             schemaTextAttributeProvider = new SchemaTextAttributeProvider();
135         }
136
137         return schemaTextAttributeProvider;
138     }
139
140
141     /**
142      * Initializes the listener on the preferences store.
143      */

144     private void initPreferencesListener()
145     {
146         Activator.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener()
147         {
148             public void propertyChange( PropertyChangeEvent event )
149             {
150                 if ( PluginConstants.PREFS_SCHEMAS_EDITOR_SPECIFIC_CORE == event.getProperty() )
151                 {
152                     // Reloading the SchemaPool
153
schemaPool.reload();
154                 }
155             }
156         } );
157     }
158 }
159
Popular Tags