Project

General

Profile

« Previous | Next » 

Revision 353ce96b

Added by Patrick Plitzner about 5 years ago

ref #6805 Fix DnD positioning when moving and adding new terms

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeDropAdapter.java
73 73
			FeatureNode parent = target.getParent();
74 74
			if(parent!=null){
75 75
			    if (location == LOCATION_BEFORE) {
76
			        position = Math.max(0, parent.getIndex(target) - 1);
76
			        position = Math.max(0, parent.getIndex(target));
77 77
			        target = parent;
78 78
			    }
79 79

  
80 80
			    if (location == LOCATION_AFTER) {
81
			        position = parent.getIndex(target);
81
			        position = parent.getIndex(target)+1;
82 82
			        target = parent;
83 83
			    }
84 84
			}
......
111 111
		for (Object droppedObject : droppedObjects) {
112 112
		    if(droppedObject instanceof FeatureNode){
113 113
		        FeatureNode droppedNode = (FeatureNode) droppedObject;
114
		        int currentPosition = target.getIndex(droppedNode);
115
		        if(currentPosition<position){
116
		            position -= 1;
117
		        }
114 118
		        MoveFeatureOperation operation = new MoveFeatureOperation(droppedNode, target, position, getCurrentOperation(), editor, editor);
115 119
		        AbstractUtility.executeOperation(operation, sync);
116 120
		    }
......
118 122
		        Feature droppedFeature = (Feature) droppedObject;
119 123
		        AddFeatureOperation operation = new AddFeatureOperation(
120 124
		                (Feature) CdmStore.getService(ITermService.class).load(droppedFeature.getUuid()),
121
		                target, editor, editor);
125
		                target, position, editor, editor);
122 126
		        AbstractUtility.executeOperation(operation, sync);
123 127
		    }
124 128
		    else if(droppedObject instanceof TermDto){
......
127 131
		            if(term.isInstanceOf(Feature.class)){
128 132
		                AddFeatureOperation operation = new AddFeatureOperation(
129 133
		                        (Feature)term,
130
		                        target, editor, editor);
134
		                        target, position, editor, editor);
131 135
		                AbstractUtility.executeOperation(operation, sync);
132 136
		            }
133 137
		            else{
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/operation/AddFeatureOperation.java
31 31
public class AddFeatureOperation extends AbstractPostOperation<Feature> {
32 32

  
33 33
    private FeatureNode node;
34
    private int position;
34 35

  
35 36
    public AddFeatureOperation(Feature element, FeatureNode node,
36 37
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
38
        this(element, node, 0, postOperationEnabled, cdmEntitySessionEnabled);
39
    }
40
    public AddFeatureOperation(Feature element, FeatureNode node, int position,
41
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
37 42
        super("Add Feature", StoreUtil.getUndoContext(), element, postOperationEnabled, cdmEntitySessionEnabled);
38 43
        this.node = node;
44
        this.position = position;
39 45
    }
40 46

  
41 47
    @Override
42 48
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
43
        UpdateResult updateResult = CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(node.getUuid(), element.getUuid());
49
        UpdateResult updateResult = CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(node.getUuid(), element.getUuid(), position);
44 50
        return postExecute(updateResult.getCdmEntity());
45 51
    }
46 52

  

Also available in: Unified diff