]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.editors/src/org/simantics/editors/Editors.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.editors / src / org / simantics / editors / Editors.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.editors;
13
14 import java.io.File;
15 import java.net.URL;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.IWorkspace;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.ui.IEditorDescriptor;
21 import org.eclipse.ui.IEditorPart;
22 import org.eclipse.ui.IEditorRegistry;
23 import org.eclipse.ui.IMemento;
24 import org.eclipse.ui.IWorkbenchPage;
25 import org.eclipse.ui.IWorkbenchWindow;
26 import org.eclipse.ui.PartInitException;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.part.FileEditorInput;
29 import org.simantics.editors.internal.SystemFile;
30 import org.simantics.utils.ui.workbench.WorkbenchUtils;
31
32 public class Editors {
33
34     public static IEditorPart openBrowser(URL url) throws PartInitException {
35         return openBrowser(url, false);
36     }
37
38     public static IEditorPart openBrowser(URL url, boolean fullscreen) throws PartInitException {
39         BrowserInput input = new BrowserInput(url, true, fullscreen);
40         return WorkbenchUtils.openEditor("org.simantics.editors.browser", input);
41     }
42     
43     public static IEditorPart openExternalEditor(File file) throws PartInitException {
44                 IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
45                 IWorkspace ws = (IWorkspace) ResourcesPlugin.getWorkspace();
46                 FileEditorInput input = new ExternalFileEditorInput(new SystemFile(file, ws));
47                 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
48                 IWorkbenchPage page = window.getActivePage();
49                 return page.openEditor(input, desc.getId());
50                 
51         }
52     
53     private static class ExternalFileEditorInput extends FileEditorInput {
54
55                 public ExternalFileEditorInput(IFile file) {
56                         super(file);
57                 }
58                 
59                 @Override
60                 public void saveState(IMemento memento) {
61                         
62                 }
63                 
64         }
65
66 }