import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.UUID;
import org.apache.log4j.Logger;
-import org.eclipse.core.commands.operations.AbstractOperation;
-import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
-import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
-import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
*
* @author p.ciardelli
* @created 03.06.2009
- * @version 1.0
*/
public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled {
private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
- /* (non-Javadoc)
- * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
- */
/** {@inheritDoc} */
@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter,
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof TreeSelection) {
- Iterator selectionIterator = ((TreeSelection) selection).iterator();
+ Iterator<?> selectionIterator = ((TreeSelection) selection).iterator();
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
return taxonNodes.size() > 0 ? taxonNodes : null;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
- */
/** {@inheritDoc} */
@Override
public IStatus validateDrop(Object target, int operation,
// check users permissions with target taxonnode and taxon
if (target instanceof TaxonNode) {
TaxonNode targetNode = (TaxonNode)target;
- Boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE);
- Boolean hasTargetTaxonPermission = CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE);
+ boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE);
+ boolean hasTargetTaxonPermission = targetNode.getTaxon() == null ?
+ true :
+ CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE);
if(logger.isDebugEnabled()){
- logger.debug("target: " + targetNode.getTaxon().getTitleCache()); //$NON-NLS-1$
+ logger.debug("target: " + targetNode.getTaxon() == null? "-" : targetNode.getTaxon().getTitleCache()); //$NON-NLS-1$
}
if(!hasTargetNodePermission || ! hasTargetNodePermission){
if(logger.isDebugEnabled()){
- logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission + " " + hasTargetTaxonPermission + " "); //$NON-NLS-1$
}
return Status.CANCEL_STATUS;
}
// do not allow to drop onto itself and
// check users permissions with all selected taxon nodes and taxa
for(TaxonNode taxonNode : getSelectedTaxa()){
- logger.debug("selectedTaxa: " + taxonNode.getTaxon().getTitleCache()); //$NON-NLS-1$
- Boolean isSameTaxonNode = taxonNode.equals(target);
- Boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
- Boolean hasTaxonPermission = CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
+ if (logger.isDebugEnabled()){
+ logger.debug("selectedTaxa: " + taxonNode.getTaxon() == null? "-" : taxonNode.getTaxon().getTitleCache());
+ }
+ boolean isSameTaxonNode = taxonNode.equals(target);
+ boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
+ boolean hasTaxonPermission = taxonNode.getTaxon() == null ?
+ true :
+ CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
if (
isSameTaxonNode
|| !hasTaxonNodePermission
|| !hasTaxonPermission
) {
if(logger.isDebugEnabled()){
- logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode.toString() + " " + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode + " " + hasTaxonNodePermission + " " + hasTaxonPermission + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return Status.CANCEL_STATUS;
}
}
- logger.debug("OK_STATUS"); //$NON-NLS-1$
+ if (logger.isDebugEnabled()){logger.debug("OK_STATUS");} //$NON-NLS-1$
return Status.OK_STATUS;
}
- logger.debug("CANCEL_STATUS"); //$NON-NLS-1$
+ if (logger.isDebugEnabled()){logger.debug("CANCEL_STATUS");} //$NON-NLS-1$
return Status.CANCEL_STATUS;
}
*/
private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
- TaxonNavigator taxonNavigator;
- taxonNavigator = (TaxonNavigator) AbstractUtility.showView(TaxonNavigator.ID);
-
- if(targetITaxonTreeNode instanceof TaxonNode){
-
- TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode;
- // Make sure parent taxon does not have unsaved changes
- if (NavigationUtil.isDirty(targetTaxonNode)){
- MessageDialog.openWarning(NavigationUtil.getShell(), TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
- return Status.CANCEL_STATUS;
- }
-
- }
- Iterator<TaxonNode> taxIterator = taxonNodes.iterator();
- Set<UUID> uuids = new HashSet<UUID>();
- TaxonNode node = null;
- while(taxIterator.hasNext()){
- node = taxIterator.next();
- uuids.add(node.getUuid());
- }
- if (!PreferencesUtil.getSortNodesNaturally()){
- IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
- if (workspaceUndoContext == null) {
- logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
- return Status.CANCEL_STATUS;
- }
-
- AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
- AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
-
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return Status.OK_STATUS;
- }else{
- String[] buttonLables = {TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CHILD, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_BEHIND, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CANCEL};
- MessageDialog dialog = new MessageDialog(null, TreeNodeDropAdapter.TARGET_NODE, null, TreeNodeDropAdapter.DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
- dialog.open();
- int returnCode = dialog.getReturnCode();
- if (returnCode == 0){
- IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
- if (workspaceUndoContext == null) {
- logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
- return Status.CANCEL_STATUS;
- }
-
- AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
- AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
-
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return Status.OK_STATUS;
- }else if (returnCode == 1){
- IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
- if (workspaceUndoContext == null) {
- logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
- return Status.CANCEL_STATUS;
- }
- TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
-
- AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.BEHIND);
- AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return Status.OK_STATUS;
-// }else if (returnCode == 2){
-// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
-// if (workspaceUndoContext == null) {
-// logger.error("Workspace undo context is null. DND operation cancelled");
-// return Status.CANCEL_STATUS;
-// }
-// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+// TaxonNavigator taxonNavigator;
+// taxonNavigator = (TaxonNavigator) AbstractUtility.showView(TaxonNavigator.ID);
+//
+// if(targetITaxonTreeNode instanceof TaxonNode){
+//
+// TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode;
+// // Make sure parent taxon does not have unsaved changes
+//// if (NavigationUtil.isDirty(targetTaxonNode)){
+//// MessageDialog.openWarning(NavigationUtil.getShell(), TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
+//// return Status.CANCEL_STATUS;
+//// }
+//
+// }
+// Iterator<TaxonNode> taxIterator = taxonNodes.iterator();
+// Set<UUID> uuids = new HashSet<>();
+// TaxonNode node = null;
+// while(taxIterator.hasNext()){
+// node = taxIterator.next();
+// uuids.add(node.getUuid());
+// }
+// if (!PreferencesUtil.getSortNodesNaturally()){
+// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+// if (workspaceUndoContext == null) {
+// logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
+//
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return Status.OK_STATUS;
+// }else{
+// String[] buttonLables = {TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CHILD, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_BEHIND, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CANCEL};
+// MessageDialog dialog = new MessageDialog(null, TreeNodeDropAdapter.TARGET_NODE, null, TreeNodeDropAdapter.DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+// dialog.open();
+// int returnCode = dialog.getReturnCode();
+// if (returnCode == 0){
+// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+// if (workspaceUndoContext == null) {
+// logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
//
-// if(CdmStore.getCurrentSessionManager().isRemoting()) {
-// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.PREVIOUS);
-// NavigationUtil.executeOperation(operation, null);
-// } else {
-// AbstractPostOperation operation = new MoveTaxonOperation
-// ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
-// NavigationUtil.executeOperation(operation);
-// }
-// logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
-// return Status.OK_STATUS;
- } else{
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return Status.OK_STATUS;
+// }else if (returnCode == 1){
+// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+// if (workspaceUndoContext == null) {
+// logger.error("Workspace undo context is null. DND operation cancelled"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
+// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+//
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.BEHIND);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return Status.OK_STATUS;
+//// }else if (returnCode == 2){
+//// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+//// if (workspaceUndoContext == null) {
+//// logger.error("Workspace undo context is null. DND operation cancelled");
+//// return Status.CANCEL_STATUS;
+//// }
+//// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+////
+//// if(CdmStore.getCurrentSessionManager().isRemoting()) {
+//// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.PREVIOUS);
+//// NavigationUtil.executeOperation(operation, null);
+//// } else {
+//// AbstractPostOperation operation = new MoveTaxonOperation
+//// ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
+//// NavigationUtil.executeOperation(operation);
+//// }
+//// logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+//// return Status.OK_STATUS;
+// } else{
return Status.CANCEL_STATUS;
- }
-
-
- }
+// }
+// }
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
- */
/** {@inheritDoc} */
@Override
public boolean postOperation(CdmBase objectAffectedByOperation) {