1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.client.ui.commands;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20 import javax.jcr.Session;
21
22 import org.argeo.eclipse.ui.dialogs.SingleValue;
23 import org.argeo.jcr.JcrUtils;
24 import org.argeo.slc.SlcException;
25 import org.argeo.slc.client.ui.ClientUiPlugin;
26 import org.argeo.slc.client.ui.model.ResultFolder;
27 import org.eclipse.core.commands.AbstractHandler;
28 import org.eclipse.core.commands.ExecutionEvent;
29 import org.eclipse.core.commands.ExecutionException;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.viewers.IStructuredSelection;
32 import org.eclipse.ui.handlers.HandlerUtil;
33
34
35
36
37
38 public class RenameResultFolder extends AbstractHandler {
39 public final static String ID = ClientUiPlugin.ID + ".renameResultFolder";
40 public final static ImageDescriptor DEFAULT_IMG_DESCRIPTOR = ClientUiPlugin
41 .getImageDescriptor("icons/rename.png");
42 public final static String DEFAULT_LABEL = "Rename...";
43
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
46 .getActiveWorkbenchWindow(event).getActivePage().getSelection();
47
48
49
50 if (selection != null && selection.size() == 1) {
51 Object obj = selection.getFirstElement();
52 try {
53 if (obj instanceof ResultFolder) {
54 ResultFolder rf = (ResultFolder) obj;
55 Node sourceNode = rf.getNode();
56 String folderName = SingleValue.ask("Rename folder",
57 "Enter a new folder name");
58 if (folderName != null) {
59 String sourcePath = sourceNode.getPath();
60 String targetPath = JcrUtils.parentPath(sourcePath)
61 + "/" + folderName;
62 Session session = sourceNode.getSession();
63 session.move(sourcePath, targetPath);
64 session.save();
65 }
66 }
67 } catch (RepositoryException e) {
68 throw new SlcException(
69 "Unexpected exception while refactoring result folder",
70 e);
71 }
72 }
73 return null;
74 }
75 }