LogicUI now works as a ERCP part!
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 23 May 2019 11:39:29 +0000 (13:39 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Thu, 23 May 2019 11:39:29 +0000 (13:39 +0200)
SampleERCP/Application.e4xmi
SampleERCP/src/sampleercp/parts/LogicUIPart.java [new file with mode: 0644]

index 1b3bd2a..6e2ca3e 100644 (file)
@@ -4,6 +4,7 @@
     <children xsi:type="basic:PartSashContainer" xmi:id="_6wlLksgZEeSyMNYR5xypkQ" elementId="Sample.partsashcontainer.sample">
       <children xsi:type="basic:PartStack" xmi:id="_6wlLk8gZEeSyMNYR5xypkQ" elementId="Sample.partstack.sample">
         <children xsi:type="basic:Part" xmi:id="_6wlLlMgZEeSyMNYR5xypkQ" elementId="Sample.part.sample" contributionURI="bundleclass://SampleERCP/sampleercp.parts.SamplePart" label="Sample Part" iconURI="platform:/plugin/SampleERCP/icons/home.png"/>
+        <children xsi:type="basic:Part" xmi:id="_cldhcH1HEema06ZDPR6BSw" elementId="sampleercp.part.logicui" contributionURI="bundleclass://SampleERCP/sampleercp.parts.LogicUIPart" label="LogicUI part"/>
       </children>
       <children xsi:type="basic:PartStack" xmi:id="_l2EzYG6wEemo__tDmTCqCQ" elementId="sample.partstack.0">
         <children xsi:type="basic:Part" xmi:id="_mW1XEG6wEemo__tDmTCqCQ" elementId="sample.part.none" label="None" tooltip="Something"/>
diff --git a/SampleERCP/src/sampleercp/parts/LogicUIPart.java b/SampleERCP/src/sampleercp/parts/LogicUIPart.java
new file mode 100644 (file)
index 0000000..7ed8377
--- /dev/null
@@ -0,0 +1,54 @@
+package sampleercp.parts;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+
+import era.mi.gui.LogicUICanvas;
+import era.mi.gui.examples.RSLatchGUIExample;
+import era.mi.logic.Simulation;
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
+
+public class LogicUIPart
+{
+       @Inject
+       private MPart part;
+
+       @PostConstruct
+       public void create(Composite parent)
+       {
+               LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE);
+               RSLatchGUIExample.addComponentsAndWires(ui);
+               ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
+               ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
+               userInput.buttonDrag = 3;
+               userInput.buttonZoom = 2;
+               userInput.enableUserInput();
+               Thread simulationThread = new Thread(() ->
+               {
+                       // TODO find a better condition
+                       while (!ui.isDisposed())
+                       {
+                               // always execute to keep timeline from "hanging behind" for too long
+                               Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
+                               long sleepTime;
+                               if (Simulation.TIMELINE.hasNext())
+                                       sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
+                               else
+                                       sleepTime = 10;
+                               try
+                               {
+                                       if (sleepTime > 0)
+                                               Thread.sleep(sleepTime);
+                               }
+                               catch (InterruptedException e)
+                               {
+                               } // it is normal execution flow to be interrupted
+                       }
+               });
+               simulationThread.start();
+       }
+}
\ No newline at end of file