]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/commands/RenameResultFolder.java
Clarify SLC project structure.
[gpl/argeo-slc.git] / cms / org.argeo.slc.client.ui / src / org / argeo / slc / client / ui / commands / RenameResultFolder.java
1 package org.argeo.slc.client.ui.commands;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6
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;
18
19 /**
20 * Rename a node of type SlcType.SLC_RESULT_FOLDER by moving it.
21 */
22
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...";
28
29 public Object execute(ExecutionEvent event) throws ExecutionException {
30 IStructuredSelection selection = (IStructuredSelection) HandlerUtil
31 .getActiveWorkbenchWindow(event).getActivePage().getSelection();
32
33 // Sanity check, already done when populating the corresponding popup
34 // menu.
35 if (selection != null && selection.size() == 1) {
36 Object obj = selection.getFirstElement();
37 try {
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)
46 + "/" + folderName;
47 Session session = sourceNode.getSession();
48 session.move(sourcePath, targetPath);
49 session.save();
50 }
51 }
52 } catch (RepositoryException e) {
53 throw new SlcException(
54 "Unexpected exception while refactoring result folder",
55 e);
56 }
57 }
58 return null;
59 }
60 }