DefinedTermDropAdapter : added selection of source objects after drop and disabled...
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 29 May 2015 14:16:34 +0000 (16:16 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 29 May 2015 14:16:34 +0000 (16:16 +0200)
DefinedTermEditor : added custom sorter for OrderedTermBase (descending)
MoveDefinedTermOperation : added possibility to move term when cursor is in the insert part of the list

eu.etaxonomy.taxeditor.application/.classpath
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDropAdapter.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermEditor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/MoveDefinedTermOperation.java

index bfb7a7aeb276f5a38d22964832ea9bcb905ac7a0..4c7e96f59500b4f98198fb4a11bdf511d1107b48 100644 (file)
@@ -1,9 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
-       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
-       <classpathentry including="**/*.java" kind="src" path="src/main/java"/>\r
-       <classpathentry including="**/*.java" kind="src" path="src/test/java"/>\r
-       <classpathentry kind="src" path="src/main/resources"/>\r
-       <classpathentry kind="output" path="target/classes"/>\r
-</classpath>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+       <classpathentry kind="src" path="src/main/resources"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
index 8744410156e8faf0c1182b8758c19fc982a8d25e..7ea235d19d1a2e77b68cd694b2cc32233cb6fc3d 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$\r
 /**\r
 * Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
 * http://www.e-taxonomy.eu\r
-* \r
+*\r
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
@@ -12,10 +12,14 @@ package eu.etaxonomy.taxeditor.editor.definedterm;
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 \r
+import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.jface.viewers.ViewerDropAdapter;\r
+import org.eclipse.swt.dnd.DND;\r
+import org.eclipse.swt.dnd.DropTargetEvent;\r
 import org.eclipse.swt.dnd.TransferData;\r
 \r
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.common.OrderedTermBase;\r
 import eu.etaxonomy.cdm.model.common.TermBase;\r
 import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;\r
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;\r
@@ -28,7 +32,7 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  */\r
 public class DefinedTermDropAdapter extends ViewerDropAdapter {\r
 \r
-       private DefinedTermEditor editor;\r
+       private final DefinedTermEditor editor;\r
        /**\r
         * @param viewer\r
         */\r
@@ -42,23 +46,32 @@ public class DefinedTermDropAdapter extends ViewerDropAdapter {
         */\r
        @Override\r
        public boolean performDrop(Object data) {\r
-               \r
+\r
                TermBase target = (TermBase) getCurrentTarget();//can be vocab\r
+               int currentLocation = getCurrentLocation();\r
+               System.out.println("current location : " + currentLocation + " , target : " + target.getTitleCache());\r
                //DefinedTermBase[] droppedElements = (DefinedTermBase[]) data;\r
                Object[] droppedTerms = (Object[]) data;\r
                Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)\r
-               \r
+\r
                for (Object droppedTerm : droppedTerms) {\r
-                       \r
+\r
                        DefinedTermBase term = (DefinedTermBase) droppedTerm;\r
                        sourceTerms.add(term);\r
-                       \r
+\r
                }\r
-               \r
-               AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions", StoreUtil.getUndoContext(), target, sourceTerms, editor);\r
+\r
+               AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions",\r
+                       StoreUtil.getUndoContext(),\r
+                       target,\r
+                       sourceTerms,\r
+                       editor,\r
+                       currentLocation);\r
                //TODO: implement execute\r
                StoreUtil.executeOperation(operation);\r
-               \r
+               // select the newly moved objects\r
+               editor.getViewer().setSelection(new StructuredSelection(sourceTerms.toArray(new TermBase[sourceTerms.size()])));\r
+\r
                return true;\r
        }\r
 \r
@@ -69,9 +82,23 @@ public class DefinedTermDropAdapter extends ViewerDropAdapter {
        public boolean validateDrop(Object target, int operation,\r
                        TransferData transferType) {\r
                boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);\r
-               System.out.println(target);\r
                // maybe don't need this - they will be all TermBase anyway\r
-               return target instanceof TermBase && transferDataIsSupported; \r
+               return target instanceof TermBase && transferDataIsSupported;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)\r
+        */\r
+       @Override\r
+       public void dragOver(DropTargetEvent event) {\r
+           super.dragOver(event);\r
+           TermBase target = (TermBase) getCurrentTarget();\r
+           if(!(target instanceof OrderedTermBase)) {\r
+               // this is to only disable insert between items\r
+               event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;\r
+           }\r
+\r
+\r
        }\r
 \r
 }\r
