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