Project

General

Profile

Revision 24c83069

ID24c83069d06bcf854a8cbc574e3473f40cc2587a
Parent ccce86df
Child c87fb375

Added by Patrick Plitzner over 3 years ago

ref #7362 Implement term import from GfBio terminology service via DnD

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDropAdapter.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.featuretree.e4;
10 10

  
11
import java.net.URI;
12
import java.util.Arrays;
13
import java.util.Collection;
14
import java.util.Collections;
15

  
11 16
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
17
import org.eclipse.jface.util.LocalSelectionTransfer;
18
import org.eclipse.jface.viewers.IStructuredSelection;
12 19
import org.eclipse.jface.viewers.TreeViewer;
13 20
import org.eclipse.jface.viewers.Viewer;
14 21
import org.eclipse.jface.viewers.ViewerDropAdapter;
......
20 27
import eu.etaxonomy.cdm.model.description.FeatureTree;
21 28
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
22 29
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
30
import eu.etaxonomy.taxeditor.l10n.Messages;
31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23 32
import eu.etaxonomy.taxeditor.store.CdmStore;
33
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
24 34

  
25 35
public class FeatureNodeDropAdapter extends ViewerDropAdapter {
26 36

  
27
    private final MDirtyable dirtyable;
37
    private MDirtyable dirtyable;
28 38

  
29 39
    public FeatureNodeDropAdapter(MDirtyable dirtyable, Viewer viewer) {
30 40
		super(viewer);
31
        this.dirtyable = dirtyable;
41
		this.dirtyable = dirtyable;
32 42
	}
33 43

  
34 44
	@Override
35 45
	public boolean performDrop(Object data) {
36
		FeatureNode target = (FeatureNode) getCurrentTarget();
46
		Object currentTarget = getCurrentTarget();
47
		FeatureNode target = null;
48
		if(currentTarget instanceof FeatureTree){
49
		    target = ((FeatureTree) currentTarget).getRoot();
50
		}
51
		else if(currentTarget instanceof FeatureNode){
52
		    target = (FeatureNode) currentTarget;
53
		}
54
		else{
55
		    MessagingUtils.warningDialog(Messages.FeatureNodeDropAdapter_INVALID_TARGET, this, Messages.FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE);
56
		    return false;
57
		}
37 58
		int position = 0;
38 59

  
39 60
		if (target != null) {
......
50 71
			}
51 72
		}
52 73

  
53
		// set target to root node if there is no target specified
54
		if (target == null) {
55
			FeatureTree featureTree = (FeatureTree) getViewer().getInput();
56
			target = featureTree.getRoot();
74
		Collection<Object> droppedObjects = Collections.emptyList();
75
		if(data instanceof Object[]){
76
		    droppedObjects = Arrays.asList((Object[])data);
77
		}
78
		else if(data instanceof IStructuredSelection){
79
		    droppedObjects = ((IStructuredSelection) data).toList();
57 80
		}
58

  
59
		Object[] droppedObjects = (Object[]) data;
60 81
		TreeViewer viewer = (TreeViewer) getViewer();
61 82

  
62 83
		// cannot drop a feature node onto itself
......
74 95
		    else if(droppedObject instanceof Feature){
75 96
		        Feature droppedFeature = (Feature) droppedObject;
76 97
		        CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(target.getUuid(), droppedFeature.getUuid());
77

  
98
		    }
99
		    else if(droppedObject instanceof OntologyTermWrapper){
100
		        OntologyTermWrapper wrapper = (OntologyTermWrapper)droppedObject;
101
		        Feature feature = Feature.NewInstance(wrapper.getLabel(), wrapper.getLabel(), wrapper.getLabel());
102
		        feature.setUri(URI.create(wrapper.getUri()));
103
		        CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(target, feature);
78 104
		    }
79 105
		}
106
		dirtyable.setDirty(true);
80 107
		viewer.refresh();
81 108
		return true;
82 109
	}
......
85 112
    public boolean validateDrop(Object target, int operation, TransferData transferData) {
86 113
        boolean isSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferData);
87 114
        isSupported |= TermTransfer.getInstance().isSupportedType(transferData);
115
        isSupported |= LocalSelectionTransfer.getTransfer().isSupportedType(transferData);
88 116
        isSupported &= getViewer().getInput()!=null;
89 117
        return isSupported;
