34b52b5c7faf5c281334da1578bc011f2b496ff7
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / ChangeHomotypicGroupOperation.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.store.operations;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
20 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 import eu.etaxonomy.cdm.model.taxon.Synonym;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23
24 /**
25 * Change the homotypical group of a given synonym.
26 *
27 * @author n.hoffmann
28 * @created 19.01.2009
29 * @version 1.0
30 */
31 public class ChangeHomotypicGroupOperation extends AbstractPostOperation {
32
33 @SuppressWarnings("unused")
34 private static final Logger logger = Logger
35 .getLogger(ChangeHomotypicGroupOperation.class);
36
37 /**
38 * The synonym to be moved.
39 */
40 private Synonym synonym;
41 /**
42 * The former homotypical group the synonym belonged to
43 */
44 private HomotypicalGroup oldHomotypicalGroup;
45 /**
46 * The homotypical group the synonym is to be moved to
47 */
48 private HomotypicalGroup newHomotypicalGroup;
49
50 public ChangeHomotypicGroupOperation(String label, IUndoContext undoContext,
51 Taxon taxon, Synonym synonym, HomotypicalGroup newHomotypicalGroup, IPostOperationEnabled editor) {
52 super(label, undoContext, taxon, editor);
53
54 this.synonym = synonym;
55 if(synonym == null){
56 throw new IllegalArgumentException(
57 "A null synonym was provided.");
58 }
59
60 this.oldHomotypicalGroup = synonym.getHomotypicGroup();
61 this.newHomotypicalGroup = newHomotypicalGroup;
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
66 */
67 @Override
68 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
69 throws ExecutionException {
70
71 // Get synonym name
72 TaxonNameBase<?, ?> synonymName = this.synonym.getName();
73
74 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
75
76 // Switch groups
77 oldHomotypicalGroup.removeTypifiedName(synonymName);
78 newHomotypicalGroup.addTypifiedName(synonymName);
79
80 // Redraw editor if it exists
81 return postExecute(synonym);
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 */
87 @Override
88 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
89 throws ExecutionException {
90 return execute(monitor, info);
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 */
96 @Override
97 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
98 throws ExecutionException {
99
100 // Get synonym name
101 TaxonNameBase<?, ?> synonymName = this.synonym.getName();
102 if(synonymName == null){
103 // TODO
104 }
105
106 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
107
108 // Switch groups
109 newHomotypicalGroup.removeTypifiedName(synonymName);
110 oldHomotypicalGroup.addTypifiedName(synonymName);
111
112 // Redraw editor if it exists
113 return postExecute(synonym);
114 }
115 }