Project

General

Profile

Revision 50c9803d

ID50c9803d2bcaeb61844b9e4455fe9be8c0f28b4c
Parent f35bd02a
Child 8b0c4c63

Added by Patrick Plitzner over 3 years ago

ref #6694 Fix session handling when moving feature nodes

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDragListener.java
10 10

  
11 11
import org.eclipse.jface.viewers.IStructuredSelection;
12 12
import org.eclipse.jface.viewers.TreeViewer;
13
import org.eclipse.swt.dnd.DND;
14 13
import org.eclipse.swt.dnd.DragSourceAdapter;
15 14
import org.eclipse.swt.dnd.DragSourceEvent;
16 15

  
......
25 24
		this.viewer = viewer;
26 25
	}
27 26

  
28
	/**
29
	 * Method declared on DragSourceListener
30
	 */
31
	@Override
32
	public void dragFinished(DragSourceEvent event) {
33
		if (!event.doit) {
34
            return;
27
    /**
28
     * Method declared on DragSourceListener
29
     */
30
    @Override
31
    public void dragSetData(DragSourceEvent event) {
32
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
33
        FeatureNode[] featureNodes = (FeatureNode[]) selection.toList().toArray(new FeatureNode[selection.size()]);
34
        if (FeatureNodeTransfer.getInstance().isSupportedType(event.dataType)) {
35
            event.data = featureNodes;
35 36
        }
36
		// if the featureNode was moved, remove it from the source viewer
37
		if (event.detail == DND.DROP_MOVE) {
38
			IStructuredSelection selection = (IStructuredSelection) viewer
39
					.getSelection();
40
			viewer.remove(selection);
41
			viewer.refresh();
42
		}
43
	}
44

  
45
	/**
46
	 * Method declared on DragSourceListener
47
	 */
48
	@Override
49
	public void dragSetData(DragSourceEvent event) {
50
		IStructuredSelection selection = (IStructuredSelection) viewer
51
				.getSelection();
52
		FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
53
				.toArray(new FeatureNode[selection.size()]);
54
		if (FeatureNodeTransfer.getInstance().isSupportedType(
55
				event.dataType)) {
56
			event.data = featureNodes;
57
		}
58
	}
37
    }
59 38

  
60 39
	/**
61 40
	 * Method declared on DragSourceListener
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDropAdapter.java
13 13
import org.eclipse.jface.viewers.ViewerDropAdapter;
14 14
import org.eclipse.swt.dnd.TransferData;
15 15

  
16
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
16 17
import eu.etaxonomy.cdm.model.description.FeatureNode;
17 18
import eu.etaxonomy.cdm.model.description.FeatureTree;
18 19
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
19
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
20 21

  
21 22
class FeatureNodeDropAdapter extends ViewerDropAdapter {
22 23

  
23
	/**
24
     *
25
     */
26 24
    private final FeatureTreeEditor featureTreeEditor;
27 25

  
28 26
    protected FeatureNodeDropAdapter(FeatureTreeEditor featureTreeEditor, Viewer viewer) {
......
60 58

  
61 59
		// cannot drop a feature node onto itself
62 60
		for (Object droppedObject : droppedObjects) {
63
			if (droppedObject == null) {
64
				MessagingUtils.warningDialog(
65
								"Operation not supported yet",
66
								this,
67
								"We are currently unable to change the order of freshly created "
68
										+ "feature trees nodes. Please close and reopen the dialog to change the order of features.");
69
				return false;
70
			}
71 61
			if (droppedObject.equals(target)) {
72 62
				return false;
73 63
			}
74 64
		}
75 65
		for (Object droppedObject : droppedObjects) {
76 66
			FeatureNode droppedNode = (FeatureNode) droppedObject;
77
			target.addChild(droppedNode, position);
78
			viewer.add(target, droppedNode);
79
			viewer.reveal(droppedNode);
67
			CdmStore.getService(IFeatureNodeService.class).moveFeatureNode(droppedNode.getUuid(), target.getUuid(), position);
68
			viewer.refresh();
69
//			viewer.reveal(droppedNode);
80 70
		}
81 71
        this.featureTreeEditor.setDirty(true);
82 72
		return true;
83 73
	}
84 74

  
85
	@Override
86
	public boolean validateDrop(Object target, int operation,
87
			TransferData transferData) {
88
		return FeatureNodeTransfer.getInstance().isSupportedType(
89
				transferData);
90
	}
75
    @Override
76
    public boolean validateDrop(Object target, int operation, TransferData transferData) {
77
        return FeatureNodeTransfer.getInstance().isSupportedType(transferData);
78
    }
91 79

  
92 80
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
89 89
                }
90 90
            }
91 91
        }, new AddButtonListener(), new RemoveSelectionListener());
92
        composite.getText_title().setEnabled(false);
92 93
	}
93 94

  
94 95
	public void setDirty(boolean isDirty){
95 96
	    this.dirty.setDirty(isDirty);
96 97
	}
97 98

  
99
	public boolean isDirty(){
100
	    return dirty.isDirty();
101
	}
102

  
98 103
    public void setSelectedTree(FeatureTree featureTree) {
99 104
		this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class);
100 105
		this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class));
101 106
		composite.getViewer().setInput(featureTree);
102 107

  
108
		composite.getText_title().setEnabled(true);
103 109
		composite.getText_title().removeModifyListener(this);
104 110
		composite.getText_title().setText(featureTree.getTitleCache());
105 111
		composite.getText_title().addModifyListener(this);
......
156 162
						.getAdditionalFeatures();
157 163
				for (Feature feature : additionalFeatures) {
158 164
					FeatureNode child = FeatureNode.NewInstance(feature);
159
					CdmStore.getService(IFeatureNodeService.class).merge(child, true);
160

  
161 165
					parent.addChild(child);
166
					CdmStore.getService(IFeatureNodeService.class).save(child);
162 167
				}
163 168
				setDirty(true);
164 169
				composite.getViewer().refresh();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)