Project

General

Profile

« Previous | Next » 

Revision 3be6ef3e

Added by Niels Hoffmann over 13 years ago

performed javacscript:fix and worked on documentation

View differences:

taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.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.operations;
11

  
12
import java.util.HashMap;
13
import java.util.Map;
14
import java.util.Set;
15

  
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.operations.IUndoContext;
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

  
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
25
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.store.StoreUtil;
28

  
29
/**
30
 * Change the taxonomic parent of a given taxon.
31
 * 
32
 * @author n.hoffmann
33
 * @created 16.01.2009
34
 * @version 1.0
35
 */
36
public class MoveTaxonOperation extends AbstractPersistentPostOperation {
37
	
38
	/**
39
	 * A reference to the new taxonomical parent.
40
	 */
41
	private ITreeNode newParentTreeNode;
42
	/**
43
	 * A reference to the former taxonomical parents
44
	 */
45
	private Map<TaxonNode, ITreeNode> oldParentTreeNodes;
46
	
47
	private Set<TaxonNode> taxonNodes;
48

  
49
	public MoveTaxonOperation(String label, IUndoContext undoContext,
50
			Set<TaxonNode> taxonNodes, ITreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
51
		super(label, undoContext, postOperationEnabled, conversationEnabled);
52

  
53
		this.taxonNodes = taxonNodes;
54
		
55
		this.newParentTreeNode = newParentTreeNode;
56
		
57
		// Save old parent ITreeNodes for undo
58
		oldParentTreeNodes = new HashMap<TaxonNode, ITreeNode>();
59
		for(TaxonNode taxonNode : taxonNodes){
60
			this.oldParentTreeNodes.put(taxonNode, taxonNode.getParent());
61
		}
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
		bind();
71
		monitor.worked(20);
72
		
73
		try {
74
			for (TaxonNode taxonNode : taxonNodes){
75
				TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode, 
76
						newParentTreeNode.getReference(), newParentTreeNode.getMicroReference(), 
77
						taxonNode.getSynonymToBeUsed());
78
				taxonNodes.add(newTaxonNode);
79
				monitor.worked(2);
80
			}
81
		} catch(IllegalAncestryException e) {
82
			StoreUtil.warningDialog("Illegal ancestry", this, e.getMessage());
83
		}
84
		monitor.worked(40);
85
		
86
		return postExecute(null);
87
	}
88

  
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
91
	 */
92
	@Override
93
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
94
			throws ExecutionException {
95
		return execute(monitor, info);
96
	}
97

  
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
100
	 */
101
	@Override
102
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
103
			throws ExecutionException {
104
		StoreUtil.warn(this.getClass(), "Not implemented yet.");
105
		
106
		// iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent		
107
		
108
		return Status.OK_STATUS;
109
	}
110
}
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.operations;
11

  
12
import java.util.HashMap;
13
import java.util.Map;
14
import java.util.Set;
15

  
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.operations.IUndoContext;
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

  
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
25
import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.taxeditor.store.StoreUtil;
28

  
29
/**
30
 * Change the taxonomic parent of a given taxon.
31
 *
32
 * @author n.hoffmann
33
 * @created 16.01.2009
34
 * @version 1.0
35
 */
36
public class MoveTaxonOperation extends AbstractPersistentPostOperation {
37
	
38
	/**
39
	 * A reference to the new taxonomical parent.
40
	 */
41
	private ITreeNode newParentTreeNode;
42
	/**
43
	 * A reference to the former taxonomical parents
44
	 */
45
	private Map<TaxonNode, ITreeNode> oldParentTreeNodes;
46
	
47
	private Set<TaxonNode> taxonNodes;
48

  
49
	/**
50
	 * <p>Constructor for MoveTaxonOperation.</p>
51
	 *
52
	 * @param label a {@link java.lang.String} object.
53
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54
	 * @param taxonNodes a {@link java.util.Set} object.
55
	 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
56
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
57
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
58
	 */
59
	public MoveTaxonOperation(String label, IUndoContext undoContext,
60
			Set<TaxonNode> taxonNodes, ITreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
61
		super(label, undoContext, postOperationEnabled, conversationEnabled);
62

  
63
		this.taxonNodes = taxonNodes;
64
		
65
		this.newParentTreeNode = newParentTreeNode;
66
		
67
		// Save old parent ITreeNodes for undo
68
		oldParentTreeNodes = new HashMap<TaxonNode, ITreeNode>();
69
		for(TaxonNode taxonNode : taxonNodes){
70
			this.oldParentTreeNodes.put(taxonNode, taxonNode.getParent());
71
		}
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76
	 */
77
	/** {@inheritDoc} */
78
	@Override
79
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
80
			throws ExecutionException {
81
		bind();
82
		monitor.worked(20);
83
		
84
		try {
85
			for (TaxonNode taxonNode : taxonNodes){
86
				TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode, 
87
						newParentTreeNode.getReference(), newParentTreeNode.getMicroReference(), 
88
						taxonNode.getSynonymToBeUsed());
89
				taxonNodes.add(newTaxonNode);
90
				monitor.worked(2);
91
			}
92
		} catch(IllegalAncestryException e) {
93
			StoreUtil.warningDialog("Illegal ancestry", this, e.getMessage());
94
		}
95
		monitor.worked(40);
96
		
97
		return postExecute(null);
98
	}
99

  
100
	/* (non-Javadoc)
101
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
102
	 */
103
	/** {@inheritDoc} */
104
	@Override
105
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
106
			throws ExecutionException {
107
		return execute(monitor, info);
108
	}
109

  
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112
	 */
113
	/** {@inheritDoc} */
114
	@Override
115
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
116
			throws ExecutionException {
117
		StoreUtil.warn(this.getClass(), "Not implemented yet.");
118
		
119
		// iterate over oldParentTreeNodes, delete each TaxonNode from its actual parent and add to its former parent		
120
		
121
		return Status.OK_STATUS;
122
	}
123
}

Also available in: Unified diff