]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.rcp/src/main/java/org/argeo/eclipse/ui/specific/OpenFile.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.specific
;
18 import java
.awt
.Desktop
;
20 import java
.io
.IOException
;
22 import org
.argeo
.ArgeoException
;
23 import org
.eclipse
.core
.commands
.AbstractHandler
;
24 import org
.eclipse
.core
.commands
.ExecutionEvent
;
25 import org
.eclipse
.core
.commands
.ExecutionException
;
28 * RCP specific command handler to open a file.
30 * The parameter "URI" is used to determine the correct method to open it.
32 * Various instances of this handler with different command ID might coexist in
33 * order to provide context specific open file service.
36 public class OpenFile
extends AbstractHandler
{
37 // private final static Log log = LogFactory.getLog(OpenFile.class);
39 public final static String PARAM_FILE_NAME
= "param.fileName";
40 public final static String PARAM_FILE_URI
= "param.fileURI";
42 private final static String FILE_SCHEME
= "file";
44 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 @SuppressWarnings("unused")
47 String fileName
= event
.getParameter(PARAM_FILE_NAME
);
48 String fileUri
= event
.getParameter(PARAM_FILE_URI
);
51 if (fileUri
== null || "".equals(fileUri
.trim()))
54 Desktop desktop
= null;
55 if (Desktop
.isDesktopSupported()) {
56 desktop
= Desktop
.getDesktop();
59 File file
= getFileFromUri(fileUri
);
63 } catch (IOException e
) {
64 throw new ArgeoException("Unable to open file with URI: "
71 protected File
getFileFromUri(String uri
) {
72 if (uri
.startsWith(FILE_SCHEME
)) {
73 String path
= uri
.substring((FILE_SCHEME
+ "://").length());
74 return new File(path
);