]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.editors.win32;\r
13 \r
14 import org.eclipse.core.runtime.IProgressMonitor;\r
15 import org.eclipse.swt.SWT;\r
16 import org.eclipse.swt.layout.FillLayout;\r
17 import org.eclipse.swt.layout.GridLayout;\r
18 import org.eclipse.swt.ole.win32.OleAutomation;\r
19 import org.eclipse.swt.ole.win32.OleClientSite;\r
20 import org.eclipse.swt.ole.win32.OleFrame;\r
21 import org.eclipse.swt.widgets.Composite;\r
22 import org.eclipse.swt.widgets.Shell;\r
23 import org.eclipse.ui.IEditorInput;\r
24 import org.eclipse.ui.IEditorSite;\r
25 import org.eclipse.ui.PartInitException;\r
26 import org.eclipse.ui.part.EditorPart;\r
27 import org.simantics.editors.win32.ole.EditorDefinition;\r
28 import org.simantics.editors.win32.ole.OleController;\r
29 \r
30 \r
31 /**\r
32  * OLEEditor is a wrapper for Windows ActiveX components.\r
33  * \r
34  * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
35  *\r
36  */\r
37 public class OLEEditor extends EditorPart {\r
38 \r
39         private OleFrame frame;\r
40         private OleClientSite site;\r
41         private OleAutomation auto;\r
42         private OleController ctrl;\r
43         \r
44         private Shell fsShell;\r
45         \r
46         public OLEEditor() {\r
47                 super();\r
48         }\r
49 \r
50         @Override\r
51         public void doSave(IProgressMonitor monitor) {\r
52 \r
53         }\r
54 \r
55         @Override\r
56         public void doSaveAs() {\r
57 \r
58         }\r
59 \r
60         @Override\r
61         public void init(IEditorSite site, IEditorInput input)\r
62                         throws PartInitException {\r
63                 if (!(input instanceof OLEEditorInput))\r
64                         throw new PartInitException("Input must be OLEEditorInput");\r
65                 setInput(input);\r
66                 setSite(site);\r
67 \r
68         }\r
69 \r
70         @Override\r
71         public boolean isDirty() {\r
72                 return false;\r
73         }\r
74 \r
75         @Override\r
76         public boolean isSaveAsAllowed() {\r
77                 return false;\r
78         }\r
79         \r
80 \r
81         @Override\r
82         public void createPartControl(Composite parent) {\r
83                 OLEEditorInput input = (OLEEditorInput)getEditorInput();\r
84                 boolean fullscreen = input.isFullscreen();\r
85                 if (fullscreen) {\r
86                         fsShell = new Shell(parent.getDisplay());\r
87                         \r
88                         fsShell.setLayout(new GridLayout(1,false));\r
89                         fsShell.setLayout(new FillLayout());\r
90                         parent = new Composite(fsShell,SWT.NONE);\r
91                         fsShell.open();\r
92                         fsShell.setFullScreen(true);\r
93                         parent.setLayout(new FillLayout());\r
94                 }\r
95                 \r
96                 \r
97                 EditorDefinition factory = input.getFactory();\r
98                 frame = new OleFrame(parent, SWT.NONE);\r
99                 \r
100                 if (factory.getProgID() == null || factory.useFileInput()) {\r
101                         site = new OleClientSite(frame,SWT.NONE,input.getFile());\r
102                 } else {\r
103                         site = new OleClientSite(frame, SWT.NONE, factory.getProgID());\r
104                         auto = new OleAutomation(site);\r
105                         ctrl = factory.createController(frame, site, auto);\r
106                         ctrl.show(input);\r
107                 }\r
108                 \r
109                 setPartName(site.getProgramID() + " : " + input.getName());\r
110                 \r
111                 if (fullscreen) {\r
112                         fsShell.layout(true, true);\r
113                 }\r
114         }\r
115 \r
116         @Override\r
117         public void setFocus() {\r
118                 frame.setFocus();\r
119         }\r
120         \r
121         /**\r
122          * Returns OleController of embedded OLE component. May return null.\r
123          * @return\r
124          */\r
125         public OleController getController() {\r
126                 return ctrl;\r
127         }\r
128         \r
129         @Override\r
130         public void dispose() {\r
131                 if (auto != null)\r
132                         auto.dispose();\r
133                 site.dispose();\r
134                 if (fsShell != null)\r
135                         fsShell.dispose();\r
136                 if (frame != null) {\r
137                         frame.dispose();\r
138                 }\r
139                 super.dispose();\r
140 \r
141         }\r
142 \r
143 }\r