<CR> in name relation - select name now the same as clicking the "Search" button.
[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 colorMap.put(ITaxEditorConstants.PROP_SHEET_RED,
500 new Color(null, 255, 0, 0));
501 }
502 return colorMap;
503 }
504
505 private void disposeColors() {
506 if (colorMap == null) {
507 return;
508 }
509 for (Color color : colorMap.values()) {
510 color.dispose();
511 }
512 colorMap.clear();
513 }
514
515 /***************************************************************************
516 * TAXONOMIC TREE
517 **************************************************************************/
518
519 public ReferenceBase getSec() {
520 return getCdmApp().getReferenceService().getReferenceByUuid(
521 UUID.fromString("f3593c18-a8d2-4e51-bdad-0befbf8fb2d1"));
522 }
523
524 private Set<Taxon> sessionRootTaxa;
525 /**
526 * The taxonomic tree content provider observes this set for changes, and
527 * makes the appropriate changes to the tree.
528 */
529 private IObservableSet observableSessionTaxonSet;
530 /**
531 * This map of taxa to their taxonomic children is used by
532 * NameTreeContentProvider's getChildren method.
533 *
534 * key = taxon, value = key's child taxa Note that a map can have a key ==
535 * null, i.e. no parent taxon
536 */
537 private HashMap<Taxon, Set<Taxon>> sessionTaxonomicChildrenMap;
538
539 public Set<Taxon> getSessionRootTaxa() {
540 if (sessionRootTaxa == null) {
541
542 sessionRootTaxa = new HashSet<Taxon>();
543 // sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
544 // getSec(), null, false));
545 sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
546 getSec(), null, true));
547 addSessionTaxa(sessionRootTaxa);
548
549 }
550 return sessionRootTaxa;
551 }
552
553 private Map<Taxon, Set<Taxon>> getTaxonomicChildrenMap() {
554 if (sessionTaxonomicChildrenMap == null) {
555 sessionTaxonomicChildrenMap = new HashMap<Taxon, Set<Taxon>>();
556 }
557 return sessionTaxonomicChildrenMap;
558 }
559
560 /**
561 * Returns a set of any child taxa for this taxon that have already been
562 * requested during this session.
563 *
564 * @param parentTaxon
565 * @return
566 */
567 public Set<Taxon> getSessionTaxonomicChildren(Taxon parentTaxon) {
568 if (!getTaxonomicChildrenMap().containsKey(parentTaxon)) {
569 if (parentTaxon == null) {
570 getTaxonomicChildrenMap().put(parentTaxon, getSessionRootTaxa());
571 } else {
572
573 // BUG deleted taxon were re-appearing as NULL children
574 Set<Taxon> childTaxa = new HashSet<Taxon>();
575
576 // TransactionStatus tx = getCdmApp().startTransaction();
577 // getCdmApp().getTaxonService().saveTaxon(parentTaxon);
578 for (Taxon taxon : parentTaxon.getTaxonomicChildren()) {
579 if (taxon != null) {
580 childTaxa.add(taxon);
581 }
582 }
583 // getCdmApp().commitTransaction(tx);
584
585 getTaxonomicChildrenMap().put(parentTaxon, childTaxa);
586 }
587 }
588 return getTaxonomicChildrenMap().get(parentTaxon);
589 }
590
591 /**
592 * @return
593 */
594 public IObservableSet getObservableSessionTaxa() {
595 if (observableSessionTaxonSet == null) {
596 Realm realm = SWTObservables.getRealm(Display.getDefault());
597 observableSessionTaxonSet = new WritableSet(realm);
598 }
599 return observableSessionTaxonSet;
600 }
601
602 /**
603 * Recursive function to clear the hashmap of a taxon's children used in
604 * this session, and the childrens' children, etc.
605 *
606 * @param taxon
607 */
608 private void clearTaxonomicChildren(Taxon taxon) {
609 Set<Taxon> children = getSessionTaxonomicChildren(taxon);
610 if (children != null) {
611 for (Taxon child : children) {
612 clearTaxonomicChildren(child);
613 }
614 getTaxonomicChildrenMap().remove(taxon);
615 getObservableSessionTaxa().removeAll(children);
616 }
617 }
618
619 /**
620 * Remove taxon from all session collections
621 *
622 * @param taxon
623 */
624 public void removeSessionTaxon(Taxon taxon) {
625
626 // Recursively remove all children, children's children, etc.
627 clearTaxonomicChildren(taxon);
628
629 Taxon parentTaxon = taxon.getTaxonomicParent();
630
631 // Remove from parent's child map, or from root taxa
632 if (parentTaxon == null) {
633 getSessionRootTaxa().remove(taxon);
634 } else {
635 getSessionTaxonomicChildren(parentTaxon).remove(taxon);
636 }
637
638 // Remove from session taxa
639 getObservableSessionTaxa().remove(taxon);
640
641 UiUtil.getTreeViewer().remove(taxon);
642 }
643
644 public void addSessionTaxa(Collection<Taxon> taxa) {
645 for (Taxon taxon : taxa) {
646 addSessionTaxon(taxon);
647 }
648 }
649
650 /**
651 * Whenever a taxon is opened, either for editing or for display in the
652 * taxonomic tree, it should be added to the collections of taxa used during
653 * this session.
654 *
655 * @param taxon
656 */
657 public void addSessionTaxon(Taxon taxon) {
658
659 // Add taxon to session taxa if not already there
660 if (!(getObservableSessionTaxa().contains(taxon))) {
661 getObservableSessionTaxa().add(taxon);
662 }
663
664 Taxon parentTaxon = taxon.getTaxonomicParent();
665
666 // If taxon has no parent, add it to root taxa
667 if (parentTaxon == null) {
668 if (!(getSessionRootTaxa().contains(taxon))) {
669 getSessionRootTaxa().add(taxon);
670 }
671 }
672
673 // Add taxon to its parent's child map
674 getSessionTaxonomicChildren(parentTaxon).add(taxon);
675
676 TaxonomicTreeViewer viewer = UiUtil.getTreeViewer();
677
678 if (viewer != null) {
679
680 if (parentTaxon == null) {
681 viewer.setInput(getSessionRootTaxa());
682 } else {
683 viewer.add(parentTaxon, taxon);
684 }
685
686 }
687 }
688
689
690 // private TaxonomicTreeView taxonomicTreeView;
691 //
692 // public void setTaxonomicTree(TaxonomicTreeView taxonomicTreeView) {
693 // this.taxonomicTreeView = taxonomicTreeView;
694 // }
695
696 /***************************************************************************
697 * RANKS
698 **************************************************************************/
699 OrderedTermVocabulary<Rank> rankVocabulary = null;
700
701 public OrderedTermVocabulary<Rank> getRankVocabulary() {
702 if (rankVocabulary == null) {
703 rankVocabulary = getCdmApp().getNameService().getRankVocabulary();
704 }
705 return rankVocabulary;
706 }
707
708 /***************************************************************************
709 * NOMENCLATURAL STATUS
710 **************************************************************************/
711 TermVocabulary<NomenclaturalStatusType> nomStatusVocabulary = null;
712
713 public TermVocabulary<NomenclaturalStatusType> getNomStatusVocabulary() {
714 if (nomStatusVocabulary == null) {
715 nomStatusVocabulary = getCdmApp().getNameService()
716 .getStatusTypeVocabulary();
717 }
718 return nomStatusVocabulary;
719 }
720
721 /***************************************************************************
722 * NAME RELATIONS
723 **************************************************************************/
724 TermVocabulary<NameRelationshipType> nameRelationshipTypeVocabulary = null;
725
726 public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary() {
727 if (nameRelationshipTypeVocabulary == null) {
728 nameRelationshipTypeVocabulary = getCdmApp().getNameService()
729 .getNameRelationshipTypeVocabulary();
730 }
731 return nameRelationshipTypeVocabulary;
732 }
733
734 public Set<NameRelationshipType> getSortedNameRelationshipTypes() {
735 return getNameRelationshipTypeVocabulary().getTermsOrderedByLabels(
736 Language.DEFAULT());
737 }
738
739 /***************************************************************************
740 * SORAYA DATA
741 **************************************************************************/
742 private Taxon getSorayasGenusTaxon() {
743
744 String[] children = new String[] {
745 "Heterospathe annectens H.E.Moore",
746 "Heterospathe arfakiana (Becc.) H.E.Moore",
747 "Heterospathe brevicaulis Fernando",
748 "Heterospathe cagayanensis Becc.",
749 "Heterospathe califrons Fernando, Palms 45: 118 (2001).",
750 "Heterospathe clemensiae (Burret) H.E.Moore",
751 "Heterospathe delicatula H.E.Moore",
752 "Heterospathe dransfieldii Fernando",
753 "Heterospathe elata Scheff.",
754 "Heterospathe elata var. elata.",
755 "Heterospathe elata var. guamensis Becc.",
756 "Heterospathe elata var. palauensis (Becc.) Becc.",
757 "Heterospathe elegans (Becc.) Becc.",
758 "Heterospathe elmeri Becc.",
759 "Heterospathe glabra (Burret) H.E.Moore",
760 "Heterospathe glauca (Scheff.) H.E.Moore",
761 "Heterospathe humilis Becc.",
762 "Heterospathe intermedia (Becc.) Fernando",
763 "Heterospathe kajewskii Burret",
764 "Heterospathe ledermanniana Becc.",
765 "Heterospathe lepidota H.E.Moore",
766 "Heterospathe longipes (H.E.Moore) Norup",
767 "Heterospathe macgregorii (Becc.) H.E.Moore",
768 "Heterospathe micrantha (Becc.) H.E.Moore",
769 "Heterospathe minor Burret",
770 "Heterospathe muelleriana (Becc.) Becc.",
771 "Heterospathe negrosensis Becc.",
772 "Heterospathe obriensis (Becc.) H.E.Moore",
773 "Heterospathe palauensis Becc.",
774 "Heterospathe parviflora Essig",
775 "Heterospathe philippinensis (Becc.) Becc.",
776 // "Heterospathe phillipsii D.Fuller & Dowe", // <--------------
777 "Heterospathe pilosa (Burret) Burret",
778 "Heterospathe pisifera (Gaertn.) Burret",
779 "Heterospathe pulchra H.E.Moore",
780 "Heterospathe ramulosa Burret",
781 "Heterospathe salomonensis Becc.",
782 "Heterospathe scitula Fernando", "Heterospathe sensisi Becc.",
783 "Heterospathe sibuyanensis Becc.",
784 "Heterospathe sphaerocarpa Burret",
785 "Heterospathe trispatha Fernando",
786 "Heterospathe uniformis Dowe",
787 "Heterospathe versteegiana Becc.",
788 "Heterospathe woodfordiana Becc." };
789
790 BotanicalName genusName = BotanicalName
791 .PARSED_NAME("Heterospathe Scheff.");
792
793 Taxon genusTaxon = Taxon.NewInstance(genusName, CdmUtil
794 .getSessionDefaultSec());
795
796 for (String child : children) {
797 BotanicalName speciesName = BotanicalName.PARSED_NAME(child);
798
799 Taxon childTaxon = Taxon.NewInstance(speciesName, CdmUtil
800 .getSessionDefaultSec());
801 childTaxon.setTaxonomicParent(genusTaxon, null, null);
802
803 if (child.equals("Heterospathe elegans (Becc.) Becc.")) {
804 BotanicalName basionym = BotanicalName
805 .PARSED_NAME("Barkerwebbia elegans Becc.");
806 speciesName.addRelationshipFromName(basionym,
807 NameRelationshipType.BASIONYM(), null);
808 childTaxon.addHomotypicSynonymName(basionym, null, null);
809 }
810
811 if (child.equals("Heterospathe humilis Becc.")) {
812 BotanicalName synonymName = BotanicalName
813 .PARSED_NAME("Barkerwebbia humilis (Becc.) Becc. ex Martelli");
814 childTaxon.addHomotypicSynonymName(synonymName, null, null);
815 }
816 }
817
818 return genusTaxon;
819 }
820
821 /***************************************************************************
822 * PROPERTY SHEET
823 **************************************************************************/
824
825 private Tree propertySheetTree;
826
827 public void setPropertySheetTree(Tree tree) {
828 this.propertySheetTree = tree;
829 }
830
831 public Tree getPropertySheetTree() {
832 return propertySheetTree;
833 }
834
835 private PropertySheetPage propertySheetPage;
836
837 public void setPropertySheetPage(PropertySheetPage page) {
838 this.propertySheetPage = page;
839 }
840
841 public PropertySheetPage getPropertySheetPage() {
842 return propertySheetPage;
843 }
844 }