]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/compositeViewer/CompositeViewer.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / compositeViewer / CompositeViewer.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.structural.ui.compositeViewer;\r
13 \r
14 import org.eclipse.core.runtime.IProgressMonitor;\r
15 import org.eclipse.core.runtime.IStatus;\r
16 import org.eclipse.core.runtime.Status;\r
17 import org.eclipse.core.runtime.jobs.Job;\r
18 import org.eclipse.swt.widgets.Composite;\r
19 import org.simantics.db.procedure.Listener;\r
20 import org.simantics.graphviz.Graph;\r
21 import org.simantics.graphviz.ui.GraphvizComponent;\r
22 import org.simantics.ui.SimanticsUI;\r
23 import org.simantics.ui.workbench.ResourceEditorPart;\r
24 \r
25 public class CompositeViewer extends ResourceEditorPart {\r
26 \r
27     GraphvizComponent component;\r
28     private boolean disposed = false;\r
29 \r
30     @Override\r
31     public void createPartControl(Composite parent) {\r
32         component = new GraphvizComponent(parent, 0);\r
33         component.waitUntilInitialized();\r
34         readGraph();\r
35     }\r
36 \r
37     private void readGraph() {\r
38         SimanticsUI.getSession().asyncRequest(new CreateCompositeGraph(\r
39                 getResourceInput().getResource()),\r
40                 new Listener<Graph>() {\r
41 \r
42             @Override\r
43             public void exception(Throwable e) {\r
44                 e.printStackTrace();\r
45             }\r
46 \r
47             @Override\r
48             public void execute(final Graph graph) {\r
49                 Job job = new Job("Layout composite graph") {\r
50 \r
51                     @Override\r
52                     protected IStatus run(IProgressMonitor monitor) {\r
53                         component.setGraph(graph, "neato");\r
54                         return Status.OK_STATUS;\r
55                     }\r
56 \r
57                 };\r
58                 job.schedule();\r
59             }\r
60 \r
61             @Override\r
62             public boolean isDisposed() {\r
63                 return disposed;\r
64             }\r
65         });\r
66     }\r
67 \r
68     @Override\r
69     public void setFocus() {\r
70         if (component != null && !component.isDisposed()) {\r
71             component.setFocus();\r
72             component.requestFocus();\r
73         }\r
74     }\r
75 \r
76     @Override\r
77     public void dispose() {\r
78         disposed  = true;\r
79     }\r
80 \r
81 }\r