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
.description
;
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
.swt
.widgets
.Composite
;
26 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
30 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
31 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
38 public class DeleteElementCompositeAction
extends Action
{
39 private static final Logger logger
= Logger
40 .getLogger(DeleteElementCompositeAction
.class);
42 private static String text
= "Delete description element";
43 private ImageDescriptor image
= TaxEditorPlugin
.getDefault()
44 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
46 private IUndoableOperation operation
;
47 private DescriptionElementBase descriptionElement
;
50 private Composite elementComposite
;
51 private Composite featureComposite
;
52 private Composite descriptionComposite
;
53 private DescriptionBase description
;
55 private DeleteElementCompositeAction() {
57 setImageDescriptor(image
);
60 public DeleteElementCompositeAction(Composite elementComposite
,
64 this.elementComposite
= elementComposite
;
66 if (elementComposite
.getData() instanceof DescriptionElementBase
) {
67 this.descriptionElement
= (DescriptionElementBase
) elementComposite
.getData();
69 throw new IllegalArgumentException(
70 "This action requires an elementComposite with a DescriptionElementBase in its data field.");
74 featureComposite
= elementComposite
.getParent();
75 descriptionComposite
= featureComposite
.getParent();
76 if (descriptionComposite
.getData() instanceof DescriptionBase
) {
77 this.description
= (DescriptionBase
) descriptionComposite
.getData();
79 throw new IllegalArgumentException(
80 "This action requires that the element composite's \"grandparent\" has a Description in its data field.");
82 operation
= new DeleteElementOperation();
86 IOperationHistory operationHistory
= GlobalController
.getOperationHistory();
87 IUndoContext undoContext
= GlobalController
.getWorkbenchUndoContext();
88 operation
.addContext(undoContext
);
90 operationHistory
.execute(operation
, null, null);
91 operationHistory
.add(operation
);
92 } catch (ExecutionException e
) {
97 class DeleteElementOperation
extends AbstractOperation
{
99 public DeleteElementOperation() {
100 super("'" + text
+ "'");
104 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
105 throws ExecutionException
{
107 // Delete element from description
108 description
.removeElement(descriptionElement
);
110 // Dipose element composite
111 elementComposite
.dispose();
113 return Status
.OK_STATUS
;
117 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
118 throws ExecutionException
{
119 // TODO Auto-generated method stub
120 return Status
.OK_STATUS
;
124 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
125 throws ExecutionException
{
126 // TODO Auto-generated method stub
127 return Status
.OK_STATUS
;