3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.description
.handler
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.swt
.widgets
.Event
;
23 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
24 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
25 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
26 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
27 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
30 import eu
.etaxonomy
.taxeditor
.editor
.description
.DescriptionLabelComposite
;
31 import eu
.etaxonomy
.taxeditor
.editor
.description
.DistributionDialog
;
32 import eu
.etaxonomy
.taxeditor
.editor
.description
.LanguageDialog
;
33 import eu
.etaxonomy
.taxeditor
.editor
.description
.TaxonDescriptionEditor
;
34 import eu
.etaxonomy
.taxeditor
.store
.operations
.CreateDescriptionElementOperation
;
41 public class CreateDescriptionElementHandler
extends AbstractHandler
{
42 private static final Logger logger
= Logger
43 .getLogger(CreateDescriptionElementHandler
.class);
45 private DescriptionElementBase element
;
48 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
51 TaxonDescriptionEditor editor
= (TaxonDescriptionEditor
) EditorUtil
.getActiveEditorPage(
54 Feature feature
= (Feature
) ((Event
)event
.getTrigger()).data
;
56 // FIXME right now we have only one description per taxon
57 // this will change in the future and then attaching the feature to
58 // the firstGroupedComposite will not work anymore
59 TaxonDescription description
= ((DescriptionLabelComposite
)editor
.getFirstGroupedComposite()).getDescription();
61 if (getElementUserInput(feature
).equals(Status
.OK_STATUS
)) {
62 IUndoableOperation operation
;
64 operation
= new CreateDescriptionElementOperation(event
.getCommand().getName(),
65 editor
.getUndoContext(), editor
.getTaxon(), description
, feature
, element
, editor
);
66 EditorUtil
.executeOperation(operation
);
67 } catch (NotDefinedException e
) {
68 logger
.warn("Command name not set");
75 * Some element types require input via the UI - initialize these here
80 private IStatus
getElementUserInput(Feature feature
) {
82 // Remove object from last execution from element
85 // -------------- Common name -------------- //
86 if (feature
.supportsCommonTaxonName()) {
87 Language language
= LanguageDialog
.getLanguage
88 ("Select language", "Select the common name's language:");
89 if (language
== null) {
90 return Status
.CANCEL_STATUS
;
92 element
= CommonTaxonName
.NewInstance("", language
);
93 // Feature must be explicitly set to sync w term in persistence layer
94 element
.setFeature(feature
);
97 // -------------- Distribution -------------- //
98 if (feature
.supportsDistribution()) {
99 element
= DistributionDialog
.getDistribution
100 ("Create distribution", null);
101 if (element
== null) {
102 return Status
.CANCEL_STATUS
;
104 // Feature must be explicitly set to sync w term in persistence layer
105 element
.setFeature(feature
);
108 return Status
.OK_STATUS
;