Project

General

Profile

Revision fb76c216

IDfb76c2166454527f95e12ed04f0f94298c10f17f
Parent c2f87993
Child a4757a22

Added by Patrick Plitzner over 2 years ago

ref #6909 migrate dnd for navigator

View differences:

eu.etaxonomy.taxeditor.navigation/fragment.e4xmi
77 77
          <children xsi:type="menu:HandledMenuItem" xmi:id="_3p8G8KqhEeeXcJGhyhlrKA" elementId="eu.etaxonomy.taxeditor.navigation.handledmenuitem.eu.etaxonomy.taxeditor.navigation.handledmenuitem.exportCsvPrint" label="%wizard.name.20" command="_mOC30KqhEeeXcJGhyhlrKA"/>
78 78
          <children xsi:type="menu:HandledMenuItem" xmi:id="_44XB4KqhEeeXcJGhyhlrKA" elementId="eu.etaxonomy.taxeditor.navigation.handledmenuitem.eu.etaxonomy.taxeditor.navigation.handledmenuitem.exportCdmLight" label="%wizard.name.22" command="_n1FHEKqhEeeXcJGhyhlrKA"/>
79 79
        </children>
80
        <children xsi:type="menu:HandledMenuItem" xmi:id="_wNp_wJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.handledmenuitem.export" label="%command.label.9" command="_ZkWNgKkOEeejedk4mZQIGw"/>
81 80
        <children xsi:type="menu:MenuSeparator" xmi:id="_x0uEMJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menuseparator.3" visible="false"/>
82 81
        <children xsi:type="menu:HandledMenuItem" xmi:id="_yH9JQJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.handledmenuitem.delete" label="%command.label.10" command="__n644JIxEeeJAdt8ZUxyaw"/>
83 82
        <children xsi:type="menu:MenuSeparator" xmi:id="_z0Q6EJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.menuseparator.4"/>
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TaxonNavigatorE4.java
25 25
import javax.annotation.PreDestroy;
26 26
import javax.inject.Inject;
27 27

  
28
import org.eclipse.core.commands.operations.UndoContext;
28 29
import org.eclipse.core.runtime.IAdaptable;
29 30
import org.eclipse.core.runtime.IProgressMonitor;
30 31
import org.eclipse.e4.ui.di.Focus;
32
import org.eclipse.e4.ui.di.UISynchronize;
31 33
import org.eclipse.e4.ui.services.EMenuService;
32 34
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
35
import org.eclipse.jface.util.LocalSelectionTransfer;
33 36
import org.eclipse.jface.viewers.ISelection;
34 37
import org.eclipse.jface.viewers.ISelectionChangedListener;
35 38
import org.eclipse.jface.viewers.IStructuredSelection;
36 39
import org.eclipse.jface.viewers.TreePath;
37 40
import org.eclipse.jface.viewers.TreeViewer;
38 41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.dnd.DND;
43
import org.eclipse.swt.dnd.Transfer;
39 44
import org.eclipse.swt.layout.FillLayout;
40 45
import org.eclipse.swt.widgets.Composite;
41 46
import org.eclipse.ui.IMemento;
......
87 92

  
88 93
	private static final String TREE_PATHS = "treepaths"; //$NON-NLS-1$
89 94

  
95
	private final int dndOperations = DND.DROP_MOVE;
96

  
90 97
	private ConversationHolder conversation;
91 98

  
92 99
	private ICdmEntitySession cdmEntitySession;
......
100 107
    @Inject
101 108
    private ESelectionService selService;
102 109

  
110
    @Inject
111
    private UISynchronize sync;
112

  
103 113
    private ISelectionChangedListener selectionChangedListener;
104 114

  
105
	@Inject
115
    private UndoContext undoContext;
116

  
117
    @Inject
106 118
    public TaxonNavigatorE4() {
119
	    undoContext = new UndoContext();
107 120
	    CdmStore.getContextManager().addContextListener(this);
108 121
    }
109 122

  
......
136 149

  
137 150
        //create context menu
138 151
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.navigator.popupmenu.taxonnavigator");
139
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.menu.import");
152

  
153
        //add drag'n'drop support
154
        Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()};
155
        viewer.addDragSupport(dndOperations, transfers, new TreeNodeDragListenerE4(viewer));
156
        viewer.addDropSupport(dndOperations, transfers, new TreeNodeDropAdapterE4(this));
