Massive refactoring of the methodology in former class UiUtils
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / actions / ui / ChangeCompositeToNewTaxonAction.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.actions.ui;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.util.IPropertyChangeListener;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.ITaxEditorConstants;
23 import eu.etaxonomy.taxeditor.TaxEditorPlugin;
24 import eu.etaxonomy.taxeditor.actions.UndoableAction;
25 import eu.etaxonomy.taxeditor.actions.cdm.ChangeSynonymToTaxonAction;
26 import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction;
27 import eu.etaxonomy.taxeditor.editor.name.NameComposite;
28
29 /**
30 * @author p.ciardelli
31 * @created 09.06.2008
32 * @version 1.0
33 *
34 * @deprecated
35 * TODO seems like this is not beeing used at the moment
36 */
37 public class ChangeCompositeToNewTaxonAction extends UndoableAction {
38 private static final Logger logger = Logger
39 .getLogger(ChangeCompositeToNewTaxonAction.class);
40
41 private static String text = "Use synonym name to make a new taxon";
42 private static ImageDescriptor image = TaxEditorPlugin.getDefault()
43 .getImageDescriptor(ITaxEditorConstants.SYNONYM_TO_TAXON_ICON);
44
45 private NameComposite composite;
46 private Taxon taxon;
47 private Synonym synonym;
48
49 public ChangeCompositeToNewTaxonAction(NameComposite composite,
50 Taxon taxon) {
51 super(text, image);
52
53 this.composite = composite;
54 this.taxon = taxon;
55
56 if (composite.getData() instanceof Synonym) {
57 this.synonym = (Synonym) composite.getData();
58 } else {
59 throw new IllegalArgumentException(
60 "This action requires a composite with a Synonym in its data field.");
61 }
62
63 }
64
65 /* (non-Javadoc)
66 * @see eu.etaxonomy.taxeditor.actions.UndoableAction#executeOperation()
67 */
68 @Override
69 protected IStatus executeOperation() {
70 Action action = new ChangeSynonymToTaxonAction(synonym);
71 action.addPropertyChangeListener(new IPropertyChangeListener() {
72 public void propertyChange(PropertyChangeEvent event) {
73 if (event.getProperty().equals(ITaxEditorConstants.TAXON)) {
74 if (event.getNewValue() instanceof Taxon) {
75
76 // Delete synonym composite in old taxon
77 composite.dispose();
78
79 Taxon newTaxon = (Taxon) event.getNewValue();
80 // TaxEditorPlugin.getDefault().addSessionTaxon(newTaxon);
81
82 new OpenTaxonEditorAction(newTaxon).run();
83 // new SaveTaxonAction(newTaxon).run();
84 }
85 }
86 }
87 });
88 action.run();
89 return Status.OK_STATUS;
90 }
91
92 /* (non-Javadoc)
93 * @see eu.etaxonomy.taxeditor.actions.UndoableAction#redoOperation()
94 */
95 @Override
96 protected IStatus redoOperation() {
97 // TODO Auto-generated method stub
98 return null;
99 }
100
101 /* (non-Javadoc)
102 * @see eu.etaxonomy.taxeditor.actions.UndoableAction#undoOperation()
103 */
104 @Override
105 protected IStatus undoOperation() {
106 // TODO Auto-generated method stub
107 return null;
108 }
109 }