Project

General

Profile

Revision fd61512c

IDfd61512cc9910bd22875010483470bf5466d55ec
Parent ece2b239
Child 3d5dce41

Added by Patrick Plitzner almost 2 years ago

ref #7887 Adapt moving terms based on DTOs

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDragListenerE4.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.e4;
10 10

  
11
import java.util.ArrayList;
12 11
import java.util.List;
13 12

  
13
import org.eclipse.jface.util.LocalSelectionTransfer;
14 14
import org.eclipse.jface.viewers.IStructuredSelection;
15 15
import org.eclipse.jface.viewers.Viewer;
16 16
import org.eclipse.swt.dnd.DragSourceAdapter;
17 17
import org.eclipse.swt.dnd.DragSourceEvent;
18 18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
19
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21 20

  
22 21
/**
23 22
 *
......
38 37
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
39 38
	    List list = selection.toList();
40 39
	    for (Object object : list) {
41
            if(!(object instanceof DefinedTermBase)){
40
            if(!(object instanceof TermDto)){
42 41
                event.doit = false;
43 42
                return;
44 43
            }
......
48 47

  
49 48
	@Override
50 49
	public void dragSetData(DragSourceEvent event) {
50
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
51
        if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
52
            LocalSelectionTransfer.getTransfer().setSelection(selection);
53
        }
51 54

  
52
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
53
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
54

  
55
		for (Object object : selection.toList()){
56
				definedTerms.add((DefinedTermBase)object);
57
			}
58

  
59
		if (TermTransfer.getInstance().isSupportedType(
60
				event.dataType)) {
61
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
62
		}
63 55
	}
64 56

  
65 57
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDropAdapterE4.java
14 14
import javax.inject.Inject;
15 15

  
16 16
import org.eclipse.e4.ui.di.UISynchronize;
17
import org.eclipse.jface.util.LocalSelectionTransfer;
18
import org.eclipse.jface.viewers.IStructuredSelection;
17 19
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.swt.dnd.DND;
19 20
import org.eclipse.swt.dnd.DropTargetEvent;
20 21
import org.eclipse.swt.dnd.TransferData;
21 22

  
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
24
import eu.etaxonomy.cdm.model.common.TermBase;
25
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
23
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermDto;
26 25
import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
26
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27 27
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
28 28
import eu.etaxonomy.taxeditor.store.StoreUtil;
29 29
import eu.etaxonomy.taxeditor.ui.EditViewerDropAdapter;
......
50 50
	@Override
51 51
	public boolean performDrop(Object data) {
52 52

  
53
		TermBase target = (TermBase) getCurrentTarget();//can be vocab
53
		AbstractTermDto target = (AbstractTermDto) getCurrentTarget();//can be vocab
54 54
		int currentLocation = getCurrentLocation();
55
		Object[] droppedTerms = (Object[]) data;
56
		Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
55
		IStructuredSelection droppedTerms = (IStructuredSelection) data;
56
		Collection<TermDto> sourceTerms = new ArrayList<>(); //Arrays.asList(droppedElements)
57 57

  
58
		for (Object droppedTerm : droppedTerms) {
59
			DefinedTermBase term = (DefinedTermBase) droppedTerm;
58
		for (Object droppedTerm : droppedTerms.toList()) {
59
		    TermDto term = (TermDto) droppedTerm;
60 60
			sourceTerms.add(term);
61 61
		}
62 62

  
......
66 66
		        sourceTerms,
67 67
		        editor,
68 68
		        currentLocation);
69
		//TODO: implement execute
70
		StoreUtil.executeOperation(operation, sync);
69
		AbstractUtility.executeOperation(operation, sync);
71 70
		// select the newly moved objects
72
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms.toArray(new TermBase[sourceTerms.size()])));
71
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms));
73 72

  
74 73
		return true;
75 74
	}
......
77 76
	@Override
78 77
	public boolean validateDrop(Object target, int operation,
79 78
			TransferData transferType) {
80
		boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);
81
		// maybe don't need this - they will be all TermBase anyway
82
		return target instanceof TermBase && transferDataIsSupported;
83
	}
84

  
85
	@Override
86
	public void dragOver(DropTargetEvent event) {
87
	    super.dragOver(event);
88
	    TermBase target = (TermBase) getCurrentTarget();
89
	    if(!(target instanceof OrderedTermBase)) {
90
	        // this is to only disable insert between items
91
	        event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
92
	    }
93

  
94

  
79
        return LocalSelectionTransfer.getTransfer().isSupportedType(transferType) && target instanceof AbstractTermDto;
95 80
	}
96 81

  
97 82
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java
25 25
import org.eclipse.e4.ui.services.EMenuService;
26 26
import org.eclipse.e4.ui.workbench.modeling.EPartService;
27 27
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28
import org.eclipse.jface.util.LocalSelectionTransfer;
28 29
import org.eclipse.jface.viewers.ISelectionChangedListener;
29 30
import org.eclipse.jface.viewers.StructuredSelection;
30 31
import org.eclipse.jface.viewers.TreeViewer;
......
47 48
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
48 49
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
49 50
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
50
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
51 51
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
52 52
import eu.etaxonomy.taxeditor.event.EventUtility;
53 53
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
......
119 119
	    viewer.setLabelProvider(new TermDtoLabelProvider());
120 120
	    viewer.setSorter(new DefinedTermSorter());
121 121

  
122
	    Transfer[] transfers = new Transfer[] { TermTransfer.getInstance() };
122
	    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
123 123
	    viewer.addDragSupport(dndOperations, transfers, new DefinedTermDragListenerE4(viewer));
124 124
	    DefinedTermDropAdapterE4 dropListener = new DefinedTermDropAdapterE4(this);
125 125
	    ContextInjectionFactory.inject(dropListener, context);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/MoveDefinedTermOperation.java
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.operation;
10 10

  
11 11
import java.util.Collection;
12
import java.util.UUID;
12 13

  
13 14
import org.eclipse.core.commands.ExecutionException;
14 15
import org.eclipse.core.commands.operations.IUndoContext;
15 16
import org.eclipse.core.runtime.IAdaptable;
16 17
import org.eclipse.core.runtime.IProgressMonitor;
17 18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.jface.viewers.ViewerDropAdapter;
20 19

  
20
import eu.etaxonomy.cdm.api.service.ITermService;
21 21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
23
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
24
import eu.etaxonomy.cdm.model.common.TermBase;
25 22
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermDto;
27 25
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
28 26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
30 28

  
31 29
/**
32 30
 * @author l.morris
......
35 33
 */
