From: Bruno Sinou Date: Fri, 4 Jul 2014 16:53:11 +0000 (+0000) Subject: + register a default command in both RAP and RCP security base apps to provide generi... X-Git-Tag: argeo-commons-2.1.30~586 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=00535f8fc1082bd936340bfd34eb6dbbe1adcbe1;p=lgpl%2Fargeo-commons.git + register a default command in both RAP and RCP security base apps to provide generic open file feature + add a Dump Node command to the JcrExplorer Browser View. git-svn-id: https://svn.argeo.org/commons/trunk@7128 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/plugins/org.argeo.security.ui.rap/META-INF/spring/commands.xml b/security/plugins/org.argeo.security.ui.rap/META-INF/spring/commands.xml index 1dc8d53ce..3dd037a3c 100644 --- a/security/plugins/org.argeo.security.ui.rap/META-INF/spring/commands.xml +++ b/security/plugins/org.argeo.security.ui.rap/META-INF/spring/commands.xml @@ -8,4 +8,15 @@ scope="prototype"> + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui.rap/plugin.xml b/security/plugins/org.argeo.security.ui.rap/plugin.xml index c85c9666d..49506de26 100644 --- a/security/plugins/org.argeo.security.ui.rap/plugin.xml +++ b/security/plugins/org.argeo.security.ui.rap/plugin.xml @@ -139,20 +139,49 @@ --> - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - org.argeo.security.ui.rap.SecureRapActivator lazy org.eclipse.rap.ui,org.eclipse.core.runtime - org.springframework.core,org.argeo.eclipse.spring,* + + org.springframework.core, + org.argeo.eclipse.spring, + org.argeo.eclipse.ui.specific, + * + diff --git a/security/plugins/org.argeo.security.ui.rcp/plugin.xml b/security/plugins/org.argeo.security.ui.rcp/plugin.xml index 53eaa525d..4ddf700d5 100644 --- a/security/plugins/org.argeo.security.ui.rcp/plugin.xml +++ b/security/plugins/org.argeo.security.ui.rcp/plugin.xml @@ -40,4 +40,25 @@ + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui.rcp/pom.xml b/security/plugins/org.argeo.security.ui.rcp/pom.xml index 4c98ef7ee..cad67aef2 100644 --- a/security/plugins/org.argeo.security.ui.rcp/pom.xml +++ b/security/plugins/org.argeo.security.ui.rcp/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 org.argeo.commons.security @@ -31,7 +33,11 @@ org.argeo.security.ui.rcp.SecureApplicationActivator lazy org.eclipse.ui,org.eclipse.core.runtime - org.argeo.eclipse.spring,* + + org.argeo.eclipse.ui.specific, + org.argeo.eclipse.spring, + * + diff --git a/server/plugins/org.argeo.jcr.ui.explorer/icons/dumpNode.gif b/server/plugins/org.argeo.jcr.ui.explorer/icons/dumpNode.gif new file mode 100644 index 000000000..14eb1be09 Binary files /dev/null and b/server/plugins/org.argeo.jcr.ui.explorer/icons/dumpNode.gif differ diff --git a/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml b/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml index a34360717..ef6be3460 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml +++ b/server/plugins/org.argeo.jcr.ui.explorer/plugin.xml @@ -105,11 +105,17 @@ id="org.argeo.jcr.ui.explorer.importFileSystem" name="Import files..."> - + --> + + + + + + + + + + + + + diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/DumpNode.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/DumpNode.java new file mode 100644 index 000000000..5bc261ea7 --- /dev/null +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/DumpNode.java @@ -0,0 +1,109 @@ +/* + * 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.jcr.ui.explorer.commands; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.specific.OpenFile; +import org.argeo.eclipse.ui.utils.CommandUtils; +import org.argeo.jcr.ui.explorer.JcrExplorerPlugin; +import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem; +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.handlers.HandlerUtil; + +/** + * If the method + * 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. + * + * Resulting stream is saved in a tmp file and opened via the "open file" + * single-sourced command. + */ +public class DumpNode extends AbstractHandler { + public final static String ID = JcrExplorerPlugin.ID + ".dumpNode"; + + private final static DateFormat df = new SimpleDateFormat( + "yyyy-MM-dd_HH-mm"); + + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event) + .getActivePage().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(); + + // TODO add a dialog to configure the export and ask for + // confirmation + // Boolean ok = MessageDialog.openConfirm( + // HandlerUtil.getActiveShell(event), "Confirm deletion", + // "Do you want to delete " + buf + "?"); + + File tmpFile; + FileOutputStream fos; + try { + tmpFile = File.createTempFile("JcrExport", ".xml"); + tmpFile.deleteOnExit(); + fos = new FileOutputStream(tmpFile); + String dateVal = df.format(new GregorianCalendar() + .getTime()); + node.getSession().exportSystemView(node.getPath(), fos, + true, false); + openGeneratedFile(tmpFile.getAbsolutePath(), + "Dump-" + node.getName() + dateVal + ".xml"); + } catch (RepositoryException e) { + throw new ArgeoException( + "Unable to perform SystemExport on " + node, e); + } catch (IOException e) { + throw new ArgeoException("Unable to SystemExport " + node, + e); + } + } + } + return null; + } + + private synchronized void openGeneratedFile(String path, String fileName) { + Map params = new HashMap(); + params.put(OpenFile.PARAM_FILE_NAME, fileName); + params.put(OpenFile.PARAM_FILE_URI, "file://" + path); + CommandUtils.callCommand("org.argeo.security.ui.specific.openFile", + params); + } +}