index c58e631de4af53a7d9408806ea1a52ca243299ec..8cae931e980bcd485a7b65b85932fae29afce75c 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.jface.viewers.TreeViewer;\r
+import org.eclipse.jface.viewers.Viewer;\r
 import org.eclipse.jface.viewers.ViewerSorter;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.dnd.DND;\r
@@ -35,6 +36,7 @@ import org.eclipse.ui.part.EditorPart;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.model.common.OrderedTermBase;\r
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;\r
 import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;\r
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;\r
@@ -84,7 +86,7 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
                        viewer.getControl().setLayoutData(LayoutConstants.FILL());\r
                        viewer.setContentProvider(new TermContentProvider());\r
                        viewer.setLabelProvider(new TermLabelProvider());\r
-                       viewer.setSorter(new ViewerSorter());\r
+                       viewer.setSorter(new DefinedTermSorter());\r
 \r
                        Transfer[] transfers = new Transfer[] { TermTransfer.getInstance() };\r
                        viewer.addDragSupport(dndOperations, transfers, new DefinedTermDragListener(viewer));\r
@@ -231,6 +233,28 @@ public class DefinedTermEditor extends EditorPart implements IConversationEnable
                return viewer;\r
        }\r
 \r
+       private class DefinedTermSorter extends ViewerSorter {\r
+\r
+           @Override\r
+           public int compare(Viewer viewer, Object e1, Object e2) {\r
+               // the comparison value in this method determines the\r
+               // location <-> add term method used in the MoveDefinedTermOperation\r
+               // execute call\r
+               if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {\r
+                   OrderedTermBase otbe1 = (OrderedTermBase)e1;\r
+                   OrderedTermBase otbe2 = (OrderedTermBase)e2;\r
+                   if(otbe1.getOrderIndex() == otbe2.getOrderIndex()) {\r
+                       return 0;\r
+                   } else if(otbe1.isHigher(otbe2)) {\r
+                       return 1;\r
+                   } else {\r
+                       return -1;\r
+                   }\r
+               } else {\r
+                   return super.compare(viewer, e1, e2);\r
+               }\r
+           }\r
+       }\r
 \r
 \r
 }