140 157

  
141 158
	    init();
142 159
	}
......
326 343
		}
327 344
	}
328 345

  
346
    public UISynchronize getSync() {
347
        return sync;
348
    }
349

  
350
    public TreeViewer getViewer() {
351
        return viewer;
352
    }
353

  
354
    public UndoContext getUndoContext() {
355
        return undoContext;
356
    }
357

  
329 358
	/** {@inheritDoc} */
330 359
	@Override
331 360
	public boolean postOperation(CdmBase objectAffectedByOperation) {
332
		// nothing to do here
361
	    viewer.refresh();
333 362
		return true;
334 363
	}
335 364

  
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TreeNodeDragListenerE4.java
1
/**
2
 * Copyright (C) 2015 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
package eu.etaxonomy.taxeditor.navigation.navigator.e4;
10

  
11
import org.eclipse.jface.util.LocalSelectionTransfer;
12
import org.eclipse.jface.viewers.ISelection;
13
import org.eclipse.jface.viewers.Viewer;
14
import org.eclipse.swt.dnd.DragSourceAdapter;
15
import org.eclipse.swt.dnd.DragSourceEvent;
16

  
17
/**
18
 * @author k.luther
19
 * @date 02.06.2015
20
 *
21
 */
22
public class TreeNodeDragListenerE4 extends DragSourceAdapter {
23
    private Viewer viewer;
24

  
25
    public TreeNodeDragListenerE4(Viewer viewer) {
26
        this.viewer = viewer;
27
    }
28

  
29
    public void setViewer(Viewer viewer){
30
        this.viewer = viewer;
31
    }
32

  
33
    @Override
34
    public void dragStart(DragSourceEvent event) {
35
        event.doit = true;// set to false if needed - default is true
36
    }
37

  
38
    @Override
39
    public void dragSetData(DragSourceEvent event) {
40
        ISelection selection = viewer.getSelection();
41
        if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
42
            LocalSelectionTransfer.getTransfer().setSelection(selection);
43
        }
44
    }
45
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TreeNodeDropAdapterE4.java
1
/**
2
* Copyright (C) 2015 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.navigation.navigator.e4;
11

  
12
import java.util.EnumSet;
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import org.apache.log4j.Logger;
19
import org.eclipse.core.commands.operations.IUndoContext;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.util.LocalSelectionTransfer;
22
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.TreeSelection;
24
import org.eclipse.jface.viewers.ViewerDropAdapter;
25
import org.eclipse.swt.dnd.DND;
26
import org.eclipse.swt.dnd.DropTargetEvent;
27
import org.eclipse.swt.dnd.TransferData;
28

  
29
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
30
import eu.etaxonomy.cdm.model.taxon.Classification;
31
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
33
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
34
import eu.etaxonomy.taxeditor.model.AbstractUtility;
35
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
36
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
37
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
38
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
39
import eu.etaxonomy.taxeditor.store.CdmStore;
40

  
41
/**
42
 * @author k.luther
43
 * @date 02.06.2015
44
 */
45
public class TreeNodeDropAdapterE4 extends ViewerDropAdapter {
46

  
47
    protected static final String TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE = Messages.TreeNodeDropAdapter_UNSAVED_PARENT_MESSAGE;
48
    protected static final String TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT = Messages.TreeNodeDropAdapter_UNSAVED_PARENT;
49
    protected static final String TREE_NODE_DROP_ADAPTER_MOVE_TAXON = Messages.TreeNodeDropAdapter_MOVE_TAXON;
50
    protected static final String TREE_NODE_DROP_ADAPTER_CANCEL = Messages.TreeNodeDropAdapter_CANCEL;
51
    protected static final String TREE_NODE_DROP_ADAPTER_BEHIND = Messages.TreeNodeDropAdapter_BEHIND;
52
    protected static final String TREE_NODE_DROP_ADAPTER_CHILD = Messages.TreeNodeDropAdapter_CHILD;
53
    protected static final String DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE = Messages.TreeNodeDropAdapter_MOVE_BEHIND;
54
    protected static final String TARGET_NODE = Messages.TreeNodeDropAdapter_TARGET_NODE;
55

  
56
    private static final Logger logger = Logger.getLogger(TreeNodeDropAdapterE4.class);
57

  
58
    private TaxonNavigatorE4 taxonNavigator;
59

  
60
	public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$
61

  
62
	private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
63

  
64
	public enum MovingType{
65
	    CHILD, PREVIOUS, BEHIND
66
	}
67

  
68
	protected TreeNodeDropAdapterE4(TaxonNavigatorE4 navigator) {
69
	    super(navigator.getViewer());
70
	    this.taxonNavigator = navigator;
71
	}
72

  
73
	/** {@inheritDoc} */
74
	@Override
75
	public boolean performDrop(Object data) {
76
        Object target = getCurrentTarget();
77
		if (getCurrentTarget() instanceof ITaxonTreeNode) {
78
			Set<TaxonNode> taxonNodes = getSelectedTaxa();
79
			ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
80
			if (targetTreeNode instanceof Classification){
81
				targetTreeNode = ((Classification)targetTreeNode).getRootNode();
82
				targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class);
83
			}
84
			if(taxonNodes != null) {
85
				if (taxonNodes.size() == 1){
86
					return moveTaxon(taxonNodes, targetTreeNode);
87
				} else{
88
					if( MessageDialog.openConfirm(null, Messages.TreeNodeDropAdapter_MOVING, Messages.TreeNodeDropAdapter_MOVING_MESSAGE)){
89
						return true;
90
					}
91
				}
92
            }
93
		}
94
		return false;
95
	}
