Project

General

Profile

« Previous | Next » 

Revision 872d7328

Added by Cherian Mathew almost 9 years ago

DefinedTermDropAdapter : added selection of source objects after drop and disabled insert feedback for non OrderedTermBase objects
DefinedTermEditor : added custom sorter for OrderedTermBase (descending)
MoveDefinedTermOperation : added possibility to move term when cursor is in the insert part of the list

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/MoveDefinedTermOperation.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
17 17
import org.eclipse.core.runtime.IProgressMonitor;
18 18
import org.eclipse.core.runtime.IStatus;
19 19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.jface.viewers.ViewerDropAdapter;
20 21

  
21 22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
24
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
22 25
import eu.etaxonomy.cdm.model.common.TermBase;
23 26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24 27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
32 35
 *
33 36
 */
34 37
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
35
	
36
	private Collection<DefinedTermBase> sourceTerms;// the actual DefinedTermBase(s) we are moving
37
	private TermBase targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
38

  
39
	private final Collection<DefinedTermBase> sourceTerms;// the actual DefinedTermBase(s) we are moving
40
	private final TermBase targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
41
	private final int currentLocation;
38 42

  
39 43
	/**
40 44
	 * @param label
41 45
	 * @param undoContext
42 46
	 * @param postOperationEnabled
43 47
	 */
44
	public MoveDefinedTermOperation(String label, IUndoContext undoContext, TermBase target, Collection<DefinedTermBase> sourceTerms,
45
			IPostOperationEnabled postOperationEnabled) {
48
	public MoveDefinedTermOperation(String label,
49
	        IUndoContext undoContext,
50
	        TermBase target,
51
	        Collection<DefinedTermBase> sourceTerms,
52
			IPostOperationEnabled postOperationEnabled,
53
			int currentLocation) {
46 54
		super(label, undoContext, postOperationEnabled);
47
		
55

  
48 56
		this.targetTermOrVocabulary = target;
49 57
		this.sourceTerms = sourceTerms;
58
		this.currentLocation = currentLocation;
50 59
	}
51 60

  
52 61
	/* (non-Javadoc)
......
55 64
	@Override
56 65
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57 66
			throws ExecutionException {
58
		
67

  
59 68
		// need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)
60 69
		// and remove it from old associations
61
		
70

  
62 71
		//TODO move to ITermService
63
		
64
		for (DefinedTermBase term : sourceTerms){
72

  
73
		for (DefinedTermBase term : sourceTerms) {
65 74
			// do nothing when moving it on itself
66 75
			if(targetTermOrVocabulary.equals(term)){
67 76
				Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term can not be added to itself");
68 77
				MessagingUtils.informationDialog("", status);
69 78
				return status;
70 79
			}
71
			
80

  
72 81
			if (targetTermOrVocabulary instanceof TermVocabulary) {
73 82
				TermVocabulary termVocabulary = (TermVocabulary)targetTermOrVocabulary;
74
				
83

  
75 84
				// do nothing when term is top level and gets added to the same vocabulary
76 85
				if(term.getPartOf() == null && termVocabulary.equals(term.getVocabulary())){
77 86
					Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term is already in this vocabulary");
78 87
					MessagingUtils.informationDialog("", status);
79 88
					return status;
80 89
				}
81
				
90

  
82 91
				cleanTerm(term);
83 92
				termVocabulary.addTerm(term);
84
				
93

  
85 94
			} else if (targetTermOrVocabulary instanceof DefinedTermBase) {
86 95
				cleanTerm(term);
87 96
				DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary;
88
				targetDefinedTerm.addIncludes(term);
89
				targetDefinedTerm.getVocabulary().addTerm(term);				
97

  
98
				if(targetTermOrVocabulary instanceof OrderedTermBase && term instanceof OrderedTermBase) {
99
				    TermVocabulary tVoc = ((DefinedTermBase) targetTermOrVocabulary).getVocabulary();
100
				    if(tVoc instanceof OrderedTermVocabulary) {
101
				        OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc;
102
				        // the link between the location and the add term (below / above)
103
				        // method is determined by the compare method in the
104
				        // DefinedTermEditor's ViewerSorter (DefinedTermSorter) class
105
				        if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
106
				            otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
107
				        }
108

  
109
				        if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
110
				            otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
111
				        }
112
				    }
113
				}
114
				if(currentLocation == ViewerDropAdapter.LOCATION_ON) {
115
				    targetDefinedTerm.addIncludes(term);
116
				    targetDefinedTerm.getVocabulary().addTerm(term);
117
				}
90 118
			}
91 119

  
92 120
		}
93 121
		//return null;
94
		return postExecute(targetTermOrVocabulary);			
122
		return postExecute(targetTermOrVocabulary);
95 123
	}
96
	
124

  
97 125
	private DefinedTermBase cleanTerm(DefinedTermBase term){
98 126

  
99 127
		DefinedTermBase partOf = term.getPartOf();
100 128
		if(partOf != null){
101 129
			partOf.removeIncludes(term);
102 130
		}
103
	
104
		
131

  
132

  
105 133
		TermVocabulary vocabulary = term.getVocabulary();
106 134
		if(vocabulary != null){
107 135
			vocabulary.removeTerm(term);
108 136
		}
109
		
137

  
110 138
		return term;
111 139
	}
112
	
140

  
113 141

  
114 142
	/* (non-Javadoc)
115 143
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)

Also available in: Unified diff