Revision 739cbae5
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/TaxonNodeDropAdapter.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 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.editor.workingSet; |
|
10 |
|
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Collection; |
|
13 |
|
|
14 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
|
15 |
import org.eclipse.jface.viewers.ISelection; |
|
16 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
17 |
import org.eclipse.jface.viewers.ITreeSelection; |
|
18 |
import org.eclipse.jface.viewers.Viewer; |
|
19 |
import org.eclipse.jface.viewers.ViewerDropAdapter; |
|
20 |
import org.eclipse.swt.dnd.TransferData; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author pplitzner |
|
26 |
* @since Dec 19, 2017 |
|
27 |
* |
|
28 |
*/ |
|
29 |
public class TaxonNodeDropAdapter extends ViewerDropAdapter { |
|
30 |
|
|
31 |
private WorkingSetEditor workingSetEditor; |
|
32 |
|
|
33 |
public TaxonNodeDropAdapter(WorkingSetEditor workingSetEditor) { |
|
34 |
super(workingSetEditor.getTaxonTreeViewer()); |
|
35 |
this.workingSetEditor = workingSetEditor; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* {@inheritDoc} |
|
40 |
*/ |
|
41 |
@Override |
|
42 |
public boolean performDrop(Object data) { |
|
43 |
ITaxonTreeNode treeNode= (ITaxonTreeNode) ((ITreeSelection) data).getFirstElement(); |
|
44 |
Viewer taxonTreeViewer = workingSetEditor.getTaxonTreeViewer(); |
|
45 |
Object input = taxonTreeViewer.getInput(); |
|
46 |
Collection<ITaxonTreeNode> treeNodes; |
|
47 |
if(input==null){ |
|
48 |
treeNodes = new ArrayList<>(); |
|
49 |
} |
|
50 |
else{ |
|
51 |
treeNodes = (Collection<ITaxonTreeNode>) input; |
|
52 |
} |
|
53 |
treeNodes.add(treeNode); |
|
54 |
taxonTreeViewer.setInput(treeNodes); |
|
55 |
return true; |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* {@inheritDoc} |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public boolean validateDrop(Object target, int operation, TransferData transferType) { |
|
63 |
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); |
|
64 |
if(selection instanceof ITreeSelection |
|
65 |
&& ((IStructuredSelection) selection).size()==1 |
|
66 |
&& ((IStructuredSelection) selection).getFirstElement() instanceof ITaxonTreeNode){ |
|
67 |
return true; |
|
68 |
} |
|
69 |
return false; |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetComposite.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
10 | 10 |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import org.eclipse.jface.viewers.ITreeSelection; |
|
14 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
15 | 11 |
import org.eclipse.jface.viewers.TreeViewer; |
16 | 12 |
import org.eclipse.swt.SWT; |
17 | 13 |
import org.eclipse.swt.layout.GridData; |
... | ... | |
21 | 17 |
import org.eclipse.swt.widgets.Text; |
22 | 18 |
import org.eclipse.swt.widgets.Tree; |
23 | 19 |
|
24 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
25 | 20 |
import eu.etaxonomy.cdm.model.common.TermType; |
26 | 21 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
27 | 22 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
28 | 23 |
import eu.etaxonomy.cdm.model.name.Rank; |
29 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
30 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
31 | 24 |
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite; |
32 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
33 | 25 |
import eu.etaxonomy.taxeditor.ui.combo.TermUuidComboViewer; |
34 | 26 |
import eu.etaxonomy.taxeditor.util.TaxonTreeNodeContentProvider; |
35 | 27 |
import eu.etaxonomy.taxeditor.util.TaxonTreeNodeLabelProvider; |
... | ... | |
51 | 43 |
public WorkingSetComposite(Composite parent, int style) { |
52 | 44 |
super(parent, style); |
53 | 45 |
|
54 |
List<Classification> list = CdmStore.getService(IClassificationService.class).list(Classification.class, null, null, null, null); |
|
55 |
|
|
56 | 46 |
setLayout(new GridLayout(3, false)); |
57 | 47 |
|
58 | 48 |
Label lblNewLabel = new Label(this, SWT.NONE); |
... | ... | |
78 | 68 |
|
79 | 69 |
taxonNodeTree.setContentProvider(new TaxonTreeNodeContentProvider()); |
80 | 70 |
taxonNodeTree.setLabelProvider(new TaxonTreeNodeLabelProvider()); |
81 |
taxonNodeTree.setInput(list); |
|
82 | 71 |
|
83 | 72 |
Label lblNewLabel_3 = new Label(this, SWT.NONE); |
84 | 73 |
lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
... | ... | |
134 | 123 |
featureTreeEditorComposite.setSelectedTree(characters, null); |
135 | 124 |
} |
136 | 125 |
|
137 |
public TaxonNode getTaxonNode(){ |
|
138 |
ITreeSelection selection = (ITreeSelection) taxonNodeTree.getSelection(); |
|
139 |
if(selection!=null && selection.getFirstElement() instanceof TaxonNode){ |
|
140 |
return (TaxonNode) selection.getFirstElement(); |
|
141 |
} |
|
142 |
return null; |
|
143 |
} |
|
144 |
public void setTaxonNode(TaxonNode taxonNode){ |
|
145 |
taxonNodeTree.setSelection(new StructuredSelection(taxonNode), true); |
|
126 |
public TreeViewer getTaxonNodeTree() { |
|
127 |
return taxonNodeTree; |
|
146 | 128 |
} |
147 | 129 |
|
148 | 130 |
public NamedArea getArea(){ |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java | ||
---|---|---|
25 | 25 |
import org.eclipse.e4.ui.di.Persist; |
26 | 26 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable; |
27 | 27 |
import org.eclipse.e4.ui.services.IServiceConstants; |
28 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
|
29 |
import org.eclipse.jface.viewers.Viewer; |
|
28 | 30 |
import org.eclipse.swt.SWT; |
31 |
import org.eclipse.swt.dnd.DND; |
|
32 |
import org.eclipse.swt.dnd.Transfer; |
|
29 | 33 |
import org.eclipse.swt.events.ModifyEvent; |
30 | 34 |
import org.eclipse.swt.events.ModifyListener; |
31 | 35 |
import org.eclipse.swt.widgets.Composite; |
32 | 36 |
import org.eclipse.swt.widgets.Display; |
33 |
import org.eclipse.swt.widgets.Listener; |
|
34 | 37 |
import org.eclipse.swt.widgets.Shell; |
35 | 38 |
|
36 | 39 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
... | ... | |
44 | 47 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
45 | 48 |
import eu.etaxonomy.cdm.model.name.Rank; |
46 | 49 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
50 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
|
47 | 51 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
48 | 52 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
49 | 53 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
64 | 68 |
|
65 | 69 |
private WorkingSet workingSet; |
66 | 70 |
|
71 |
private final int dndOperations = DND.DROP_MOVE; |
|
72 |
|
|
67 | 73 |
@Inject |
68 | 74 |
private MDirtyable dirty; |
69 | 75 |
|
70 |
private Listener nameAreaSelectionListener; |
|
71 |
|
|
72 | 76 |
private ModifyListener labelModifyListener; |
73 | 77 |
|
74 | 78 |
@PostConstruct |
... | ... | |
100 | 104 |
} |
101 | 105 |
dirty.setDirty(true); |
102 | 106 |
}); |
107 |
|
|
108 |
//add drag'n'drop support |
|
109 |
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()}; |
|
110 |
composite.getTaxonNodeTree().addDropSupport(dndOperations, transfers, new TaxonNodeDropAdapter(this)); |
|
111 |
|
|
103 | 112 |
} |
104 | 113 |
|
105 | 114 |
public void init(UUID workingSetUuid) { |
... | ... | |
137 | 146 |
if(area!=null){ |
138 | 147 |
areas.add(area); |
139 | 148 |
} |
140 |
TaxonNode taxonNode = composite.getTaxonNode(); |
|
141 |
Set<NamedArea> descriptions; |
|
142 |
if(taxonNode!=null && taxonNode.getTaxon()!=null){ |
|
143 |
Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class); |
|
144 |
Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null); |
|
145 |
for (SpecimenOrObservationBase specimen : specimens) { |
|
146 |
Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions(); |
|
147 |
for (SpecimenDescription specimenDescription : specimenDescriptions) { |
|
148 |
workingSet.addDescription(specimenDescription); |
|
149 |
Object input = composite.getTaxonNodeTree().getInput(); |
|
150 |
if(input!=null){ |
|
151 |
Collection<ITaxonTreeNode> taxonNodes = (Collection<ITaxonTreeNode>) input; |
|
152 |
for (ITaxonTreeNode taxonTreeNode : taxonNodes) { |
|
153 |
if(taxonTreeNode instanceof TaxonNode){ |
|
154 |
TaxonNode taxonNode = (TaxonNode)taxonTreeNode; |
|
155 |
workingSet.addTaxonSubtree(taxonNode); |
|
156 |
Set<NamedArea> descriptions; |
|
157 |
if(taxonNode!=null && taxonNode.getTaxon()!=null){ |
|
158 |
Taxon taxon = HibernateProxyHelper.deproxy(taxonNode.getTaxon(), Taxon.class); |
|
159 |
Collection<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null); |
|
160 |
for (SpecimenOrObservationBase specimen : specimens) { |
|
161 |
Set<SpecimenDescription> specimenDescriptions = specimen.getSpecimenDescriptions(); |
|
162 |
for (SpecimenDescription specimenDescription : specimenDescriptions) { |
|
163 |
workingSet.addDescription(specimenDescription); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
149 | 167 |
} |
150 | 168 |
} |
151 | 169 |
} |
... | ... | |
164 | 182 |
workingSet.setMaxRank(rankMax); |
165 | 183 |
workingSet.setMinRank(rankMin); |
166 | 184 |
workingSet.setDescriptiveSystem(characters); |
167 |
workingSet.addTaxonSubtree(taxonNode); |
|
168 | 185 |
workingSet.setGeoFilter(areas); |
169 | 186 |
|
170 | 187 |
conversation.commit(); |
... | ... | |
188 | 205 |
} |
189 | 206 |
} |
190 | 207 |
|
208 |
public Viewer getTaxonTreeViewer() { |
|
209 |
return composite.getTaxonNodeTree(); |
|
210 |
} |
|
211 |
|
|
191 | 212 |
} |
Also available in: Unified diff
ref #7086 Allow drag and drop for taxon filter from taxon navigator