--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.graphviz.ui;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.IEditorInput;\r
+import org.eclipse.ui.IEditorSite;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.part.EditorPart;\r
+import org.simantics.graphviz.Graph;\r
+\r
+public abstract class AbstractGraphvizEditorPart extends EditorPart {\r
+\r
+ GraphvizComponent component;\r
+ \r
+ @Override\r
+ public void doSave(IProgressMonitor monitor) {\r
+ }\r
+\r
+ @Override\r
+ public void doSaveAs() {\r
+ }\r
+\r
+ @Override\r
+ public void init(IEditorSite site, IEditorInput input)\r
+ throws PartInitException {\r
+ setSite(site);\r
+ setInput(input);\r
+ }\r
+\r
+ @Override\r
+ public boolean isDirty() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean isSaveAsAllowed() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public void createPartControl(Composite parent) { \r
+ component = new GraphvizComponent(parent, 0);\r
+ }\r
+ \r
+ /**\r
+ * Sets a new graph to be drawn. This operation may take a while. It can\r
+ * be called from any thread.\r
+ * @param graph\r
+ */\r
+ public void setGraph(Graph graph) {\r
+ component.setGraph(graph);\r
+ }\r
+ \r
+ public void setGraph(Graph graph, String algorithm) {\r
+ component.setGraph(graph, algorithm);\r
+ }\r
+\r
+ /**\r
+ * Sets a new graph to be drawn. The graph is layouted in a Eclipse job.\r
+ * The component is redrawn after the layout is complete.\r
+ * @param graph\r
+ */\r
+ public void asyncSetGraph(final Graph graph) {\r
+ Job job = new Job("Layouting a graph") {\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ setGraph(graph);\r
+ return Status.OK_STATUS;\r
+ }\r
+ \r
+ };\r
+ job.schedule();\r
+ }\r
+ \r
+ @Override\r
+ public void setFocus() {\r
+ if(component != null)\r
+ component.requestFocus();\r
+ }\r
+\r
+}\r