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.IUndoContext;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
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.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
-import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
-import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
// 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$ //$NON-NLS-2$ //$NON-NLS-3$
}
return false;
}
// 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()); //$NON-NLS-1$
+ }
+ boolean isSameTaxonNode = taxonNode.equals(target);
+ boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
+ boolean hasTaxonPermission = taxonNode.getTaxon() == null ?
+ true :
+ CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
if (
isSameTaxonNode
|| !hasTaxonNodePermission
|| !hasTaxonPermission
) {
if(logger.isDebugEnabled()){
- logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode.toString() + Messages.TreeNodeDropAdapter_10 + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode + Messages.TreeNodeDropAdapter_10 + hasTaxonNodePermission + " " + hasTaxonPermission + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return false;
}
*/
private boolean moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
- TaxonNavigator taxonNavigator;
- taxonNavigator = (TaxonNavigator) NavigationUtil.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(), TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
- return false;
- }
-
- }
- 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 false;
- }
-
- AbstractPostOperation<?> operation = new MoveTaxonOperation
- (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
- NavigationUtil.executeOperation(operation);
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return true;
- }else{
- String[] buttonLables = {TREE_NODE_DROP_ADAPTER_CHILD, TREE_NODE_DROP_ADAPTER_BEHIND,TREE_NODE_DROP_ADAPTER_CANCEL};
- 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);
- 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 false;
- }
-
- AbstractPostOperation<?> operation = new MoveTaxonOperation
- (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
- NavigationUtil.executeOperation(operation);
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return true;
- }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 false;
- }
- TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
-
- AbstractPostOperation<?> operation = new MoveTaxonOperation
- (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
- NavigationUtil.executeOperation(operation);
-
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
- return true;
- }
-// } else if (returnCode == 2){
-// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
-// if (workspaceUndoContext == null) {
-// logger.error("Workspace undo context is null. DND operation cancelled");
-// return false;
-// }
-// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+// TaxonNavigator taxonNavigator;
+// taxonNavigator = (TaxonNavigator) NavigationUtil.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(), TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
+//// return false;
+//// }
+//
+// }
+// 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 false;
+// }
+//
+// AbstractPostOperation<?> operation = new MoveTaxonOperation
+// (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
+// NavigationUtil.executeOperation(operation);
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return true;
+// }else{
+// String[] buttonLables = {TREE_NODE_DROP_ADAPTER_CHILD, TREE_NODE_DROP_ADAPTER_BEHIND,TREE_NODE_DROP_ADAPTER_CANCEL};
+// 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);
+// 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 false;
+// }
+//
+// AbstractPostOperation<?> operation = new MoveTaxonOperation
+// (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, MovingType.CHILD);
+// NavigationUtil.executeOperation(operation);
//
-// AbstractPostOperation operation = new MoveTaxonOperation
-// ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.BEHIND);
-// NavigationUtil.executeOperation(operation);
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return true;
+// }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 false;
+// }
+// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
//
-// logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
-// return true;
-// }
- else{
+// AbstractPostOperation<?> operation = new MoveTaxonOperation
+// (TREE_NODE_DROP_ADAPTER_MOVE_TAXON, workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
+// NavigationUtil.executeOperation(operation);
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return true;
+// }
+//// } else if (returnCode == 2){
+//// IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+//// if (workspaceUndoContext == null) {
+//// logger.error("Workspace undo context is null. DND operation cancelled");
+//// return false;
+//// }
+//// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+////
+//// AbstractPostOperation operation = new MoveTaxonOperation
+//// ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.BEHIND);
+//// NavigationUtil.executeOperation(operation);
+////
+//// logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+//// return true;
+//// }
+// else{
return false;
- }
-
-
- }
+// }
+//
+//
+// }
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
- */
/** {@inheritDoc} */
@Override
public boolean postOperation(CdmBase objectAffectedByOperation) {