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
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
15 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.swt
.graphics
.Font
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.ui
.forms
.IManagedForm
;
23 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
25 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
28 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
29 import eu
.etaxonomy
.taxeditor
.UiUtil
;
30 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
31 import eu
.etaxonomy
.taxeditor
.operations
.name
.ChangeMisappliedNameToSynonymOperation
;
32 import eu
.etaxonomy
.taxeditor
.operations
.name
.RemoveMisappliedNameOperation
;
33 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.TaxonBasePropertySource
;
40 public class MisappliedNameComposite
extends NameComposite
{
41 private static final Logger logger
= Logger
42 .getLogger(MisappliedNameComposite
.class);
44 private Taxon misappliedName
;
46 public MisappliedNameComposite(Composite parent
, IManagedForm form
,
47 Taxon taxon
, Taxon misappliedName
) {
48 super(parent
, form
, NameComposite
.MISAPPLIED_NAME
, misappliedName
);
51 this.misappliedName
= misappliedName
;
54 setIcon(MISAPPLIEDNAME_ICON
);
55 setFont(getViewerFont());
56 setIndent(MISAPPLIEDNAME_INDENT
);
60 initNameViewer(misappliedName
);
63 public Taxon
getMisappliedName() {
64 return misappliedName
;
67 private void createMenu() {
69 ContextMenu contextMenu
= createContextMenu();
71 final IOperationHistory operationHistory
= UiUtil
.getOperationHistory();
72 final IUndoContext undoContext
= UiUtil
.getTaxonNameEditorUndoContext(taxon
);
74 // Remove misapplied name from taxon
75 String text
= "Remove misapplied name from taxon"; //$NON-NLS-1$
76 ImageDescriptor image
= TaxEditorPlugin
.getDefault()
77 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
78 contextMenu
.addAction(new Action(text
, image
){
81 IUndoableOperation operation
= new RemoveMisappliedNameOperation
82 (this.getText(), undoContext
, taxon
, misappliedName
);
84 IStatus status
= operationHistory
.execute(operation
, null, null);
85 } catch (ExecutionException e
) {
86 // TODO Auto-generated catch block
93 public boolean setParent(Composite parent
) {
95 if (super.setParent(parent
)) {
97 // If this has been moved to the misapplied names group, do nothing
98 if (parent
instanceof MisappliedGroupComposite
) {
102 // Has this been moved to a HomotypicalGroup?
103 if (parent
instanceof HomotypicalGroupComposite
) {
105 HomotypicalGroup homotypicalGroup
=
106 ((HomotypicalGroupComposite
)parent
).getGroup();
108 IOperationHistory operationHistory
= UiUtil
.getOperationHistory();
109 IUndoContext undoContext
= UiUtil
.getTaxonNameEditorUndoContext(taxon
);
110 IUndoableOperation operation
= new ChangeMisappliedNameToSynonymOperation
111 ("change misapplication to synonym", undoContext
, taxon
, misappliedName
, homotypicalGroup
);
114 IStatus status
= operationHistory
.execute(operation
, null, null);
115 } catch (ExecutionException e
) {
116 // TODO Auto-generated catch block
126 public IPropertySource
getPropertySource() {
127 return new TaxonBasePropertySource(misappliedName
);
131 protected Font
getViewerFont() {
132 return MISAPPLIEDNAME_FONT
;