1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.example.chassis;
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;
26 public class ViewPartExample extends ViewPart {
30 public void createPartControl(Composite parent) {
31 c = new SWTChassis(parent, 0);
34 IThreadWorkQueue thread = AWTThread.getThreadAccess();
35 CanvasContext canvasContext = TestCanvas.createTestCanvas(thread);
37 c.setCanvasContext(canvasContext);
39 c.addChassisListener(new IChassisListener() {
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() {
46 ICanvasContext ctx = c.getCanvasContext();
47 c.getAWTComponent().setCanvasContext(null);
56 public void setFocus() {