]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/OpenFile.java
1 package org
.argeo
.eclipse
.ui
.specific
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
6 import org
.argeo
.eclipse
.ui
.util
.SingleSourcingConstants
;
7 import org
.eclipse
.core
.commands
.AbstractHandler
;
8 import org
.eclipse
.core
.commands
.ExecutionEvent
;
9 import org
.eclipse
.rap
.rwt
.RWT
;
10 import org
.eclipse
.rap
.rwt
.client
.service
.UrlLauncher
;
13 * RWT specific object to open a file retrieved from the server. It forwards the
14 * request to the correct service after encoding file name and path in the
18 * The parameter "URI" is used to determine the correct file service, the path
19 * and the file name. An optional file name can be added to present the end user
20 * with a different file name as the one used to retrieve it.
25 * The instance specific service is called by its ID and must have been
29 public class OpenFile
extends AbstractHandler
{
30 private final static Log log
= LogFactory
.getLog(OpenFile
.class);
32 public final static String ID
= SingleSourcingConstants
.OPEN_FILE_CMD_ID
;
33 public final static String PARAM_FILE_NAME
= SingleSourcingConstants
.PARAM_FILE_NAME
;
34 public final static String PARAM_FILE_URI
= SingleSourcingConstants
.PARAM_FILE_URI
;;
36 /* DEPENDENCY INJECTION */
37 private String openFileServiceId
;
39 public Object
execute(ExecutionEvent event
) {
40 String fileName
= event
.getParameter(PARAM_FILE_NAME
);
41 String fileUri
= event
.getParameter(PARAM_FILE_URI
);
43 if (fileUri
== null || "".equals(fileUri
.trim()) || openFileServiceId
== null
44 || "".equals(openFileServiceId
.trim()))
47 org
.argeo
.eclipse
.ui
.specific
.OpenFile openFileClient
= new org
.argeo
.eclipse
.ui
.specific
.OpenFile();
48 openFileClient
.execute(openFileServiceId
, fileUri
, fileName
);
52 public Object
execute(String openFileServiceId
, String fileUri
, String fileName
) {
53 StringBuilder url
= new StringBuilder();
54 url
.append(RWT
.getServiceManager().getServiceHandlerUrl(openFileServiceId
));
56 if (EclipseUiUtils
.notEmpty(fileName
))
57 url
.append("&").append(SingleSourcingConstants
.PARAM_FILE_NAME
).append("=").append(fileName
);
58 url
.append("&").append(SingleSourcingConstants
.PARAM_FILE_URI
).append("=").append(fileUri
);
60 String downloadUrl
= url
.toString();
61 if (log
.isTraceEnabled())
62 log
.trace("Calling OpenFileService with ID: " + openFileServiceId
+ " , with download URL: " + downloadUrl
);
64 UrlLauncher launcher
= RWT
.getClient().getService(UrlLauncher
.class);
65 launcher
.openURL(downloadUrl
);
69 /* DEPENDENCY INJECTION */
70 public void setOpenFileServiceId(String openFileServiceId
) {
71 this.openFileServiceId
= openFileServiceId
;