--- /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.rap</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
+#Wed Mar 02 13:27:08 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/,\
+ .,\
\ No newline at end of file
--- /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.rap</artifactId>
+ <name>Commons Eclipse UI RAP</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.rap.ui,org.eclipse.rwt.widgets.upload,org.eclipse.core.runtime</Require-Bundle>
+ <!-- IMPORTANT : Note that we must exclude certain packages that are
+ provided by dependencies to be sure that packages used in the current workspace
+ are those provided by the require-bundles. Especially rwt.widgets.upload
+ by instance. -->
+ <Import-Package>
+ org.apache.commons.io,
+ org.argeo,
+ org.springframework.beans.factory,
+ org.springframework.core.io.support,
+ !org.eclipse.rwt.widgets,
+ !org.eclipse.core.runtime,
+ !org.eclipse.core.commands,
+ !org.eclipse.ui.plugin,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- deleted from import package : javax.servlet, javax.servlet.http,org.argeo.eclipse.ui.dialogs,
+ org.eclipse.jface.dialogs, -->
+ <dependencies>
+ <dependency>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>org.argeo.basic.nodeps</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Argeo common distribution for RAP projects -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rap</artifactId>
+ <version>1.1.4-SNAPSHOT</version>
+ </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 java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.argeo.ArgeoException;
+import org.eclipse.rwt.RWT;
+import org.eclipse.rwt.service.IServiceHandler;
+
+public class DownloadServiceHandler implements IServiceHandler {
+
+ private FileProvider provider;
+
+ public DownloadServiceHandler(FileProvider provider) {
+ this.provider = provider;
+ }
+
+ public void service() throws IOException, ServletException {
+ // Which file to download?
+ String fileName = RWT.getRequest().getParameter("filename");
+ String fileId = RWT.getRequest().getParameter("fileid");
+
+ // Get the file content
+ byte[] download = provider.getByteArrayFileFromId(fileId);
+
+ // Send the file in the response
+ HttpServletResponse response = RWT.getResponse();
+ response.setContentType("application/octet-stream");
+ response.setContentLength(download.length);
+ String contentDisposition = "attachment; filename=\"" + fileName + "\"";
+ response.setHeader("Content-Disposition", contentDisposition);
+
+ // Various header fields that can be set to solve some issues with some
+ // old browsers.
+ // Unused.
+ // String contentType = "application/force-download; name=\"" + fileName
+ // + "\"";
+ // response.setContentType(contentType);
+ // response.setHeader("Content-Transfer-Encoding", "binary");
+ // response.setHeader("Pragma", "no-cache");
+ // response.setHeader("Cache-Control", "no-cache, must-revalidate");
+ // response.setHeader("Expires", "0");
+ // response.setHeader("Connection", "Keep-Alive");
+ // response.setHeader("Keep-Alive", "timeout=5, max=86");
+ // response.setHeader("transfer-Encoding", "chunked");
+
+ try {
+ response.getOutputStream().write(download);
+ } catch (IOException ioe) {
+ throw new ArgeoException("Error while writing the file " + fileName
+ + " to the servlet response", ioe);
+ }
+ }
+}
--- /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.AbstractTableViewer;
+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 only for {@link AbstractTableViewer} in RAP
+ *
+ * @see ColumnViewerToolTipSupport#enableFor(AbstractTableViewer)
+ */
+ public static void enableToolTipSupport(Viewer viewer) {
+ if (viewer instanceof AbstractTableViewer)
+ ColumnViewerToolTipSupport.enableFor((AbstractTableViewer) 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.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.rwt.RWT;
+import org.eclipse.rwt.service.IServiceHandler;
+import org.eclipse.rwt.service.IServiceManager;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * RAP SPECIFIC handler to enable the opening of a download dialog box triggered
+ * by whatever action in the UI
+ *
+ * Manages the registration of the effective DownloadServiceHandler at
+ * instantiation time.
+ *
+ * Manages the process of forwarding the request to the handler at runtime to
+ * open the dialog box
+ *
+ */
+public class FileHandler {
+ public final static String FORCED_DOWNLOAD_URL_BASE_PROPERTY = "argeo.rap.specific.forcedDownloadUrlBase";
+
+ private final static Log log = LogFactory.getLog(FileHandler.class);
+
+ public FileHandler(FileProvider provider) {
+ // Instantiate and register the DownloadServicHandler.
+ IServiceManager manager = RWT.getServiceManager();
+ IServiceHandler handler = new DownloadServiceHandler(provider);
+ manager.registerServiceHandler("downloadServiceHandler", handler);
+ }
+
+ public void openFile(String fileName, String fileId) {
+
+ // See RAP FAQ:
+ // http://wiki.eclipse.org/RAP/FAQ#How_to_provide_download_link.3F
+ // And forum discussion :
+ // http://www.eclipse.org/forums/index.php?t=msg&th=205487&start=0&S=43d85dacc88b505402420592109c7240
+
+ try {
+ if (log.isTraceEnabled())
+ log.trace("URL : " + createFullDownloadUrl(fileName, fileId));
+
+ URL url = new URL(createFullDownloadUrl(fileName, fileId));
+ PlatformUI.getWorkbench().getBrowserSupport()
+ .createBrowser("DownloadDialog").openURL(url);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // These lines are useless in the current use case but might be
+ // necessary with new browsers. Stored here for memo
+ // response.setContentType("application/force-download");
+ // response.setHeader("Content-Disposition", contentDisposition);
+ // response.setHeader("Content-Transfer-Encoding", "binary");
+ // response.setHeader("Pragma", "no-cache");
+ // response.setHeader("Cache-Control", "no-cache, must-revalidate");
+ }
+
+ private String createFullDownloadUrl(String fileName, String fileId) {
+ StringBuilder url = new StringBuilder();
+ // in case RAP is proxied we need to specify the actual base URL
+ // TODO find a cleaner way
+ String forcedDownloadUrlBase = System
+ .getProperty(FORCED_DOWNLOAD_URL_BASE_PROPERTY);
+ if (forcedDownloadUrlBase != null)
+ url.append(forcedDownloadUrlBase);
+ else
+ url.append(RWT.getRequest().getRequestURL());
+ url.append(createParamUrl(fileName, fileId));
+ return url.toString();
+ }
+
+ private String createParamUrl(String filename, String fileId) {
+ StringBuilder url = new StringBuilder();
+ url.append("?");
+ url.append(IServiceHandler.REQUEST_PARAM);
+ url.append("=downloadServiceHandler");
+ url.append("&filename=");
+ url.append(filename);
+ url.append("&fileid=");
+ url.append(fileId);
+ String encodedURL = RWT.getResponse().encodeURL(url.toString());
+ return encodedURL;
+ }
+}
--- /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.
+ */
+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.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.eclipse.rwt.widgets.Upload;
+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.Composite;
+
+public class GenericUploadControl extends Composite {
+ private final static Log log = LogFactory
+ .getLog(GenericUploadControl.class);
+
+ private Upload upload;
+
+ public GenericUploadControl(Composite parent, int style, String browseLabel) {
+ super(parent, style);
+ createControl(this, browseLabel);
+
+ }
+
+ private void createControl(Composite parent, String browseLabel) {
+ parent.setLayout(new GridLayout(1, false));
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+
+ upload = new Upload(parent, SWT.BORDER);
+ upload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ upload.setBrowseButtonText(browseLabel);
+ // upload.addModifyListener(new UploadListener());
+ parent.pack();
+ }
+
+ /**
+ * Wrap upload.getLastFileUploaded(). Gets the name of the last uploaded
+ * file. This method can be called even if the upload has not finished yet.
+ */
+ public String getLastFileUploadedName() {
+ return upload.getLastFileUploaded();
+ }
+
+ public boolean isControlEmpty() {
+ String path = upload.getPath();
+ if (log.isTraceEnabled())
+ log.trace("UploadControl chosen path : " + path);
+ if (path == null || "".equals(path.trim()))
+ return true;
+ else
+ return false;
+ }
+
+ public byte[] performUpload() {
+ boolean success = upload.performUpload();
+ if (success) {
+ if (upload.getUploadItem().getFileSize() == -1)
+ throw new ArgeoException("File "
+ + upload.getUploadItem().getFileName()
+ + " has not been uploaded, its size is -1");
+
+ InputStream inStream = null;
+ byte[] fileBA = null;
+ try {
+ inStream = upload.getUploadItem().getFileInputStream();
+ fileBA = IOUtils.toByteArray(inStream);
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot read uploaded data", e);
+ } finally {
+ IOUtils.closeQuietly(inStream);
+ }
+ return fileBA;
+ }
+ return null;
+ }
+
+ public void addModifyListener(ModifyListener listener) {
+ upload.addModifyListener(listener);
+ }
+
+ // private class UploadManager extends UploadAdapter {
+ // private Upload upload;
+ //
+ // public UploadManager(Upload upload) {
+ // super();
+ // this.upload = upload;
+ // }
+ //
+ // public void uploadFinished(UploadEvent uploadEvent) {
+ // handleUploadFinished(upload);
+ // }
+ //
+ // public void uploadInProgress(UploadEvent uploadEvent) {
+ // }
+ //
+ // public void uploadException(UploadEvent uploadEvent) {
+ // Exception exc = uploadEvent.getUploadException();
+ // if (exc != null) {
+ // MessageDialog.openError(Display.getCurrent().getActiveShell(),
+ // "Error", exc.getMessage());
+ // }
+ // }
+ //
+ // }
+ //
+
+}
--- /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.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.rwt.widgets.Upload;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+public class ImportToServerWizardPage extends WizardPage {
+ private final static Log log = LogFactory
+ .getLog(ImportToServerWizardPage.class);
+
+ public final static String FILE_ITEM_TYPE = "FILE";
+ public final static String FOLDER_ITEM_TYPE = "FOLDER";
+
+ private Upload uploadFile;
+
+ public ImportToServerWizardPage() {
+ super("Import from file system");
+ setDescription("Import files from the local file system to the server");
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ new Label(composite, SWT.NONE).setText("Pick up a file");
+ uploadFile = new Upload(composite, SWT.BORDER);
+ uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ uploadFile.setBrowseButtonText("Open...");
+ setControl(composite);
+ }
+
+ public String getObjectPath() {
+ // NOTE Returns the full file name of the last uploaded file including
+ // the file path as selected by the user on his local machine.
+ // The full path including the directory and file drive are only
+ // returned, if the browser supports reading this properties. In Firefox
+ // 3, only the filename is returned.
+ return uploadFile.getPath();
+ }
+
+ public String getObjectName() {
+ return uploadFile.getUploadItem().getFileName();
+ }
+
+ public String getObjectType() {
+ return FILE_ITEM_TYPE;
+ }
+
+ public void performFinish() {
+ boolean success = uploadFile.performUpload();
+ if (!success)
+ throw new ArgeoException("Cannot upload file named "
+ + uploadFile.getPath());
+ }
+
+ protected void handleUploadFinished(final Upload upload) {
+ }
+
+ public InputStream getFileInputStream() {
+ return uploadFile.getUploadItem().getFileInputStream();
+ }
+
+ public boolean getNeedsProgressMonitor() {
+ return false;
+ }
+
+}
+++ /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.rap</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
-#Wed Mar 02 13:27:08 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/,\
- .,\
\ No newline at end of file
+++ /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.rap</artifactId>
- <name>Commons Eclipse UI RAP</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.rap.ui,org.eclipse.rwt.widgets.upload,org.eclipse.core.runtime</Require-Bundle>
- <!-- IMPORTANT : Note that we must exclude certain packages that are
- provided by dependencies to be sure that packages used in the current workspace
- are those provided by the require-bundles. Especially rwt.widgets.upload
- by instance. -->
- <Import-Package>
- org.apache.commons.io,
- org.argeo,
- org.springframework.beans.factory,
- org.springframework.core.io.support,
- !org.eclipse.rwt.widgets,
- !org.eclipse.core.runtime,
- !org.eclipse.core.commands,
- !org.eclipse.ui.plugin,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <!-- deleted from import package : javax.servlet, javax.servlet.http,org.argeo.eclipse.ui.dialogs,
- org.eclipse.jface.dialogs, -->
- <dependencies>
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.nodeps</artifactId>
- <version>1.1.4-SNAPSHOT</version>
- </dependency>
-
- <!-- Argeo common distribution for RAP projects -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.rap</artifactId>
- <version>1.1.4-SNAPSHOT</version>
- </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 java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-
-import org.argeo.ArgeoException;
-import org.eclipse.rwt.RWT;
-import org.eclipse.rwt.service.IServiceHandler;
-
-public class DownloadServiceHandler implements IServiceHandler {
-
- private FileProvider provider;
-
- public DownloadServiceHandler(FileProvider provider) {
- this.provider = provider;
- }
-
- public void service() throws IOException, ServletException {
- // Which file to download?
- String fileName = RWT.getRequest().getParameter("filename");
- String fileId = RWT.getRequest().getParameter("fileid");
-
- // Get the file content
- byte[] download = provider.getByteArrayFileFromId(fileId);
-
- // Send the file in the response
- HttpServletResponse response = RWT.getResponse();
- response.setContentType("application/octet-stream");
- response.setContentLength(download.length);
- String contentDisposition = "attachment; filename=\"" + fileName + "\"";
- response.setHeader("Content-Disposition", contentDisposition);
-
- // Various header fields that can be set to solve some issues with some
- // old browsers.
- // Unused.
- // String contentType = "application/force-download; name=\"" + fileName
- // + "\"";
- // response.setContentType(contentType);
- // response.setHeader("Content-Transfer-Encoding", "binary");
- // response.setHeader("Pragma", "no-cache");
- // response.setHeader("Cache-Control", "no-cache, must-revalidate");
- // response.setHeader("Expires", "0");
- // response.setHeader("Connection", "Keep-Alive");
- // response.setHeader("Keep-Alive", "timeout=5, max=86");
- // response.setHeader("transfer-Encoding", "chunked");
-
- try {
- response.getOutputStream().write(download);
- } catch (IOException ioe) {
- throw new ArgeoException("Error while writing the file " + fileName
- + " to the servlet response", ioe);
- }
- }
-}
+++ /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.AbstractTableViewer;
-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 only for {@link AbstractTableViewer} in RAP
- *
- * @see ColumnViewerToolTipSupport#enableFor(AbstractTableViewer)
- */
- public static void enableToolTipSupport(Viewer viewer) {
- if (viewer instanceof AbstractTableViewer)
- ColumnViewerToolTipSupport.enableFor((AbstractTableViewer) 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.net.URL;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.rwt.RWT;
-import org.eclipse.rwt.service.IServiceHandler;
-import org.eclipse.rwt.service.IServiceManager;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * RAP SPECIFIC handler to enable the opening of a download dialog box triggered
- * by whatever action in the UI
- *
- * Manages the registration of the effective DownloadServiceHandler at
- * instantiation time.
- *
- * Manages the process of forwarding the request to the handler at runtime to
- * open the dialog box
- *
- */
-public class FileHandler {
- public final static String FORCED_DOWNLOAD_URL_BASE_PROPERTY = "argeo.rap.specific.forcedDownloadUrlBase";
-
- private final static Log log = LogFactory.getLog(FileHandler.class);
-
- public FileHandler(FileProvider provider) {
- // Instantiate and register the DownloadServicHandler.
- IServiceManager manager = RWT.getServiceManager();
- IServiceHandler handler = new DownloadServiceHandler(provider);
- manager.registerServiceHandler("downloadServiceHandler", handler);
- }
-
- public void openFile(String fileName, String fileId) {
-
- // See RAP FAQ:
- // http://wiki.eclipse.org/RAP/FAQ#How_to_provide_download_link.3F
- // And forum discussion :
- // http://www.eclipse.org/forums/index.php?t=msg&th=205487&start=0&S=43d85dacc88b505402420592109c7240
-
- try {
- if (log.isTraceEnabled())
- log.trace("URL : " + createFullDownloadUrl(fileName, fileId));
-
- URL url = new URL(createFullDownloadUrl(fileName, fileId));
- PlatformUI.getWorkbench().getBrowserSupport()
- .createBrowser("DownloadDialog").openURL(url);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- // These lines are useless in the current use case but might be
- // necessary with new browsers. Stored here for memo
- // response.setContentType("application/force-download");
- // response.setHeader("Content-Disposition", contentDisposition);
- // response.setHeader("Content-Transfer-Encoding", "binary");
- // response.setHeader("Pragma", "no-cache");
- // response.setHeader("Cache-Control", "no-cache, must-revalidate");
- }
-
- private String createFullDownloadUrl(String fileName, String fileId) {
- StringBuilder url = new StringBuilder();
- // in case RAP is proxied we need to specify the actual base URL
- // TODO find a cleaner way
- String forcedDownloadUrlBase = System
- .getProperty(FORCED_DOWNLOAD_URL_BASE_PROPERTY);
- if (forcedDownloadUrlBase != null)
- url.append(forcedDownloadUrlBase);
- else
- url.append(RWT.getRequest().getRequestURL());
- url.append(createParamUrl(fileName, fileId));
- return url.toString();
- }
-
- private String createParamUrl(String filename, String fileId) {
- StringBuilder url = new StringBuilder();
- url.append("?");
- url.append(IServiceHandler.REQUEST_PARAM);
- url.append("=downloadServiceHandler");
- url.append("&filename=");
- url.append(filename);
- url.append("&fileid=");
- url.append(fileId);
- String encodedURL = RWT.getResponse().encodeURL(url.toString());
- return encodedURL;
- }
-}
+++ /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.
- */
-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.InputStream;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.eclipse.rwt.widgets.Upload;
-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.Composite;
-
-public class GenericUploadControl extends Composite {
- private final static Log log = LogFactory
- .getLog(GenericUploadControl.class);
-
- private Upload upload;
-
- public GenericUploadControl(Composite parent, int style, String browseLabel) {
- super(parent, style);
- createControl(this, browseLabel);
-
- }
-
- private void createControl(Composite parent, String browseLabel) {
- parent.setLayout(new GridLayout(1, false));
- parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-
- upload = new Upload(parent, SWT.BORDER);
- upload.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- upload.setBrowseButtonText(browseLabel);
- // upload.addModifyListener(new UploadListener());
- parent.pack();
- }
-
- /**
- * Wrap upload.getLastFileUploaded(). Gets the name of the last uploaded
- * file. This method can be called even if the upload has not finished yet.
- */
- public String getLastFileUploadedName() {
- return upload.getLastFileUploaded();
- }
-
- public boolean isControlEmpty() {
- String path = upload.getPath();
- if (log.isTraceEnabled())
- log.trace("UploadControl chosen path : " + path);
- if (path == null || "".equals(path.trim()))
- return true;
- else
- return false;
- }
-
- public byte[] performUpload() {
- boolean success = upload.performUpload();
- if (success) {
- if (upload.getUploadItem().getFileSize() == -1)
- throw new ArgeoException("File "
- + upload.getUploadItem().getFileName()
- + " has not been uploaded, its size is -1");
-
- InputStream inStream = null;
- byte[] fileBA = null;
- try {
- inStream = upload.getUploadItem().getFileInputStream();
- fileBA = IOUtils.toByteArray(inStream);
- } catch (Exception e) {
- throw new ArgeoException("Cannot read uploaded data", e);
- } finally {
- IOUtils.closeQuietly(inStream);
- }
- return fileBA;
- }
- return null;
- }
-
- public void addModifyListener(ModifyListener listener) {
- upload.addModifyListener(listener);
- }
-
- // private class UploadManager extends UploadAdapter {
- // private Upload upload;
- //
- // public UploadManager(Upload upload) {
- // super();
- // this.upload = upload;
- // }
- //
- // public void uploadFinished(UploadEvent uploadEvent) {
- // handleUploadFinished(upload);
- // }
- //
- // public void uploadInProgress(UploadEvent uploadEvent) {
- // }
- //
- // public void uploadException(UploadEvent uploadEvent) {
- // Exception exc = uploadEvent.getUploadException();
- // if (exc != null) {
- // MessageDialog.openError(Display.getCurrent().getActiveShell(),
- // "Error", exc.getMessage());
- // }
- // }
- //
- // }
- //
-
-}
+++ /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.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.rwt.widgets.Upload;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-
-public class ImportToServerWizardPage extends WizardPage {
- private final static Log log = LogFactory
- .getLog(ImportToServerWizardPage.class);
-
- public final static String FILE_ITEM_TYPE = "FILE";
- public final static String FOLDER_ITEM_TYPE = "FOLDER";
-
- private Upload uploadFile;
-
- public ImportToServerWizardPage() {
- super("Import from file system");
- setDescription("Import files from the local file system to the server");
- }
-
- public void createControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new GridLayout(2, false));
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- new Label(composite, SWT.NONE).setText("Pick up a file");
- uploadFile = new Upload(composite, SWT.BORDER);
- uploadFile.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- uploadFile.setBrowseButtonText("Open...");
- setControl(composite);
- }
-
- public String getObjectPath() {
- // NOTE Returns the full file name of the last uploaded file including
- // the file path as selected by the user on his local machine.
- // The full path including the directory and file drive are only
- // returned, if the browser supports reading this properties. In Firefox
- // 3, only the filename is returned.
- return uploadFile.getPath();
- }
-
- public String getObjectName() {
- return uploadFile.getUploadItem().getFileName();
- }
-
- public String getObjectType() {
- return FILE_ITEM_TYPE;
- }
-
- public void performFinish() {
- boolean success = uploadFile.performUpload();
- if (!success)
- throw new ArgeoException("Cannot upload file named "
- + uploadFile.getPath());
- }
-
- protected void handleUploadFinished(final Upload upload) {
- }
-
- public InputStream getFileInputStream() {
- return uploadFile.getUploadItem().getFileInputStream();
- }
-
- public boolean getNeedsProgressMonitor() {
- return false;
- }
-
-}