Fix drag and drop for multiple flows between these 2 pages.
authorBruno Sinou <bsinou@argeo.org>
Fri, 22 Mar 2013 16:37:56 +0000 (16:37 +0000)
committerBruno Sinou <bsinou@argeo.org>
Fri, 22 Mar 2013 16:37:56 +0000 (16:37 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6209 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java
plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrExecutionModulesView.java

index 3c757ff9aea291100761a170d21dac4f2247803e..6ed8debf636a5df345f3f864425f8f3784133177 100644 (file)
@@ -615,32 +615,40 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
 
                @Override
                public boolean performDrop(Object data) {
-                       String path = data.toString();
-                       try {
-                               // either a node or a whole directory was dragged
-                               QueryManager qm = processNode.getSession().getWorkspace()
-                                               .getQueryManager();
-                               String statement = "SELECT * FROM ["
-                                               + SlcTypes.SLC_EXECUTION_FLOW
-                                               + "] WHERE ISDESCENDANTNODE(['" + path
-                                               + "']) OR ISSAMENODE(['" + path + "'])";
-                               // log.debug(statement);
-                               Query query = qm.createQuery(statement, Query.JCR_SQL2);
-
-                               // order paths
-                               SortedSet<String> paths = new TreeSet<String>();
-                               for (NodeIterator nit = query.execute().getNodes(); nit
-                                               .hasNext();) {
-                                       paths.add(nit.nextNode().getPath());
-                               }
 
-                               for (String p : paths) {
-                                       addFlow(p);
+                       // Parse the received String, paths are separated with a carriage
+                       // return
+                       String[] paths = data.toString().split(new String("\n"));
+                       SortedSet<String> resultPaths = new TreeSet<String>();
+                       for (String path : paths) {
+                               try {
+                                       // either a node or a whole directory can have been dragged
+                                       QueryManager qm = processNode.getSession().getWorkspace()
+                                                       .getQueryManager();
+                                       String statement = "SELECT * FROM ["
+                                                       + SlcTypes.SLC_EXECUTION_FLOW
+                                                       + "] WHERE ISDESCENDANTNODE(['" + path
+                                                       + "']) OR ISSAMENODE(['" + path + "'])";
+                                       Query query = qm.createQuery(statement, Query.JCR_SQL2);
+
+                                       // order paths
+                                       for (NodeIterator nit = query.execute().getNodes(); nit
+                                                       .hasNext();) {
+                                               String currPath = nit.nextNode().getPath();
+                                               // do not add twice a same flow
+                                               if (!resultPaths.contains(currPath))
+                                                       resultPaths.add(currPath);
+                                       }
+                               } catch (RepositoryException e) {
+                                       throw new SlcException("Cannot query flows under " + path,
+                                                       e);
                                }
-                               return true;
-                       } catch (RepositoryException e) {
-                               throw new SlcException("Cannot query flows under " + path, e);
                        }
+                       for (String p : resultPaths) {
+                               addFlow(p);
+                       }
+                       return true;
+
                }
 
                @Override
@@ -668,6 +676,12 @@ public class ProcessBuilderPage extends FormPage implements SlcNames {
                                        if (!specAttrNode
                                                        .isNodeType(SlcTypes.SLC_EXECUTION_SPEC_ATTRIBUTE))
                                                continue specAttrs;
+                                       // workaround to enable hiding of necessary but unusable
+                                       // flow parameters
+                                       else if (specAttrNode.hasProperty(SlcNames.SLC_IS_HIDDEN)
+                                                       && specAttrNode.getProperty(SlcNames.SLC_IS_HIDDEN)
+                                                                       .getBoolean())
+                                               continue specAttrs;
                                        specAttributes.add(specAttrNode);
                                }
                                return specAttributes.toArray();
index 3aa59d693f9aeba03d7838459a6f58908a27ee17..dca7fc79988fa4bb003b3547befca357344c6916 100644 (file)
@@ -344,19 +344,74 @@ public class JcrExecutionModulesView extends ViewPart implements SlcTypes,
 
        /** Listen to drags */
        class ViewDragListener extends DragSourceAdapter {
+
+               // Check if the drag action should start.
+               public void dragStart(DragSourceEvent event) {
+                       // we only start drag if at least one of the selected elements is
+                       // valid
+                       boolean doIt = false;
+                       IStructuredSelection selection = (IStructuredSelection) viewer
+                                       .getSelection();
+                       @SuppressWarnings("rawtypes")
+                       Iterator it = selection.iterator();
+                       try {
+                               while (it.hasNext()) {
+                                       Object obj = it.next();
+                                       if (obj instanceof Node) {
+                                               Node node = (Node) obj;
+                                               if (node.isNodeType(SlcTypes.SLC_EXECUTION_FLOW)
+                                                               || node.isNodeType(SlcTypes.SLC_EXECUTION_MODULE)) {
+                                                       doIt = true;
+                                               }
+                                       }
+                               }
+                       } catch (RepositoryException e) {
+                               throw new SlcException("Cannot read node to set drag data", e);
+                       }
+                       event.doit = doIt;
+               }
+
                public void dragSetData(DragSourceEvent event) {
                        IStructuredSelection selection = (IStructuredSelection) viewer
                                        .getSelection();
-                       if (selection.getFirstElement() instanceof Node) {
-                               Node node = (Node) selection.getFirstElement();
-                               if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
-                                       try {
-                                               event.data = node.getPath();
-                                       } catch (RepositoryException e) {
-                                               throw new SlcException("Cannot read node", e);
+                       StringBuilder buf = new StringBuilder();
+                       @SuppressWarnings("rawtypes")
+                       Iterator it = selection.iterator();
+                       try {
+
+                               while (it.hasNext()) {
+                                       Object obj = it.next();
+
+                                       if (obj instanceof Node) {
+                                               Node node = (Node) obj;
+                                               if ((node.isNodeType(SlcTypes.SLC_EXECUTION_FLOW) || node
+                                                               .isNodeType(SlcTypes.SLC_EXECUTION_MODULE))
+                                                               && TextTransfer.getInstance().isSupportedType(
+                                                                               event.dataType)) {
+                                                       buf.append(node.getPath()).append('\n');
+                                               }
                                        }
                                }
+                       } catch (RepositoryException e) {
+                               throw new SlcException("Cannot read node to set drag data", e);
+                       }
+
+                       if (buf.length() > 0) {
+                               if (buf.charAt(buf.length() - 1) == '\n')
+                                       buf.deleteCharAt(buf.length() - 1);
+                               event.data = buf.toString();
+                               log.debug("data set to : " + buf.toString());
                        }
+                       // if (selection.getFirstElement() instanceof Node) {
+                       // Node node = (Node) selection.getFirstElement();
+                       // if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
+                       // try {
+                       // event.data = node.getPath();
+                       // } catch (RepositoryException e) {
+                       // throw new SlcException("Cannot read node", e);
+                       // }
+                       // }
+                       // }
                }
        }