90 118
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
28 28
import org.eclipse.e4.ui.services.EMenuService;
29 29
import org.eclipse.e4.ui.workbench.modeling.EPartService;
30 30
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
31
import org.eclipse.jface.util.LocalSelectionTransfer;
31 32
import org.eclipse.jface.viewers.ISelectionChangedListener;
32 33
import org.eclipse.jface.viewers.IStructuredSelection;
33 34
import org.eclipse.jface.viewers.SelectionChangedEvent;
......
112 113
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
113 114

  
114 115
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
115
        Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
116
                .getInstance(), TermTransfer.getInstance() };
116
        Transfer[] transfers = new Transfer[] {
117
                FeatureNodeTransfer.getInstance(),
118
                TermTransfer.getInstance(),
119
                LocalSelectionTransfer.getTransfer()};
117 120
        viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(viewer));
118 121
        viewer.addDropSupport(ops, transfers, new FeatureNodeDropAdapter(dirty, viewer));
119 122
        viewer.addSelectionChangedListener(this);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
256 256

  
257 257

  
258 258

  
259
    public static String FeatureNodeDropAdapter_INVALID_TARGET;
260

  
261

  
262
    public static String FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE;
263

  
264

  
259 265
    public static String FeatureTreeEditorComposite_ADD_FEATURE;
260 266

  
261 267

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
207 207
ExcelDistributionUpdateWizard_ConfiguratorWizard_label=Configure Excel distribution update
208 208
AbstractImportWizard_ConfigurationLabel=Configure the Import
209 209
TCSImportWizard_ConfiguratorWizard_label=Configure the TCS import
210
FeatureNodeDropAdapter_INVALID_TARGET=Invalid target
211
FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE=Chosen target is not valid
210 212
FeatureTreeEditorComposite_ADD_FEATURE=Add a feature to this feature tree.
211 213
FeatureTreeEditorComposite_FEATURE_TREE=Feature Tree
212 214
FeatureTreeEditorComposite_OPEN_TREE=Open Tree
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties
207 207
ExcelDistributionUpdateWizard_ConfiguratorWizard_label=Konfiguration des Excel Distribution Updates
208 208
AbstractImportWizard_ConfigurationLabel=Konfiguration des Imports
209 209
TCSImportWizard_ConfiguratorWizard_label=Konfiguration des TCS Imports
210
FeatureNodeDropAdapter_INVALID_TARGET=Ziel ung?ltig
211
FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE=Das ausgew?hlte Ziel ist ung?tlig
210 212
FeatureTreeEditorComposite_ADD_FEATURE=Merkmal zum Merkmalsbaum hinzuf?gen
211 213
FeatureTreeEditorComposite_FEATURE_TREE=Merkmalsbaum
212 214
FeatureTreeEditorComposite_OPEN_TREE=Merkmalsbaum ?ffnen
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/webimport/termimport/GfBioTerminologyImportPresenter.java
14 14
import org.eclipse.swt.SWT;
15 15
import org.eclipse.swt.dnd.DND;
16 16
import org.eclipse.swt.dnd.DragSourceAdapter;
17
import org.eclipse.swt.dnd.DragSourceEvent;
17 18
import org.eclipse.swt.dnd.Transfer;
18 19
import org.eclipse.swt.events.KeyAdapter;
19 20
import org.eclipse.swt.events.KeyEvent;
......
58 59
        composite.getTreeTermHierarchy().setContentProvider(new OntologyTermContentProvider());
59 60
        composite.getTreeTermHierarchy().setLabelProvider(new OntologyTermLabelProvider());
60 61
        Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),};
61
        composite.getTreeTermHierarchy().addDragSupport(DND.DROP_COPY,
62
        composite.getTreeTermHierarchy().addDragSupport(DND.DROP_MOVE,
62 63
                transfers, new DragSourceAdapter() {
64

  
63 65
            @Override
64
            public void dragSetData(org.eclipse.swt.dnd.DragSourceEvent event) {
66
            public void dragSetData(DragSourceEvent event) {
65 67
                if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
66 68
                    LocalSelectionTransfer.getTransfer().setSelection(composite.getTreeTermHierarchy().getSelection());
67 69
                }
68 70
            }
71
            @Override
72
            public void dragStart(DragSourceEvent event) {
73
                event.doit = !composite.getTreeTermHierarchy().getSelection().isEmpty();
74
            }
69 75
        });
70 76
    }
71 77

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)