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
.editor
.name
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.swt
.graphics
.Font
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.ui
.forms
.IManagedForm
;
20 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
22 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
27 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
28 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SwapSynonymAndTaxonAction
;
29 import eu
.etaxonomy
.taxeditor
.actions
.name
.ChangeSynonymToConceptRelationAction
;
30 import eu
.etaxonomy
.taxeditor
.actions
.name
.ChangeSynonymToMisapplicationAction
;
31 import eu
.etaxonomy
.taxeditor
.actions
.name
.CreateSynonymInGroupAction
;
32 import eu
.etaxonomy
.taxeditor
.actions
.name
.CreateNewTaxonFromSynonymAction
;
33 import eu
.etaxonomy
.taxeditor
.actions
.name
.MakeBasionymAction
;
34 import eu
.etaxonomy
.taxeditor
.actions
.name
.Messages
;
35 import eu
.etaxonomy
.taxeditor
.actions
.name
.RemoveSynonymAction
;
36 import eu
.etaxonomy
.taxeditor
.actions
.name
.UnmakeBasionymAction
;
37 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
38 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
39 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
40 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
41 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeHomotypicGroupOperation
;
42 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeSynonymToMisappliedNameOperation
;
43 import eu
.etaxonomy
.taxeditor
.operations
.name
.UnmakeSynonymGroupBasionymOperation
;
44 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.TaxonBasePropertySource
;
51 public class SynonymComposite
extends NameComposite
{
52 @SuppressWarnings("unused")
53 private static final Logger logger
= Logger
54 .getLogger(SynonymComposite
.class);
56 private Synonym synonym
;
58 private IUndoContext undoContext
;
60 public SynonymComposite(Composite parent
, IManagedForm form
,
61 Taxon taxon
, Synonym synonym
) {
62 super(parent
, form
, synonym
);
65 this.synonym
= synonym
;
67 this.undoContext
= EditorController
.getUndoContext(taxon
);
70 setFont(getViewerFont());
71 setIndent(SYNONYM_INDENT
);
74 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
75 setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
);
77 setIcon(HOMOTYPIC_SYNONYM_ICON
);
80 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
81 setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
);
83 setIcon(HETEROTYPIC_SYNONYM_ICON
);
89 initTextViewer(synonym
);
92 private boolean isHomotypic() {
93 HomotypicalGroup group
= synonym
.getHomotypicGroup();
94 return group
.equals(taxon
.getHomotypicGroup());
97 public Synonym
getSynonym() {
101 public boolean setParent(Composite parent
) {
103 if (super.setParent(parent
)) {
105 // Has this been moved to the misapplied names group?
106 if (parent
instanceof MisappliedGroupComposite
) {
108 IUndoableOperation operation
= new ChangeSynonymToMisappliedNameOperation
109 ("change to misapplication", undoContext
, taxon
, synonym
); //$NON-NLS-1$
111 GlobalController
.executeOperation(operation
);
114 // Has this been moved to a HomotypicalGroup?
115 if (parent
instanceof HomotypicalGroupComposite
) {
117 HomotypicalGroup homotypicalGroup
=
118 ((HomotypicalGroupComposite
)parent
).getGroup();
120 // Make sure we are not dropping synonym on its own group
121 if (homotypicalGroup
.equals(synonym
.getHomotypicGroup())) {
125 IUndoableOperation operation
= new ChangeHomotypicGroupOperation
126 ("change type", undoContext
, taxon
, synonym
, homotypicalGroup
); //$NON-NLS-1$
128 GlobalController
.executeOperation(operation
);
137 * @param nameComposite
139 private void createMenu() {
141 ContextMenu contextMenu
= createContextMenu();
143 contextMenu
.addAction(new RemoveSynonymAction(taxon
, synonym
));
144 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
145 contextMenu
.addAction(new UnmakeBasionymAction(taxon
, synonym
));
147 contextMenu
.addAction(new MakeBasionymAction(taxon
, synonym
));
149 // Add synonym to this synonyms homotypical group
150 // FIXME not working with the new menu action
151 // contextMenu.addAction(new CreateSynonymInGroupAction(synonym.getHomotypicGroup()));
152 contextMenu
.addSeparator();
153 contextMenu
.addAction(new ChangeSynonymToMisapplicationAction(taxon
, synonym
));
154 contextMenu
.addAction(new ChangeSynonymToConceptRelationAction(taxon
, synonym
));
155 contextMenu
.addSeparator();
156 // Change this synonym to the taxon's accepted name
157 Action swapAction
= new SwapSynonymAndTaxonAction(taxon
, synonym
);
158 contextMenu
.addAction(swapAction
);
159 // TODO fix operation
160 swapAction
.setEnabled(false);
162 // Make a new taxon with this synonym as the accepted name
163 contextMenu
.addAction(new CreateNewTaxonFromSynonymAction(taxon
, synonym
));
167 public IPropertySource
getPropertySource() {
168 return new TaxonBasePropertySource(synonym
, "Synonym Name");
172 protected Font
getViewerFont() {
177 protected TaxonNameBase
getName() {
178 return synonym
.getName();
181 public Object
getData () {