]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/AddResultFolder.java
Migrate SLC modules
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / commands / AddResultFolder.java
index e1b357482d85e6a3e014bc12a8f0b486d9d95bfc..8c2839a0d87d1e494bfcd6c0e9dfac8e5af165e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.argeo.slc.client.ui.commands;
 
 import javax.jcr.Node;
@@ -23,6 +22,7 @@ import org.argeo.eclipse.ui.ErrorFeedback;
 import org.argeo.eclipse.ui.dialogs.SingleValue;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.client.ui.ClientUiPlugin;
+import org.argeo.slc.client.ui.model.ParentNodeFolder;
 import org.argeo.slc.client.ui.model.ResultFolder;
 import org.argeo.slc.jcr.SlcJcrResultUtils;
 import org.eclipse.core.commands.AbstractHandler;
@@ -40,7 +40,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 public class AddResultFolder extends AbstractHandler {
        public final static String ID = ClientUiPlugin.ID + ".addResultFolder";
        public final static String DEFAULT_ICON_REL_PATH = "icons/addFolder.gif";
-       public final static String DEFAULT_LABEL = "New result folder";
+       public final static String DEFAULT_LABEL = "Add folder...";
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                IStructuredSelection selection = (IStructuredSelection) HandlerUtil
@@ -48,18 +48,36 @@ public class AddResultFolder extends AbstractHandler {
 
                // Sanity check, already done when populating the corresponding popup
                // menu.
-               if (selection != null && selection.size() == 1
-                               && selection.getFirstElement() instanceof ResultFolder) {
-                       ResultFolder rf = (ResultFolder) selection.getFirstElement();
+               if (selection != null && selection.size() == 1) {
+                       Object obj = selection.getFirstElement();
                        try {
-                               String folderName = SingleValue.ask("Folder name",
-                                               "Enter folder name");
-                               if (folderName != null) {
-                                       Node parentNode = rf.getNode();
-                                       String absPath = parentNode.getPath()+ "/"
-                                                       + folderName;
-                                       SlcJcrResultUtils.createResultFolderNode(
-                                                       parentNode.getSession(), absPath);
+                               Node parentNode = null;
+                               if (obj instanceof ResultFolder) {
+                                       ResultFolder rf = (ResultFolder) obj;
+                                       parentNode = rf.getNode();
+                               } else if (obj instanceof ParentNodeFolder) {
+                                       Node node = ((ParentNodeFolder) obj).getNode();
+                                       if (node.getPath().startsWith(
+                                                       SlcJcrResultUtils.getMyResultsBasePath(node
+                                                                       .getSession())))
+                                               parentNode = node;
+                               }
+
+                               if (parentNode != null) {
+                                       String folderName = SingleValue.ask("Folder name",
+                                                       "Enter folder name");
+                                       if (folderName != null) {
+                                               if (folderName.contains("/")) {
+                                                       ErrorFeedback
+                                                                       .show("Folder names can't contain a '/'.");
+                                                       return null;
+                                               }
+
+                                               String absPath = parentNode.getPath() + "/"
+                                                               + folderName;
+                                               SlcJcrResultUtils.createResultFolderNode(
+                                                               parentNode.getSession(), absPath);
+                                       }
                                }
                        } catch (RepositoryException e) {
                                throw new SlcException(