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
.databinding
.observable
.list
.WritableList
;
18 import org
.eclipse
.core
.runtime
.FileLocator
;
19 import org
.eclipse
.core
.runtime
.IPath
;
20 import org
.eclipse
.core
.runtime
.Path
;
21 import org
.eclipse
.jface
.resource
.FontRegistry
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
23 import org
.eclipse
.jface
.resource
.ImageRegistry
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.graphics
.Color
;
26 import org
.eclipse
.swt
.graphics
.Font
;
27 import org
.eclipse
.swt
.graphics
.FontData
;
28 import org
.eclipse
.swt
.graphics
.Image
;
29 import org
.eclipse
.swt
.widgets
.Display
;
30 import org
.eclipse
.swt
.widgets
.Tree
;
31 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
32 import org
.eclipse
.ui
.views
.properties
.PropertySheetPage
;
33 import org
.osgi
.framework
.BundleContext
;
35 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
36 import eu
.etaxonomy
.cdm
.database
.DataSourceNotFoundException
;
37 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
38 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
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 return applicationController
;
176 public CdmApplicationController
getApplicationController() {
177 if (applicationController
== null) {
178 throw new IllegalStateException("CdmApplicationController not yet set.");
180 return applicationController
;
183 /***************************************************************************
185 **************************************************************************/
186 public ImageDescriptor
getImageDescriptor(String key
) {
187 return getImageRegistry().getDescriptor(key
);
190 public Image
getImage(String key
) {
191 return getImageRegistry().get(key
);
194 protected void initializeImageRegistry(ImageRegistry registry
) {
195 registerImage(registry
, ITaxEditorConstants
.EDIT_ICON
, "edit_16x16.ico");
196 registerImage(registry
, ITaxEditorConstants
.WARNING_ICON
,
198 registerImage(registry
, ITaxEditorConstants
.BLACK_SQUARE_ICON
,
199 "accepted_small.gif");
200 registerImage(registry
, ITaxEditorConstants
.HOMOTYPIC_SYN_ICON
,
201 "homosyn_no_bg.gif");
202 registerImage(registry
,
203 ITaxEditorConstants
.HOMOTYPIC_SYN_ORIGINAL_ICON
,
204 "homosyn_original_no_bg.gif");
205 registerImage(registry
, ITaxEditorConstants
.HETEROTYPIC_SYN_ICON
,
206 "heterosyn_no_bg.gif");
207 registerImage(registry
,
208 ITaxEditorConstants
.HETEROTYPIC_SYN_ORIGINAL_ICON
,
209 "heterosyn_original_no_bg.gif");
210 registerImage(registry
, ITaxEditorConstants
.MISAPPLIED_NAME_ICON
,
211 "misapplied_no_bg.gif");
212 registerImage(registry
, ITaxEditorConstants
.CONCEPT_ICON
,
213 "concept_no_bg.gif");
214 registerImage(registry
, ITaxEditorConstants
.AUTONYM_ICON
,
215 "autonym_no_bg.gif");
216 registerImage(registry
, ITaxEditorConstants
.BASIONYM_ICON
,
217 "basionym_no_bg.gif");
218 registerImage(registry
, ITaxEditorConstants
.ORTHOGRAPHIC_VARIANT_ICON
,
219 "orthovariant_no_bg.gif");
220 registerImage(registry
, ITaxEditorConstants
.DB_ICON
, "db.gif");
221 registerImage(registry
, ITaxEditorConstants
.MOVE_ICON
,
222 "correction_change.gif");
223 registerImage(registry
, ITaxEditorConstants
.ACTIVE_DELETE_ICON
,
225 registerImage(registry
, ITaxEditorConstants
.SYNONYM_TO_TAXON_ICON
,
227 registerImage(registry
, ITaxEditorConstants
.OPEN_TAXON_ICON
, "open.gif");
228 registerImage(registry
, ITaxEditorConstants
.ADD_CHILD_TAXON_ICON
,
230 registerImage(registry
,
231 ITaxEditorConstants
.SWAP_SYNONYM_AND_TAXON_ICON
, "swap2.gif");
232 registerImage(registry
, ITaxEditorConstants
.QUICK_ADD_ICON
,
234 registerImage(registry
, ITaxEditorConstants
.TAXON_TO_SYNONYM_ICON
,
236 registerImage(registry
, ITaxEditorConstants
.ERROR_ANNOTATION_ICON
,
237 "quickfix_error_obj.gif");
238 registerImage(registry
, ITaxEditorConstants
.EDIT_BITMAP_ICON
,
239 "256color_16x16.bmp");
242 private void registerImage(ImageRegistry registry
, String key
,
245 IPath path
= new Path("icons/" + fileName
); //$NON-NLS-1$
246 URL url
= FileLocator
.find(getBundle(), path
, null);
248 ImageDescriptor desc
= ImageDescriptor
.createFromURL(url
);
249 registry
.put(key
, desc
);
251 } catch (Exception e
) {
255 /***************************************************************************
257 **************************************************************************/
258 private FontRegistry fontRegistry
;
260 private FontRegistry
getFontRegistry() {
261 if (fontRegistry
== null) {
262 fontRegistry
= new FontRegistry(Display
.getCurrent());
264 fontRegistry
.put(ITaxEditorConstants
.DATASOURCE_FONT
,
265 new FontData
[] { new FontData("Arial", 8, SWT
.NONE
) });
266 fontRegistry
.put(ITaxEditorConstants
.MENU_ITEM_ITALICS_FONT
,
267 new FontData
[] { new FontData("Arial", 9, SWT
.ITALIC
) });
268 fontRegistry
.put(ITaxEditorConstants
.ACCEPTED_TAXON_FONT
,
269 new FontData
[] { new FontData("Georgia", 12, SWT
.NONE
) });
270 fontRegistry
.put(ITaxEditorConstants
.SYNONYM_FONT
,
271 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
272 fontRegistry
.put(ITaxEditorConstants
.MISAPPLIEDNAME_FONT
,
273 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
274 fontRegistry
.put(ITaxEditorConstants
.CONCEPT_FONT
,
275 new FontData
[] { new FontData("Georgia", 10, SWT
.NONE
) });
276 fontRegistry
.put(ITaxEditorConstants
.CHOOSE_NAME_TEXT_FONT
,
277 new FontData
[] { new FontData("Arial", 12, SWT
.BOLD
) });
278 fontRegistry
.put(ITaxEditorConstants
.DEFAULT_PROMPT_FONT
,
279 new FontData
[] { new FontData("Georgia", 10, SWT
.ITALIC
) });
284 public Font
getFont(String key
) {
285 return getFontRegistry().get(key
);
288 /***************************************************************************
290 **************************************************************************/
291 private static HashMap
<String
, Color
> colorRegistry
;
293 public Color
getColor(String key
) {
294 return getColorRegistry().get(key
);
297 private HashMap
<String
, Color
> getColorRegistry() {
298 if (colorRegistry
== null) {
299 colorRegistry
= new HashMap
<String
, Color
>();
301 colorRegistry
.put(ITaxEditorConstants
.GROUP_GRAY_BKG_COLOR
,
302 new Color(null, 240, 240, 240));
303 colorRegistry
.put(ITaxEditorConstants
.PROP_SHEET_RED
,
304 new Color(null, 255, 0, 0));
306 return colorRegistry
;
309 private void disposeColors() {
310 if (colorRegistry
== null) {
313 for (Color color
: colorRegistry
.values()) {
316 colorRegistry
.clear();
319 /***************************************************************************
321 **************************************************************************/
323 private Tree propertySheetTree
;
325 public void setPropertySheetTree(Tree tree
) {
326 this.propertySheetTree
= tree
;
329 public Tree
getPropertySheetTree() {
330 return propertySheetTree
;
333 private PropertySheetPage propertySheetPage
;
335 public void setPropertySheetPage(PropertySheetPage page
) {
336 this.propertySheetPage
= page
;
339 public PropertySheetPage
getPropertySheetPage() {
340 return propertySheetPage
;