96

  
97
	private Set<TaxonNode> getSelectedTaxa(){
98
		HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
99

  
100
		ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
101
		if (selection instanceof TreeSelection) {
102

  
103
			Iterator<?> selectionIterator = ((TreeSelection) selection).iterator();
104

  
105
			while (selectionIterator.hasNext()){
106
				Object object = selectionIterator.next();
107
				if(object instanceof TaxonNode){
108
					TaxonNode taxonNode = (TaxonNode) object;
109
					taxonNodes.add(taxonNode);
110
				}
111
			}
112
		}
113
		return taxonNodes;
114
	}
115

  
116
	/** {@inheritDoc} */
117
	@Override
118
	public boolean validateDrop(Object target, int operation,
119
			TransferData transferType) {
120

  
121
		if (target instanceof ITaxonTreeNode) {
122

  
123
		    // check users permissions with target taxonnode and taxon
124
		    if (target instanceof TaxonNode) {
125
		        TaxonNode targetNode = (TaxonNode)target;
126
		        boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE);
127
		        boolean hasTargetTaxonPermission = targetNode.getTaxon() == null ?
128
		        			true :
129
		        			CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE);
130

  
131
                if(logger.isDebugEnabled()){
132
                    logger.debug("target: " + targetNode.getTaxon() == null? "-" : targetNode.getTaxon().getTitleCache()); //$NON-NLS-1$
133
                }
134

  
135
		        if(!hasTargetNodePermission || ! hasTargetNodePermission){
136
		            if(logger.isDebugEnabled()){
137
		                logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission + " " + hasTargetTaxonPermission + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
138
		            }
139
		            return false;
140
		        }
141
		    }
142

  
143
		    // do not allow to drop onto itself and
144
		    // check users permissions with all selected taxon nodes and taxa
145
		    for(TaxonNode taxonNode : getSelectedTaxa()){
146
			    if (logger.isDebugEnabled()){
147
			    	logger.debug("selectedTaxa: " + taxonNode.getTaxon() == null? "-" : taxonNode.getTaxon().getTitleCache()); //$NON-NLS-1$
148
			    }
149
			    boolean isSameTaxonNode = taxonNode.equals(target);
150
				boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
151
				boolean hasTaxonPermission = taxonNode.getTaxon() == null ?
152
	        			true :
153
	        			CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
154
                if (
155
			        isSameTaxonNode
156
			        || !hasTaxonNodePermission
157
    	            || !hasTaxonPermission
158
	                ) {
159
                    if(logger.isDebugEnabled()){
160
                        logger.debug("CANCEL_STATUS for selected  " + isSameTaxonNode + Messages.TreeNodeDropAdapter_10 + hasTaxonNodePermission + " " + hasTaxonPermission + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
161
                    }
162
					return false;
163
				}
164
			}
165
			logger.debug("OK_STATUS"); //$NON-NLS-1$
166
			return true;
167
		}
168
		logger.debug("CANCEL_STATUS"); //$NON-NLS-1$
169
		return false;
170
	}
171

  
172

  
173
	private boolean moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
