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
.actions
.ui
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
15 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
18 import org
.eclipse
.core
.runtime
.IAdaptable
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.jface
.action
.Action
;
23 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
24 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
25 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
29 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
30 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.DeleteMisappliedNameFromTaxonAction
;
31 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
32 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameComposite
;
39 public class DeleteMisappliedNameCompositeAction
extends Action
{
40 private static final Logger logger
= Logger
41 .getLogger(DeleteMisappliedNameCompositeAction
.class);
43 private static String text
= "Delete misapplied name from taxon";
44 private ImageDescriptor image
= TaxEditorPlugin
.getDefault()
45 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
47 private Taxon misappliedName
;
50 private NameComposite composite
;
51 private IUndoableOperation operation
;
53 private DeleteMisappliedNameCompositeAction() {
55 setImageDescriptor(image
);
58 public DeleteMisappliedNameCompositeAction(NameComposite composite
, Taxon taxon
) {
61 if (composite
.getData() instanceof Taxon
) {
62 this.misappliedName
= (Taxon
) composite
.getData();
64 throw new IllegalArgumentException(
65 "This action requires a composite with a Taxon in its data field.");
69 this.composite
= composite
;
71 operation
= new DeleteSynonymOperation();
75 IOperationHistory operationHistory
= GlobalController
.getOperationHistory();
76 IUndoContext undoContext
= GlobalController
.getWorkbenchUndoContext();
77 operation
.addContext(undoContext
);
79 operationHistory
.execute(operation
, null, null);
80 operationHistory
.add(operation
);
81 } catch (ExecutionException e
) {
86 class DeleteSynonymOperation
extends AbstractOperation
{
88 public DeleteSynonymOperation() {
89 super("'" + text
+ "'");
93 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
94 throws ExecutionException
{
95 // Delete synonym from taxon
96 Action action
= new DeleteMisappliedNameFromTaxonAction(misappliedName
, taxon
);
97 action
.addPropertyChangeListener(new IPropertyChangeListener() {
98 public void propertyChange(PropertyChangeEvent event
) {
99 if (event
.getProperty().equals(
100 ITaxEditorConstants
.MISAPPLIED_NAME
)) {
101 // Delete namecomposite
102 // TODO: put this in taxonFactory?
109 return Status
.OK_STATUS
;
113 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
114 throws ExecutionException
{
115 // TODO Auto-generated method stub
116 return Status
.OK_STATUS
;
120 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
121 throws ExecutionException
{
122 // TODO Auto-generated method stub
123 return Status
.OK_STATUS
;