]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.editors/src/org/simantics/editors/Editors.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.editors / src / org / simantics / editors / Editors.java
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 (file)
index 0000000..fe344b1
--- /dev/null
@@ -0,0 +1,66 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.editors;\r
+\r
+import java.io.File;\r
+import java.net.URL;\r
+\r
+import org.eclipse.core.resources.IFile;\r
+import org.eclipse.core.resources.IWorkspace;\r
+import org.eclipse.core.resources.ResourcesPlugin;\r
+import org.eclipse.ui.IEditorDescriptor;\r
+import org.eclipse.ui.IEditorPart;\r
+import org.eclipse.ui.IEditorRegistry;\r
+import org.eclipse.ui.IMemento;\r
+import org.eclipse.ui.IWorkbenchPage;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.part.FileEditorInput;\r
+import org.simantics.editors.internal.SystemFile;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+public class Editors {\r
+\r
+    public static IEditorPart openBrowser(URL url) throws PartInitException {\r
+        return openBrowser(url, false);\r
+    }\r
+\r
+    public static IEditorPart openBrowser(URL url, boolean fullscreen) throws PartInitException {\r
+        BrowserInput input = new BrowserInput(url, true, fullscreen);\r
+        return WorkbenchUtils.openEditor("org.simantics.editors.browser", input);\r
+    }\r
+    \r
+    public static IEditorPart openExternalEditor(File file) throws PartInitException {\r
+               IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);\r
+               IWorkspace ws = (IWorkspace) ResourcesPlugin.getWorkspace();\r
+               FileEditorInput input = new ExternalFileEditorInput(new SystemFile(file, ws));\r
+               IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();\r
+               IWorkbenchPage page = window.getActivePage();\r
+               return page.openEditor(input, desc.getId());\r
+               \r
+       }\r
+    \r
+    private static class ExternalFileEditorInput extends FileEditorInput {\r
+\r
+               public ExternalFileEditorInput(IFile file) {\r
+                       super(file);\r
+               }\r
+               \r
+               @Override\r
+               public void saveState(IMemento memento) {\r
+                       \r
+               }\r
+               \r
+       }\r
+\r
+}\r