]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/commands/AddFileFolder.java
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.
16 package org
.argeo
.eclipse
.ui
.jcr
.commands
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.nodetype
.NodeType
;
22 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
23 import org
.argeo
.eclipse
.ui
.dialogs
.SingleValue
;
24 import org
.argeo
.eclipse
.ui
.jcr
.JcrUiPlugin
;
25 import org
.argeo
.eclipse
.ui
.jcr
.views
.AbstractJcrBrowser
;
26 import org
.eclipse
.core
.commands
.AbstractHandler
;
27 import org
.eclipse
.core
.commands
.ExecutionEvent
;
28 import org
.eclipse
.core
.commands
.ExecutionException
;
29 import org
.eclipse
.jface
.viewers
.ISelection
;
30 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
31 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
33 /** Adds a node of type nt:folder */
34 public class AddFileFolder
extends AbstractHandler
{
36 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
37 ISelection selection
= HandlerUtil
.getActiveWorkbenchWindow(event
)
38 .getActivePage().getSelection();
39 AbstractJcrBrowser view
= (AbstractJcrBrowser
) HandlerUtil
40 .getActiveWorkbenchWindow(event
).getActivePage()
41 .findView(HandlerUtil
.getActivePartId(event
));
42 if (selection
!= null && !selection
.isEmpty()
43 && selection
instanceof IStructuredSelection
) {
44 Object obj
= ((IStructuredSelection
) selection
).getFirstElement();
46 if (obj
instanceof Node
) {
47 String folderName
= SingleValue
.ask("Folder name",
49 if (folderName
!= null) {
50 Node parentNode
= (Node
) obj
;
52 Node newNode
= parentNode
.addNode(folderName
,
54 view
.nodeAdded(parentNode
, newNode
);
55 parentNode
.getSession().save();
56 } catch (RepositoryException e
) {
57 ErrorFeedback
.show("Cannot create folder " + folderName
58 + " under " + parentNode
, e
);
62 ErrorFeedback
.show(JcrUiPlugin
63 .getMessage("errorUnvalidNtFolderNodeType"));