X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.editors.win32%2Fsrc%2Forg%2Fsimantics%2Feditors%2Fwin32%2FEditors.java;h=d4c2f3142ec99633d3a3e5a733985d06d8a5d805;hb=e235ff48dd50e787f5508a2280826372ef20a3d7;hp=cb1557b060fac0b396a4bcb69f337e2cf55b9cb0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/Editors.java b/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/Editors.java index cb1557b06..d4c2f3142 100644 --- a/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/Editors.java +++ b/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/Editors.java @@ -1,134 +1,134 @@ -/******************************************************************************* - * 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) { -// -// -// } -} +/******************************************************************************* + * 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) { +// +// +// } +}