]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/Editors.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.editors.win32 / src / org / simantics / editors / win32 / Editors.java
index cb1557b060fac0b396a4bcb69f337e2cf55b9cb0..d4c2f3142ec99633d3a3e5a733985d06d8a5d805 100644 (file)
-/*******************************************************************************\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.win32;\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.BrowserInput;\r
-import org.simantics.editors.internal.SystemFile;\r
-import org.simantics.editors.win32.ole.EditorDefinition;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-\r
-\r
-public class Editors {\r
-\r
-       @Deprecated\r
-       /**\r
-        * Opens extenal application for a file.\r
-        * \r
-        * Deprecated: Since the functionality is not Windows specific feature, this method has been moved to org.simantics.editors.Editors class.\r
-        * @param file\r
-        * @return\r
-        * @throws PartInitException\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
-       public static IEditorPart openEmbeddedEditor(File file) {\r
-               return openEmbeddedEditor(file,false);\r
-       }\r
-       \r
-       public static boolean isSupported(String filename) {\r
-               String suffix = "";\r
-               int index = filename.lastIndexOf(".");\r
-               if (index != -1)\r
-                       suffix = filename.substring(index+1).toLowerCase();\r
-               else\r
-                       suffix = filename.toLowerCase();\r
-               EditorDefinition factory = EditorDefinitionManager.getInstance().getFactoryForSuffix(suffix);\r
-               return factory != null;\r
-       }\r
-       \r
-       public static IEditorPart openEmbeddedEditor(File file, boolean fullscreen) {\r
-               return openEmbeddedEditor(file, file.getName(), fullscreen);\r
-       }\r
-       public static IEditorPart openEmbeddedEditor(File file, String title, boolean fullscreen) {\r
-               String filename = file.getAbsoluteFile().toString();\r
-               String suffix = "";\r
-               int index = filename.lastIndexOf(".");\r
-               if (index != -1)\r
-                       suffix = filename.substring(index+1).toLowerCase();\r
-               else\r
-                       suffix = filename.toLowerCase();\r
-               \r
-               \r
-               \r
-               try {\r
-                       EditorDefinition factory = EditorDefinitionManager.getInstance().getFactoryForSuffix(suffix);\r
-                       if (factory == null) {\r
-                               throw new RuntimeException("Cannot find editorDefinition for " + suffix);\r
-                       }\r
-                       \r
-\r
-                       if (!factory.useBrowser()) {\r
-                               OLEEditorInput input = new OLEEditorInput(factory, file, title, fullscreen);\r
-                               return WorkbenchUtils.openEditor("org.simantics.editors.win32.oleeditor", input);\r
-                       }\r
-                       URL url = file.toURI().toURL();\r
-                       BrowserInput input = new BrowserInput(url,false, fullscreen);\r
-                       input.setName(title);\r
-                       return WorkbenchUtils.openEditor("org.simantics.editors.browser", input);\r
-               \r
-               } catch (Exception e) {\r
-                       ErrorLogger.defaultLogError("Cannot use internal editor, trying external editor", e);\r
-               }\r
-\r
-               //ErrorLogger.defaultLogError("Cannot embed ActiveX contol, using external application.", null);\r
-               try {\r
-                       // show the file contents in external editor / application\r
-                       return org.simantics.editors.Editors.openExternalEditor(file);\r
-               } catch (Exception err) {\r
-                       ErrorLogger.defaultLogError(err);\r
-               }\r
-               return null;\r
-       }\r
-       \r
-//     public static void openEmbeddedEditor(URL url) {\r
-//             \r
-//             \r
-//     }\r
-}\r
+/*******************************************************************************
+ * 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.win32;
+
+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.BrowserInput;
+import org.simantics.editors.internal.SystemFile;
+import org.simantics.editors.win32.ole.EditorDefinition;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+
+
+public class Editors {
+
+       @Deprecated
+       /**
+        * Opens extenal application for a file.
+        * 
+        * Deprecated: Since the functionality is not Windows specific feature, this method has been moved to org.simantics.editors.Editors class.
+        * @param file
+        * @return
+        * @throws PartInitException
+        */
+       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) {
+                       
+               }
+               
+       }
+       
+       public static IEditorPart openEmbeddedEditor(File file) {
+               return openEmbeddedEditor(file,false);
+       }
+       
+       public static boolean isSupported(String filename) {
+               String suffix = "";
+               int index = filename.lastIndexOf(".");
+               if (index != -1)
+                       suffix = filename.substring(index+1).toLowerCase();
+               else
+                       suffix = filename.toLowerCase();
+               EditorDefinition factory = EditorDefinitionManager.getInstance().getFactoryForSuffix(suffix);
+               return factory != null;
+       }
+       
+       public static IEditorPart openEmbeddedEditor(File file, boolean fullscreen) {
+               return openEmbeddedEditor(file, file.getName(), fullscreen);
+       }
+       public static IEditorPart openEmbeddedEditor(File file, String title, boolean fullscreen) {
+               String filename = file.getAbsoluteFile().toString();
+               String suffix = "";
+               int index = filename.lastIndexOf(".");
+               if (index != -1)
+                       suffix = filename.substring(index+1).toLowerCase();
+               else
+                       suffix = filename.toLowerCase();
+               
+               
+               
+               try {
+                       EditorDefinition factory = EditorDefinitionManager.getInstance().getFactoryForSuffix(suffix);
+                       if (factory == null) {
+                               throw new RuntimeException("Cannot find editorDefinition for " + suffix);
+                       }
+                       
+
+                       if (!factory.useBrowser()) {
+                               OLEEditorInput input = new OLEEditorInput(factory, file, title, fullscreen);
+                               return WorkbenchUtils.openEditor("org.simantics.editors.win32.oleeditor", input);
+                       }
+                       URL url = file.toURI().toURL();
+                       BrowserInput input = new BrowserInput(url,false, fullscreen);
+                       input.setName(title);
+                       return WorkbenchUtils.openEditor("org.simantics.editors.browser", input);
+               
+               } catch (Exception e) {
+                       ErrorLogger.defaultLogError("Cannot use internal editor, trying external editor", e);
+               }
+
+               //ErrorLogger.defaultLogError("Cannot embed ActiveX contol, using external application.", null);
+               try {
+                       // show the file contents in external editor / application
+                       return org.simantics.editors.Editors.openExternalEditor(file);
+               } catch (Exception err) {
+                       ErrorLogger.defaultLogError(err);
+               }
+               return null;
+       }
+       
+//     public static void openEmbeddedEditor(URL url) {
+//             
+//             
+//     }
+}