1 package org
.argeo
.slc
.client
.ui
.commands
;
4 import javax
.jcr
.Property
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Session
;
8 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
9 import org
.argeo
.jcr
.JcrUtils
;
10 import org
.argeo
.slc
.SlcException
;
11 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
12 import org
.argeo
.slc
.client
.ui
.model
.SingleResultNode
;
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
.dialogs
.MessageDialog
;
17 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.swt
.widgets
.Display
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
23 * Rename a node of type SlcType.SLC_RESULT_FOLDER by moving it.
26 public class RenameResultNode
extends AbstractHandler
{
27 public final static String ID
= ClientUiPlugin
.ID
+ ".renameResultNode";
28 public final static ImageDescriptor DEFAULT_IMG_DESCRIPTOR
= ClientUiPlugin
29 .getImageDescriptor("icons/rename.png");
30 public final static String DEFAULT_LABEL
= "Rename result";
32 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
33 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
34 .getActiveWorkbenchWindow(event
).getActivePage().getSelection();
36 // Sanity check, already done when populating the corresponding popup
38 if (selection
!= null && selection
.size() == 1) {
39 Object obj
= selection
.getFirstElement();
41 if (obj
instanceof SingleResultNode
) {
42 SingleResultNode rf
= (SingleResultNode
) obj
;
43 Node sourceNode
= rf
.getNode();
44 String folderName
= SingleValue
.ask("Rename result",
45 "Enter a new result name");
46 if (folderName
!= null) {
48 if (sourceNode
.getParent().hasNode(folderName
)) {
50 .openError(Display
.getDefault()
51 .getActiveShell(), "Error",
52 "Another object with the same name already exists.");
56 String sourcePath
= sourceNode
.getPath();
57 String targetPath
= JcrUtils
.parentPath(sourcePath
)
59 Session session
= sourceNode
.getSession();
60 session
.move(sourcePath
, targetPath
);
61 session
.getNode(targetPath
).setProperty(
62 Property
.JCR_TITLE
, folderName
);
66 } catch (RepositoryException e
) {
67 throw new SlcException(
68 "Unexpected exception while refactoring result folder",