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
.name
.TaxonNameBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
29 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
30 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
31 import eu
.etaxonomy
.taxeditor
.UiUtil
;
32 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.MakeGroupBasionymAction
;
33 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameComposite
;
34 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
41 public class AddBasionymCompositeAction
extends Action
{
42 private static final Logger logger
= Logger
43 .getLogger(AddBasionymCompositeAction
.class);
46 private ImageDescriptor image
= TaxEditorPlugin
.getDefault()
47 .getImageDescriptor(ITaxEditorConstants
.BASIONYM_ICON
);
49 private TaxonNameBase basionymName
;
51 private NameComposite composite
;
52 private IUndoableOperation operation
;
54 private AddBasionymCompositeAction() {
56 setImageDescriptor(image
);
59 public AddBasionymCompositeAction(NameComposite composite
) {
62 if (composite
.getData() instanceof Synonym
) {
63 Synonym synonym
= (Synonym
) composite
.getData();
64 this.basionymName
= synonym
.getName();
66 throw new IllegalArgumentException(
67 "This action requires a composite with a Synonym in its data field."); //$NON-NLS-1$
70 text
= Messages
.getString("AddBasionymCompositeAction.0", basionymName
); //$NON-NLS-1$
73 this.composite
= composite
;
75 operation
= new AddBasionymOperation();
77 if (CdmUtil
.isNameGroupBasionym(basionymName
)) {
85 IOperationHistory operationHistory
= UiUtil
.getOperationHistory();
86 IUndoContext undoContext
= UiUtil
.getWorkbenchUndoContext();
87 operation
.addContext(undoContext
);
89 operationHistory
.execute(operation
, null, null);
90 operationHistory
.add(operation
);
91 } catch (ExecutionException e
) {
96 class AddBasionymOperation
extends AbstractOperation
{
98 public AddBasionymOperation() {
99 super("'" + text
+ "'"); //$NON-NLS-1$ //$NON-NLS-2$
103 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
104 throws ExecutionException
{
105 Action action
= new MakeGroupBasionymAction(basionymName
);
106 action
.addPropertyChangeListener(new IPropertyChangeListener() {
107 public void propertyChange(PropertyChangeEvent event
) {
108 if (event
.getProperty().equals(
109 ITaxEditorConstants
.BASIONYM
)) {
110 composite
.transform(NameComposite
.ADD_GROUP_BASIONYM
);
112 firePropertyChange(ITaxEditorConstants
.BASIONYM
, null, basionymName
);
118 return Status
.OK_STATUS
;
122 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
123 throws ExecutionException
{
124 // TODO Auto-generated method stub
125 return Status
.OK_STATUS
;
129 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
130 throws ExecutionException
{
131 // TODO Auto-generated method stub
132 return Status
.OK_STATUS
;