1 package org
.argeo
.slc
.client
.ui
.commands
;
4 import javax
.jcr
.RepositoryException
;
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
;
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
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...";
30 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
31 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
32 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
34 // Sanity check, already done when populating the corresponding popup
36 if (selection
!= null && selection
.size() == 1) {
37 Object obj
= selection
.getFirstElement();
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
51 if (parentNode
!= null) {
52 String folderName
= SingleValue
.ask("Folder name",
54 if (folderName
!= null) {
55 if (folderName
.contains("/")) {
57 .show("Folder names can't contain a '/'.");
61 String absPath
= parentNode
.getPath() + "/"
63 SlcJcrResultUtils
.createResultFolderNode(
64 parentNode
.getSession(), absPath
);
67 } catch (RepositoryException e
) {
68 throw new SlcException(
69 "Unexpected exception while creating result folder", e
);
72 ErrorFeedback
.show("Can only add file folder to a node");