1 package org
.argeo
.slc
.client
.ui
.commands
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
8 import org
.argeo
.jcr
.JcrUtils
;
9 import org
.argeo
.slc
.SlcException
;
10 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
11 import org
.argeo
.slc
.client
.ui
.model
.ResultFolder
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
20 * Rename a node of type SlcType.SLC_RESULT_FOLDER by moving it.
23 public class RenameResultFolder
extends AbstractHandler
{
24 public final static String ID
= ClientUiPlugin
.ID
+ ".renameResultFolder";
25 public final static ImageDescriptor DEFAULT_IMG_DESCRIPTOR
= ClientUiPlugin
26 .getImageDescriptor("icons/rename.png");
27 public final static String DEFAULT_LABEL
= "Rename...";
29 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
30 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
31 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
33 // Sanity check, already done when populating the corresponding popup
35 if (selection
!= null && selection
.size() == 1) {
36 Object obj
= selection
.getFirstElement();
38 if (obj
instanceof ResultFolder
) {
39 ResultFolder rf
= (ResultFolder
) obj
;
40 Node sourceNode
= rf
.getNode();
41 String folderName
= SingleValue
.ask("Rename folder",
42 "Enter a new folder name");
43 if (folderName
!= null) {
44 String sourcePath
= sourceNode
.getPath();
45 String targetPath
= JcrUtils
.parentPath(sourcePath
)
47 Session session
= sourceNode
.getSession();
48 session
.move(sourcePath
, targetPath
);
52 } catch (RepositoryException e
) {
53 throw new SlcException(
54 "Unexpected exception while refactoring result folder",