]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/example/chassis/ViewPartExample.java
Automatically import also SCLMain modules of dependent index roots
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / example / chassis / ViewPartExample.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.g2d.example.chassis;
13
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.part.ViewPart;
16 import org.simantics.g2d.canvas.ICanvasContext;
17 import org.simantics.g2d.canvas.impl.CanvasContext;
18 import org.simantics.g2d.chassis.ICanvasChassis;
19 import org.simantics.g2d.chassis.IChassisListener;
20 import org.simantics.g2d.chassis.SWTChassis;
21 import org.simantics.g2d.example.TestCanvas;
22 import org.simantics.utils.threads.AWTThread;
23 import org.simantics.utils.threads.IThreadWorkQueue;
24 import org.simantics.utils.threads.ThreadUtils;
25
26 public class ViewPartExample extends ViewPart {
27     SWTChassis c;
28
29     @Override
30     public void createPartControl(Composite parent) {
31         c = new SWTChassis(parent, 0);
32         c.syncPopulate();
33
34         IThreadWorkQueue thread = AWTThread.getThreadAccess();
35         CanvasContext canvasContext = TestCanvas.createTestCanvas(thread);
36
37         c.setCanvasContext(canvasContext);
38
39         c.addChassisListener(new IChassisListener() {
40             @Override
41             public void chassisClosed(ICanvasChassis sender) {
42                 // Prevent deadlock while disposing which using syncExec would result in. 
43                 ThreadUtils.asyncExec(c.getCanvasContext().getThreadAccess(), new Runnable() {
44                     @Override
45                     public void run() {
46                         ICanvasContext ctx = c.getCanvasContext();
47                         c.getAWTComponent().setCanvasContext(null);
48                         ctx.dispose();
49                     }
50                 });
51             }
52         });
53     }
54
55     @Override
56     public void setFocus() {
57         c.setFocus();
58     }
59
60 }