]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/AddResultFolder.java
Remove unused.
[gpl/argeo-slc.git] / cms / org.argeo.slc.client.ui / src / org / argeo / slc / client / ui / commands / AddResultFolder.java
1 package org.argeo.slc.client.ui.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
7 import org.argeo.eclipse.ui.dialogs.SingleValue;
8 import org.argeo.slc.SlcException;
9 import org.argeo.slc.client.ui.ClientUiPlugin;
10 import org.argeo.slc.client.ui.model.ParentNodeFolder;
11 import org.argeo.slc.client.ui.model.ResultFolder;
12 import org.argeo.slc.jcr.SlcJcrResultUtils;
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.ui.handlers.HandlerUtil;
18
19 /**
20 * Add a new SlcType.SLC_RESULT_FOLDER node to the current user "my result"
21 * tree. This handler is only intended to bu used with JcrResultTreeView and its
22 * descendants.
23 */
24
25 public class AddResultFolder extends AbstractHandler {
26 public final static String ID = ClientUiPlugin.ID + ".addResultFolder";
27 public final static String DEFAULT_ICON_REL_PATH = "icons/addFolder.gif";
28 public final static String DEFAULT_LABEL = "Add folder...";
29
30 public Object execute(ExecutionEvent event) throws ExecutionException {
31 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
32 .getActiveWorkbenchWindow(event).getActivePage().getSelection();
33
34 // Sanity check, already done when populating the corresponding popup
35 // menu.
36 if (selection != null && selection.size() == 1) {
37 Object obj = selection.getFirstElement();
38 try {
39 Node parentNode = null;
40 if (obj instanceof ResultFolder) {
41 ResultFolder rf = (ResultFolder) obj;
42 parentNode = rf.getNode();
43 } else if (obj instanceof ParentNodeFolder) {
44 Node node = ((ParentNodeFolder) obj).getNode();
45 if (node.getPath().startsWith(
46 SlcJcrResultUtils.getMyResultsBasePath(node
47 .getSession())))
48 parentNode = node;
49 }
50
51 if (parentNode != null) {
52 String folderName = SingleValue.ask("Folder name",
53 "Enter folder name");
54 if (folderName != null) {
55 if (folderName.contains("/")) {
56 ErrorFeedback
57 .show("Folder names can't contain a '/'.");
58 return null;
59 }
60
61 String absPath = parentNode.getPath() + "/"
62 + folderName;
63 SlcJcrResultUtils.createResultFolderNode(
64 parentNode.getSession(), absPath);
65 }
66 }
67 } catch (RepositoryException e) {
68 throw new SlcException(
69 "Unexpected exception while creating result folder", e);
70 }
71 } else {
72 ErrorFeedback.show("Can only add file folder to a node");
73 }
74 return null;
75 }
76 }