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