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