From: Mathieu Baudier Date: Tue, 17 Jul 2012 12:30:40 +0000 (+0000) Subject: Move to Commons Base X-Git-Tag: argeo-commons-2.1.30~885 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=654a906a9507d52d3f3b8f1505c6ad56ad68334a;p=lgpl%2Fargeo-commons.git Move to Commons Base git-svn-id: https://svn.argeo.org/commons/trunk@5477 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/base/runtime/org.argeo.eclipse.ui.rap/.classpath b/base/runtime/org.argeo.eclipse.ui.rap/.classpath new file mode 100644 index 000000000..8cf7f48a0 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/base/runtime/org.argeo.eclipse.ui.rap/.project b/base/runtime/org.argeo.eclipse.ui.rap/.project new file mode 100644 index 000000000..df496c27d --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/.project @@ -0,0 +1,28 @@ + + + org.argeo.eclipse.ui.rap + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/base/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs b/base/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..ffba01eed --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#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 diff --git a/base/runtime/org.argeo.eclipse.ui.rap/build.properties b/base/runtime/org.argeo.eclipse.ui.rap/build.properties new file mode 100644 index 000000000..7cc98e7f8 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/build.properties @@ -0,0 +1,4 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + .,\ \ No newline at end of file diff --git a/base/runtime/org.argeo.eclipse.ui.rap/pom.xml b/base/runtime/org.argeo.eclipse.ui.rap/pom.xml new file mode 100644 index 000000000..dd4acebd6 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/pom.xml @@ -0,0 +1,78 @@ + + 4.0.0 + + org.argeo.commons.eclipse + 1.1.4-SNAPSHOT + runtime + .. + + org.argeo.eclipse.ui.rap + Commons Eclipse UI RAP + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + + + + lazy + org.argeo.eclipse.ui.ArgeoUiPlugin + org.eclipse.rap.ui,org.eclipse.rwt.widgets.upload,org.eclipse.core.runtime + + + 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, + * + + + + + + + + + + + org.argeo.commons.basic + org.argeo.basic.nodeps + 1.1.4-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rap + 1.1.4-SNAPSHOT + + + + + org.argeo.tp + slf4j.org.apache.commons.logging + + + \ No newline at end of file diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java new file mode 100644 index 000000000..a8e2c345d --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java @@ -0,0 +1,71 @@ +/* + * 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); + } + } +} diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java new file mode 100644 index 000000000..932d65b0b --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java @@ -0,0 +1,37 @@ +/* + * 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() { + } + +} diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java new file mode 100644 index 000000000..ad551b479 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java @@ -0,0 +1,103 @@ +/* + * 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; + } +} diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java new file mode 100644 index 000000000..ca7dc0880 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java @@ -0,0 +1,30 @@ +/* + * 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); + +} diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java new file mode 100644 index 000000000..13e695d39 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java @@ -0,0 +1,125 @@ +/* + * 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()); + // } + // } + // + // } + // + +} diff --git a/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java new file mode 100644 index 000000000..d087ebe99 --- /dev/null +++ b/base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java @@ -0,0 +1,91 @@ +/* + * 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; + } + +} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/.classpath b/eclipse/runtime/org.argeo.eclipse.ui.rap/.classpath deleted file mode 100644 index 8cf7f48a0..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/.project b/eclipse/runtime/org.argeo.eclipse.ui.rap/.project deleted file mode 100644 index df496c27d..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.eclipse.ui.rap - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs b/eclipse/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index ffba01eed..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#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 diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/build.properties b/eclipse/runtime/org.argeo.eclipse.ui.rap/build.properties deleted file mode 100644 index 7cc98e7f8..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = META-INF/,\ - .,\ \ No newline at end of file diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/pom.xml b/eclipse/runtime/org.argeo.eclipse.ui.rap/pom.xml deleted file mode 100644 index dd4acebd6..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - 4.0.0 - - org.argeo.commons.eclipse - 1.1.4-SNAPSHOT - runtime - .. - - org.argeo.eclipse.ui.rap - Commons Eclipse UI RAP - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - - - - lazy - org.argeo.eclipse.ui.ArgeoUiPlugin - org.eclipse.rap.ui,org.eclipse.rwt.widgets.upload,org.eclipse.core.runtime - - - 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, - * - - - - - - - - - - - org.argeo.commons.basic - org.argeo.basic.nodeps - 1.1.4-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rap - 1.1.4-SNAPSHOT - - - - - org.argeo.tp - slf4j.org.apache.commons.logging - - - \ No newline at end of file diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java deleted file mode 100644 index a8e2c345d..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/DownloadServiceHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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); - } - } -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java deleted file mode 100644 index 932d65b0b..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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() { - } - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java deleted file mode 100644 index ad551b479..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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; - } -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java deleted file mode 100644 index ca7dc0880..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/FileProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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); - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java deleted file mode 100644 index 13e695d39..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/GenericUploadControl.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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()); - // } - // } - // - // } - // - -} diff --git a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java b/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java deleted file mode 100644 index d087ebe99..000000000 --- a/eclipse/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/ImportToServerWizardPage.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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; - } - -}