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
.controller
.EditorController
;
29 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
30 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
31 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
32 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeHomotypicGroupOperation
;
33 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeSynonymToConceptOperation
;
34 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeSynonymToMisappliedNameOperation
;
35 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeSynonymToTaxonOperation
;
36 import eu
.etaxonomy
.taxeditor
.operations
.name
.MakeSynonymAcceptedOperation
;
37 import eu
.etaxonomy
.taxeditor
.operations
.name
.MakeSynonymGroupBasionymOperation
;
38 import eu
.etaxonomy
.taxeditor
.operations
.name
.RemoveSynonymOperation
;
39 import eu
.etaxonomy
.taxeditor
.operations
.name
.UnmakeSynonymGroupBasionymOperation
;
40 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.TaxonBasePropertySource
;
47 public class SynonymComposite
extends NameComposite
{
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
50 .getLogger(SynonymComposite
.class);
52 private Synonym synonym
;
54 private IUndoContext undoContext
;
56 public SynonymComposite(Composite parent
, IManagedForm form
,
57 Taxon taxon
, Synonym synonym
) {
58 super(parent
, form
, null, synonym
);
61 this.synonym
= synonym
;
63 this.undoContext
= EditorController
.getUndoContext(taxon
);
66 setFont(getViewerFont());
67 setIndent(SYNONYM_INDENT
);
70 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
71 setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
);
73 setIcon(HOMOTYPIC_SYNONYM_ICON
);
76 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
77 setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
);
79 setIcon(HETEROTYPIC_SYNONYM_ICON
);
85 initNameViewer(synonym
);
88 private boolean isHomotypic() {
89 HomotypicalGroup group
= synonym
.getHomotypicGroup();
90 return group
.equals(taxon
.getHomotypicGroup());
93 public Synonym
getSynonym() {
97 public boolean setParent(Composite parent
) {
99 if (super.setParent(parent
)) {
101 // Has this been moved to the misapplied names group?
102 if (parent
instanceof MisappliedGroupComposite
) {
104 IUndoableOperation operation
= new ChangeSynonymToMisappliedNameOperation
105 ("change to misapplication", undoContext
, taxon
, synonym
); //$NON-NLS-1$
107 GlobalController
.executeOperation(operation
);
110 // Has this been moved to a HomotypicalGroup?
111 if (parent
instanceof HomotypicalGroupComposite
) {
113 HomotypicalGroup homotypicalGroup
=
114 ((HomotypicalGroupComposite
)parent
).getGroup();
116 // Make sure we are not dropping synonym on its own group
117 if (homotypicalGroup
.equals(synonym
.getHomotypicGroup())) {
121 IUndoableOperation operation
= new ChangeHomotypicGroupOperation
122 ("change type", undoContext
, taxon
, synonym
, homotypicalGroup
); //$NON-NLS-1$
124 GlobalController
.executeOperation(operation
);
133 * @param nameComposite
135 private void createMenu() {
137 ContextMenu contextMenu
= createContextMenu();
139 // Change composite to a misapplied name
140 String text
= "Change synonym to misapplied name"; //$NON-NLS-1$
141 ImageDescriptor image
= TaxEditorPlugin
.getDefault()
142 .getImageDescriptor(ITaxEditorConstants
.MISAPPLIED_NAME_ICON
);
143 contextMenu
.addAction(new Action(text
, image
){
146 IUndoableOperation operation
= new ChangeSynonymToMisappliedNameOperation
147 (this.getText(), undoContext
, taxon
, synonym
);
149 GlobalController
.executeOperation(operation
);
153 // Change synonym to conccept relation
154 text
= "Change synonym to concept relation"; //$NON-NLS-1$
155 image
= TaxEditorPlugin
.getDefault()
156 .getImageDescriptor(ITaxEditorConstants
.CONCEPT_ICON
);
158 contextMenu
.addAction(new Action(text
, image
){
161 IUndoableOperation operation
= new ChangeSynonymToConceptOperation
162 (this.getText(), undoContext
, taxon
, synonym
);
164 GlobalController
.executeOperation(operation
);
169 text
= "Remove synonym from taxon"; //$NON-NLS-1$
170 image
= TaxEditorPlugin
.getDefault()
171 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
172 contextMenu
.addAction(new Action(text
, image
){
175 IUndoableOperation operation
= new RemoveSynonymOperation
176 (this.getText(), undoContext
, taxon
, synonym
);
178 GlobalController
.executeOperation(operation
);
183 contextMenu
.addSeparator();
185 // Make the synonym the basionym of the homotypic group
186 text
= Messages
.getString
187 ("AddBasionymCompositeAction.0", synonym
.getName()); //$NON-NLS-1$
188 image
= TaxEditorPlugin
.getDefault()
189 .getImageDescriptor(ITaxEditorConstants
.BASIONYM_ICON
);
190 Action makeBasionymAction
= new Action(text
, image
){
193 IUndoableOperation operation
= new MakeSynonymGroupBasionymOperation
194 (this.getText(), undoContext
, taxon
, synonym
);
196 GlobalController
.executeOperation(operation
);
199 contextMenu
.addAction(makeBasionymAction
);
201 // Action to remove the composite as basionym of the homotypic group
202 text
= Messages
.getString
203 ("RemoveBasionymCompositeAction.0", synonym
.getName()); //$NON-NLS-1$
204 image
= TaxEditorPlugin
.getDefault()
205 .getImageDescriptor(ITaxEditorConstants
.BASIONYM_ICON
);
206 Action unmakeBasionymAction
= new Action(text
, image
){
209 IUndoableOperation operation
= new UnmakeSynonymGroupBasionymOperation
210 (this.getText(), undoContext
, taxon
, synonym
);
212 GlobalController
.executeOperation(operation
);
215 contextMenu
.addAction(unmakeBasionymAction
);
217 if (CdmUtil
.isNameGroupBasionym(synonym
.getName())) {
219 // Gray out action for "make synonym group basionym"
220 makeBasionymAction
.setEnabled(false);
223 // Gray out action for "unmake synonym group basionym"
224 unmakeBasionymAction
.setEnabled(false);
228 contextMenu
.addSeparator();
230 // Change this synonym to the taxon's accepted name
231 text
= "Make synonym this taxon's accepted taxon"; //$NON-NLS-1$
232 image
= TaxEditorPlugin
.getDefault()
233 .getImageDescriptor(ITaxEditorConstants
.SWAP_SYNONYM_AND_TAXON_ICON
);
234 Action swapAction
= new Action(text
, image
){
237 IUndoableOperation operation
= new MakeSynonymAcceptedOperation
238 (this.getText(), undoContext
, taxon
, synonym
);
240 GlobalController
.executeOperation(operation
);
243 contextMenu
.addAction(swapAction
);
244 // TODO fix operation
245 swapAction
.setEnabled(false);
247 // Make a new taxon with this synonym as the accepted name
248 text
= "Use synonym name to make a new taxon"; //$NON-NLS-1$
249 image
= TaxEditorPlugin
.getDefault()
250 .getImageDescriptor(ITaxEditorConstants
.SYNONYM_TO_TAXON_ICON
);
252 contextMenu
.addAction(new Action(text
, image
){
255 IUndoableOperation operation
= new ChangeSynonymToTaxonOperation
256 (this.getText(), undoContext
, taxon
, synonym
);
258 GlobalController
.executeOperation(operation
);
264 // public IPropertySource getPropertySource() {
265 // if (getSynonym() == null) {
268 // return getPropertySourceByName(getSynonym().getName());
271 public IPropertySource
getPropertySource() {
272 return new TaxonBasePropertySource(synonym
, "Synonym Name");
276 protected Font
getViewerFont() {
281 protected TaxonNameBase
getName() {
282 return synonym
.getName();