X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FAddResultFolder.java;fp=plugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fcommands%2FAddResultFolder.java;h=e1b357482d85e6a3e014bc12a8f0b486d9d95bfc;hb=e8997305e4d5fe939e2e4ec55195afdc0d488bbc;hp=0000000000000000000000000000000000000000;hpb=3c8e43e258464f8efe44c80f2a4f5c3080f28d4f;p=gpl%2Fargeo-slc.git diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/AddResultFolder.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/AddResultFolder.java new file mode 100644 index 000000000..e1b357482 --- /dev/null +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/commands/AddResultFolder.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.argeo.slc.client.ui.commands; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.eclipse.ui.ErrorFeedback; +import org.argeo.eclipse.ui.dialogs.SingleValue; +import org.argeo.slc.SlcException; +import org.argeo.slc.client.ui.ClientUiPlugin; +import org.argeo.slc.client.ui.model.ResultFolder; +import org.argeo.slc.jcr.SlcJcrResultUtils; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Add a new SlcType.SLC_RESULT_FOLDER node to the current user "my result" + * tree. This handler is only intended to bu used with JcrResultTreeView and its + * descendants. + */ + +public class AddResultFolder extends AbstractHandler { + public final static String ID = ClientUiPlugin.ID + ".addResultFolder"; + public final static String DEFAULT_ICON_REL_PATH = "icons/addFolder.gif"; + public final static String DEFAULT_LABEL = "New result folder"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + IStructuredSelection selection = (IStructuredSelection) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage().getSelection(); + + // Sanity check, already done when populating the corresponding popup + // menu. + if (selection != null && selection.size() == 1 + && selection.getFirstElement() instanceof ResultFolder) { + ResultFolder rf = (ResultFolder) selection.getFirstElement(); + try { + String folderName = SingleValue.ask("Folder name", + "Enter folder name"); + if (folderName != null) { + Node parentNode = rf.getNode(); + String absPath = parentNode.getPath()+ "/" + + folderName; + SlcJcrResultUtils.createResultFolderNode( + parentNode.getSession(), absPath); + } + } catch (RepositoryException e) { + throw new SlcException( + "Unexpected exception while creating result folder", e); + } + } else { + ErrorFeedback.show("Can only add file folder to a node"); + } + return null; + } +} \ No newline at end of file