Added ability to color individual property sheet fields, which are implemented as...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / TaxEditorPlugin.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor;
11
12 import java.net.URL;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Locale;
19 import java.util.Map;
20 import java.util.ResourceBundle;
21 import java.util.Set;
22 import java.util.UUID;
23
24 import org.apache.log4j.Logger;
25 import org.eclipse.core.databinding.observable.Realm;
26 import org.eclipse.core.databinding.observable.list.WritableList;
27 import org.eclipse.core.databinding.observable.set.IObservableSet;
28 import org.eclipse.core.databinding.observable.set.WritableSet;
29 import org.eclipse.core.runtime.FileLocator;
30 import org.eclipse.core.runtime.IPath;
31 import org.eclipse.core.runtime.Path;
32 import org.eclipse.jface.databinding.swt.SWTObservables;
33 import org.eclipse.jface.resource.FontRegistry;
34 import org.eclipse.jface.resource.ImageDescriptor;
35 import org.eclipse.jface.resource.ImageRegistry;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.graphics.Color;
38 import org.eclipse.swt.graphics.Font;
39 import org.eclipse.swt.graphics.FontData;
40 import org.eclipse.swt.graphics.Image;
41 import org.eclipse.swt.widgets.Display;
42 import org.eclipse.swt.widgets.Tree;
43 import org.eclipse.ui.forms.FormColors;
44 import org.eclipse.ui.plugin.AbstractUIPlugin;
45 import org.eclipse.ui.views.properties.PropertySheetPage;
46 import org.osgi.framework.BundleContext;
47 import org.springframework.transaction.TransactionStatus;
48
49 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
50 import eu.etaxonomy.cdm.api.service.IDescriptionService;
51 import eu.etaxonomy.cdm.api.service.INameService;
52 import eu.etaxonomy.cdm.api.service.IReferenceService;
53 import eu.etaxonomy.cdm.api.service.ITaxonService;
54 import eu.etaxonomy.cdm.database.CdmDataSource;
55 import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
56 import eu.etaxonomy.cdm.database.DbSchemaValidation;
57 import eu.etaxonomy.cdm.database.ICdmDataSource;
58 import eu.etaxonomy.cdm.model.agent.Person;
59 import eu.etaxonomy.cdm.model.common.Language;
60 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
61 import eu.etaxonomy.cdm.model.common.TermVocabulary;
62 import eu.etaxonomy.cdm.model.common.init.TermNotFoundException;
63 import eu.etaxonomy.cdm.model.name.BotanicalName;
64 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
65 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
66 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
67 import eu.etaxonomy.cdm.model.name.Rank;
68 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
69 import eu.etaxonomy.cdm.model.taxon.Taxon;
70 import eu.etaxonomy.taxeditor.model.CdmUtil;
71 import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeViewer;
72
73 /**
74 * The class controlling the plug-in life cycle.
75 * </p>
76 * <ul>
77 * <li>Initializes datastore as necessary.</li>
78 * <li>Initializes default preferences.</li>
79 * <li>Gateway to CDM service layer.</li>
80 * <li>Stores taxa for application session.</li>
81 * <li>Stores registries for colors, fonts, images.</li>
82 * </ul>
83 *
84 * @author p.ciardelli
85 * @created 15.05.2008
86 * @version 1.0
87 */
88 public class TaxEditorPlugin extends AbstractUIPlugin {
89 private static final Logger logger = Logger
90 .getLogger(TaxEditorPlugin.class);
91
92 /**
93 * The plug-in ID
94 */
95 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.plugin";
96 /**
97 * The shared instance
98 */
99 private static TaxEditorPlugin plugin;
100
101 // private DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
102 private DbSchemaValidation dbSchemaValidation = DbSchemaValidation.UPDATE;
103
104 /**
105 * The constructor
106 */
107 public TaxEditorPlugin() {
108 // logger.fatal("Fatal");
109 // logger.error("Error");
110 // logger.debug("Debug");
111 // logger.info("Info");
112 // logger.warn("Warn");
113 // logger.trace("Trace");
114 }
115
116 /*
117 * (non-Javadoc)
118 *
119 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
120 */
121 public void start(BundleContext context) throws Exception {
122 super.start(context);
123 plugin = this;
124
125 // If the preferences INITIALIZED has not been set, the IF clause
126 // will return false, i.e. datastore will be initialized first
127 // time the application is run after being installed.
128 boolean initialized = false;
129 if (getPreferenceStore()
130 .contains(ITaxEditorConstants.INITIALIZED)) {
131 initialized = getPreferenceStore().getBoolean(
132 ITaxEditorConstants.INITIALIZED);
133 }
134
135 if (!initialized) {
136
137 logger.warn("Initializing datastore");
138
139 dbSchemaValidation = DbSchemaValidation.CREATE;
140
141 if (getPreferenceStore().getBoolean(
142 ITaxEditorConstants.INITIALIZE_W_TESTDATA)) {
143 initDatastore();
144 getPreferenceStore().setValue(
145 ITaxEditorConstants.INITIALIZE_W_TESTDATA, false);
146 }
147
148 getPreferenceStore()
149 .setValue(ITaxEditorConstants.INITIALIZED, true);
150 }
151
152 cdmApp = getCdmApp();
153
154 Locale locale = new Locale("en", "", "icbn");
155 Locale.setDefault(locale);
156 }
157
158 /*
159 * (non-Javadoc)
160 *
161 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
162 */
163 public void stop(BundleContext context) throws Exception {
164 commitTransaction();
165 plugin = null;
166 super.stop(context);
167
168 disposeColors();
169 }
170
171 void initDatastore() {
172
173 boolean useSoraya = true;
174 // useSoraya = false;
175 Taxon genusTaxon;
176 if (useSoraya) {
177 genusTaxon = getSorayasGenusTaxon();
178 } else {
179
180 BotanicalName botanicalName = BotanicalName.NewInstance(Rank
181 .GENUS());
182 botanicalName.setTitleCache("Hieracium L.");
183 botanicalName.setGenusOrUninomial("Hieracium");
184 botanicalName.setCombinationAuthorTeam(Person.NewInstance());
185 botanicalName.getCombinationAuthorTeam()
186 .setNomenclaturalTitle("L.");
187 genusTaxon = Taxon.NewInstance(botanicalName, CdmUtil
188 .getSessionDefaultSec());
189
190 BotanicalName botSpecies = BotanicalName
191 .NewInstance(Rank.SPECIES());
192 botSpecies.setTitleCache("Hieracium asturianum Pau");
193 botSpecies.setGenusOrUninomial("Hieracium");
194 botSpecies.setSpecificEpithet("asturianum");
195 botSpecies.setCombinationAuthorTeam(Person.NewInstance());
196 botSpecies.getCombinationAuthorTeam().setNomenclaturalTitle("Pau");
197 Taxon childTaxon = Taxon.NewInstance(botSpecies, null);
198 childTaxon.setTaxonomicParent(genusTaxon, null, null);
199
200 BotanicalName botSpecies2 = BotanicalName.NewInstance(Rank
201 .SPECIES());
202 botSpecies2.setTitleCache("Hieracium wolffii Zahn");
203 botSpecies2.setGenusOrUninomial("Hieracium");
204 botSpecies2.setSpecificEpithet("wolffii");
205 botSpecies2.setCombinationAuthorTeam(Person.NewInstance());
206 botSpecies2.getCombinationAuthorTeam()
207 .setNomenclaturalTitle("Zahn");
208 Taxon childTaxon2 = Taxon.NewInstance(botSpecies2, CdmUtil
209 .getSessionDefaultSec());
210 // childTaxon2.setName(botSpecies2);
211 // childTaxon2.setSec(null);
212 childTaxon2.setTaxonomicParent(genusTaxon, null, null);
213
214 // Add some name relations to botSpecies2
215 botSpecies2.addRelationshipFromName(botSpecies,
216 NameRelationshipType.BASIONYM(), null);
217 botSpecies2.addRelationshipToName(botSpecies, NameRelationshipType
218 .REPLACED_SYNONYM(), null);
219 logger.warn("Name relations created");
220
221 // Add name status to botSpecies2
222 botSpecies2.addStatus(NomenclaturalStatus
223 .NewInstance(NomenclaturalStatusType.NOVUM()));
224 logger.warn("Nom. status created");
225 }
226
227 getCdmApp().getTaxonService().saveTaxon(genusTaxon);
228
229 // System.exit(-1);
230 }
231
232 /**
233 * Returns the shared instance
234 *
235 * @return the shared instance
236 */
237 public static TaxEditorPlugin getDefault() {
238 return plugin;
239 }
240
241 /***************************************************************************
242 * CDM SERVICES
243 **************************************************************************/
244 /**
245 * All CDM services are called via the application controller
246 */
247 private CdmApplicationController cdmApp;
248 private TransactionStatus txStatus;
249
250 public CdmApplicationController getCdmApp() {
251 if (cdmApp == null) {
252 try {
253 // cdmApp.getDatabaseService().getDatabaseEnum();
254 // cdmApp.getDatabaseService().saveDataSource(strDataSourceName, databaseTypeEnum, server, database, username, password)
255
256 // // Open ds by string
257 // CdmPersistentDataSource ds = CdmPersistentDataSource.NewInstance(dataSourceName)
258 //
259 // // Open default instance
260 // CdmPersistentDataSource ds = CdmPersistentDataSource.NewDefaultInstance();
261 //
262 // CdmPersistentDataSource.getAllDataSources();
263 //
264 // // Open CdmApp w default DB
265 // CdmApplicationController.NewInstance(dbSchemaValidation);
266
267 // System.exit(-1);
268
269 cdmDatasource =
270 CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "");
271 //// CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_editor_test1", "edit", "wp5");
272 //// CdmPersistentDataSource.NewLocalHsqlInstance();
273 cdmApp = CdmApplicationController
274 .NewInstance(cdmDatasource, dbSchemaValidation);
275
276 // cdmApp = CdmApplicationController.NewInstance(dbSchemaValidation);
277
278 startTransaction();
279
280 // cdmApp.commitTransaction((TransactionStatus) txStatus);
281
282 } catch (DataSourceNotFoundException e) {
283 // TODO Auto-generated catch block
284 e.printStackTrace();
285 } catch (TermNotFoundException e) {
286 // TODO Auto-generated catch block
287 e.printStackTrace();
288 }
289 }
290 return cdmApp;
291 }
292
293 public void startTransaction() {
294 if (cdmApp != null) {
295 txStatus = cdmApp.startTransaction();
296 }
297 }
298
299 public void commitTransaction() {
300 if (txStatus != null) {
301 cdmApp.commitTransaction(txStatus);
302 txStatus = null;
303 }
304 }
305
306 private ITaxonService taxonService;
307
308 public ITaxonService getTaxonService() {
309 if (taxonService == null) {
310 taxonService = getCdmApp().getTaxonService();
311 }
312 return taxonService;
313 }
314
315 private INameService nameService;
316
317 public INameService getNameService() {
318 if (nameService == null) {
319 nameService = getCdmApp().getNameService();
320 }
321 return nameService;
322 }
323
324 private IDescriptionService descriptionService;
325
326 public IDescriptionService getDescriptionService() {
327 if (descriptionService == null) {
328 descriptionService = getCdmApp().getDescriptionService();
329 }
330 return descriptionService;
331 }
332
333 private IReferenceService referenceService;
334
335 public IReferenceService getReferenceService() {
336 if (referenceService == null) {
337 referenceService = getCdmApp().getReferenceService();
338 }
339 return referenceService;
340 }
341
342 private List<ICdmDataSource> dataSources;
343
344 public List<ICdmDataSource> getDataSources() {
345 if (dataSources == null) {
346 dataSources = new ArrayList<ICdmDataSource>();
347 dataSources.add(CdmDataSource.
348 NewH2EmbeddedInstance("cdm", "sa", ""));
349 dataSources.add(CdmDataSource.
350 NewMySqlInstance("192.168.2.10", "cdm_editor_test1",
351 "edit", "wp5"));
352 }
353 return dataSources;
354 }
355
356 private ICdmDataSource cdmDatasource;
357
358 public ICdmDataSource getCdmDataSource() {
359 return cdmDatasource;
360 }
361
362 /***************************************************************************
363 * OBSERVABLE LISTS
364 **************************************************************************/
365
366 private WritableList observableRecentNamesList = null;
367 private WritableList observableFavoritesList = null;
368
369 public WritableList getObservableRecentNamesList() {
370 if (observableRecentNamesList == null) {
371 observableRecentNamesList = new WritableList();
372 }
373 return observableRecentNamesList;
374 }
375
376 public WritableList getObservableFavoritesList() {
377 if (observableFavoritesList == null) {
378 observableFavoritesList = new WritableList();
379 }
380 return observableFavoritesList;
381 }
382
383 /***************************************************************************
384 * IMAGE REGISTRY
385 **************************************************************************/
386 public ImageDescriptor getImageDescriptor(String key) {
387 return getImageRegistry().getDescriptor(key);
388 }
389
390 public Image getImage(String key) {
391 return getImageRegistry().get(key);
392 }
393
394 // Resource bundle.
395 private ResourceBundle resourceBundle;
396 private FormColors formColors;
397
398 protected void initializeImageRegistry(ImageRegistry registry) {
399 registerImage(registry, ITaxEditorConstants.EDIT_ICON, "edit_16x16.ico");
400 registerImage(registry, ITaxEditorConstants.WARNING_ICON,
401 "warn_tsk.gif");
402 registerImage(registry, ITaxEditorConstants.BLACK_SQUARE_ICON,
403 "accepted_small.gif");
404 registerImage(registry, ITaxEditorConstants.HOMOTYPIC_SYN_ICON,
405 "homosyn_no_bg.gif");
406 registerImage(registry,
407 ITaxEditorConstants.HOMOTYPIC_SYN_ORIGINAL_ICON,
408 "homosyn_original_no_bg.gif");
409 registerImage(registry, ITaxEditorConstants.HETEROTYPIC_SYN_ICON,
410 "heterosyn_no_bg.gif");
411 registerImage(registry,
412 ITaxEditorConstants.HETEROTYPIC_SYN_ORIGINAL_ICON,
413 "heterosyn_original_no_bg.gif");
414 registerImage(registry, ITaxEditorConstants.MISAPPLIED_NAME_ICON,
415 "misapplied_no_bg.gif");
416 registerImage(registry, ITaxEditorConstants.AUTONYM_ICON,
417 "autonym_no_bg.gif");
418 registerImage(registry, ITaxEditorConstants.BASIONYM_ICON,
419 "basionym_no_bg.gif");
420 registerImage(registry, ITaxEditorConstants.ORTHOGRAPHIC_VARIANT_ICON,
421 "orthovariant_no_bg.gif");
422 registerImage(registry, ITaxEditorConstants.DB_ICON, "db.gif");
423 registerImage(registry, ITaxEditorConstants.MOVE_ICON,
424 "correction_change.gif");
425 registerImage(registry, ITaxEditorConstants.ACTIVE_DELETE_ICON,
426 "delete_edit.gif");
427 registerImage(registry, ITaxEditorConstants.SYNONYM_TO_TAXON_ICON,
428 "change.gif");
429 registerImage(registry, ITaxEditorConstants.OPEN_TAXON_ICON, "open.gif");
430 registerImage(registry, ITaxEditorConstants.ADD_CHILD_TAXON_ICON,
431 "new_child.gif");
432 registerImage(registry,
433 ITaxEditorConstants.SWAP_SYNONYM_AND_TAXON_ICON, "swap2.gif");
434 registerImage(registry, ITaxEditorConstants.QUICK_ADD_ICON,
435 "quick_add.gif");
436 registerImage(registry, ITaxEditorConstants.TAXON_TO_SYNONYM_ICON,
437 "tax_to_syn.gif");
438 }
439
440 private void registerImage(ImageRegistry registry, String key,
441 String fileName) {
442 try {
443 IPath path = new Path("icons/" + fileName); //$NON-NLS-1$
444 URL url = FileLocator.find(getBundle(), path, null);
445 if (url != null) {
446 ImageDescriptor desc = ImageDescriptor.createFromURL(url);
447 registry.put(key, desc);
448 }
449 } catch (Exception e) {
450 }
451 }
452
453 /***************************************************************************
454 * FONT REGISTRY
455 **************************************************************************/
456 private FontRegistry fontRegistry;
457
458 private FontRegistry getFontRegistry() {
459 if (fontRegistry == null) {
460 fontRegistry = new FontRegistry(Display.getCurrent());
461
462 fontRegistry.put(ITaxEditorConstants.DATASOURCE_FONT,
463 new FontData[] { new FontData("Arial", 8, SWT.NONE) });
464 fontRegistry.put(ITaxEditorConstants.MENU_ITEM_ITALICS_FONT,
465 new FontData[] { new FontData("Arial", 9, SWT.ITALIC) });
466 fontRegistry.put(ITaxEditorConstants.ACCEPTED_TAXON_FONT,
467 new FontData[] { new FontData("Georgia", 12, SWT.NONE) });
468 fontRegistry.put(ITaxEditorConstants.SYNONYM_FONT,
469 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
470 fontRegistry.put(ITaxEditorConstants.MISAPPLIEDNAME_FONT,
471 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
472 fontRegistry.put(ITaxEditorConstants.CHOOSE_NAME_TEXT_FONT,
473 new FontData[] { new FontData("Arial", 12, SWT.BOLD) });
474 fontRegistry.put(ITaxEditorConstants.DEFAULT_PROMPT_FONT,
475 new FontData[] { new FontData("Georgia", 10, SWT.ITALIC) });
476 }
477 return fontRegistry;
478 }
479
480 public Font getFont(String key) {
481 return getFontRegistry().get(key);
482 }
483
484 /***************************************************************************
485 * COLOR MAP
486 **************************************************************************/
487 private static HashMap<String, Color> colorMap;
488
489 public Color getColor(String key) {
490 return getColorMap().get(key);
491 }
492
493 private HashMap<String, Color> getColorMap() {
494 if (colorMap == null) {
495 colorMap = new HashMap<String, Color>();
496
497 colorMap.put(ITaxEditorConstants.GROUP_GRAY_BKG_COLOR,
498 new Color(null, 240, 240, 240));
499 }
500 return colorMap;
501 }
502
503 private void disposeColors() {
504 if (colorMap == null) {
505 return;
506 }
507 for (Color color : colorMap.values()) {
508 color.dispose();
509 }
510 colorMap.clear();
511 }
512
513 /***************************************************************************
514 * TAXONOMIC TREE
515 **************************************************************************/
516
517 public ReferenceBase getSec() {
518 return getCdmApp().getReferenceService().getReferenceByUuid(
519 UUID.fromString("f3593c18-a8d2-4e51-bdad-0befbf8fb2d1"));
520 }
521
522 private Set<Taxon> sessionRootTaxa;
523 /**
524 * The taxonomic tree content provider observes this set for changes, and
525 * makes the appropriate changes to the tree.
526 */
527 private IObservableSet observableSessionTaxonSet;
528 /**
529 * This map of taxa to their taxonomic children is used by
530 * NameTreeContentProvider's getChildren method.
531 *
532 * key = taxon, value = key's child taxa Note that a map can have a key ==
533 * null, i.e. no parent taxon
534 */
535 private HashMap<Taxon, Set<Taxon>> sessionTaxonomicChildrenMap;
536
537 public Set<Taxon> getSessionRootTaxa() {
538 if (sessionRootTaxa == null) {
539
540 sessionRootTaxa = new HashSet<Taxon>();
541 // sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
542 // getSec(), null, false));
543 sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
544 getSec(), null, true));
545 addSessionTaxa(sessionRootTaxa);
546
547 }
548 return sessionRootTaxa;
549 }
550
551 private Map<Taxon, Set<Taxon>> getTaxonomicChildrenMap() {
552 if (sessionTaxonomicChildrenMap == null) {
553 sessionTaxonomicChildrenMap = new HashMap<Taxon, Set<Taxon>>();
554 }
555 return sessionTaxonomicChildrenMap;
556 }
557
558 /**
559 * Returns a set of any child taxa for this taxon that have already been
560 * requested during this session.
561 *
562 * @param parentTaxon
563 * @return
564 */
565 public Set<Taxon> getSessionTaxonomicChildren(Taxon parentTaxon) {
566 if (!getTaxonomicChildrenMap().containsKey(parentTaxon)) {
567 if (parentTaxon == null) {
568 getTaxonomicChildrenMap().put(parentTaxon, getSessionRootTaxa());
569 } else {
570
571 // BUG deleted taxon were re-appearing as NULL children
572 Set<Taxon> childTaxa = new HashSet<Taxon>();
573
574 // TransactionStatus tx = getCdmApp().startTransaction();
575 // getCdmApp().getTaxonService().saveTaxon(parentTaxon);
576 for (Taxon taxon : parentTaxon.getTaxonomicChildren()) {
577 if (taxon != null) {
578 childTaxa.add(taxon);
579 }
580 }
581 // getCdmApp().commitTransaction(tx);
582
583 getTaxonomicChildrenMap().put(parentTaxon, childTaxa);
584 }
585 }
586 return getTaxonomicChildrenMap().get(parentTaxon);
587 }
588
589 /**
590 * @return
591 */
592 public IObservableSet getObservableSessionTaxa() {
593 if (observableSessionTaxonSet == null) {
594 Realm realm = SWTObservables.getRealm(Display.getDefault());
595 observableSessionTaxonSet = new WritableSet(realm);
596 }
597 return observableSessionTaxonSet;
598 }
599
600 /**
601 * Recursive function to clear the hashmap of a taxon's children used in
602 * this session, and the childrens' children, etc.
603 *
604 * @param taxon
605 */
606 private void clearTaxonomicChildren(Taxon taxon) {
607 Set<Taxon> children = getSessionTaxonomicChildren(taxon);
608 if (children != null) {
609 for (Taxon child : children) {
610 clearTaxonomicChildren(child);
611 }
612 getTaxonomicChildrenMap().remove(taxon);
613 getObservableSessionTaxa().removeAll(children);
614 }
615 }
616
617 /**
618 * Remove taxon from all session collections
619 *
620 * @param taxon
621 */
622 public void removeSessionTaxon(Taxon taxon) {
623
624 // Recursively remove all children, children's children, etc.
625 clearTaxonomicChildren(taxon);
626
627 Taxon parentTaxon = taxon.getTaxonomicParent();
628
629 // Remove from parent's child map, or from root taxa
630 if (parentTaxon == null) {
631 getSessionRootTaxa().remove(taxon);
632 } else {
633 getSessionTaxonomicChildren(parentTaxon).remove(taxon);
634 }
635
636 // Remove from session taxa
637 getObservableSessionTaxa().remove(taxon);
638
639 UiUtil.getTreeViewer().remove(taxon);
640 }
641
642 public void addSessionTaxa(Collection<Taxon> taxa) {
643 for (Taxon taxon : taxa) {
644 addSessionTaxon(taxon);
645 }
646 }
647
648 /**
649 * Whenever a taxon is opened, either for editing or for display in the
650 * taxonomic tree, it should be added to the collections of taxa used during
651 * this session.
652 *
653 * @param taxon
654 */
655 public void addSessionTaxon(Taxon taxon) {
656
657 // Add taxon to session taxa if not already there
658 if (!(getObservableSessionTaxa().contains(taxon))) {
659 getObservableSessionTaxa().add(taxon);
660 }
661
662 Taxon parentTaxon = taxon.getTaxonomicParent();
663
664 // If taxon has no parent, add it to root taxa
665 if (parentTaxon == null) {
666 if (!(getSessionRootTaxa().contains(taxon))) {
667 getSessionRootTaxa().add(taxon);
668 }
669 }
670
671 // Add taxon to its parent's child map
672 getSessionTaxonomicChildren(parentTaxon).add(taxon);
673
674 TaxonomicTreeViewer viewer = UiUtil.getTreeViewer();
675
676 if (viewer != null) {
677
678 if (parentTaxon == null) {
679 viewer.setInput(getSessionRootTaxa());
680 } else {
681 viewer.add(parentTaxon, taxon);
682 }
683
684 }
685 }
686
687
688 // private TaxonomicTreeView taxonomicTreeView;
689 //
690 // public void setTaxonomicTree(TaxonomicTreeView taxonomicTreeView) {
691 // this.taxonomicTreeView = taxonomicTreeView;
692 // }
693
694 /***************************************************************************
695 * RANKS
696 **************************************************************************/
697 OrderedTermVocabulary<Rank> rankVocabulary = null;
698
699 public OrderedTermVocabulary<Rank> getRankVocabulary() {
700 if (rankVocabulary == null) {
701 rankVocabulary = getCdmApp().getNameService().getRankVocabulary();
702 }
703 return rankVocabulary;
704 }
705
706 /***************************************************************************
707 * NOMENCLATURAL STATUS
708 **************************************************************************/
709 TermVocabulary<NomenclaturalStatusType> nomStatusVocabulary = null;
710
711 public TermVocabulary<NomenclaturalStatusType> getNomStatusVocabulary() {
712 if (nomStatusVocabulary == null) {
713 nomStatusVocabulary = getCdmApp().getNameService()
714 .getStatusTypeVocabulary();
715 }
716 return nomStatusVocabulary;
717 }
718
719 /***************************************************************************
720 * NAME RELATIONS
721 **************************************************************************/
722 TermVocabulary<NameRelationshipType> nameRelationshipTypeVocabulary = null;
723
724 public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary() {
725 if (nameRelationshipTypeVocabulary == null) {
726 nameRelationshipTypeVocabulary = getCdmApp().getNameService()
727 .getNameRelationshipTypeVocabulary();
728 }
729 return nameRelationshipTypeVocabulary;
730 }
731
732 public Set<NameRelationshipType> getSortedNameRelationshipTypes() {
733 return getNameRelationshipTypeVocabulary().getTermsOrderedByLabels(
734 Language.DEFAULT());
735 }
736
737 /***************************************************************************
738 * SORAYA DATA
739 **************************************************************************/
740 private Taxon getSorayasGenusTaxon() {
741
742 String[] children = new String[] {
743 "Heterospathe annectens H.E.Moore",
744 "Heterospathe arfakiana (Becc.) H.E.Moore",
745 "Heterospathe brevicaulis Fernando",
746 "Heterospathe cagayanensis Becc.",
747 "Heterospathe califrons Fernando, Palms 45: 118 (2001).",
748 "Heterospathe clemensiae (Burret) H.E.Moore",
749 "Heterospathe delicatula H.E.Moore",
750 "Heterospathe dransfieldii Fernando",
751 "Heterospathe elata Scheff.",
752 "Heterospathe elata var. elata.",
753 "Heterospathe elata var. guamensis Becc.",
754 "Heterospathe elata var. palauensis (Becc.) Becc.",
755 "Heterospathe elegans (Becc.) Becc.",
756 "Heterospathe elmeri Becc.",
757 "Heterospathe glabra (Burret) H.E.Moore",
758 "Heterospathe glauca (Scheff.) H.E.Moore",
759 "Heterospathe humilis Becc.",
760 "Heterospathe intermedia (Becc.) Fernando",
761 "Heterospathe kajewskii Burret",
762 "Heterospathe ledermanniana Becc.",
763 "Heterospathe lepidota H.E.Moore",
764 "Heterospathe longipes (H.E.Moore) Norup",
765 "Heterospathe macgregorii (Becc.) H.E.Moore",
766 "Heterospathe micrantha (Becc.) H.E.Moore",
767 "Heterospathe minor Burret",
768 "Heterospathe muelleriana (Becc.) Becc.",
769 "Heterospathe negrosensis Becc.",
770 "Heterospathe obriensis (Becc.) H.E.Moore",
771 "Heterospathe palauensis Becc.",
772 "Heterospathe parviflora Essig",
773 "Heterospathe philippinensis (Becc.) Becc.",
774 // "Heterospathe phillipsii D.Fuller & Dowe", // <--------------
775 "Heterospathe pilosa (Burret) Burret",
776 "Heterospathe pisifera (Gaertn.) Burret",
777 "Heterospathe pulchra H.E.Moore",
778 "Heterospathe ramulosa Burret",
779 "Heterospathe salomonensis Becc.",
780 "Heterospathe scitula Fernando", "Heterospathe sensisi Becc.",
781 "Heterospathe sibuyanensis Becc.",
782 "Heterospathe sphaerocarpa Burret",
783 "Heterospathe trispatha Fernando",
784 "Heterospathe uniformis Dowe",
785 "Heterospathe versteegiana Becc.",
786 "Heterospathe woodfordiana Becc." };
787
788 BotanicalName genusName = BotanicalName
789 .PARSED_NAME("Heterospathe Scheff.");
790
791 Taxon genusTaxon = Taxon.NewInstance(genusName, CdmUtil
792 .getSessionDefaultSec());
793
794 for (String child : children) {
795 BotanicalName speciesName = BotanicalName.PARSED_NAME(child);
796
797 Taxon childTaxon = Taxon.NewInstance(speciesName, CdmUtil
798 .getSessionDefaultSec());
799 childTaxon.setTaxonomicParent(genusTaxon, null, null);
800
801 if (child.equals("Heterospathe elegans (Becc.) Becc.")) {
802 BotanicalName basionym = BotanicalName
803 .PARSED_NAME("Barkerwebbia elegans Becc.");
804 speciesName.addRelationshipFromName(basionym,
805 NameRelationshipType.BASIONYM(), null);
806 childTaxon.addHomotypicSynonymName(basionym, null, null);
807 }
808
809 if (child.equals("Heterospathe humilis Becc.")) {
810 BotanicalName synonymName = BotanicalName
811 .PARSED_NAME("Barkerwebbia humilis (Becc.) Becc. ex Martelli");
812 childTaxon.addHomotypicSynonymName(synonymName, null, null);
813 }
814 }
815
816 return genusTaxon;
817 }
818
819 /***************************************************************************
820 * PROPERTY SHEET
821 **************************************************************************/
822
823 private Tree propertySheetTree;
824
825 public void setPropertySheetTree(Tree tree) {
826 this.propertySheetTree = tree;
827 }
828
829 public Tree getPropertySheetTree() {
830 return propertySheetTree;
831 }
832
833 private PropertySheetPage propertySheetPage;
834
835 public void setPropertySheetPage(PropertySheetPage page) {
836 this.propertySheetPage = page;
837 }
838
839 public PropertySheetPage getPropertySheetPage() {
840 return propertySheetPage;
841 }
842 }