174

  
175

  
176
		if(targetITaxonTreeNode instanceof TaxonNode){
177

  
178
		// Make sure parent taxon does not have unsaved changes
179
//			if (NavigationUtil.isDirty(targetTaxonNode)){
180
//				MessageDialog.openWarning(NavigationUtil.getShell(), TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
181
//				return false;
182
//			}
183

  
184
		}
185
		Iterator<TaxonNode> taxIterator = taxonNodes.iterator();
186
        Set<UUID> uuids = new HashSet<UUID>();
187
        TaxonNode node = null;
188
        while(taxIterator.hasNext()){
189
            node = taxIterator.next();
190
            uuids.add(node.getUuid());
191
        }
192
        IUndoContext workspaceUndoContext = taxonNavigator.getUndoContext();
193
		if (!PreferencesUtil.getSortNodesNaturally()){
194
			if (workspaceUndoContext == null) {
195
				logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
196
				return false;
197
			}
198

  
199
			AbstractPostOperation<?> operation = new MoveTaxonOperation
200
			        (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, taxonNavigator, taxonNavigator, MovingType.CHILD);
201
			AbstractUtility.executeOperation(operation, taxonNavigator.getSync());
202

  
203
			logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
204
			return true;
205
		}else{
206
			String[] buttonLables = {TREE_NODE_DROP_ADAPTER_CHILD, TREE_NODE_DROP_ADAPTER_BEHIND,TREE_NODE_DROP_ADAPTER_CANCEL};
207
			MessageDialog dialog = new MessageDialog(null, TARGET_NODE, null, DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
208
			dialog.open();
209
			int returnCode = dialog.getReturnCode();
210
			if (returnCode == 0){
211
				if (workspaceUndoContext == null) {
212
					logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
213
					return false;
214
				}
215

  
216
				AbstractPostOperation<?> operation = new MoveTaxonOperation
217
						(TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, taxonNavigator, taxonNavigator, MovingType.CHILD);
218
				AbstractUtility.executeOperation(operation, taxonNavigator.getSync());
219

  
220
				logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
221
				return true;
222
			}else if (returnCode == 1){
223
				if (workspaceUndoContext == null) {
224
					logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
225
					return false;
226
				}
227
				TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
228

  
229
				AbstractPostOperation<?> operation = new MoveTaxonOperation
230
						(TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetNode, taxonNavigator, taxonNavigator, MovingType.PREVIOUS);
231
				AbstractUtility.executeOperation(operation, taxonNavigator.getSync());
232

  
233
				logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
234
				return true;
235
			}
236
//			} else if (returnCode == 2){
237
//                IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
238
//                if (workspaceUndoContext == null) {
239
//                    logger.error("Workspace undo context is null. DND operation cancelled");
240
//                    return false;
241
//                }
242
//                TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
243
//
244
//                AbstractPostOperation operation = new MoveTaxonOperation
245
//                        ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.BEHIND);
246
//                NavigationUtil.executeOperation(operation);
247
//
248
//                logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
249
//                return true;
250
//            }
251
				else{
252
				return false;
253
			}
254

  
255

  
256
		}
257
	}
258

  
259
	@Override
260
	public void dragOver(DropTargetEvent event) {
261
		super.dragOver(event);
262
		event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_INSERT_AFTER;
263
	}
264

  
265
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/MoveTaxonHandlerE4.java
36 36
import eu.etaxonomy.taxeditor.model.AbstractUtility;
37 37
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
38 38
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
39
import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
40 39
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
40
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
41 41
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
42 42
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
43 43
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java
21 21

  
22 22
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23 23
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
24
import eu.etaxonomy.cdm.api.service.UpdateResult;
25 24
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
26 25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27 26
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
28
import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
27
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
29 28
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
30 29
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31 30
import eu.etaxonomy.taxeditor.store.CdmStore;
......
50 49

  
51 50
	private final Set<UUID> taxonNodesUuid;
52 51
	private final MovingType moveToParentNode;
53
	/**
54
	 * <p>Constructor for MoveTaxonOperation.</p>
55
	 *
56
	 * @param label a {@link java.lang.String} object.
57
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
58
	 * @param taxonNodes a {@link java.util.Set} object.
59
	 * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
60
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
61
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
62
	 */