36 34
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
37 35

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

  
42 40
	public MoveDefinedTermOperation(String label,
43 41
	        IUndoContext undoContext,
44
	        TermBase target,
45
	        Collection<DefinedTermBase> sourceTerms,
42
	        AbstractTermDto target,
43
	        Collection<TermDto> sourceTerms,
46 44
			IPostOperationEnabled postOperationEnabled,
47 45
			int currentLocation) {
48 46
		super(label, undoContext, postOperationEnabled);
......
55 53
	@Override
56 54
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57 55
			throws ExecutionException {
58

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

  
62
		//TODO move to ITermService
63

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

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

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

  
82
				cleanTerm(term);
83
				termVocabulary.addTerm(term);
84

  
85
			} else if (targetTermOrVocabulary instanceof DefinedTermBase) {
86
				cleanTerm(term);
87
				DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary;
88

  
89
				if(targetDefinedTerm instanceof OrderedTermBase && term instanceof OrderedTermBase) {
90
				    OrderedTermBase targetOrderedDefinedTerm = (OrderedTermBase)targetDefinedTerm;
91
				    TermVocabulary tVoc = targetOrderedDefinedTerm.getVocabulary();
92
				    if(tVoc instanceof OrderedTermVocabulary) {
93
				        OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc;
94
				        // the link between the location and the add term (below / above)
95
				        // method is determined by the compare method in the
96
				        // DefinedTermEditor's ViewerSorter (DefinedTermSorter) class
97
				        if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
98
				            otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
99
				            if (targetOrderedDefinedTerm.getPartOf() != null){
100
				                targetOrderedDefinedTerm.getPartOf().addIncludes(term);
101
				            }
102
				        }
103

  
104
				        if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
105
				            otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
106
				            if (targetOrderedDefinedTerm.getPartOf() != null){
107
				                targetOrderedDefinedTerm.getPartOf().addIncludes(term);
108
                            }
109
				        }
110
				        if(currentLocation == ViewerDropAdapter.LOCATION_ON) {
111
				            targetOrderedDefinedTerm.addIncludes(term);
112
				            targetOrderedDefinedTerm.getVocabulary().addTerm(term);
113
						}
114
				    }
115
				} else{
116
					targetDefinedTerm.addIncludes(term);
117
				    targetDefinedTerm.getVocabulary().addTerm(term);
118
				}
