--- /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
--- /dev/null
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .,\
--- /dev/null
+<?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.eclipse</groupId>
+ <version>1.1.4-SNAPSHOT</version>
+ <artifactId>runtime</artifactId>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.eclipse.ui.rcp</artifactId>
+ <name>Commons Eclipse UI RCP</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+ <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
+ <Require-Bundle>org.eclipse.ui,org.eclipse.core.runtime</Require-Bundle>
+ <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,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- Argeo Commons for Eclipse (not specific) -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.ui</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Argeo Commons third party distribution for RCP projects -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>org.argeo.basic.nodeps</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Others. -->
+ <dependency>
+ <groupId>org.argeo.tp</groupId>
+ <artifactId>org.apache.commons.io</artifactId>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.argeo.tp</groupId>
+ <artifactId>slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.specific;
+
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.Viewer;
+
+/** Static utilities to bridge differences between RCP and RAP */
+public class EclipseUiSpecificUtils {
+ /**
+ * TootlTip support is supported for {@link ColumnViewer} in RCP
+ *
+ * @see ColumnViewerToolTipSupport#enableFor(Viewer)
+ */
+ public static void enableToolTipSupport(Viewer viewer) {
+ if (viewer instanceof ColumnViewer)
+ ColumnViewerToolTipSupport.enableFor((ColumnViewer) viewer);
+ }
+
+ private EclipseUiSpecificUtils() {
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.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 {
+
+ private FileProvider provider;
+
+ public FileHandler(FileProvider provider) {
+ this.provider = provider;
+ }
+
+ public void openFile(String fileName, String fileId) {
+ String tmpFileName = fileName;
+ String prefix = "", extension = "";
+ if (fileName != null) {
+ int ind = fileName.lastIndexOf('.');
+ if (ind > 0) {
+ prefix = fileName.substring(0, ind);
+ extension = fileName.substring(ind);
+ }
+ }
+
+ InputStream is = null;
+ try {
+ is = provider.getInputStreamFromFileId(fileId);
+ File file = createTmpFile(prefix, extension, is);
+ tmpFileName = file.getName();
+ Desktop desktop = null;
+ if (Desktop.isDesktopSupported()) {
+ desktop = Desktop.getDesktop();
+ }
+ desktop.open(file);
+ } catch (IOException e) {
+ // Note : tmpFileName = fileName if the error has been thrown while
+ // creating the tmpFile.
+ throw new ArgeoException("Cannot open file " + tmpFileName, e);
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+
+ 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;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.specific;
+
+import java.io.InputStream;
+
+/**
+ * Used for file download : subclasses must implement model specific methods to
+ * get a byte array representing a file given is ID.
+ *
+ * @author bsinou
+ *
+ */
+public interface FileProvider {
+
+ public byte[] getByteArrayFileFromId(String fileId);
+
+ public InputStream getInputStreamFromFileId(String fileId);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.specific;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.argeo.ArgeoException;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * RCP specific composite that provides a control to upload a file. WARNING: for
+ * the time being we set a GridLayout(2, false) on th eparent control.
+ */
+public class GenericUploadControl extends Composite {
+ // private final static Log log = LogFactory
+ // .getLog(GenericUploadControl.class);
+
+ private FileDialog dialog;
+ private Text filePath;
+
+ public GenericUploadControl(Composite parent, int style, String browseLabel) {
+ super(parent, style);
+ createControl(this, browseLabel);
+
+ }
+
+ private void createControl(final Composite parent, String browseLabel) {
+ parent.setLayout(new GridLayout(2, false));
+
+ filePath = new Text(parent, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.FILL_HORIZONTAL);
+ filePath.setEditable(false);
+ filePath.setLayoutData(gd);
+
+ // Execute button
+ Button execute = new Button(parent, SWT.PUSH);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ execute.setLayoutData(gridData);
+ execute.setText(browseLabel);
+
+ // Button listener
+ Listener executeListener = new Listener() {
+ public void handleEvent(Event event) {
+ dialog = new FileDialog(parent.getShell());
+ filePath.setText(dialog.open());
+ }
+ };
+ parent.layout();
+ execute.addListener(SWT.Selection, executeListener);
+ }
+
+ public boolean isControlEmpty() {
+ String path = filePath.getText();
+ if (path == null || "".equals(path.trim()))
+ return true;
+ else
+ return false;
+ }
+
+ public byte[] performUpload() {
+ String path = filePath.getText();
+ if (path != null) {
+ try {
+ File file = new File(path);
+ byte[] fileBA = FileUtils.readFileToByteArray(file);
+ return fileBA;
+ } catch (IOException e) {
+ throw new ArgeoException("Unexpected error while "
+ + "reading file at path " + path, e);
+ }
+ }
+ return null;
+ }
+
+ public void addModifyListener(ModifyListener listener) {
+ filePath.addModifyListener(listener);
+ }
+
+ /**
+ * Always returns null in an RCP environment
+ */
+ public String getLastFileUploadedName() {
+ return null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.specific;
+
+import java.io.InputStream;
+
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+public class ImportToServerWizardPage extends WizardPage {
+
+ public final static String FILE_ITEM_TYPE = "FILE";
+ public final static String FOLDER_ITEM_TYPE = "FOLDER";
+
+ private DirectoryFieldEditor dfe;
+
+ public ImportToServerWizardPage() {
+ super("Import from file system");
+ setDescription("Import files from the local file system into the JCR repository");
+ }
+
+ public void createControl(Composite parent) {
+ dfe = new DirectoryFieldEditor("directory", "From", parent);
+ setControl(dfe.getTextControl(parent));
+ }
+
+ public String getObjectPath() {
+ return dfe.getStringValue();
+ }
+
+ public String getObjectType() {
+ return FOLDER_ITEM_TYPE;
+ }
+
+ public boolean getNeedsProgressMonitor() {
+ return true;
+ }
+
+ // Dummy methods : useless in RCP context but useful for RAP
+ /** WARNING : always return null in RCP context */
+ public String getObjectName() {
+ return null;
+ }
+
+ /** WARNING : do nothing in RCP context */
+ public void performFinish() {
+ }
+
+ /** WARNING : always return null in RCP context */
+ public InputStream getFileInputStream() {
+ return null;
+ }
+}
\ No newline at end of file
+++ /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
+++ /dev/null
-source.. = src/main/java/
-output.. = target/classes/
-bin.includes = META-INF/,\
- .,\
+++ /dev/null
-<?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.eclipse</groupId>
- <version>1.1.4-SNAPSHOT</version>
- <artifactId>runtime</artifactId>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>org.argeo.eclipse.ui.rcp</artifactId>
- <name>Commons Eclipse UI RCP</name>
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
-
- <configuration>
- <instructions>
- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
- <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
- <Require-Bundle>org.eclipse.ui,org.eclipse.core.runtime</Require-Bundle>
- <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,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <!-- Argeo Commons for Eclipse (not specific) -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.ui</artifactId>
- <version>1.1.4-SNAPSHOT</version>
- </dependency>
-
- <!-- Argeo Commons third party distribution for RCP projects -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
- <version>1.1.4-SNAPSHOT</version>
- </dependency>
-
-
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.nodeps</artifactId>
- <version>1.1.4-SNAPSHOT</version>
- </dependency>
-
- <!-- Others. -->
- <dependency>
- <groupId>org.argeo.tp</groupId>
- <artifactId>org.apache.commons.io</artifactId>
- </dependency>
-
- <!-- Logging -->
- <dependency>
- <groupId>org.argeo.tp</groupId>
- <artifactId>slf4j.org.apache.commons.logging</artifactId>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * 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.specific;
-
-import org.eclipse.jface.viewers.ColumnViewer;
-import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
-import org.eclipse.jface.viewers.Viewer;
-
-/** Static utilities to bridge differences between RCP and RAP */
-public class EclipseUiSpecificUtils {
- /**
- * TootlTip support is supported for {@link ColumnViewer} in RCP
- *
- * @see ColumnViewerToolTipSupport#enableFor(Viewer)
- */
- public static void enableToolTipSupport(Viewer viewer) {
- if (viewer instanceof ColumnViewer)
- ColumnViewerToolTipSupport.enableFor((ColumnViewer) viewer);
- }
-
- private EclipseUiSpecificUtils() {
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * 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.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 {
-
- private FileProvider provider;
-
- public FileHandler(FileProvider provider) {
- this.provider = provider;
- }
-
- public void openFile(String fileName, String fileId) {
- String tmpFileName = fileName;
- String prefix = "", extension = "";
- if (fileName != null) {
- int ind = fileName.lastIndexOf('.');
- if (ind > 0) {
- prefix = fileName.substring(0, ind);
- extension = fileName.substring(ind);
- }
- }
-
- InputStream is = null;
- try {
- is = provider.getInputStreamFromFileId(fileId);
- File file = createTmpFile(prefix, extension, is);
- tmpFileName = file.getName();
- Desktop desktop = null;
- if (Desktop.isDesktopSupported()) {
- desktop = Desktop.getDesktop();
- }
- desktop.open(file);
- } catch (IOException e) {
- // Note : tmpFileName = fileName if the error has been thrown while
- // creating the tmpFile.
- throw new ArgeoException("Cannot open file " + tmpFileName, e);
- } finally {
- IOUtils.closeQuietly(is);
- }
- }
-
- 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;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * 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.specific;
-
-import java.io.InputStream;
-
-/**
- * Used for file download : subclasses must implement model specific methods to
- * get a byte array representing a file given is ID.
- *
- * @author bsinou
- *
- */
-public interface FileProvider {
-
- public byte[] getByteArrayFileFromId(String fileId);
-
- public InputStream getInputStreamFromFileId(String fileId);
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * 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.specific;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-import org.argeo.ArgeoException;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * RCP specific composite that provides a control to upload a file. WARNING: for
- * the time being we set a GridLayout(2, false) on th eparent control.
- */
-public class GenericUploadControl extends Composite {
- // private final static Log log = LogFactory
- // .getLog(GenericUploadControl.class);
-
- private FileDialog dialog;
- private Text filePath;
-
- public GenericUploadControl(Composite parent, int style, String browseLabel) {
- super(parent, style);
- createControl(this, browseLabel);
-
- }
-
- private void createControl(final Composite parent, String browseLabel) {
- parent.setLayout(new GridLayout(2, false));
-
- filePath = new Text(parent, SWT.BORDER | SWT.SINGLE);
- GridData gd = new GridData(GridData.GRAB_HORIZONTAL
- | GridData.FILL_HORIZONTAL);
- filePath.setEditable(false);
- filePath.setLayoutData(gd);
-
- // Execute button
- Button execute = new Button(parent, SWT.PUSH);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.BEGINNING;
- execute.setLayoutData(gridData);
- execute.setText(browseLabel);
-
- // Button listener
- Listener executeListener = new Listener() {
- public void handleEvent(Event event) {
- dialog = new FileDialog(parent.getShell());
- filePath.setText(dialog.open());
- }
- };
- parent.layout();
- execute.addListener(SWT.Selection, executeListener);
- }
-
- public boolean isControlEmpty() {
- String path = filePath.getText();
- if (path == null || "".equals(path.trim()))
- return true;
- else
- return false;
- }
-
- public byte[] performUpload() {
- String path = filePath.getText();
- if (path != null) {
- try {
- File file = new File(path);
- byte[] fileBA = FileUtils.readFileToByteArray(file);
- return fileBA;
- } catch (IOException e) {
- throw new ArgeoException("Unexpected error while "
- + "reading file at path " + path, e);
- }
- }
- return null;
- }
-
- public void addModifyListener(ModifyListener listener) {
- filePath.addModifyListener(listener);
- }
-
- /**
- * Always returns null in an RCP environment
- */
- public String getLastFileUploadedName() {
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Mathieu Baudier
- *
- * 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.specific;
-
-import java.io.InputStream;
-
-import org.eclipse.jface.preference.DirectoryFieldEditor;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.widgets.Composite;
-
-public class ImportToServerWizardPage extends WizardPage {
-
- public final static String FILE_ITEM_TYPE = "FILE";
- public final static String FOLDER_ITEM_TYPE = "FOLDER";
-
- private DirectoryFieldEditor dfe;
-
- public ImportToServerWizardPage() {
- super("Import from file system");
- setDescription("Import files from the local file system into the JCR repository");
- }
-
- public void createControl(Composite parent) {
- dfe = new DirectoryFieldEditor("directory", "From", parent);
- setControl(dfe.getTextControl(parent));
- }
-
- public String getObjectPath() {
- return dfe.getStringValue();
- }
-
- public String getObjectType() {
- return FOLDER_ITEM_TYPE;
- }
-
- public boolean getNeedsProgressMonitor() {
- return true;
- }
-
- // Dummy methods : useless in RCP context but useful for RAP
- /** WARNING : always return null in RCP context */
- public String getObjectName() {
- return null;
- }
-
- /** WARNING : do nothing in RCP context */
- public void performFinish() {
- }
-
- /** WARNING : always return null in RCP context */
- public InputStream getFileInputStream() {
- return null;
- }
-}
\ No newline at end of file