\r
import org.eclipse.jface.viewers.ISelection;\r
import org.eclipse.jface.viewers.StructuredSelection;\r
+import org.eclipse.swt.widgets.Composite;\r
import org.eclipse.ui.IWorkbenchPartSite;\r
import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
import org.simantics.browsing.ui.swt.IPropertyPage;\r
import org.simantics.g2d.connection.IConnectionAdvisor;\r
import org.simantics.g2d.diagram.DiagramHints;\r
import org.simantics.g2d.diagram.participant.DeleteHandler;\r
+import org.simantics.g2d.diagram.participant.ElementPainter;\r
import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
import org.simantics.g2d.element.ElementClassProviders;\r
import org.simantics.g2d.element.ElementClasses;\r
*/\r
public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer {\r
\r
- protected String getPopupId() {\r
- return "#SysdynDiagramPopup";\r
- }\r
+ protected String getPopupId() {\r
+ return "#SysdynDiagramPopup";\r
+ }\r
\r
@Override\r
- protected Set<String> getPropertyPageContexts() {\r
- return Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser");\r
- }\r
-\r
- @Override\r
- protected IPropertyPage createPropertyPage(IWorkbenchPartSite site, Set<String> contexts) {\r
- return new SysdynPropertyPage(site, contexts);\r
- }\r
-\r
- @Override\r
- protected IElementClassProvider createElementClassProvider(ReadGraph graph) {\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
-\r
- return ElementClassProviders.mappedProvider(\r
- ElementClasses.CONNECTION, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.FlowConnection)),\r
- ElementClasses.FLAG, FlagClassFactory.createFlagClass(dr.Flag),\r
- ConnectionClasses.FLOW, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.FlowConnection)),\r
- ConnectionClasses.DEPENDENCY, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.DependencyConnection))\r
- );\r
- \r
- \r
- }\r
-\r
- @Override\r
- protected void onCreated() {\r
- sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE);\r
- }\r
-\r
- @Override\r
- protected void addKeyBindingParticipants(CanvasContext ctx) {\r
- ctx.add(new DeleteHandler(getEditorSite().getActionBars().getStatusLineManager()));\r
- ctx.add(new CopyPasteHandler(getEditorSite().getActionBars().getStatusLineManager()));\r
- ctx.add(new CreateVariablesShortcutParticipant(synchronizer));\r
- }\r
-\r
- @Override\r
- protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) {\r
- super.initializeSynchronizationContext(graph, context);\r
-\r
- // Make sure SysdynResource is available.\r
- SysdynResource.getInstance(graph);\r
- }\r
-\r
- @Override\r
- protected void addStructureParticipants(ICanvasContext ctx) {\r
-\r
- ctx.add(new WorkbenchSelectionProvider(swt, getSite()) {\r
-\r
- @Override\r
- protected ISelection constructAdaptableSelection(Iterable<?> selection) {\r
- ArrayList<Object> objects = new ArrayList<Object>();\r
- Resource runtime = sourceDiagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);\r
- for (Object o : selection) {\r
- if (o instanceof IElement) {\r
- IElement e = (IElement) o;\r
- Object object = e.getHint(ElementHints.KEY_OBJECT);\r
- if (object != null && runtime != null) {\r
- IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
- context.setHint(SelectionHints.KEY_MAIN, object);\r
- if (runtime != null)\r
- context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
- objects.add(context);\r
- }\r
- } else {\r
- System.out.println(" unrecognized selection: " + o.getClass() + ": " + o);\r
- }\r
- }\r
- if(objects.isEmpty() && runtime != null) {\r
- HintContext context = new HintContext();\r
- context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
- objects.add(context);\r
- }\r
- return new StructuredSelection(objects);\r
- }\r
-\r
- });\r
- // Add visual browsing capabilities for structural models\r
- \r
-// Remove double click handler, because it is not working properly\r
-// ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, getResourceInput2()));\r
- ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext));\r
- \r
- }\r
-\r
- @Override\r
- protected void addOtherParticipants(CanvasContext ctx) {\r
- }\r
- \r
- @Override \r
- protected PointerInteractor getPointerInteractor() {\r
- return new org.simantics.sysdyn.ui.editor.participant.PointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider());\r
- }\r
- \r
- @Override\r
- protected IConnectionAdvisor getConnectionAdvisor(IModelingRules modelingRules, Session session) {\r
- return new SysdynConnectionAdvisor(modelingRules, sessionContext.getSession());\r
- }\r
+ public void createPartControl(Composite parent) {\r
+ super.createPartControl(parent);\r
+ \r
+ ElementPainter ep = canvasContext.getSingleItem(ElementPainter.class);\r
+ for(IElement e : sourceDiagram.getElements()) {\r
+ if(e.getElementClass().getId().contains("Connection")){\r
+ ep.update(e);\r
+ }\r
+ }\r
+ scheduleZoomToFit();\r
+ } \r
+\r
+ @Override\r
+ protected Set<String> getPropertyPageContexts() {\r
+ return Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser");\r
+ }\r
+\r
+ @Override\r
+ protected IPropertyPage createPropertyPage(IWorkbenchPartSite site, Set<String> contexts) {\r
+ return new SysdynPropertyPage(site, contexts);\r
+ }\r
+\r
+ @Override\r
+ protected IElementClassProvider createElementClassProvider(ReadGraph graph) {\r
+ DiagramResource dr = DiagramResource.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+ return ElementClassProviders.mappedProvider(\r
+ ElementClasses.CONNECTION, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.FlowConnection)),\r
+ ElementClasses.FLAG, FlagClassFactory.createFlagClass(dr.Flag),\r
+ ConnectionClasses.FLOW, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.FlowConnection)),\r
+ ConnectionClasses.DEPENDENCY, SysdynConnectionClass.CLASS.newClassWith(new StaticObjectAdapter(sr.DependencyConnection))\r
+ );\r
+\r
+\r
+ }\r
+\r
+ @Override\r
+ protected void onCreated() {\r
+ sourceDiagram.setHint(DiagramHints.KEY_ALLOW_ROUTE_POINTS, Boolean.FALSE);\r
+ }\r
+\r
+ @Override\r
+ protected void addKeyBindingParticipants(CanvasContext ctx) {\r
+ ctx.add(new DeleteHandler(getEditorSite().getActionBars().getStatusLineManager()));\r
+ ctx.add(new CopyPasteHandler(getEditorSite().getActionBars().getStatusLineManager()));\r
+ ctx.add(new CreateVariablesShortcutParticipant(synchronizer));\r
+ }\r
+\r
+ @Override\r
+ protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) {\r
+ super.initializeSynchronizationContext(graph, context);\r
+\r
+ // Make sure SysdynResource is available.\r
+ SysdynResource.getInstance(graph);\r
+ }\r
+\r
+ @Override\r
+ protected void addStructureParticipants(ICanvasContext ctx) {\r
+\r
+ ctx.add(new WorkbenchSelectionProvider(swt, getSite()) {\r
+\r
+ @Override\r
+ protected ISelection constructAdaptableSelection(Iterable<?> selection) {\r
+ ArrayList<Object> objects = new ArrayList<Object>();\r
+ Resource runtime = sourceDiagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);\r
+ for (Object o : selection) {\r
+ if (o instanceof IElement) {\r
+ IElement e = (IElement) o;\r
+ Object object = e.getHint(ElementHints.KEY_OBJECT);\r
+ if (object != null && runtime != null) {\r
+ IHintContext context = new AdaptableHintContext(SelectionHints.KEY_MAIN);\r
+ context.setHint(SelectionHints.KEY_MAIN, object);\r
+ if (runtime != null)\r
+ context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
+ objects.add(context);\r
+ }\r
+ } else {\r
+ System.out.println(" unrecognized selection: " + o.getClass() + ": " + o);\r
+ }\r
+ }\r
+ if(objects.isEmpty() && runtime != null) {\r
+ HintContext context = new HintContext();\r
+ context.setHint(SelectionHints.KEY_VARIABLE_RESOURCE, runtime);\r
+ objects.add(context);\r
+ }\r
+ return new StructuredSelection(objects);\r
+ }\r
+\r
+ });\r
+ // Add visual browsing capabilities for structural models\r
+\r
+ // Remove double click handler, because it is not working properly\r
+ // ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, getResourceInput2()));\r
+ ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext));\r
+\r
+ }\r
+\r
+ @Override\r
+ protected void addOtherParticipants(CanvasContext ctx) {\r
+ }\r
+\r
+ @Override \r
+ protected PointerInteractor getPointerInteractor() {\r
+ return new org.simantics.sysdyn.ui.editor.participant.PointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider());\r
+ }\r
+\r
+ @Override\r
+ protected IConnectionAdvisor getConnectionAdvisor(IModelingRules modelingRules, Session session) {\r
+ return new SysdynConnectionAdvisor(modelingRules, sessionContext.getSession());\r
+ }\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.databoard.serialization.SerializationException;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.TransferableGraphRequest;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class ExportModelHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ final Resource model = ResourceAdaptionUtils.toSingleResource(sel);\r
+ if(model == null) return null;\r
+ \r
+ // FIXME: Model browser doesn't change its selection even if the selected object is removed,\r
+ // so you can try to export a removed model \r
+ boolean isRemoved = true;\r
+ try {\r
+ isRemoved = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
+\r
+ @Override\r
+ public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+ return !graph.hasStatement(model, Layer0.getInstance(graph).PartOf);\r
+ }\r
+ \r
+ });\r
+ } catch (DatabaseException e1) {\r
+ e1.printStackTrace();\r
+ }\r
+ if(isRemoved) return null;\r
+ \r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Export..");\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ final String selected = fd.open();\r
+ if(selected == null) return null;\r
+ \r
+ \r
+ SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ String name = graph.syncRequest(new PossibleRelatedValue<String>(model, l0.HasName, StringBindingDefault.INSTANCE ));\r
+ ArrayList<Pair<Resource, String>> roots = new ArrayList<Pair<Resource, String>>();\r
+ roots.add(Pair.make(model, name));\r
+ TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest(roots, model));\r
+\r
+ try {\r
+ Files.createFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ } catch (SerializationException e) {\r
+ e.printStackTrace();\r
+ } catch (BindingException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ \r
+ }\r
+ });\r
+ \r
+\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.databoard.serialization.SerializationException;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ImportModelHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ \r
+ Resource project = SimanticsUI.getProject().get();\r
+ if(project == null) return null;\r
+\r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+ fd.setText("Import...");\r
+ fd.setFilterPath(Platform.getLocation().toOSString());\r
+ String[] filterExt = {"*.tg"};\r
+ fd.setFilterExtensions(filterExt);\r
+ String selected = fd.open();\r
+ if(selected == null) return null;\r
+\r
+ TransferableGraph1 tg = null;\r
+ try {\r
+ tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
+ } catch (RuntimeBindingConstructionException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ } catch (SerializationException e) {\r
+ e.printStackTrace();\r
+ }\r
+ if(tg == null) return null;\r
+ \r
+ org.simantics.graph.db.IImportAdvisor ia = new DefaultPasteImportAdvisor(project);\r
+ DefaultPasteHandler.defaultExecute(tg, SimanticsUI.getProject().get(), ia);\r
+\r
+ return null;\r
+ }\r
+\r
+}\r