2 * Copyright (C) 2007-2012 Mathieu Baudier
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.
17 package org
.argeo
.slc
.client
.ui
.commands
;
19 import javax
.jcr
.Node
;
20 import javax
.jcr
.RepositoryException
;
22 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
23 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
26 import org
.argeo
.slc
.client
.ui
.model
.ParentNodeFolder
;
27 import org
.argeo
.slc
.client
.ui
.model
.ResultFolder
;
28 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
29 import org
.eclipse
.core
.commands
.AbstractHandler
;
30 import org
.eclipse
.core
.commands
.ExecutionEvent
;
31 import org
.eclipse
.core
.commands
.ExecutionException
;
32 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
33 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
36 * Add a new SlcType.SLC_RESULT_FOLDER node to the current user "my result"
37 * tree. This handler is only intended to bu used with JcrResultTreeView and its
41 public class AddResultFolder
extends AbstractHandler
{
42 public final static String ID
= ClientUiPlugin
.ID
+ ".addResultFolder";
43 public final static String DEFAULT_ICON_REL_PATH
= "icons/addFolder.gif";
44 public final static String DEFAULT_LABEL
= "New result folder";
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
48 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
50 // Sanity check, already done when populating the corresponding popup
52 if (selection
!= null && selection
.size() == 1) {
53 Object obj
= selection
.getFirstElement();
55 Node parentNode
= null;
56 if (obj
instanceof ResultFolder
) {
57 ResultFolder rf
= (ResultFolder
) obj
;
58 parentNode
= rf
.getNode();
59 } else if (obj
instanceof ParentNodeFolder
) {
60 Node node
= ((ParentNodeFolder
) obj
).getNode();
61 if (node
.getPath().startsWith(
62 SlcJcrResultUtils
.getMyResultsBasePath(node
67 if (parentNode
!= null) {
68 String folderName
= SingleValue
.ask("Folder name",
70 if (folderName
!= null) {
71 String absPath
= parentNode
.getPath() + "/"
73 SlcJcrResultUtils
.createResultFolderNode(
74 parentNode
.getSession(), absPath
);
77 } catch (RepositoryException e
) {
78 throw new SlcException(
79 "Unexpected exception while creating result folder", e
);
82 ErrorFeedback
.show("Can only add file folder to a node");