Merge branch 'develop' of ssh://dev.e-taxonomy.eu/var/git/taxeditor into develop
authorU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Tue, 18 Aug 2015 12:45:59 +0000 (14:45 +0200)
committerU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Tue, 18 Aug 2015 12:45:59 +0000 (14:45 +0200)
eu.etaxonomy.taxeditor.editor/OSGI-INF/l10n/plugin_de.properties
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java [new file with mode: 0644]

index 1a5c8c375b97e97b4bd45a7856de192db4b9f223..a4d096a11d103606e828005e75ba6cb461142e33 100644 (file)
@@ -139,8 +139,8 @@ marker.field.2 = Attribut
 marker.field.3 = Problematischer Wert
 marker.field.4 = Problembeschreibung
 marker.field.5 = Validierer
-marker.field.6 = Entittsklasse
-marker.field.7 = Entitts ID
+marker.field.6 = Entit\u00e4tsklasse
+marker.field.7 = Entit\u00e4ts ID
 extension.name.0 = Validierungs-Fehler
 command.label.51 = \u00d6ffne Specimen-Editor
 command.label.52 = L\u00f6schen
index d06b782aa811d6b29e2875ed6f37b4a6d63f1d12..b9a3d50db54a0e6946d6ef4b413333c62c4b3d6a 100644 (file)
             <visibleWhen
                   checkEnabled="true">
                <or>
-                  <reference
-                        definitionId="isDescriptionElement">
-                  </reference>
                   <reference
                         definitionId="isFeatureNodeContainer">
                   </reference>
             id="eu.etaxonomy.taxeditor.editor.media.command.delete"
             name="%command.name.49">
       </command>
+      
       <category
             id="eu.etaxonomy.taxeditor.editor.new.category"
             name="%category.name.4">
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.MoveDescriptionToOtherTaxonHandler"
-            id="eu.etaxonomy.taxeditor.editor.commands.description.moveDescriptionToTaxon"
+            id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionToTaxon"
             name="%command.name.13">
       </command>
+       
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.MoveDescriptionElementsHandler"
-            id="eu.etaxonomy.taxeditor.description.commands.moveDescriptionElements"
+            id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElements"
             name="%command.name.12">
       </command>
         
index 0c2306ba6081a6da06c1e32e6b2dedc3cd552664..9a801a4d412797995c6899f6ae3f8c6045152438 100644 (file)
@@ -20,25 +20,36 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.Page;
+import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 
 
 /**
@@ -46,8 +57,9 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
  * @created Feb 8, 2011
  * @version 1.0
  */
