+ register a default command in both RAP and RCP security base apps to provide generi...
authorBruno Sinou <bsinou@argeo.org>
Fri, 4 Jul 2014 16:53:11 +0000 (16:53 +0000)
committerBruno Sinou <bsinou@argeo.org>
Fri, 4 Jul 2014 16:53:11 +0000 (16:53 +0000)
+ 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

security/plugins/org.argeo.security.ui.rap/META-INF/spring/commands.xml
security/plugins/org.argeo.security.ui.rap/plugin.xml
security/plugins/org.argeo.security.ui.rap/pom.xml
security/plugins/org.argeo.security.ui.rcp/plugin.xml
security/plugins/org.argeo.security.ui.rcp/pom.xml
server/plugins/org.argeo.jcr.ui.explorer/icons/dumpNode.gif [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/plugin.xml
server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/DumpNode.java [new file with mode: 0644]

index 1dc8d53cecea3c460d9fdc96a466c4ee69bb1cf7..3dd037a3c3c1b022fccca68f362bd6fbaf5edf90 100644 (file)
@@ -8,4 +8,15 @@
                scope="prototype">
                <property name="userDetailsManager" ref="userDetailsManager" />
        </bean>
+
+
+       <!-- RAP Specific command and corresponding service to enable open file -->
+       <bean id="org.argeo.security.ui.specific.openFile" class="org.argeo.eclipse.ui.specific.OpenFile"
+               scope="prototype">
+               <property name="openFileServiceId"
+                       value="org.argeo.security.ui.specific.openFileService" />
+       </bean>
+       <!-- Useless - nothing to inject -->
+       <!-- <bean id="org.argeo.security.ui.specific.openFileService" class="org.argeo.eclipse.ui.specific.OpenFileService" 
+               scope="prototype"> </bean> -->
 </beans>
index c85c9666df144a9dd9dce86bc0af956c71c3875c..49506de26c1c7f9af3cfd03568babb9d8fd830d8 100644 (file)
      </menuContribution> -->
   </extension>
 
-   <extension point="org.eclipse.ui.commands">
-      <command
-            id="org.argeo.security.ui.rap.openChangePasswordDialog"
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            name="Change Password">
-      </command>
-      <command
-            id="org.argeo.security.ui.rap.mainMenuCommand"
-            defaultHandler="org.argeo.security.ui.commands.OpenHomePerspective"
-            name="Main">
-      </command>
-    </extension>
+       <!-- COMMANDS --> 
+       <extension point="org.eclipse.ui.commands">
+               <command
+                       id="org.argeo.security.ui.rap.openChangePasswordDialog"
+                       defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+                       name="Change Password">
+               </command>
+               <command
+                       id="org.argeo.security.ui.rap.mainMenuCommand"
+                       defaultHandler="org.argeo.security.ui.commands.OpenHomePerspective"
+                       name="Main">
+               </command>
+               
+       <!-- Register a default command that enable an "open file" action in a single sourced application  -->  
+               <command
+                       defaultHandler="org.argeo.eclipse.spring.SpringExtensionFactory"
+                       id="org.argeo.security.ui.specific.openFile"
+                       name="OpenFile">
+                       <commandParameter
+                       id="param.fileName"
+                       name="The name of the file to open (optional)">
+                       </commandParameter>
+            <commandParameter
+                       id="param.fileURI"
+                       name="The URI of this file on the server">
+                       </commandParameter>
+                       <commandParameter
+                       id="param.filePath"
+                       name="The absolute path of this file on the server file system">
+                       </commandParameter>
+               </command>
+       </extension>
+       <!-- SERVICE HANDLERS --> 
+       <extension point="org.eclipse.rap.ui.serviceHandler">
+               <!-- The required rap specific handler to call the open file command over the internet-->
+               <serviceHandler
+                       class="org.argeo.eclipse.ui.specific.OpenFileService"
+                       id="org.argeo.security.ui.specific.openFileService">
+               </serviceHandler>
+       </extension>
     
-  <extension
+       <extension
            point="org.eclipse.ui.activities">
         <activity
               description="Anonymous"
index 743e4a04c93a3da5c95bbd40c9fa348f0d86d204..2c1754bd124bf15aae982c1ff805279f0ae4793d 100644 (file)
                                                <Bundle-Activator>org.argeo.security.ui.rap.SecureRapActivator</Bundle-Activator>
                                                <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                                                <Require-Bundle>org.eclipse.rap.ui,org.eclipse.core.runtime</Require-Bundle>
-                                               <Import-Package>org.springframework.core,org.argeo.eclipse.spring,*</Import-Package>
+                                               <Import-Package>
+                                                               org.springframework.core,
+                                                               org.argeo.eclipse.spring,
+                                                               org.argeo.eclipse.ui.specific,
+                                                               *
+                                               </Import-Package>
                                        </instructions>
                                </configuration>
                        </plugin>
index 53eaa525dbbbd2b15145f679f8769161c1722413..4ddf700d5456c41c166c5d01eb25e977cd5a38c7 100644 (file)
       </callbackHandlerMapping>
    </extension>
    
+       <!-- COMMANDS --> 
+       <extension point="org.eclipse.ui.commands">
+               <!-- Register a default command that enable an "open file" action in a single sourced application  -->  
+               <command
+                       defaultHandler="org.argeo.eclipse.ui.specific.OpenFile"
+                       id="org.argeo.security.ui.specific.openFile"
+                       name="OpenFile">
+                       <commandParameter
+                       id="param.fileName"
+                       name="The name of the file to open (optional)">
+                       </commandParameter>
+            <commandParameter
+                       id="param.fileURI"
+                       name="The URI of this file on the server">
+                       </commandParameter>
+                       <commandParameter
+                       id="param.filePath"
+                       name="The absolute path of this file on the server file system">
+                       </commandParameter>
+               </command>
+       </extension>
 </plugin>
index 4c98ef7ee7f58fc0a13ebcb1d322226193504e97..cad67aef2e18d8ed6546abc8d087441985496283 100644 (file)
@@ -1,4 +1,6 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons.security</groupId>
                                                <Bundle-Activator>org.argeo.security.ui.rcp.SecureApplicationActivator</Bundle-Activator>
                                                <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                                                <Require-Bundle>org.eclipse.ui,org.eclipse.core.runtime</Require-Bundle>
-                                               <Import-Package>org.argeo.eclipse.spring,*</Import-Package>
+                                               <Import-Package>
+                                                       org.argeo.eclipse.ui.specific,
+                                                       org.argeo.eclipse.spring,
+                                                       *
+                                               </Import-Package>
                                        </instructions>
                                </configuration>
                        </plugin>
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 (file)
index 0000000..14eb1be
Binary files /dev/null and b/server/plugins/org.argeo.jcr.ui.explorer/icons/dumpNode.gif differ
index a3436071732e892bc0988c2b1ca84ad56ab33b34..ef6be346035edb8685fd9b32cd6960e6fc47368b 100644 (file)
                id="org.argeo.jcr.ui.explorer.importFileSystem"
                name="Import files...">
          </command>
-         <command
+        <!-- <command
                defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
                id="org.argeo.jcr.ui.explorer.openFile"
                name="Open current file">
          </command>
+         -->
+         <command
+               defaultHandler="org.argeo.jcr.ui.explorer.commands.DumpNode"
+               id="org.argeo.jcr.ui.explorer.dumpNode"
+               name="Import files...">
+         </command>
          <command
             defaultHandler="org.argeo.jcr.ui.explorer.commands.SortChildNodes"
             id="org.argeo.jcr.ui.explorer.sortChildNodes"
                                        </iterate>
                                        </visibleWhen>
                        </command>
+                       <command
+                        commandId="org.argeo.jcr.ui.explorer.dumpNode"
+                        icon="icons/dumpNode.gif"
+                        label="Dump Node"
+                        style="push">
+                               <visibleWhen>
+                                       <iterate>
+                                     <and>
+                                               <instanceof value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem"></instanceof>
+                               <with variable="activeMenuSelection"><count value="1"/></with>
+                                     </and>
+                                       </iterate>
+                               </visibleWhen>
+                       </command>
+                       
                </menuContribution>
        </extension>
 
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 (file)
index 0000000..5bc261e
--- /dev/null
@@ -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
+ * <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.
+ * 
+ * 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<String, String> params = new HashMap<String, String>();
+               params.put(OpenFile.PARAM_FILE_NAME, fileName);
+               params.put(OpenFile.PARAM_FILE_URI, "file://" + path);
+               CommandUtils.callCommand("org.argeo.security.ui.specific.openFile",
+                               params);
+       }
+}