X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.editors%2Fsrc%2Forg%2Fsimantics%2Feditors%2FEditors.java;fp=bundles%2Forg.simantics.editors%2Fsrc%2Forg%2Fsimantics%2Feditors%2FEditors.java;h=fe344b16df0b7a26c5244d57fc4dff7ca116b587;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.editors/src/org/simantics/editors/Editors.java b/bundles/org.simantics.editors/src/org/simantics/editors/Editors.java new file mode 100644 index 000000000..fe344b16d --- /dev/null +++ b/bundles/org.simantics.editors/src/org/simantics/editors/Editors.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.editors; + +import java.io.File; +import java.net.URL; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.FileEditorInput; +import org.simantics.editors.internal.SystemFile; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +public class Editors { + + public static IEditorPart openBrowser(URL url) throws PartInitException { + return openBrowser(url, false); + } + + public static IEditorPart openBrowser(URL url, boolean fullscreen) throws PartInitException { + BrowserInput input = new BrowserInput(url, true, fullscreen); + return WorkbenchUtils.openEditor("org.simantics.editors.browser", input); + } + + public static IEditorPart openExternalEditor(File file) throws PartInitException { + IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + IWorkspace ws = (IWorkspace) ResourcesPlugin.getWorkspace(); + FileEditorInput input = new ExternalFileEditorInput(new SystemFile(file, ws)); + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + IWorkbenchPage page = window.getActivePage(); + return page.openEditor(input, desc.getId()); + + } + + private static class ExternalFileEditorInput extends FileEditorInput { + + public ExternalFileEditorInput(IFile file) { + super(file); + } + + @Override + public void saveState(IMemento memento) { + + } + + } + +}