-public class MoveDescriptionElementsHandler extends AbstractHandler {
-
+public class MoveDescriptionElementsHandler extends AbstractHandler implements IPostOperationEnabled{
+       private UUID newAcceptedTaxonNodeUuid;
+       private TaxonNameEditor editor;
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
@@ -55,7 +67,7 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
        public Object execute(ExecutionEvent event) throws ExecutionException {
                
 //             ConversationHolder conversation = CdmStore.createConversation();
-               
+               editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
                ISelection selection = HandlerUtil.getCurrentSelection(event);
                
                if(selection instanceof IStructuredSelection){
@@ -81,14 +93,28 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                        if(elements.size() == 0){
                                return null;
                        }
+                       DescriptionBase description = elements.get(0).getInDescription();
+                       List<UUID> excludeTaxa = new ArrayList<UUID>();
+                       if (description.isInstanceOf(TaxonDescription.class)){
+                               TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
+                               Taxon actualTaxon = taxonDescription.getTaxon();
+                               excludeTaxa.add(actualTaxon.getUuid());
+                       }
                        
-                       Taxon targetTaxon = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), EditorUtil.getActiveMultiPageTaxonEditor().getConversationHolder(), null);
+                       
+                       TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+                                       editor.getConversationHolder(),
+                                       "Choose the accepted taxon",
+                                       excludeTaxa,
+                                       null,
+                                       null);
+                       Taxon targetTaxon = newAcceptedTaxonNode.getTaxon();
                        
                        if(targetTaxon == null){
                                // canceled
                                return null;
                        }
-                                               
+                       newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();                      
                        TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon);
                        String moveMessage = String.format("Elements moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
                        targetDescription.setTitleCache(moveMessage, true);
@@ -99,10 +125,11 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                        try {
                                AbstractPostOperation operation = new MoveDescriptionElementsOperation(
                                                event.getCommand().getName(), EditorUtil.getUndoContext(), 
-                                               targetDescription, elements, false, (IPostOperationEnabled) EditorUtil.getView(DescriptiveViewPart.ID, true));
+                                               targetDescription, elements, false, this);
+                               
                                EditorUtil.executeOperation(operation);
-//                             conversation.commit(true);
-                               CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
+                               
+                               //CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
                                
                        } catch (NotDefinedException e) {
                                MessagingUtils.error(getClass(), e);
@@ -112,4 +139,44 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                return null;
        }
 
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
+               
+               editor.getConversationHolder().bind();
+               editor.getConversationHolder().commit(true);
+               Display.getDefault().asyncExec(new Runnable(){
+                       
+            public void run() {
+                               //AbstractUtility.close(editor.getMultiPageTaxonEditor());
+
+                               try {
+                                       MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
+                                       if(possibleOpenEditor != null){
+                                               AbstractUtility.close(possibleOpenEditor);
+                                       }
+                                       EditorUtil.openTaxonNode(newAcceptedTaxonNodeUuid);
+                               } catch (PartInitException e) {
+                                       MessagingUtils.error(this.getClass(), e);
+                                       throw new RuntimeException(e);
+                               } catch (Exception e) {
+                                       MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
+                               }
+                       }
+
+               });
+
+
+               return true;
+       }
+
+       @Override
+       public boolean onComplete() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+       
 }
index ab67cf8c6221f297bd97db55a4176b697e168e5d..c4b57e9cb4629968822bd35d951b0bbb9c407a00 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -28,6 +29,7 @@ import eu.etaxonomy.taxeditor.editor.Page;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionToOtherTaxonOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -66,8 +68,14 @@ public class MoveDescriptionToOtherTaxonHandler extends AbstractHandler
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
 
                        for(Object element : structuredSelection.toArray()){
-                               if (element instanceof TaxonDescription){
-                                       UUID uuid = ((TaxonDescription)element).getUuid();
+                               UUID uuid = null;
+                               if (element instanceof FeatureNodeContainer){
+                                       uuid = ((FeatureNodeContainer)element).getDescription().getUuid();
+                               }       else if (element instanceof DescriptionBase){
+                                       uuid = ((DescriptionBase)element).getUuid();
+                               }
+                               
+                               if (uuid != null){
                                        descriptions.add((TaxonDescription) CdmStore.getService(IDescriptionService.class).load(uuid, null));
                                }
                        }
index 5b4b0053ed727bfea012bd536bf289b3378dd06e..fd74d72745e6dc55a6ef9ba1e3f7b74ca6c2f8d1 100644 (file)
@@ -17,10 +17,17 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -30,7 +37,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created Feb 8, 2011
  * @version 1.0
  */
-public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation {
+public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation{
 
        private Collection<DescriptionElementBase> descriptionElements;
        private DescriptionBase targetDescription;
@@ -68,6 +75,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation
                
                service.moveDescriptionElementsToDescription(descriptionElements, targetDescription, isCopy);
                
+               
                return postExecute(targetDescription);
        }
 
@@ -90,5 +98,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation
                // TODO Auto-generated method stub
                return null;
        }
+       
+       
 
 }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorContentService.java
