2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.commands
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
22 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
23 import org
.argeo
.slc
.SlcException
;
24 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
25 import org
.argeo
.slc
.client
.ui
.model
.ParentNodeFolder
;
26 import org
.argeo
.slc
.client
.ui
.model
.ResultFolder
;
27 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
28 import org
.eclipse
.core
.commands
.AbstractHandler
;
29 import org
.eclipse
.core
.commands
.ExecutionEvent
;
30 import org
.eclipse
.core
.commands
.ExecutionException
;
31 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
32 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
35 * Add a new SlcType.SLC_RESULT_FOLDER node to the current user "my result"
36 * tree. This handler is only intended to bu used with JcrResultTreeView and its
40 public class AddResultFolder
extends AbstractHandler
{
41 public final static String ID
= ClientUiPlugin
.ID
+ ".addResultFolder";
42 public final static String DEFAULT_ICON_REL_PATH
= "icons/addFolder.gif";
43 public final static String DEFAULT_LABEL
= "New result folder";
45 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
46 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
47 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
49 // Sanity check, already done when populating the corresponding popup
51 if (selection
!= null && selection
.size() == 1) {
52 Object obj
= selection
.getFirstElement();
54 Node parentNode
= null;
55 if (obj
instanceof ResultFolder
) {
56 ResultFolder rf
= (ResultFolder
) obj
;
57 parentNode
= rf
.getNode();
58 } else if (obj
instanceof ParentNodeFolder
) {
59 Node node
= ((ParentNodeFolder
) obj
).getNode();
60 if (node
.getPath().startsWith(
61 SlcJcrResultUtils
.getMyResultsBasePath(node
66 if (parentNode
!= null) {
67 String folderName
= SingleValue
.ask("Folder name",
69 if (folderName
!= null) {
70 String absPath
= parentNode
.getPath() + "/"
72 SlcJcrResultUtils
.createResultFolderNode(
73 parentNode
.getSession(), absPath
);
76 } catch (RepositoryException e
) {
77 throw new SlcException(
78 "Unexpected exception while creating result folder", e
);
81 ErrorFeedback
.show("Can only add file folder to a node");