]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/OLEEditor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.editors.win32 / src / org / simantics / editors / win32 / OLEEditor.java
diff --git a/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/OLEEditor.java b/bundles/org.simantics.editors.win32/src/org/simantics/editors/win32/OLEEditor.java
new file mode 100644 (file)
index 0000000..db7752e
--- /dev/null
@@ -0,0 +1,143 @@
+/*******************************************************************************\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 org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.ole.win32.OleAutomation;\r
+import org.eclipse.swt.ole.win32.OleClientSite;\r
+import org.eclipse.swt.ole.win32.OleFrame;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IEditorInput;\r
+import org.eclipse.ui.IEditorSite;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.part.EditorPart;\r
+import org.simantics.editors.win32.ole.EditorDefinition;\r
+import org.simantics.editors.win32.ole.OleController;\r
+\r
+\r
+/**\r
+ * OLEEditor is a wrapper for Windows ActiveX components.\r
+ * \r
+ * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class OLEEditor extends EditorPart {\r
+\r
+       private OleFrame frame;\r
+       private OleClientSite site;\r
+       private OleAutomation auto;\r
+       private OleController ctrl;\r
+       \r
+       private Shell fsShell;\r
+       \r
+       public OLEEditor() {\r
+               super();\r
+       }\r
+\r
+       @Override\r
+       public void doSave(IProgressMonitor monitor) {\r
+\r
+       }\r
+\r
+       @Override\r
+       public void doSaveAs() {\r
+\r
+       }\r
+\r
+       @Override\r
+       public void init(IEditorSite site, IEditorInput input)\r
+                       throws PartInitException {\r
+               if (!(input instanceof OLEEditorInput))\r
+                       throw new PartInitException("Input must be OLEEditorInput");\r
+               setInput(input);\r
+               setSite(site);\r
+\r
+       }\r
+\r
+       @Override\r
+       public boolean isDirty() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean isSaveAsAllowed() {\r
+               return false;\r
+       }\r
+       \r
+\r
+       @Override\r
+       public void createPartControl(Composite parent) {\r
+               OLEEditorInput input = (OLEEditorInput)getEditorInput();\r
+               boolean fullscreen = input.isFullscreen();\r
+               if (fullscreen) {\r
+                       fsShell = new Shell(parent.getDisplay());\r
+                       \r
+                       fsShell.setLayout(new GridLayout(1,false));\r
+                       fsShell.setLayout(new FillLayout());\r
+                       parent = new Composite(fsShell,SWT.NONE);\r
+                       fsShell.open();\r
+                       fsShell.setFullScreen(true);\r
+                       parent.setLayout(new FillLayout());\r
+               }\r
+               \r
+               \r
+               EditorDefinition factory = input.getFactory();\r
+               frame = new OleFrame(parent, SWT.NONE);\r
+               \r
+               if (factory.getProgID() == null || factory.useFileInput()) {\r
+                       site = new OleClientSite(frame,SWT.NONE,input.getFile());\r
+               } else {\r
+                       site = new OleClientSite(frame, SWT.NONE, factory.getProgID());\r
+                       auto = new OleAutomation(site);\r
+                       ctrl = factory.createController(frame, site, auto);\r
+                       ctrl.show(input);\r
+               }\r
+               \r
+               setPartName(site.getProgramID() + " : " + input.getName());\r
+               \r
+               if (fullscreen) {\r
+                       fsShell.layout(true, true);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void setFocus() {\r
+               frame.setFocus();\r
+       }\r
+       \r
+       /**\r
+        * Returns OleController of embedded OLE component. May return null.\r
+        * @return\r
+        */\r
+       public OleController getController() {\r
+               return ctrl;\r
+       }\r
+       \r
+       @Override\r
+       public void dispose() {\r
+               if (auto != null)\r
+                       auto.dispose();\r
+               site.dispose();\r
+               if (fsShell != null)\r
+                       fsShell.dispose();\r
+               if (frame != null) {\r
+                       frame.dispose();\r
+               }\r
+               super.dispose();\r
+\r
+       }\r
+\r
+}\r