new file mode 100644 (file)
index 0000000..46c659b
--- /dev/null
@@ -0,0 +1,30 @@
+package eu.etaxonomy.taxeditor.navigation.navigator;
+
+import org.eclipse.ui.internal.navigator.NavigatorContentService;
+import org.eclipse.ui.navigator.INavigatorDnDService;
+
+public class TaxonNavigatorContentService extends NavigatorContentService {
+
+       private TaxonNavigatorDnDService navigatorDnDService;
+
+       public TaxonNavigatorContentService(String viewerID) {
+               super(viewerID);
+               
+               
+       }
+       
+       public TaxonNavigatorContentService(String aViewerId,
+                       TaxonNavigatorViewer taxonNavigatorViewer) {
+               super(aViewerId, taxonNavigatorViewer);
+               getDnDService();
+       }
+
+       @Override
+       public TaxonNavigatorDnDService getDnDService() {
+               if (navigatorDnDService == null) {
+                       navigatorDnDService = new TaxonNavigatorDnDService(this);
+               }
+               return navigatorDnDService;
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorDnDService.java
new file mode 100644 (file)
index 0000000..5de170c
--- /dev/null
@@ -0,0 +1,170 @@
+package eu.etaxonomy.taxeditor.navigation.navigator;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.ui.internal.navigator.dnd.CommonDropAdapterDescriptor;
+import org.eclipse.ui.internal.navigator.dnd.CommonDropDescriptorManager;
+import org.eclipse.ui.internal.navigator.extensions.CommonDragAssistantDescriptor;
+import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptor;
+import org.eclipse.ui.navigator.CommonDragAdapterAssistant;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
+import org.eclipse.ui.navigator.INavigatorContentService;
+import org.eclipse.ui.navigator.INavigatorDnDService;
+
+import eu.etaxonomy.taxeditor.navigation.navigator.dnd.TaxonNavigatorDragAdapterAssistant;
+
+public class TaxonNavigatorDnDService implements INavigatorDnDService {
+       private static final CommonDropAdapterAssistant[] NO_ASSISTANTS = new CommonDropAdapterAssistant[0];
+
+       private INavigatorContentService contentService;
+
+       private TaxonNavigatorDragAdapterAssistant[] dragAssistants;
+       
+       private TreeNodeDropAdapter dropAdapter;
+
+       private final Map dropAssistants = new HashMap();
+       
+       public TaxonNavigatorDnDService(INavigatorContentService contentService){
+               this.contentService = contentService;
+       }
+       
+       
+       @Override
+       public CommonDragAdapterAssistant[] getCommonDragAssistants() {
+               
+               return dragAssistants;
+       }
+
+       @Override
+       public void bindDragAssistant(CommonDragAdapterAssistant anAssistant) {
+               if(dragAssistants == null) 
+                       initializeDragAssistants(); 
+               TaxonNavigatorDragAdapterAssistant[] newDragAssistants = new TaxonNavigatorDragAdapterAssistant[dragAssistants.length + 1];
+               System.arraycopy(dragAssistants, 0, newDragAssistants, 0, dragAssistants.length);
+               newDragAssistants[dragAssistants.length] = (TaxonNavigatorDragAdapterAssistant) anAssistant;
+               dragAssistants = newDragAssistants;             
+
+       }
+       
+       private void initializeDragAssistants() {
+               int i = 0;
+               Set dragDescriptors = ((NavigatorViewerDescriptor) contentService
+                               .getViewerDescriptor()).getDragAssistants();
+               dragAssistants = new TaxonNavigatorDragAdapterAssistant[dragDescriptors
+                               .size()];
+               for (Iterator iter = dragDescriptors.iterator(); iter.hasNext();) {
+                       CommonDragAssistantDescriptor descriptor = (CommonDragAssistantDescriptor) iter
+                                       .next();
+                       dragAssistants[i++] = (TaxonNavigatorDragAdapterAssistant) descriptor.createDragAssistant();
+               }
+       }
+
+       @Override
+       public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
+                       Object aDropTarget, TransferData aTransferType) {
+               CommonDropAdapterDescriptor[] descriptors = CommonDropDescriptorManager
+                               .getInstance().findCommonDropAdapterAssistants(aDropTarget,
+                                               contentService);
+
+               if (descriptors.length == 0) {
+                       return NO_ASSISTANTS;
+               }
+
+               if (LocalSelectionTransfer.getTransfer().isSupportedType(aTransferType)  
+                                               && LocalSelectionTransfer.getTransfer().getSelection() instanceof IStructuredSelection) {
+                       return getAssistantsBySelection(descriptors, (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection());
+               } 
+               return getAssistantsByTransferData(descriptors, aTransferType);
+       }
+       
+       private CommonDropAdapterAssistant[] getAssistantsByTransferData(
+                       CommonDropAdapterDescriptor[] descriptors,
+                       TransferData aTransferType) {
+
+               Set assistants = new LinkedHashSet();
+               for (int i = 0; i < descriptors.length; i++) {
+                       CommonDropAdapterAssistant asst = getAssistant(descriptors[i]);
+                       if (asst.isSupportedType(aTransferType)) {
+                               assistants.add(asst);
+                       }
+               }
+               return sortAssistants((CommonDropAdapterAssistant[]) assistants
+                               .toArray(new CommonDropAdapterAssistant[assistants.size()]));
+
+       }
+       
+       private CommonDropAdapterAssistant[] getAssistantsBySelection(
+                       CommonDropAdapterDescriptor[] descriptors, IStructuredSelection aSelection) {
+
+               Set assistants = new LinkedHashSet(); 
+                       
+               for (int i = 0; i < descriptors.length; i++) {
+                       if(descriptors[i].areDragElementsSupported(aSelection)) {
+                               assistants.add(getAssistant(descriptors[i]));
+                       }
+               }  
+
+               return sortAssistants((CommonDropAdapterAssistant[]) assistants
+                               .toArray(new CommonDropAdapterAssistant[assistants.size()]));
+       }
+       
+       private CommonDropAdapterAssistant getAssistant(
+                       CommonDropAdapterDescriptor descriptor) {
+               TreeNodeDropAdapterAssistant asst = (TreeNodeDropAdapterAssistant) dropAssistants
+                               .get(descriptor);
+               if (asst != null) {
+                       return asst;
+               }
+               synchronized (dropAssistants) {
+                       asst = (TreeNodeDropAdapterAssistant) dropAssistants.get(descriptor);
+                       if (asst == null) {
+                               dropAssistants.put(descriptor, (asst = (TreeNodeDropAdapterAssistant) descriptor
+                                               .createDropAssistant()));
+                               asst.init(contentService);
+                               //asst.setCommonDropAdapter(dropAdapter);
+                       }
+               }
+               return asst;
+       }
+
+
+       private CommonDropAdapterAssistant[] sortAssistants(CommonDropAdapterAssistant[] array) {
+               Arrays.sort(array, new Comparator() {
+                       public int compare(Object arg0, Object arg1) {
+                               CommonDropAdapterAssistant a = (CommonDropAdapterAssistant) arg0;
+                               CommonDropAdapterAssistant b = (CommonDropAdapterAssistant) arg1;
+                               // This is to ensure that the navigator resources drop assistant will
+                               // always be first on the list of drop assistant, if a conflict ever 
+                               // occurs.
+                               String id = "org.eclipse.ui.navigator.resources."; //$NON-NLS-1$
+                               if (a.getClass().getName().startsWith(id))
+                                       return -1;
+                               if (b.getClass().getName().startsWith(id))
+                                       return 1;
+                               return a.getClass().getName().compareTo(b.getClass().getName());
+                       }
+               });
+               return array;
+       }
+
+       @Override
+       public CommonDropAdapterAssistant[] findCommonDropAdapterAssistants(
+                       Object aDropTarget, IStructuredSelection theDragSelection) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public void setDropAdaptor(TreeNodeDropAdapter da) {
+               dropAdapter = da;
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNavigatorViewer.java
new file mode 100644 (file)
index 0000000..8fdabb8
--- /dev/null
@@ -0,0 +1,54 @@
+package eu.etaxonomy.taxeditor.navigation.navigator;
+
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.internal.navigator.NavigatorContentService;
+import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
+import org.eclipse.ui.navigator.CommonDragAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.navigator.INavigatorContentService;
+
+import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
+
+public class TaxonNavigatorViewer extends CommonViewer {
+
+       private NavigatorContentService contentService;
+       String viewerId;
+
+       public TaxonNavigatorViewer(String aViewerId, Composite aParent, int aStyle) {
+               super(aViewerId, aParent, aStyle);
+               contentService = new TaxonNavigatorContentService(aViewerId, this);
+               viewerId = aViewerId;
+       }
+
+       @Override
+       protected void initDragAndDrop() {
+
+               int operations =  DND.DROP_MOVE ;
+
+               CommonDragAdapter dragAdapter = createDragAdapter();
+               addDragSupport(operations, dragAdapter.getSupportedDragTransfers(),
+                               dragAdapter);
+               Transfer[] transfers = new Transfer[] { TaxonNodeTransfer.getInstance() };
+               TreeNodeDropAdapter dropAdapter = createTreeNodeDropAdapter();
+               addDropSupport(operations, transfers, dropAdapter);
+
+               TaxonNavigatorDnDService dnd = (TaxonNavigatorDnDService)getNavigatorContentService().getDnDService();
+               dnd.setDropAdaptor(dropAdapter);
+       }
+       
+       
+       protected TreeNodeDropAdapter createTreeNodeDropAdapter() {
+               return new TreeNodeDropAdapter(this);
+       }
+       
+       public NavigatorContentService getNavigatorContentService(){
+               if (contentService == null){
+                       contentService = new TaxonNavigatorContentService(viewerId);
+               } 
+               return contentService;
+       }
+       
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDragListener.java
new file mode 100644 (file)
index 0000000..9cd02f9
--- /dev/null
@@ -0,0 +1,83 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.navigation.navigator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.dnd.DragSourceAdapter;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.ui.navigator.CommonViewer;
+
+
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
+import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
+
+/**
+ * @author k.luther
+ * @date 02.06.2015
+ *
+ */
+public class TreeNodeDragListener extends DragSourceAdapter {
+       private CommonViewer viewer;
+
+       /**
+        * 
+        */
+       public TreeNodeDragListener(CommonViewer viewer) {
+               this.viewer = viewer;
+       }
+
+       
+       public void setViewer(CommonViewer viewer){
+               this.viewer = viewer;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
+        */
+       @Override
+       public void dragStart(DragSourceEvent event) {
+               
+               event.doit = true;// set to false if needed - default is true
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DragSourceAdapter#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
+        */
+       @Override
+       public void dragFinished(DragSourceEvent event) {
+               // TODO Auto-generated method stub
+               super.dragFinished(event);
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
+        */
+       @Override
+       public void dragSetData(DragSourceEvent event) {
+               
+               IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+               List<ITaxonTreeNode> taxonNodes = new ArrayList<ITaxonTreeNode>();
+               
+               for (Object object : selection.toList()){
+                       taxonNodes.add((ITaxonTreeNode)object);
+                       }
+                       
+               if (TaxonNodeTransfer.getInstance().isSupportedType(
+                               event.dataType)) {
+                       event.data = taxonNodes.toArray(new TaxonNode[taxonNodes.size()]);
+               }
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapter.java
new file mode 100644 (file)
index 0000000..448da05
--- /dev/null
@@ -0,0 +1,284 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.navigation.navigator;
+
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IconAndMessageDialog;
+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 org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.navigator.CommonDropAdapter;
+import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
+import org.eclipse.ui.navigator.CommonViewer;
+
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.OrderedTermBase;
+import eu.etaxonomy.cdm.model.common.TermBase;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+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.editor.definedterm.DefinedTermEditor;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+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;
+
+/**
+ * <p>TreeNodeDropAdapter class.</p>
+ *
+ * @author k.luther
+ * @date 02.06.2015
+ * @version 1.0
+ */
+public class TreeNodeDropAdapter extends ViewerDropAdapter implements IPostOperationEnabled {
+
+       /**
+        * @param viewer
+        */
+       protected TreeNodeDropAdapter(TaxonNavigatorViewer navigatorViewer) {
+               super(navigatorViewer);
+               this.navigatorViewer = navigatorViewer;
+               
+       }
+       
+       private final TaxonNavigatorViewer navigatorViewer;
+       private static final Logger logger = Logger.getLogger(TreeNodeDropAdapter.class);
+
+       /** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */
+       public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$
+
+       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 boolean performDrop(Object target) {
+
+               
+               if (target instanceof ITaxonTreeNode) {
+                       Set<TaxonNode> taxonNodes = getSelectedTaxa();
+                       ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
+                       if (targetTreeNode instanceof Classification){
+                               targetTreeNode = ((Classification)targetTreeNode).getRootNode();
+                               targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class);
+                       }
+                       if(taxonNodes != null) {
+                               if (taxonNodes.size() == 1){
+                                       return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
+                               } else{
+                                       if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
+                                               return true;
+                                       }
+                               }
+            }
+               }
+               
+               return false;
+       }
+
+       private Set<TaxonNode> getSelectedTaxa(){
+               HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+
+               ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
+               if (selection instanceof TreeSelection) {
+
+                       Iterator selectionIterator = ((TreeSelection) selection).iterator();
+
+                       while (selectionIterator.hasNext()){
+                               Object object = selectionIterator.next();
+                               if(object instanceof TaxonNode){
+                                       TaxonNode taxonNode = (TaxonNode) object;
+                                       taxonNodes.add(taxonNode);
+                               }
+                       }
+               }
+               return taxonNodes.size() > 0 ? taxonNodes : null;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.navigator.CommonDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public boolean validateDrop(Object target, int operation,
+                       TransferData transferType) {
+               
+               if (target instanceof ITaxonTreeNode) {
+                       
+                   // 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);
+
+                if(logger.isDebugEnabled()){
+                    logger.debug("target: " + targetNode.getTaxon().getTitleCache());
+                }
+
+                       if(!hasTargetNodePermission || ! hasTargetNodePermission){
+                           if(logger.isDebugEnabled()){
+                               logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " ");
+                           }
+                           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());
+                               Boolean isSameTaxonNode = taxonNode.equals(target);
+                               Boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
+                               Boolean hasTaxonPermission = CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
+                if (
+                               isSameTaxonNode
+                               || !hasTaxonNodePermission
+                   || !hasTaxonPermission
+                       ) {
+                    if(logger.isDebugEnabled()){
+                        logger.debug("CANCEL_STATUS for selected  " + isSameTaxonNode.toString() + " " + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " ");
+                    }
+                                       return false;
+                               }
+                       }
+                       logger.debug("OK_STATUS");
+                       return true;
+               }
+               logger.debug("CANCEL_STATUS");
+               return false;
+       }
+
+
+       /**
+        * @param childTaxonNode
+        * @param parentTaxon
+        * @return
+        */
+       private boolean moveTaxon(TaxonNode taxonNode, 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(), "Unsaved Parent Taxon", "There are unsaved " +
+                               "changes in the parent taxon. Pleas save first.");
+                               return false;
+                       }
+
+               }
+               if (!PreferencesUtil.getSortNodesNaturally()){
+                       IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+                       if (workspaceUndoContext == null) {
+                               logger.error("Workspace undo context is null. DND operation cancelled");
+                               return false;
+                       }
+       
+                       AbstractPostOperation operation = new MoveTaxonOperation
+                                       ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+                       NavigationUtil.executeOperation(operation);
+                       
+                       logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+                       return true;
+               }else{
+                       String[] buttonLables = {"Parent", "Predecessor", "Cancel"};
+                       MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", 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");
+                                       return false;
+                               }
+               
+                               AbstractPostOperation operation = new MoveTaxonOperation
+                                               ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+                               NavigationUtil.executeOperation(operation);
+                               
+                               logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+                               return true;
+                       }else if (returnCode == 1){
+                               IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+                               if (workspaceUndoContext == null) {
+                                       logger.error("Workspace undo context is null. DND operation cancelled");
+                                       return false;
+                               }
+               
+                               AbstractPostOperation operation = new MoveTaxonOperation
+                                               ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
+                               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) {
+               return true;
+       }
+
+       /**
+        * <p>onComplete</p>
+        *
+        * @return a boolean.
+        */
+       @Override
+    public boolean onComplete() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+       @Override
+       public void dragOver(DropTargetEvent event) {
+               super.dragOver(event);
+               event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_INSERT_AFTER;
+               
+       }
+       
+}