name="Dump Current Selected Node">
</command>
<command
+ defaultHandler="org.argeo.eclipse.ui.workbench.commands.RenameNode"
+ id="org.argeo.eclipse.ui.workbench.renameNode"
+ name="Rename Current Selected Node">
+ </command>
+ <command
defaultHandler="org.argeo.eclipse.ui.workbench.commands.NodeConfigurableDump"
id="org.argeo.eclipse.ui.workbench.nodeConfigurableDump"
name="Configurable dump of the selected Node">
</visibleWhen>
</command>
<command
+ commandId="org.argeo.eclipse.ui.workbench.renameNode"
+ icon="icons/rename.gif"
+ label="Rename..."
+ style="push">
+ <visibleWhen>
+ <iterate> <and>
+ <instanceof value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem"></instanceof>
+ <with variable="activeMenuSelection"><count value="1"/></with>
+ </and> </iterate>
+ </visibleWhen>
+ </command>
+ <command
commandId="org.argeo.eclipse.ui.workbench.nodeConfigurableDump"
icon="icons/dumpNode.gif"
label="Configurable dump..."
import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.specific.OpenFile;
import org.argeo.eclipse.ui.workbench.CommandUtils;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.jcr.JcrUtils;
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.ui.handlers.HandlerUtil;
/**
- * If the method
- * <code> HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection() </code>
- * 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 {
.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);
--- /dev/null
+/*
+ * 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
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;
* 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);
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;
}
//