Revision cedc4ff1
Added by Katja Luther about 6 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TreeNodeDropAdapterE4.java | ||
---|---|---|
26 | 26 |
import org.eclipse.swt.dnd.DropTargetEvent; |
27 | 27 |
import org.eclipse.swt.dnd.TransferData; |
28 | 28 |
|
29 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
30 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; |
|
29 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
30 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
|
32 | 31 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
32 |
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto; |
|
33 | 33 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD; |
34 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
35 | 34 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
36 |
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation; |
|
37 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
38 | 35 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
39 | 36 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
40 | 37 |
|
... | ... | |
56 | 53 |
private static final Logger logger = Logger.getLogger(TreeNodeDropAdapterE4.class); |
57 | 54 |
|
58 | 55 |
private TaxonNavigatorE4 taxonNavigator; |
56 |
UpdateResult result; |
|
59 | 57 |
|
60 | 58 |
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ |
61 | 59 |
|
... | ... | |
74 | 72 |
@Override |
75 | 73 |
public boolean performDrop(Object data) { |
76 | 74 |
Object target = getCurrentTarget(); |
77 |
if (getCurrentTarget() instanceof ITaxonTreeNode) {
|
|
78 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
|
79 |
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
|
|
80 |
if (targetTreeNode instanceof Classification){
|
|
81 |
targetTreeNode = ((Classification)targetTreeNode).getRootNode(); |
|
82 |
targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); |
|
83 |
} |
|
75 |
if (getCurrentTarget() instanceof TaxonNodeDto) {
|
|
76 |
Set<TaxonNodeDto> taxonNodes = getSelectedTaxa();
|
|
77 |
TaxonNodeDto targetTreeNode = (TaxonNodeDto) target;
|
|
78 |
// if (targetTreeNode.getType() != null && targetTreeNode.getType().equals(Classification.class)){
|
|
79 |
// targetTreeNode = ((Classification)targetTreeNode).getRootNode();
|
|
80 |
// targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class);
|
|
81 |
// }
|
|
84 | 82 |
if(taxonNodes != null) { |
85 | 83 |
if (taxonNodes.size() == 1){ |
86 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
84 |
boolean success = moveTaxon(taxonNodes, targetTreeNode); |
|
85 |
if (success){ |
|
86 |
taxonNavigator.refresh(); |
|
87 |
} |
|
88 |
return success; |
|
87 | 89 |
} else{ |
88 | 90 |
if( MessageDialog.openConfirm(null, Messages.TreeNodeDropAdapter_MOVING, Messages.TreeNodeDropAdapter_MOVING_MESSAGE)){ |
89 | 91 |
return true; |
... | ... | |
94 | 96 |
return false; |
95 | 97 |
} |
96 | 98 |
|
97 |
private Set<TaxonNode> getSelectedTaxa(){ |
|
98 |
HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
|
|
99 |
private Set<TaxonNodeDto> getSelectedTaxa(){
|
|
100 |
HashSet<TaxonNodeDto> taxonNodes = new HashSet();
|
|
99 | 101 |
|
100 | 102 |
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); |
101 | 103 |
if (selection instanceof TreeSelection) { |
... | ... | |
104 | 106 |
|
105 | 107 |
while (selectionIterator.hasNext()){ |
106 | 108 |
Object object = selectionIterator.next(); |
107 |
if(object instanceof TaxonNode){ |
|
108 |
TaxonNode taxonNode = (TaxonNode) object;
|
|
109 |
if(object instanceof TaxonNodeDto){
|
|
110 |
TaxonNodeDto taxonNode = (TaxonNodeDto) object;
|
|
109 | 111 |
taxonNodes.add(taxonNode); |
110 | 112 |
} |
111 | 113 |
} |
... | ... | |
118 | 120 |
public boolean validateDrop(Object target, int operation, |
119 | 121 |
TransferData transferType) { |
120 | 122 |
|
121 |
if (target instanceof ITaxonTreeNode) {
|
|
123 |
if (target instanceof TaxonNodeDto) {
|
|
122 | 124 |
|
123 | 125 |
// check users permissions with target taxonnode and taxon |
124 |
if (target instanceof TaxonNode) { |
|
125 |
TaxonNode targetNode = (TaxonNode)target; |
|
126 |
boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE); |
|
127 |
boolean hasTargetTaxonPermission = targetNode.getTaxon() == null ? |
|
126 |
if (target instanceof TaxonNodeDto) { |
|
127 |
TaxonNodeDto targetNode = (TaxonNodeDto)target; |
|
128 |
TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(targetNode.getUuid()); |
|
129 |
boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(node, UPDATE); |
|
130 |
boolean hasTargetTaxonPermission = node.getTaxon() == null ? |
|
128 | 131 |
true : |
129 |
CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE);
|
|
132 |
CdmStore.currentAuthentiationHasPermission(node.getTaxon(), UPDATE);
|
|
130 | 133 |
|
131 | 134 |
if(logger.isDebugEnabled()){ |
132 |
logger.debug("target: " + targetNode.getTaxon() == null? "-" : targetNode.getTaxon().getTitleCache()); //$NON-NLS-1$
|
|
135 |
logger.debug("target: " + node.getTaxon() == null? "-" : node.getTaxon().getTitleCache()); //$NON-NLS-1$
|
|
133 | 136 |
} |
134 | 137 |
|
135 | 138 |
if(!hasTargetNodePermission || ! hasTargetNodePermission){ |
... | ... | |
142 | 145 |
|
143 | 146 |
// do not allow to drop onto itself and |
144 | 147 |
// check users permissions with all selected taxon nodes and taxa |
145 |
for(TaxonNode taxonNode : getSelectedTaxa()){ |
|
148 |
for(TaxonNodeDto taxonNode : getSelectedTaxa()){
|
|
146 | 149 |
if (logger.isDebugEnabled()){ |
147 |
logger.debug("selectedTaxa: " + taxonNode.getTaxon() == null? "-" : taxonNode.getTaxon().getTitleCache()); //$NON-NLS-1$
|
|
150 |
logger.debug("selectedTaxa: " + taxonNode.getTaxonUuid() == null? "-" : taxonNode.getTitleCache()); //$NON-NLS-1$
|
|
148 | 151 |
} |
149 |
boolean isClassification = !taxonNode.hasTaxon();
|
|
152 |
boolean isClassification = taxonNode.getTaxonUuid()== null;
|
|
150 | 153 |
if (isClassification) { |
151 | 154 |
if(logger.isDebugEnabled()){ |
152 |
logger.debug("CANCEL_STATUS for selected classification " + taxonNode.getClassification().getTitleCache()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
155 |
logger.debug("CANCEL_STATUS for selected classification " + taxonNode.getClassificationUUID()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
153 | 156 |
} |
154 | 157 |
return false; |
155 | 158 |
} |
156 | 159 |
boolean isSameTaxonNode = taxonNode.equals(target); |
157 |
boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE); |
|
160 |
TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(taxonNode.getUuid()); |
|
161 |
boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(node, UPDATE); |
|
158 | 162 |
|
159 | 163 |
boolean hasTaxonPermission = |
160 |
CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
|
|
164 |
CdmStore.currentAuthentiationHasPermission(node.getTaxon(), UPDATE);CdmStore.currentAuthentiationHasPermission(node.getTaxon(), UPDATE);
|
|
161 | 165 |
if ( |
162 | 166 |
isSameTaxonNode |
163 | 167 |
|| !hasTaxonNodePermission |
... | ... | |
177 | 181 |
} |
178 | 182 |
|
179 | 183 |
|
180 |
private boolean moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) { |
|
181 |
|
|
182 |
|
|
183 |
if(targetITaxonTreeNode instanceof TaxonNode){ |
|
184 |
|
|
185 |
// Make sure parent taxon does not have unsaved changes |
|
186 |
// if (NavigationUtil.isDirty(targetTaxonNode)){ |
|
187 |
// MessageDialog.openWarning(NavigationUtil.getShell(), TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE); |
|
188 |
// return false; |
|
189 |
// } |
|
190 |
|
|
191 |
} |
|
192 |
Iterator<TaxonNode> taxIterator = taxonNodes.iterator(); |
|
184 |
private boolean moveTaxon(Set<TaxonNodeDto> taxonNodes, TaxonNodeDto targetITaxonTreeNode) { |
|
185 |
Iterator<TaxonNodeDto> taxIterator = taxonNodes.iterator(); |
|
193 | 186 |
Set<UUID> uuids = new HashSet<UUID>(); |
194 |
TaxonNode node = null; |
|
187 |
TaxonNodeDto node = null;
|
|
195 | 188 |
while(taxIterator.hasNext()){ |
196 | 189 |
node = taxIterator.next(); |
197 | 190 |
uuids.add(node.getUuid()); |
... | ... | |
202 | 195 |
logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$ |
203 | 196 |
return false; |
204 | 197 |
} |
205 |
|
|
206 |
AbstractPostOperation<?> operation = new MoveTaxonOperation |
|
207 |
(TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, taxonNavigator, taxonNavigator, MovingType.CHILD); |
|
208 |
AbstractUtility.executeOperation(operation, taxonNavigator.getSync()); |
|
198 |
result =CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(uuids,targetITaxonTreeNode.getUuid(), 0); |
|
209 | 199 |
|
210 | 200 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$ |
211 | 201 |
return true; |
... | ... | |
214 | 204 |
MessageDialog dialog = new MessageDialog(null, TARGET_NODE, null, DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0); |
215 | 205 |
dialog.open(); |
216 | 206 |
int returnCode = dialog.getReturnCode(); |
207 |
|
|
217 | 208 |
if (returnCode == 0){ |
218 | 209 |
if (workspaceUndoContext == null) { |
219 | 210 |
logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$ |
220 | 211 |
return false; |
221 | 212 |
} |
222 | 213 |
|
223 |
AbstractPostOperation<?> operation = new MoveTaxonOperation |
|
224 |
(TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, taxonNavigator, taxonNavigator, MovingType.CHILD); |
|
225 |
AbstractUtility.executeOperation(operation, taxonNavigator.getSync()); |
|
214 |
result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(uuids,targetITaxonTreeNode.getUuid(), 0); |
|
226 | 215 |
|
227 | 216 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$ |
228 | 217 |
return true; |
... | ... | |
231 | 220 |
logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$ |
232 | 221 |
return false; |
233 | 222 |
} |
234 |
TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode; |
|
235 | 223 |
|
236 |
AbstractPostOperation<?> operation = new MoveTaxonOperation |
|
237 |
(TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetNode, taxonNavigator, taxonNavigator, MovingType.PREVIOUS); |
|
238 |
AbstractUtility.executeOperation(operation, taxonNavigator.getSync()); |
|
239 | 224 |
|
225 |
CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(uuids,targetITaxonTreeNode.getUuid(), 2); |
|
240 | 226 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$ |
241 | 227 |
return true; |
242 | 228 |
} |
Also available in: Unified diff
ref #2380: implement usage of Dto for taxon navigator