From: Bruno Sinou Date: Wed, 22 Jul 2015 20:50:10 +0000 (+0000) Subject: Add a rename node command X-Git-Tag: argeo-commons-2.1.30~215 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=0947eeab5f5224be47a038e23ba5ae68b760d048;p=lgpl%2Fargeo-commons.git Add a rename node command git-svn-id: https://svn.argeo.org/commons/trunk@8283 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.eclipse.ui.workbench/icons/rename.gif b/org.argeo.eclipse.ui.workbench/icons/rename.gif new file mode 100644 index 000000000..8048405a7 Binary files /dev/null and b/org.argeo.eclipse.ui.workbench/icons/rename.gif differ diff --git a/org.argeo.eclipse.ui.workbench/plugin.xml b/org.argeo.eclipse.ui.workbench/plugin.xml index 210046381..5e281b29a 100644 --- a/org.argeo.eclipse.ui.workbench/plugin.xml +++ b/org.argeo.eclipse.ui.workbench/plugin.xml @@ -165,6 +165,11 @@ name="Dump Current Selected Node"> + + @@ -369,6 +374,18 @@ + + + + + + + + HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection() - * exits and has a SingleJcrNodeElem as first element, it canonically calls the - * JCR Session.exportSystemView() method on the underlying node with both - * skipBinary & noRecurse boolean flags set to false. + * Canonically call JCR {@link Session#exportSystemView()} on the first element + * returned by {@link HandlerUtil#getActiveWorkbenchWindow()} + * (...getActivePage().getSelection()), if it is a {@link SingleJcrNodeElem}, + * with both skipBinary & noRecurse boolean flags set to false. * - * Resulting stream is saved in a tmp file and opened via the "open file" + * Resulting stream is saved in a tmp file and opened via the {@link OpenFile} * single-sourced command. */ public class DumpNode extends AbstractHandler { @@ -86,8 +86,9 @@ public class DumpNode extends AbstractHandler { .getTime()); node.getSession().exportSystemView(node.getPath(), fos, true, false); - openGeneratedFile(tmpFile.getAbsolutePath(), - "Dump-" + JcrUtils.replaceInvalidChars(node.getName())+ "-" + dateVal + ".xml"); + openGeneratedFile(tmpFile.getAbsolutePath(), "Dump-" + + JcrUtils.replaceInvalidChars(node.getName()) + + "-" + dateVal + ".xml"); } catch (RepositoryException e) { throw new ArgeoException( "Unable to perform SystemExport on " + node, e); diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java new file mode 100644 index 000000000..aaab72749 --- /dev/null +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * 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.eclipse.ui.workbench.commands; + +import java.util.Iterator; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.dialogs.SingleValue; +import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; +import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView; +import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem; +import org.argeo.jcr.JcrUtils; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Canonically call JCR {@link Session#move(String, String)} on the first + * element returned by {@link HandlerUtil#getActiveWorkbenchWindow()} + * (...getActivePage().getSelection()), if it is a {@link SingleJcrNodeElem}. + * The user must then fill a new name in and confirm + */ +public class RenameNode extends AbstractHandler { + public final static String ID = WorkbenchUiPlugin.ID + ".renameNode"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchPage iwp = HandlerUtil.getActiveWorkbenchWindow(event) + .getActivePage(); + + ISelection selection = iwp.getSelection(); + if (selection == null || !(selection instanceof IStructuredSelection)) + return null; + + Iterator lst = ((IStructuredSelection) selection).iterator(); + if (lst.hasNext()) { + Object element = lst.next(); + if (element instanceof SingleJcrNodeElem) { + SingleJcrNodeElem sjn = (SingleJcrNodeElem) element; + Node node = sjn.getNode(); + Session session = null; + String newName = null; + String oldPath = null; + try { + newName = SingleValue.ask("New node name", + "Please provide a new name for [" + node.getName() + + "]"); + // TODO sanity check and user feedback + newName = JcrUtils.replaceInvalidChars(newName); + oldPath = node.getPath(); + session = node.getSession(); + session.move(oldPath, JcrUtils.parentPath(oldPath) + "/" + + newName); + session.save(); + + // Manually refresh the browser view. Must be enhanced + if (iwp.getActivePart() instanceof JcrBrowserView) + ((JcrBrowserView) iwp.getActivePart()).refresh(sjn); + } catch (RepositoryException e) { + throw new ArgeoException("Unable to rename " + node + + " to " + newName, e); + } + } + } + return null; + } +} \ No newline at end of file diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/GenericPropertyPage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/GenericPropertyPage.java index 194720253..0de0af824 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/GenericPropertyPage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/GenericPropertyPage.java @@ -28,6 +28,8 @@ import org.argeo.ArgeoException; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.jcr.internal.PropertyLabelProvider; +import org.eclipse.jface.layout.TreeColumnLayout; +import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; @@ -45,7 +47,6 @@ import org.eclipse.ui.forms.widgets.ScrolledForm; * Generic editor property page. Lists all properties of current node as a * complex tree. TODO: enable editing */ - public class GenericPropertyPage extends FormPage implements WorkbenchConstants { // private final static Log log = // LogFactory.getLog(GenericPropertyPage.class); @@ -61,39 +62,52 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants protected void createFormContent(IManagedForm managedForm) { ScrolledForm form = managedForm.getForm(); form.setText(WorkbenchUiPlugin.getMessage("genericNodePageTitle")); + + Composite body = form.getBody(); FillLayout layout = new FillLayout(); layout.marginHeight = 5; layout.marginWidth = 5; - form.getBody().setLayout(layout); - - createComplexTree(form.getBody()); + body.setLayout(layout); + createComplexTree(body); + // TODO TreeColumnLayout triggers a scroll issue with the form: + // The inside body is always to big and a scroll bar is shown + // Composite tableCmp = new Composite(body, SWT.NO_FOCUS); + // createComplexTree(tableCmp); } private TreeViewer createComplexTree(Composite parent) { int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION; Tree tree = new Tree(parent, style); - createColumn(tree, "Property", SWT.LEFT, 200); - createColumn(tree, "Value(s)", SWT.LEFT, 300); - createColumn(tree, "Attributes", SWT.LEFT, 65); + TreeColumnLayout tableColumnLayout = new TreeColumnLayout(); + + createColumn(tree, tableColumnLayout, "Property", SWT.LEFT, 200, 30); + createColumn(tree, tableColumnLayout, "Value(s)", SWT.LEFT, 300, 60); + createColumn(tree, tableColumnLayout, "Attributes", SWT.LEFT, 75, 0); + // Do not apply the treeColumnLayout it does not work yet + // parent.setLayout(tableColumnLayout); + tree.setLinesVisible(true); tree.setHeaderVisible(true); - TreeViewer result = new TreeViewer(tree); - result.setContentProvider(new TreeContentProvider()); - result.setLabelProvider(new PropertyLabelProvider()); - result.setInput(currentNode); - result.expandAll(); - return result; + TreeViewer treeViewer = new TreeViewer(tree); + treeViewer.setContentProvider(new TreeContentProvider()); + treeViewer.setLabelProvider(new PropertyLabelProvider()); + treeViewer.setInput(currentNode); + treeViewer.expandAll(); + return treeViewer; } - private static TreeColumn createColumn(Tree parent, String name, int style, - int width) { - TreeColumn result = new TreeColumn(parent, style); - result.setText(name); - result.setWidth(width); - result.setMoveable(true); - result.setResizable(true); - return result; + private static TreeColumn createColumn(Tree parent, + TreeColumnLayout tableColumnLayout, String name, int style, + int width, int weight) { + TreeColumn column = new TreeColumn(parent, style); + column.setText(name); + column.setWidth(width); + column.setMoveable(true); + column.setResizable(true); + tableColumnLayout.setColumnData(column, new ColumnWeightData(weight, + width, true)); + return column; } //