1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.editors;
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;
32 public class Editors {
34 public static IEditorPart openBrowser(URL url) throws PartInitException {
35 return openBrowser(url, false);
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);
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());
53 private static class ExternalFileEditorInput extends FileEditorInput {
55 public ExternalFileEditorInput(IFile file) {
60 public void saveState(IMemento memento) {