\ No newline at end of file
index 5096f49ac31c8ad0113b0ec408e4985d31b4ed2d..e6513b9a60912384a7c5cc4ea2f03e1c3d9cf5aa 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$\r
 /**\r
 * Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
 * http://www.e-taxonomy.eu\r
-* \r
+*\r
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
@@ -17,8 +17,11 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.core.runtime.Status;\r
+import org.eclipse.jface.viewers.ViewerDropAdapter;\r
 \r
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.common.OrderedTermBase;\r
+import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;\r
 import eu.etaxonomy.cdm.model.common.TermBase;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
@@ -32,21 +35,27 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  *\r
  */\r
 public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {\r
-       \r
-       private Collection<DefinedTermBase> sourceTerms;// the actual DefinedTermBase(s) we are moving\r
-       private TermBase targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to\r
+\r
+       private final Collection<DefinedTermBase> sourceTerms;// the actual DefinedTermBase(s) we are moving\r
+       private final TermBase targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to\r
+       private final int currentLocation;\r
 \r
        /**\r
         * @param label\r
         * @param undoContext\r
         * @param postOperationEnabled\r
         */\r
-       public MoveDefinedTermOperation(String label, IUndoContext undoContext, TermBase target, Collection<DefinedTermBase> sourceTerms,\r
-                       IPostOperationEnabled postOperationEnabled) {\r
+       public MoveDefinedTermOperation(String label,\r
+               IUndoContext undoContext,\r
+               TermBase target,\r
+               Collection<DefinedTermBase> sourceTerms,\r
+                       IPostOperationEnabled postOperationEnabled,\r
+                       int currentLocation) {\r
                super(label, undoContext, postOperationEnabled);\r
-               \r
+\r
                this.targetTermOrVocabulary = target;\r
                this.sourceTerms = sourceTerms;\r
+               this.currentLocation = currentLocation;\r
        }\r
 \r
        /* (non-Javadoc)\r
@@ -55,61 +64,80 @@ public class MoveDefinedTermOperation extends AbstractPostTaxonOperation {
        @Override\r
        public IStatus execute(IProgressMonitor monitor, IAdaptable info)\r
                        throws ExecutionException {\r
-               \r
+\r
                // need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target)\r
                // and remove it from old associations\r
-               \r
+\r
                //TODO move to ITermService\r
-               \r
-               for (DefinedTermBase term : sourceTerms){\r
+\r
+               for (DefinedTermBase term : sourceTerms) {\r
                        // do nothing when moving it on itself\r
                        if(targetTermOrVocabulary.equals(term)){\r
                                Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term can not be added to itself");\r
                                MessagingUtils.informationDialog("", status);\r
                                return status;\r
                        }\r
-                       \r
+\r
                        if (targetTermOrVocabulary instanceof TermVocabulary) {\r
                                TermVocabulary termVocabulary = (TermVocabulary)targetTermOrVocabulary;\r
-                               \r
+\r
                                // do nothing when term is top level and gets added to the same vocabulary\r
                                if(term.getPartOf() == null && termVocabulary.equals(term.getVocabulary())){\r
                                        Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term is already in this vocabulary");\r
                                        MessagingUtils.informationDialog("", status);\r
                                        return status;\r
                                }\r
-                               \r
+\r
                                cleanTerm(term);\r
                                termVocabulary.addTerm(term);\r
-                               \r
+\r
                        } else if (targetTermOrVocabulary instanceof DefinedTermBase) {\r
                                cleanTerm(term);\r
                                DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary;\r
-                               targetDefinedTerm.addIncludes(term);\r
-                               targetDefinedTerm.getVocabulary().addTerm(term);                                \r
+\r
+                               if(targetTermOrVocabulary instanceof OrderedTermBase && term instanceof OrderedTermBase) {\r
+                                   TermVocabulary tVoc = ((DefinedTermBase) targetTermOrVocabulary).getVocabulary();\r
+                                   if(tVoc instanceof OrderedTermVocabulary) {\r
+                                       OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc;\r
+                                       // the link between the location and the add term (below / above)\r
+                                       // method is determined by the compare method in the\r
+                                       // DefinedTermEditor's ViewerSorter (DefinedTermSorter) class\r
+                                       if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) {\r
+                                           otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);\r
+                                       }\r
+\r
+                                       if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) {\r
+                                           otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary);\r
+                                       }\r
+                                   }\r
+                               }\r
+                               if(currentLocation == ViewerDropAdapter.LOCATION_ON) {\r
+                                   targetDefinedTerm.addIncludes(term);\r
+                                   targetDefinedTerm.getVocabulary().addTerm(term);\r
+                               }\r
                        }\r
 \r
                }\r
                //return null;\r
-               return postExecute(targetTermOrVocabulary);                     \r
+               return postExecute(targetTermOrVocabulary);\r
        }\r
-       \r
+\r
        private DefinedTermBase cleanTerm(DefinedTermBase term){\r
 \r
                DefinedTermBase partOf = term.getPartOf();\r
                if(partOf != null){\r
                        partOf.removeIncludes(term);\r
                }\r
-       \r
-               \r
+\r
+\r
                TermVocabulary vocabulary = term.getVocabulary();\r
                if(vocabulary != null){\r
                        vocabulary.removeTerm(term);\r
                }\r
-               \r
+\r
                return term;\r
        }\r
-       \r
+\r
 \r
        /* (non-Javadoc)\r
         * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)\r