63 52
	public MoveTaxonOperation(String label, IUndoContext undoContext,
64
			Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, 
65
			IPostOperationEnabled postOperationEnabled, 
53
			Set<UUID> taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode,
54
			IPostOperationEnabled postOperationEnabled,
66 55
			IConversationEnabled conversationEnabled, MovingType moveToParentNode) {
67 56
		super(label, undoContext, postOperationEnabled, conversationEnabled);
68 57

  
......
84 73
			throws ExecutionException {
85 74
		bind();
86 75
		monitor.worked(20);
87
		UpdateResult result;
88 76
		switch(this.moveToParentNode){
89 77
		case CHILD:
90
		    result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 0);
78
		    CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 0);
79
		    break;
91 80
		case PREVIOUS:
92
		    result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 1);
81
		    CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 1);
82
		    break;
93 83
		case BEHIND:
94
		    result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 2);
84
		    CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid(), 2);
85
		    break;
95 86
		}
96 87

  
97 88
//		try {
eu.etaxonomy.taxeditor.navigation/src/test/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperationTest.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
22 22
import eu.etaxonomy.cdm.model.taxon.Classification;
23 23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24 24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
25
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
26 26
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
27 27

  
28 28
/**
......
37 37
	private static TaxonNode oldParentTaxonNode;
38 38
	private static TaxonNode newParentTaxonNode;
39 39
	private static TaxonNode taxonNode;
40
	
40

  
41 41
	/**
42 42
	 * @throws java.lang.Exception
43 43
	 */
44 44
	@BeforeClass
45 45
	public static void setUpBeforeClass() throws Exception {
46 46

  
47
		
47

  
48 48
		taxon = Taxon.NewInstance(null, null);
49 49

  
50 50
		oldParentTaxon = Taxon.NewInstance(null, null);
51 51
		newParentTaxon = Taxon.NewInstance(null, null);
52
		
52

  
53 53
		tree = Classification.NewInstance(null);
54 54
		oldParentTaxonNode = tree.addChildTaxon(oldParentTaxon, null, null);
55 55
		newParentTaxonNode = tree.addChildTaxon(newParentTaxon, null, null);
56
		
56

  
57 57
		taxonNode = oldParentTaxonNode.addChildTaxon(taxon, null, null);
58
		
58

  
59 59
		Set<UUID> taxonNodeUuidSet = new HashSet<UUID>();
60 60
		//TODO ??
61 61
		IConversationEnabled conversationEnabled = null;
62 62
		taxonNodeUuidSet.add(taxonNode.getUuid());
63
		operation = new MoveTaxonOperation("Move Taxon To Different Parent", 
64
				undoContext, taxonNodeUuidSet, newParentTaxonNode, postOperation, 
63
		operation = new MoveTaxonOperation("Move Taxon To Different Parent",
64
				undoContext, taxonNodeUuidSet, newParentTaxonNode, postOperation,
65 65
				conversationEnabled, MovingType.CHILD);
66 66
	}
67 67

  
68 68
	/**
69 69
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
70
	 * @throws ExecutionException 
70
	 * @throws ExecutionException
71 71
	 */
72 72
	@Test
73 73
	public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
74 74
		operation.execute(monitor, info);
75
		
75

  
76 76
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
77 77
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
78 78
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
......
81 81

  
82 82
	/**
83 83
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
84
	 * @throws ExecutionException 
84
	 * @throws ExecutionException
85 85
	 */
86 86
	@Test
87 87
	public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
88 88
		operation.undo(monitor, info);
89
		
89

  
90 90
		Assert.assertEquals(oldParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
91 91
		Assert.assertEquals(0, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());
92 92
		Assert.assertEquals(taxon, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
93 93
	}
94
	
94

  
95 95
	/**
96 96
	 * Test method for {@link eu.etaxonomy.taxeditor.navigation.operation.MoveTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
97
	 * @throws ExecutionException 
97
	 * @throws ExecutionException
98 98
	 */
99 99
	@Test
100 100
	public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
101 101
		operation.redo(monitor, info);
102
		
102

  
103 103
		Assert.assertEquals(newParentTaxon ,taxon.getTaxonNodes().iterator().next().getParent().getTaxon());
104 104
		Assert.assertEquals(taxon, newParentTaxon.getTaxonNodes().iterator().next().getChildNodes().iterator().next());
105 105
		Assert.assertEquals(0, oldParentTaxon.getTaxonNodes().iterator().next().getChildNodes().size());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)