]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graphviz.ui/src/org/simantics/graphviz/ui/AbstractGraphvizEditorPart.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graphviz.ui / src / org / simantics / graphviz / ui / AbstractGraphvizEditorPart.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.graphviz.ui;\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.eclipse.ui.IEditorInput;\r
20 import org.eclipse.ui.IEditorSite;\r
21 import org.eclipse.ui.PartInitException;\r
22 import org.eclipse.ui.part.EditorPart;\r
23 import org.simantics.graphviz.Graph;\r
24 \r
25 public abstract class AbstractGraphvizEditorPart extends EditorPart {\r
26 \r
27     GraphvizComponent component;\r
28     \r
29     @Override\r
30     public void doSave(IProgressMonitor monitor) {\r
31     }\r
32 \r
33     @Override\r
34     public void doSaveAs() {\r
35     }\r
36 \r
37     @Override\r
38     public void init(IEditorSite site, IEditorInput input)\r
39         throws PartInitException {\r
40         setSite(site);\r
41         setInput(input);\r
42     }\r
43 \r
44     @Override\r
45     public boolean isDirty() {\r
46         return false;\r
47     }\r
48 \r
49     @Override\r
50     public boolean isSaveAsAllowed() {\r
51         return false;\r
52     }\r
53 \r
54     @Override\r
55     public void createPartControl(Composite parent) {       \r
56         component = new GraphvizComponent(parent, 0);\r
57     }\r
58     \r
59         /**\r
60          * Sets a new graph to be drawn. This operation may take a while. It can\r
61          * be called from any thread.\r
62          * @param graph\r
63          */\r
64     public void setGraph(Graph graph) {\r
65         component.setGraph(graph);\r
66     }\r
67     \r
68     public void setGraph(Graph graph, String algorithm) {\r
69         component.setGraph(graph, algorithm);\r
70     }\r
71 \r
72     /**\r
73          * Sets a new graph to be drawn. The graph is layouted in a Eclipse job.\r
74          * The component is redrawn after the layout is complete.\r
75          * @param graph\r
76          */\r
77     public void asyncSetGraph(final Graph graph) {\r
78         Job job = new Job("Layouting a graph") {\r
79 \r
80                         @Override\r
81                         protected IStatus run(IProgressMonitor monitor) {\r
82                                 setGraph(graph);\r
83                                 return Status.OK_STATUS;\r
84                         }\r
85                 \r
86         };\r
87         job.schedule();\r
88     }\r
89     \r
90     @Override\r
91     public void setFocus() {\r
92         if(component != null)\r
93                 component.requestFocus();\r
94     }\r
95 \r
96 }\r