119

  
120
			}
121

  
122
		}
56
	    sourceTerms.forEach(term->
57
	    {
58
            UUID parentUuid = targetTermOrVocabulary.getUuid();
59
            boolean isKindOf = term.getKindOfUuid()!=null && term.getKindOfUuid().equals(parentUuid);
60
            CdmStore.getService(ITermService.class).moveTerm(term.getUuid(), parentUuid, isKindOf);
61
            //FIXME: implement moving for ordered terms
62
        });
63
//		// need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)
64
//		// and remove it from old associations
65
//
66
//
67
//		for (DefinedTermBase term : sourceTerms) {
68
//			// do nothing when moving it on itself
69
//			if(targetTermOrVocabulary.equals(term)){
70
//				Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term can not be added to itself");
71
//				MessagingUtils.informationDialog("", status);
72
//				return status;
73
//			}
74
//
75
//			if (targetTermOrVocabulary instanceof TermVocabulary) {
76
//				TermVocabulary termVocabulary = (TermVocabulary)targetTermOrVocabulary;
77
//
78
//				// do nothing when term is top level and gets added to the same vocabulary
79
//				if(term.getPartOf() == null && termVocabulary.equals(term.getVocabulary())){
80
//					Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term is already in this vocabulary");
81
//					MessagingUtils.informationDialog("", status);
82
//					return status;
83
//				}
84
//
85
//				cleanTerm(term);
86
//				termVocabulary.addTerm(term);
87
//
88
//			} else if (targetTermOrVocabulary instanceof DefinedTermBase) {
89
//				cleanTerm(term);
90
//				DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary;
91
//
92
//				if(targetDefinedTerm instanceof OrderedTermBase && term instanceof OrderedTermBase) {
93
//				    OrderedTermBase targetOrderedDefinedTerm = (OrderedTermBase)targetDefinedTerm;
94
//				    TermVocabulary tVoc = targetOrderedDefinedTerm.getVocabulary();
95
//				    if(tVoc instanceof OrderedTermVocabulary) {
96
//				        OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc;
97
//				        // the link between the location and the add term (below / above)
98
//				        // method is determined by the compare method in the
99
//				        // DefinedTermEditor's ViewerSorter (DefinedTermSorter) class
100
//				        if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {
101
//				            otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
102
//				            if (targetOrderedDefinedTerm.getPartOf() != null){
103
//				                targetOrderedDefinedTerm.getPartOf().addIncludes(term);
104
//				            }
105
//				        }
106
//
107
//				        if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {
108
//				            otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);
109
//				            if (targetOrderedDefinedTerm.getPartOf() != null){
110
//				                targetOrderedDefinedTerm.getPartOf().addIncludes(term);
111
//                            }
112
//				        }
113
//				        if(currentLocation == ViewerDropAdapter.LOCATION_ON) {
114
//				            targetOrderedDefinedTerm.addIncludes(term);
115
//				            targetOrderedDefinedTerm.getVocabulary().addTerm(term);
116
//						}
117
//				    }
118
//				} else{
119
//					targetDefinedTerm.addIncludes(term);
120
//				    targetDefinedTerm.getVocabulary().addTerm(term);
121
//				}
122
//
123
//			}
124
//
125
//		}
123 126
		return postExecute(targetTermOrVocabulary);
124 127
	}
125 128

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)