Revision 85732b4d
Added by Niels Hoffmann almost 13 years ago
.gitattributes | ||
---|---|---|
532 | 532 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigator.java -text |
533 | 533 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDataChangeBehavior.java -text |
534 | 534 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeContentProvider.java -text |
535 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeDropAdapterAssistant.java -text |
|
536 | 535 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java -text |
537 | 536 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodePropertyTester.java -text |
537 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java -text |
|
538 | 538 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java -text |
539 | 539 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/EditHandler.java -text |
540 | 540 |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java -text |
eu.etaxonomy.taxeditor.navigation/plugin.xml | ||
---|---|---|
365 | 365 |
value="eu.etaxonomy.cdm.model.taxon.TaxonNode"> |
366 | 366 |
</instanceof> |
367 | 367 |
</possibleChildren> |
368 |
<dropAssistant |
|
369 |
class="eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapterAssistant" |
|
370 |
id="eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"> |
|
371 |
<possibleDropTargets></possibleDropTargets> |
|
372 |
</dropAssistant> |
|
368 | 373 |
</navigatorContent> |
369 | 374 |
<navigatorContent |
370 | 375 |
contentProvider="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodeContentProvider" |
... | ... | |
388 | 393 |
</or> |
389 | 394 |
</triggerPoints> |
390 | 395 |
<dropAssistant |
391 |
class="eu.etaxonomy.taxeditor.navigation.navigator.TaxonNodeDropAdapterAssistant"
|
|
396 |
class="eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapterAssistant"
|
|
392 | 397 |
id="eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"> |
393 | 398 |
<possibleDropTargets> |
394 | 399 |
<or> |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeDropAdapterAssistant.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.navigation.navigator; |
|
12 |
|
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.Iterator; |
|
15 |
import java.util.Set; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.eclipse.core.commands.operations.IUndoContext; |
|
19 |
import org.eclipse.core.runtime.IStatus; |
|
20 |
import org.eclipse.core.runtime.Status; |
|
21 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
22 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
|
23 |
import org.eclipse.jface.viewers.ISelection; |
|
24 |
import org.eclipse.jface.viewers.TreeSelection; |
|
25 |
import org.eclipse.swt.dnd.DropTargetEvent; |
|
26 |
import org.eclipse.swt.dnd.TransferData; |
|
27 |
import org.eclipse.ui.navigator.CommonDropAdapter; |
|
28 |
import org.eclipse.ui.navigator.CommonDropAdapterAssistant; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.ITreeNode; |
|
32 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
33 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
34 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; |
|
35 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
36 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
37 |
|
|
38 |
/** |
|
39 |
* <p>TaxonNodeDropAdapterAssistant class.</p> |
|
40 |
* |
|
41 |
* @author p.ciardelli |
|
42 |
* @created 03.06.2009 |
|
43 |
* @version 1.0 |
|
44 |
*/ |
|
45 |
public class TaxonNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled{ |
|
46 |
private static final Logger logger = Logger |
|
47 |
.getLogger(TaxonNodeDropAdapterAssistant.class); |
|
48 |
|
|
49 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */ |
|
50 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ |
|
51 |
|
|
52 |
/* (non-Javadoc) |
|
53 |
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) |
|
54 |
*/ |
|
55 |
/** {@inheritDoc} */ |
|
56 |
@Override |
|
57 |
public IStatus handleDrop(CommonDropAdapter dropAdapter, |
|
58 |
DropTargetEvent dropTargetEvent, Object target) { |
|
59 |
|
|
60 |
if (target instanceof ITreeNode) { |
|
61 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
|
62 |
ITreeNode targetTreeNode = (ITreeNode) target; |
|
63 |
if(taxonNodes != null) |
|
64 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
65 |
} |
|
66 |
|
|
67 |
return Status.CANCEL_STATUS; |
|
68 |
} |
|
69 |
|
|
70 |
private Set<TaxonNode> getSelectedTaxa(){ |
|
71 |
HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>(); |
|
72 |
|
|
73 |
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); |
|
74 |
if (selection instanceof TreeSelection) { |
|
75 |
|
|
76 |
Iterator selectionIterator = ((TreeSelection) selection).iterator(); |
|
77 |
|
|
78 |
while (selectionIterator.hasNext()){ |
|
79 |
Object object = selectionIterator.next(); |
|
80 |
if(object instanceof TaxonNode){ |
|
81 |
TaxonNode taxonNode = (TaxonNode) object; |
|
82 |
taxonNodes.add(taxonNode); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
return taxonNodes.size() > 0 ? taxonNodes : null; |
|
87 |
} |
|
88 |
|
|
89 |
/* (non-Javadoc) |
|
90 |
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) |
|
91 |
*/ |
|
92 |
/** {@inheritDoc} */ |
|
93 |
@Override |
|
94 |
public IStatus validateDrop(Object target, int operation, |
|
95 |
TransferData transferType) { |
|
96 |
if (target instanceof ITreeNode) { |
|
97 |
// do not allow to drop onto itself |
|
98 |
for(TaxonNode taxonNode : getSelectedTaxa()){ |
|
99 |
if (taxonNode.equals(target)) { |
|
100 |
return Status.CANCEL_STATUS; |
|
101 |
} |
|
102 |
} |
|
103 |
return Status.OK_STATUS; |
|
104 |
} |
|
105 |
return Status.CANCEL_STATUS; |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* @param childTaxonNode |
|
111 |
* @param parentTaxon |
|
112 |
* @return |
|
113 |
*/ |
|
114 |
private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITreeNode targetITreeNode) { |
|
115 |
|
|
116 |
TaxonNavigator taxonNavigator; |
|
117 |
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); |
|
118 |
|
|
119 |
if(targetITreeNode instanceof TaxonNode){ |
|
120 |
|
|
121 |
TaxonNode targetTaxonNode = (TaxonNode) targetITreeNode; |
|
122 |
|
|
123 |
// for(TaxonNode taxonNode : taxonNodes){ |
|
124 |
// if (taxonNode.equals(targetTaxonNode)) { |
|
125 |
// return Status.CANCEL_STATUS; |
|
126 |
// } |
|
127 |
// } |
|
128 |
|
|
129 |
// Make sure parent taxon does not have unsaved changes |
|
130 |
if (NavigationUtil.isDirty(targetTaxonNode)){ |
|
131 |
MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + |
|
132 |
"changes in the parent taxon. Pleas save first."); |
|
133 |
return Status.CANCEL_STATUS; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
// Make sure parentTaxon is not the drop target |
|
138 |
// if (!childTaxonNode.isTopmostNode() && childTaxonNode.getParent().equals(targetTaxonNode)){ |
|
139 |
// return Status.CANCEL_STATUS; |
|
140 |
// } |
|
141 |
|
|
142 |
// Make sure taxon is not being dropped onto itself |
|
143 |
// if (childTaxonNode.equals(targetTaxonNode)) { |
|
144 |
// return Status.CANCEL_STATUS; |
|
145 |
// } |
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); |
|
152 |
if (workspaceUndoContext == null) { |
|
153 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
|
154 |
return Status.CANCEL_STATUS; |
|
155 |
} |
|
156 |
|
|
157 |
AbstractPostOperation operation = new MoveTaxonOperation |
|
158 |
("Move Taxon", workspaceUndoContext, taxonNodes, targetITreeNode, this, taxonNavigator); |
|
159 |
NavigationUtil.executeOperation(operation); |
|
160 |
|
|
161 |
logger.info("Moved taxa to new parent " + targetITreeNode); |
|
162 |
return Status.OK_STATUS; |
|
163 |
} |
|
164 |
|
|
165 |
/* (non-Javadoc) |
|
166 |
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) |
|
167 |
*/ |
|
168 |
/** {@inheritDoc} */ |
|
169 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
170 |
return true; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* <p>onComplete</p> |
|
175 |
* |
|
176 |
* @return a boolean. |
|
177 |
*/ |
|
178 |
public boolean onComplete() { |
|
179 |
// TODO Auto-generated method stub |
|
180 |
return false; |
|
181 |
} |
|
182 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.taxeditor.navigation.navigator; |
|
12 |
|
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.Iterator; |
|
15 |
import java.util.Set; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
18 |
import org.eclipse.core.commands.operations.IUndoContext; |
|
19 |
import org.eclipse.core.runtime.IStatus; |
|
20 |
import org.eclipse.core.runtime.Status; |
|
21 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
22 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
|
23 |
import org.eclipse.jface.viewers.ISelection; |
|
24 |
import org.eclipse.jface.viewers.TreeSelection; |
|
25 |
import org.eclipse.swt.dnd.DropTargetEvent; |
|
26 |
import org.eclipse.swt.dnd.TransferData; |
|
27 |
import org.eclipse.ui.navigator.CommonDropAdapter; |
|
28 |
import org.eclipse.ui.navigator.CommonDropAdapterAssistant; |
|
29 |
|
|
30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.ITreeNode; |
|
32 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
33 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
34 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; |
|
35 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
36 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
|
37 |
|
|
38 |
/** |
|
39 |
* <p>TaxonNodeDropAdapterAssistant class.</p> |
|
40 |
* |
|
41 |
* @author p.ciardelli |
|
42 |
* @created 03.06.2009 |
|
43 |
* @version 1.0 |
|
44 |
*/ |
|
45 |
public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled{ |
|
46 |
private static final Logger logger = Logger |
|
47 |
.getLogger(TreeNodeDropAdapterAssistant.class); |
|
48 |
|
|
49 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */ |
|
50 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ |
|
51 |
|
|
52 |
/* (non-Javadoc) |
|
53 |
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) |
|
54 |
*/ |
|
55 |
/** {@inheritDoc} */ |
|
56 |
@Override |
|
57 |
public IStatus handleDrop(CommonDropAdapter dropAdapter, |
|
58 |
DropTargetEvent dropTargetEvent, Object target) { |
|
59 |
|
|
60 |
if (target instanceof ITreeNode) { |
|
61 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
|
62 |
ITreeNode targetTreeNode = (ITreeNode) target; |
|
63 |
if(taxonNodes != null) |
|
64 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
65 |
} |
|
66 |
|
|
67 |
return Status.CANCEL_STATUS; |
|
68 |
} |
|
69 |
|
|
70 |
private Set<TaxonNode> getSelectedTaxa(){ |
|
71 |
HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>(); |
|
72 |
|
|
73 |
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); |
|
74 |
if (selection instanceof TreeSelection) { |
|
75 |
|
|
76 |
Iterator selectionIterator = ((TreeSelection) selection).iterator(); |
|
77 |
|
|
78 |
while (selectionIterator.hasNext()){ |
|
79 |
Object object = selectionIterator.next(); |
|
80 |
if(object instanceof TaxonNode){ |
|
81 |
TaxonNode taxonNode = (TaxonNode) object; |
|
82 |
taxonNodes.add(taxonNode); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
return taxonNodes.size() > 0 ? taxonNodes : null; |
|
87 |
} |
|
88 |
|
|
89 |
/* (non-Javadoc) |
|
90 |
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) |
|
91 |
*/ |
|
92 |
/** {@inheritDoc} */ |
|
93 |
@Override |
|
94 |
public IStatus validateDrop(Object target, int operation, |
|
95 |
TransferData transferType) { |
|
96 |
if (target instanceof ITreeNode) { |
|
97 |
// do not allow to drop onto itself |
|
98 |
for(TaxonNode taxonNode : getSelectedTaxa()){ |
|
99 |
if (taxonNode.equals(target)) { |
|
100 |
return Status.CANCEL_STATUS; |
|
101 |
} |
|
102 |
} |
|
103 |
return Status.OK_STATUS; |
|
104 |
} |
|
105 |
return Status.CANCEL_STATUS; |
|
106 |
} |
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* @param childTaxonNode |
|
111 |
* @param parentTaxon |
|
112 |
* @return |
|
113 |
*/ |
|
114 |
private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITreeNode targetITreeNode) { |
|
115 |
|
|
116 |
TaxonNavigator taxonNavigator; |
|
117 |
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); |
|
118 |
|
|
119 |
if(targetITreeNode instanceof TaxonNode){ |
|
120 |
|
|
121 |
TaxonNode targetTaxonNode = (TaxonNode) targetITreeNode; |
|
122 |
|
|
123 |
// for(TaxonNode taxonNode : taxonNodes){ |
|
124 |
// if (taxonNode.equals(targetTaxonNode)) { |
|
125 |
// return Status.CANCEL_STATUS; |
|
126 |
// } |
|
127 |
// } |
|
128 |
|
|
129 |
// Make sure parent taxon does not have unsaved changes |
|
130 |
if (NavigationUtil.isDirty(targetTaxonNode)){ |
|
131 |
MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + |
|
132 |
"changes in the parent taxon. Pleas save first."); |
|
133 |
return Status.CANCEL_STATUS; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
// Make sure parentTaxon is not the drop target |
|
138 |
// if (!childTaxonNode.isTopmostNode() && childTaxonNode.getParent().equals(targetTaxonNode)){ |
|
139 |
// return Status.CANCEL_STATUS; |
|
140 |
// } |
|
141 |
|
|
142 |
// Make sure taxon is not being dropped onto itself |
|
143 |
// if (childTaxonNode.equals(targetTaxonNode)) { |
|
144 |
// return Status.CANCEL_STATUS; |
|
145 |
// } |
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); |
|
152 |
if (workspaceUndoContext == null) { |
|
153 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
|
154 |
return Status.CANCEL_STATUS; |
|
155 |
} |
|
156 |
|
|
157 |
AbstractPostOperation operation = new MoveTaxonOperation |
|
158 |
("Move Taxon", workspaceUndoContext, taxonNodes, targetITreeNode, this, taxonNavigator); |
|
159 |
NavigationUtil.executeOperation(operation); |
|
160 |
|
|
161 |
logger.info("Moved taxa to new parent " + targetITreeNode); |
|
162 |
return Status.OK_STATUS; |
|
163 |
} |
|
164 |
|
|
165 |
/* (non-Javadoc) |
|
166 |
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) |
|
167 |
*/ |
|
168 |
/** {@inheritDoc} */ |
|
169 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
|
170 |
return true; |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
174 |
* <p>onComplete</p> |
|
175 |
* |
|
176 |
* @return a boolean. |
|
177 |
*/ |
|
178 |
public boolean onComplete() { |
|
179 |
// TODO Auto-generated method stub |
|
180 |
return false; |
|
181 |
} |
|
182 |
} |
Also available in: Unified diff
It is now possible to drag a taxon onto another classification, previously it one was only able to drag onto taxon nodes