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