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
.taxon
.Taxon
;
24 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
25 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
26 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
27 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
28 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
29 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeMisappliedNameToSynonymOperation
;
30 import eu
.etaxonomy
.taxeditor
.operations
.name
.RemoveMisappliedNameOperation
;
31 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.TaxonBasePropertySource
;
38 public class MisappliedNameComposite
extends NameComposite
{
39 private static final Logger logger
= Logger
40 .getLogger(MisappliedNameComposite
.class);
42 private Taxon misappliedName
;
44 public MisappliedNameComposite(Composite parent
, IManagedForm form
,
45 Taxon taxon
, Taxon misappliedName
) {
46 super(parent
, form
, NameComposite
.MISAPPLIED_NAME
, misappliedName
);
49 this.misappliedName
= misappliedName
;
52 setIcon(MISAPPLIEDNAME_ICON
);
53 setFont(getViewerFont());
54 setIndent(MISAPPLIEDNAME_INDENT
);
58 initNameViewer(misappliedName
);
61 public Taxon
getMisappliedName() {
62 return misappliedName
;
65 private void createMenu() {
67 ContextMenu contextMenu
= createContextMenu();
69 final IUndoContext undoContext
= EditorController
.getUndoContext(taxon
);
71 // Remove misapplied name from taxon
72 String text
= "Remove misapplied name from taxon"; //$NON-NLS-1$
73 ImageDescriptor image
= TaxEditorPlugin
.getDefault()
74 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
75 contextMenu
.addAction(new Action(text
, image
){
78 IUndoableOperation operation
= new RemoveMisappliedNameOperation
79 (this.getText(), undoContext
, taxon
, misappliedName
);
81 GlobalController
.executeOperation(operation
);
86 public boolean setParent(Composite parent
) {
88 if (super.setParent(parent
)) {
90 // If this has been moved to the misapplied names group, do nothing
91 if (parent
instanceof MisappliedGroupComposite
) {
95 // Has this been moved to a HomotypicalGroup?
96 if (parent
instanceof HomotypicalGroupComposite
) {
98 HomotypicalGroup homotypicalGroup
=
99 ((HomotypicalGroupComposite
)parent
).getGroup();
101 IUndoContext undoContext
= EditorController
.getUndoContext(taxon
);
102 IUndoableOperation operation
= new ChangeMisappliedNameToSynonymOperation
103 ("change misapplication to synonym", undoContext
, taxon
, misappliedName
, homotypicalGroup
);
105 GlobalController
.executeOperation(operation
);
113 public IPropertySource
getPropertySource() {
114 return new TaxonBasePropertySource(misappliedName
);
118 protected Font
getViewerFont() {
119 return MISAPPLIEDNAME_FONT
;