<?xml version="1.0" encoding="UTF-8"?>
-<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">
+<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.eclipse</groupId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
- <!-- RCP Only -->
<dependency>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui</artifactId>
-<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">
+<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.eclipse</groupId>
<Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
<Import-Package>
org.eclipse.swt,
+ org.argeo.eclipse.ui.specific,
*
</Import-Package>
<Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
<version>0.2.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.ui.rcp</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
<!-- Argeo Commons -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
</dependency>
-
+
</dependencies>
</project>
package org.argeo.eclipse.ui.jcr.views;
+import java.io.BufferedInputStream;
+import java.io.File;
import java.util.Arrays;
import javax.jcr.Node;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
+import org.apache.commons.io.IOUtils;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.dialogs.Error;
import org.argeo.eclipse.ui.jcr.browser.NodeContentProvider;
import org.argeo.eclipse.ui.jcr.browser.NodeLabelProvider;
import org.argeo.eclipse.ui.jcr.browser.PropertiesContentProvider;
import org.argeo.eclipse.ui.jcr.browser.RepositoryNode;
import org.argeo.eclipse.ui.jcr.browser.WorkspaceNode;
+import org.argeo.eclipse.ui.specific.FileHandler;
import org.argeo.jcr.RepositoryRegister;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ColumnLabelProvider;
} else if (obj instanceof WorkspaceNode) {
((WorkspaceNode) obj).login();
nodesViewer.refresh(obj);
+ } // call the openFile commands on node
+ else if (obj instanceof Node) {
+ Node node = (Node) obj;
+ try {
+ if (node.isNodeType("nt:file")) {
+
+ Node child = node.getNodes().nextNode();
+ if (!child.isNodeType("nt:resource")) {
+ Error.show("Cannot open file children Node that are not of 'nt:resource' type.");
+ return;
+ }
+ BufferedInputStream fis = null;
+
+ try {
+ fis = (BufferedInputStream) child
+ .getProperty("jcr:data").getBinary()
+ .getStream();
+
+ String name = node.getName();
+
+ // Instantiate the generic object that fits for
+ // both
+ // RCP & RAP.
+ FileHandler fh = new FileHandler();
+ fh.openFile(name,
+ fis);
+ //fh.openFile(file);
+ } catch (Exception e) {
+ throw new ArgeoException(
+ "Stream error while opening file", e);
+ } finally {
+ IOUtils.closeQuietly(fis);
+ }
+ }
+ } catch (RepositoryException re) {
+ re.printStackTrace();
+
+ }
}
}
--- /dev/null
+package org.argeo.eclipse.ui.specific;
+
+import java.awt.Desktop;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.argeo.ArgeoException;
+
+//import org.apache.commons.io;
+
+public class FileHandler {
+
+ private BufferedInputStream bis;
+
+ public FileHandler() {
+ }
+
+ public File createTmpFile(String fileName, String suffix, InputStream is) {
+ File tmpFile = null;
+ OutputStream os = null;
+ try {
+ tmpFile = File.createTempFile(fileName, suffix);
+ os = new FileOutputStream(tmpFile);
+ IOUtils.copy(is, os);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + fileName, e);
+ } finally {
+ IOUtils.closeQuietly(os);
+ }
+ return tmpFile;
+ }
+
+ public void openFile(String fileName, InputStream is) {
+
+ String prefix ="", extension = "";
+
+ if (fileName != null){
+ int ind = fileName.
+ if (true){
+ }
+ }
+
+ prefix = .substring(0,
+ node.getName().lastIndexOf('.'));
+ extension = node.getName().substring(
+ node.getName().lastIndexOf('.'));
+ try {
+ Desktop desktop = null;
+ if (Desktop.isDesktopSupported()) {
+ desktop = Desktop.getDesktop();
+ }
+ desktop.open(file);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + file.getName(), e);
+ }
+ }
+
+
+ public void openFile(File file) {
+ try {
+ Desktop desktop = null;
+ if (Desktop.isDesktopSupported()) {
+ desktop = Desktop.getDesktop();
+ }
+ desktop.open(file);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + file.getName(), e);
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.eclipse.ui.rcp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Tue Mar 01 19:20:51 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
<Import-Package>
org.springframework.beans.factory,
org.springframework.core.io.support,
+ org.apache.commons.io,
+ org.argeo,
!org.eclipse.core.runtime,
!org.eclipse.core.commands,
!org.eclipse.ui.plugin,
<artifactId>org.argeo.eclipse.ui</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>org.argeo.basic.nodeps</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
--- /dev/null
+package org.argeo.eclipse.ui.specific;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.argeo.ArgeoException;
+
+/**
+ * Abstraction that enable to implement runtime environment specific (typically
+ * RCP or RAP) methods while dealing with files in the UI.
+ *
+ */
+public class FileHandler {
+
+ public FileHandler() {
+ }
+
+ public void openFile(String fileName, InputStream is) {
+
+ String prefix = "", extension = "";
+ if (fileName != null) {
+ int ind = fileName.lastIndexOf('.');
+ if (ind > 0) {
+ prefix = fileName.substring(0, ind);
+ extension = fileName.substring(ind);
+ }
+ }
+
+ File file = createTmpFile(prefix, extension, is);
+
+ try {
+ Desktop desktop = null;
+ if (Desktop.isDesktopSupported()) {
+ desktop = Desktop.getDesktop();
+ }
+ desktop.open(file);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + file.getName(), e);
+ }
+ }
+
+ public void openFile(File file) {
+ try {
+ Desktop desktop = null;
+ if (Desktop.isDesktopSupported()) {
+ desktop = Desktop.getDesktop();
+ }
+ desktop.open(file);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + file.getName(), e);
+ }
+ }
+
+ private File createTmpFile(String prefix, String suffix, InputStream is) {
+ File tmpFile = null;
+ OutputStream os = null;
+ try {
+ tmpFile = File.createTempFile(prefix, suffix);
+ os = new FileOutputStream(tmpFile);
+ IOUtils.copy(is, os);
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot open file " + prefix + "."
+ + suffix, e);
+ } finally {
+ IOUtils.closeQuietly(os);
+ }
+ return tmpFile;
+ }
+
+}
-<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">
+<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.eclipse</groupId>
<plugin id="org.argeo.dep.osgi.tika"/>
<plugin id="org.argeo.eclipse.ui"/>
<plugin id="org.argeo.eclipse.ui.jcr"/>
+ <plugin id="org.argeo.eclipse.ui.rcp"/>
<plugin id="org.argeo.jackrabbit.webapp"/>
<plugin id="org.argeo.jcr.ui.explorer"/>
<plugin id="org.argeo.node.repo.jackrabbit"/>
id="org.argeo.jcr.ui.explorer.importFileSystem"
name="Import files...">
</command>
+ <!-- TEST -->
+ <command
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ id="org.argeo.jcr.ui.explorer.openFile"
+ name="Open current file">
+ </command>
+ <!-- TEST END -->
+
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution