2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
;
13 import java
.util
.HashMap
;
14 import java
.util
.Locale
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.runtime
.FileLocator
;
18 import org
.eclipse
.core
.runtime
.IPath
;
19 import org
.eclipse
.core
.runtime
.Path
;
20 import org
.eclipse
.jface
.resource
.FontRegistry
;
21 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
22 import org
.eclipse
.jface
.resource
.ImageRegistry
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.graphics
.Color
;
25 import org
.eclipse
.swt
.graphics
.Font
;
26 import org
.eclipse
.swt
.graphics
.FontData
;
27 import org
.eclipse
.swt
.graphics
.Image
;
28 import org
.eclipse
.swt
.widgets
.Display
;
29 import org
.eclipse
.swt
.widgets
.Tree
;
30 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
31 import org
.eclipse
.ui
.views
.properties
.PropertySheetPage
;
32 import org
.osgi
.framework
.BundleContext
;
34 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
35 import eu
.etaxonomy
.cdm
.database
.DataSourceNotFoundException
;
36 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
37 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
38 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
39 import eu
.etaxonomy
.cdm
.model
.common
.init
.TermNotFoundException
;
40 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
41 import eu
.etaxonomy
.taxeditor
.datasource
.CdmTransactionController
;
42 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
45 * The class controlling the plug-in life cycle.
48 * <li>Initializes datastore as necessary.</li>
49 * <li>Initializes CDM application controller.</li>
50 * <li>Initializes default preferences.</li>
51 * <li>Stores registries for colors, fonts, images.</li>
58 public class TaxEditorPlugin
extends AbstractUIPlugin
{
59 private static final Logger logger
= Logger
60 .getLogger(TaxEditorPlugin
.class);
65 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.plugin";
69 private static TaxEditorPlugin plugin
;
71 // private DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
72 private DbSchemaValidation dbSchemaValidation
= DbSchemaValidation
.UPDATE
;
77 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
79 public void start(BundleContext context
) throws Exception
{
84 // Check whether this is the first time the application has ever been run
85 checkInitialExecution();
87 // Initialize application controller
88 initApplicationController();
90 // Start a transaction
91 CdmTransactionController
.startTransaction();
93 // Forgot what this is ...
94 Locale locale
= new Locale("en", "", "icbn");
95 Locale
.setDefault(locale
);
102 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
104 public void stop(BundleContext context
) throws Exception
{
105 CdmTransactionController
.commitTransaction();
113 * Returns the shared instance
115 * @return the shared instance
117 public static TaxEditorPlugin
getDefault() {
121 private void checkInitialExecution() {
123 // Check in the prefs store whether the application (i.e. its default
124 // data source) has been initialized
125 boolean initialized
= false;
126 if (getPreferenceStore().contains(ITaxEditorConstants
.INITIALIZED
)) {
127 initialized
= getPreferenceStore().getBoolean(
128 ITaxEditorConstants
.INITIALIZED
);
134 // ... set validation to CREATE
135 logger
.warn("Initializing datastore");
136 dbSchemaValidation
= DbSchemaValidation
.CREATE
;
138 // ... and note in prefs that application has been initialized
139 getPreferenceStore().setValue(ITaxEditorConstants
.INITIALIZED
, true);
143 /***************************************************************************
145 **************************************************************************/
148 * All CDM services are called via the application controller
150 private CdmApplicationController applicationController
;
152 private CdmApplicationController
initApplicationController() {
154 // Get the "current" - i.e. most recently used - data source
155 ICdmDataSource cdmDatasource
= CdmDataSourceRepository
.getDefault().
156 getCurrentDataSource();
158 // Initialize the controller with the data source
160 applicationController
= CdmApplicationController
.NewInstance(cdmDatasource
, dbSchemaValidation
);
161 } catch (DataSourceNotFoundException e
) {
162 // TODO user-friendly failure here
164 } catch (TermNotFoundException e
) {
168 // Set application controller for objects that use it
169 CdmTransactionController
.setApplicationController(applicationController
);
170 CdmDataSourceRepository
.getDefault().setCdmApplicationController(applicationController
);
171 CdmSessionDataRepository
.getDefault().setApplicationController(applicationController
);
173 // Terms have to be initialized explicitly as of now
174 DefaultTermInitializer vocabularyStore
= new DefaultTermInitializer();
175 vocabularyStore
.initialize();
177 return applicationController
;
180 public CdmApplicationController
getApplicationController() {
181 if (applicationController
== null) {
182 throw new IllegalStateException("CdmApplicationController not yet set.");
184 return applicationController
;
187 /***************************************************************************
189 **************************************************************************/
190 public ImageDescriptor
getImageDescriptor(String key
) {
191 return getImageRegistry().getDescriptor(key
);
194 public Image
getImage(String key
) {
195 return getImageRegistry().get(key
);
198 protected void initializeImageRegistry(ImageRegistry registry
) {
199 registerImage(registry
, ITaxEditorConstants
.EDIT_ICON
, "edit_16x16.ico");
200 registerImage(registry
, ITaxEditorConstants
.WARNING_ICON
,
202 registerImage(registry
, ITaxEditorConstants
.BLACK_SQUARE_ICON
,
203 "accepted_small.gif");
204 registerImage(registry
, ITaxEditorConstants
.HOMOTYPIC_SYN_ICON
,
205 "homosyn_no_bg.gif");
206 registerImage(registry
,
207 ITaxEditorConstants
.HOMOTYPIC_SYN_ORIGINAL_ICON
,
208 "homosyn_original_no_bg.gif");
209 registerImage(registry
, ITaxEditorConstants
.HETEROTYPIC_SYN_ICON
,
210 "heterosyn_no_bg.gif");
211 registerImage(registry
,
212 ITaxEditorConstants
.HETEROTYPIC_SYN_ORIGINAL_ICON
,
213 "heterosyn_original_no_bg.gif");
214 registerImage(registry
, ITaxEditorConstants
.MISAPPLIED_NAME_ICON
,
215 "misapplied_no_bg.gif");
216 registerImage(registry
, ITaxEditorConstants
.CONCEPT_ICON
,
217 "concept_no_bg.gif");
218 registerImage(registry
, ITaxEditorConstants
.AUTONYM_ICON
,
219 "autonym_no_bg.gif");
220 registerImage(registry
, ITaxEditorConstants
.BASIONYM_ICON
,
221 "basionym_no_bg.gif");
222 registerImage(registry
, ITaxEditorConstants
.ORTHOGRAPHIC_VARIANT_ICON
,
223 "orthovariant_no_bg.gif");
224 registerImage(registry
, ITaxEditorConstants
.DB_ICON
, "db.gif");
225 registerImage(registry
, ITaxEditorConstants
.MOVE_ICON
,
226 "correction_change.gif");
227 registerImage(registry
, ITaxEditorConstants
.ACTIVE_DELETE_ICON
,
229 registerImage(registry
, ITaxEditorConstants
.SYNONYM_TO_TAXON_ICON
,
231 registerImage(registry
, ITaxEditorConstants
.OPEN_TAXON_ICON
, "open.gif");
232 registerImage(registry
, ITaxEditorConstants
.ADD_CHILD_TAXON_ICON
,
234 registerImage(registry
,
235 ITaxEditorConstants
.SWAP_SYNONYM_AND_TAXON_ICON
, "swap2.gif");
236 registerImage(registry
, ITaxEditorConstants
.QUICK_ADD_ICON
,
238 registerImage(registry
, ITaxEditorConstants
.TAXON_TO_SYNONYM_ICON
,
240 registerImage(registry
, ITaxEditorConstants
.ERROR_ANNOTATION_ICON
,
242 registerImage(registry
, ITaxEditorConstants
.EDIT_BITMAP_ICON
,
243 "256color_16x16.bmp");
246 private void registerImage(ImageRegistry registry
, String key
,
249 IPath path
= new Path("icons/" + fileName
); //$NON-NLS-1$
250 URL url
= FileLocator
.find(getBundle(), path
, null);
252 ImageDescriptor desc
= ImageDescriptor
.createFromURL(url
);
253 registry
.put(key
, desc
);
255 } catch (Exception e
) {
259 /***************************************************************************
261 **************************************************************************/
262 private FontRegistry fontRegistry
;
264 private FontRegistry
getFontRegistry() {
265 if (fontRegistry
== null) {
266 fontRegistry
= new FontRegistry(Display
.getCurrent());
268 fontRegistry
.put(ITaxEditorConstants
.DATASOURCE_FONT
,
269 new FontData
[] { new FontData("Arial", 8, SWT
.NONE
) });
270 fontRegistry
.put(ITaxEditorConstants
.MENU_ITEM_ITALICS_FONT
,
271 new FontData
[] { new FontData("Arial", 9, SWT
.ITALIC
) });
272 fontRegistry
.put(ITaxEditorConstants
.ACCEPTED_TAXON_FONT
,
273 new FontData
[] { new FontData("Georgia", 12, SWT
.NONE
) });
274 fontRegistry
.put(ITaxEditorConstants
.SYNONYM_FONT
,
275 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
276 fontRegistry
.put(ITaxEditorConstants
.MISAPPLIEDNAME_FONT
,
277 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
278 fontRegistry
.put(ITaxEditorConstants
.CONCEPT_FONT
,
279 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
280 fontRegistry
.put(ITaxEditorConstants
.CHOOSE_NAME_TEXT_FONT
,
281 new FontData
[] { new FontData("Arial", 12, SWT
.BOLD
) });
282 fontRegistry
.put(ITaxEditorConstants
.DEFAULT_PROMPT_FONT
,
283 new FontData
[] { new FontData("Georgia", 10, SWT
.ITALIC
) });
288 public Font
getFont(String key
) {
289 return getFontRegistry().get(key
);
292 /***************************************************************************
294 **************************************************************************/
295 private static HashMap
<String
, Color
> colorRegistry
;
297 public Color
getColor(String key
) {
298 return getColorRegistry().get(key
);
301 private HashMap
<String
, Color
> getColorRegistry() {
302 if (colorRegistry
== null) {
303 colorRegistry
= new HashMap
<String
, Color
>();
305 colorRegistry
.put(ITaxEditorConstants
.GROUP_GRAY_BKG_COLOR
,
306 new Color(null, 240, 240, 240));
307 colorRegistry
.put(ITaxEditorConstants
.PROP_SHEET_RED
,
308 new Color(null, 255, 0, 0));
310 return colorRegistry
;
313 private void disposeColors() {
314 if (colorRegistry
== null) {
317 for (Color color
: colorRegistry
.values()) {
320 colorRegistry
.clear();
323 /***************************************************************************
325 **************************************************************************/
327 private Tree propertySheetTree
;
329 public void setPropertySheetTree(Tree tree
) {
330 this.propertySheetTree
= tree
;
333 public Tree
getPropertySheetTree() {
334 return propertySheetTree
;
337 private PropertySheetPage propertySheetPage
;
339 public void setPropertySheetPage(PropertySheetPage page
) {
340 this.propertySheetPage
= page
;
343 public PropertySheetPage
getPropertySheetPage() {
344 return propertySheetPage
;