Просмотр исходного кода

refactored traffic light example

terfloth@itemis.de 13 лет назад
Родитель
Сommit
eca0764408
36 измененных файлов с 365 добавлено и 656 удалено
  1. 40 34
      examples/org.yakindu.sct.example.trafficlight/.project
  2. 26 9
      examples/org.yakindu.sct.example.trafficlight/GenModelJava.sgen
  3. 26 26
      examples/org.yakindu.sct.example.trafficlight/TrafficLightWaiting.sct
  4. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/Event.java
  5. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/EventNotification.java
  6. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/EventVector.java
  7. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/INotificationListener.java
  8. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/INotificationSender.java
  9. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/IStatemachine.java
  10. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimedStatemachine.java
  11. 18 29
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimerNotificationListener.java
  12. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimerService.java
  13. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/Notification.java
  14. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationSender.java
  15. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationType.java
  16. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeCycleNotification.java
  17. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java
  18. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java
  19. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimerService.java
  20. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ValuedEvent.java
  21. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/VariableNotification.java
  22. 3 13
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterface.java
  23. 4 14
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterfaceEventBasedImpl.java
  24. 11 22
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterfaceImpl.java
  25. 2 12
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IDefaultInterfaceImpl.java
  26. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IInterfacePedestrianImpl.java
  27. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IInterfaceTrafficLightImpl.java
  28. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfacePedestrian.java
  29. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfacePedestrianImpl.java
  30. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfaceTrafficLight.java
  31. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfaceTrafficLightImpl.java
  32. 28 35
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java
  33. 0 10
      examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingEventBasedStatemachine.java
  34. 140 0
      examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoBase.java
  35. 38 112
      examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoCycleBased.java
  36. 29 110
      examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoEventBased.java

+ 40 - 34
examples/org.yakindu.sct.example.trafficlight/.project

@@ -1,34 +1,40 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>org.yakindu.sct.examples.trafficlight</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.pde.ManifestBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.pde.SchemaBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
-		<nature>org.eclipse.pde.PluginNature</nature>
-	</natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.examples.trafficlight</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.yakindu.sct.builder.SCTBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.yakindu.sct.builder.SCTNature</nature>
+		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+	</natures>
+</projectDescription>

+ 26 - 9
examples/org.yakindu.sct.example.trafficlight/GenModelJava.sgen

@@ -1,25 +1,42 @@
 GeneratorModel for yakindu::java {
-	statechart TrafficLightWaiting {
-		
+
+	statechart  TrafficLightWaiting {
+	 	
 		feature Outlet {
 			targetProject = "org.yakindu.sct.examples.trafficlight"
 			targetFolder = "src-gen"
 		}
 
+
 		feature GeneralFeatures {
 			EventBasedStatemachine = true
 			InterfaceObserverSupport = false
 			TimerService = true
 			RuntimeService = true
 		}
+ 
+//		feature FunctionInlining {
+//			inlineChoices = true
+//			inlineEnterSequences = true
+//			inlineEntryActions = true
+//			inlineExitActions = true
+//			inlineExitSequences = true
+//			inlineReactions = true
+//		}
+		
+		
+		feature LicenseHeader {
+			licenseText = "
+Copyright (c) 2011 committers of YAKINDU and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
 
-		feature FunctionInlining {
-			inlineChoices = true
-			inlineEnterSequences = true
-			inlineEntryActions = true
-			inlineExitActions = true
-			inlineExitSequences = true
-			inlineReactions = true
+Contributors:
+    committers of YAKINDU - initial API and implementation
+â"
 		}
+		
 	}
 }

Разница между файлами не показана из-за своего большого размера
+ 26 - 26
examples/org.yakindu.sct.example.trafficlight/TrafficLightWaiting.sct


+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/Event.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/EventNotification.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import org.yakindu.sct.runtime.java.Event;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/EventVector.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import java.util.Collection;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/INotificationListener.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/INotificationSender.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/IStatemachine.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimedStatemachine.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import org.yakindu.sct.runtime.java.ITimerNotificationListener;

+ 18 - 29
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimerNotificationListener.java

@@ -1,29 +1,18 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
-package org.yakindu.sct.runtime.java;
-
-/**
- * 
- * Interface for {@link TimeEvent} listeners. These listers can be registered at
- * a {@link ITimerService}. Used by {@link ITimedStatemachine} to register
- * itself at the {@link ITimerService}.
- * 
- */
-public interface ITimerNotificationListener {
-
-	/**
-	 * Callback method if a {@link TimeEvent} occurred.
-	 * 
-	 * @param timeEvent
-	 */
-	public void onTimeEventRaised(TimeEvent<? extends Enum<?>> timeEvent);
-
-}
+package org.yakindu.sct.runtime.java;
+
+/**
+ * 
+ * Interface for {@link TimeEvent} listeners. These listers can be registered at
+ * a {@link ITimerService}. Used by {@link ITimedStatemachine} to register
+ * itself at the {@link ITimerService}.
+ * 
+ */
+public interface ITimerNotificationListener {
+
+	/**
+	 * Callback method if a {@link TimeEvent} occurred.
+	 * @param timeEvent
+	 */
+	public void onTimeEventRaised(TimeEvent<? extends Enum<?>> timeEvent);
+
+}

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ITimerService.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/Notification.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationSender.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import java.util.HashSet;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/NotificationType.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeCycleNotification.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/RuntimeService.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import java.util.LinkedList;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimeEvent.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/TimerService.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 import java.util.HashMap;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/ValuedEvent.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/VariableNotification.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java;
 
 /**

+ 3 - 13
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterface.java

@@ -1,23 +1,13 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public interface DefaultInterface {
 
 	public enum Events {
-		Keypress1, Keypress2,
+		PedestrianRequest, OnOff,
 	}
 
-	public void raiseKeypress1();
+	public void raisePedestrianRequest();
 
-	public void raiseKeypress2();
+	public void raiseOnOff();
 
 }

+ 4 - 14
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterfaceEventBasedImpl.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public class DefaultInterfaceEventBasedImpl extends DefaultInterfaceImpl {
@@ -17,12 +7,12 @@ public class DefaultInterfaceEventBasedImpl extends DefaultInterfaceImpl {
 		super(statemachine);
 	}
 
-	public void raiseKeypress1() {
-		super.raiseKeypress1();
+	public void raisePedestrianRequest() {
+		super.raisePedestrianRequest();
 		statemachine.runCycle();
 	}
-	public void raiseKeypress2() {
-		super.raiseKeypress2();
+	public void raiseOnOff() {
+		super.raiseOnOff();
 		statemachine.runCycle();
 	}
 

+ 11 - 22
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/DefaultInterfaceImpl.java

@@ -1,22 +1,11 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 import org.yakindu.sct.runtime.java.Event;
 
 public class DefaultInterfaceImpl implements IDefaultInterfaceImpl {
-	protected final Event<Events> Keypress1 = new Event<Events>(
-			Events.Keypress1, 0);
-	protected final Event<Events> Keypress2 = new Event<Events>(
-			Events.Keypress2, 0);
+	protected final Event<Events> PedestrianRequest = new Event<Events>(
+			Events.PedestrianRequest, 0);
+	protected final Event<Events> OnOff = new Event<Events>(Events.OnOff, 0);
 
 	protected TrafficLightWaitingCycleBasedStatemachine statemachine;
 
@@ -26,20 +15,20 @@ public class DefaultInterfaceImpl implements IDefaultInterfaceImpl {
 		this.statemachine = statemachine;
 	}
 
-	public void raiseKeypress1() {
-		statemachine.getOccuredEvents().add(getEventKeypress1());
+	public void raisePedestrianRequest() {
+		statemachine.getOccuredEvents().add(getEventPedestrianRequest());
 	}
 
-	public Event<Events> getEventKeypress1() {
-		return Keypress1;
+	public Event<Events> getEventPedestrianRequest() {
+		return PedestrianRequest;
 	}
 
-	public void raiseKeypress2() {
-		statemachine.getOccuredEvents().add(getEventKeypress2());
+	public void raiseOnOff() {
+		statemachine.getOccuredEvents().add(getEventOnOff());
 	}
 
-	public Event<Events> getEventKeypress2() {
-		return Keypress2;
+	public Event<Events> getEventOnOff() {
+		return OnOff;
 	}
 
 }

+ 2 - 12
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IDefaultInterfaceImpl.java

@@ -1,21 +1,11 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 import org.yakindu.sct.runtime.java.Event;
 
 public interface IDefaultInterfaceImpl extends DefaultInterface {
 
-	public Event<Events> getEventKeypress1();
+	public Event<Events> getEventPedestrianRequest();
 
-	public Event<Events> getEventKeypress2();
+	public Event<Events> getEventOnOff();
 
 }

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IInterfacePedestrianImpl.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public interface IInterfacePedestrianImpl extends InterfacePedestrian {

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/IInterfaceTrafficLightImpl.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public interface IInterfaceTrafficLightImpl extends InterfaceTrafficLight {

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfacePedestrian.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public interface InterfacePedestrian {

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfacePedestrianImpl.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public class InterfacePedestrianImpl implements IInterfacePedestrianImpl {

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfaceTrafficLight.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public interface InterfaceTrafficLight {

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/InterfaceTrafficLightImpl.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 public class InterfaceTrafficLightImpl implements IInterfaceTrafficLightImpl {

+ 28 - 35
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingCycleBasedStatemachine.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 import java.util.Collection;
@@ -152,16 +142,18 @@ public class TrafficLightWaitingCycleBasedStatemachine
 		return defaultInterface;
 	}
 
-	public void raiseKeypress1() {
-		getDefaultInterface().raiseKeypress1();
+	public void raisePedestrianRequest() {
+		getDefaultInterface().raisePedestrianRequest();
 	}
 
-	public void raiseKeypress2() {
-		getDefaultInterface().raiseKeypress2();
+	public void raiseOnOff() {
+		getDefaultInterface().raiseOnOff();
 	}
 
 	public void enter() {
 		cycleStartTime = System.currentTimeMillis();
+
+		// unknown function type org.yakindu.sct.model.sexec.impl.SequenceImpl@759376db (name: entryAction) (comment: Entry action for statechart 'TrafficLightWaiting'.)();
 		getInterfaceTrafficLightImpl().setVarRed(false);
 		getInterfaceTrafficLightImpl().setVarYellow(false);
 		getInterfaceTrafficLightImpl().setVarGreen(true);
@@ -247,13 +239,13 @@ public class TrafficLightWaitingCycleBasedStatemachine
 				break;
 		}
 
+		// unknown function type org.yakindu.sct.model.sexec.impl.SequenceImpl@6e1f487e (name: exitAction) (comment: Exit action for state 'TrafficLightWaiting'.)();
 	}
 
 	private void reactOn() {
 	}
 	private void reactStreetGreen() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -323,13 +315,14 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
 
 		} else {
 			if (occuredEvents.contains(getDefaultInterfaceImpl()
-					.getEventKeypress1())) {
+					.getEventPedestrianRequest())) {
 				stateVector[0] = State.$NullState$;
 
 				getTimerService().setTimer(PedWaiting_time_event_0, (7 * 1000),
@@ -350,8 +343,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 	private void reactPedWaiting() {
 	}
 	private void reactWaitOn() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -421,6 +413,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -478,8 +471,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactWaitOff() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -549,6 +541,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -606,8 +599,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactStreetAttention() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -677,6 +669,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -701,8 +694,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactStreetRed() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -772,6 +764,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -795,8 +788,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactPedestrianGreen() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -866,6 +858,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -889,8 +882,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactPedestrianRed() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -960,6 +952,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -984,8 +977,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactStreetPrepare() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -1055,6 +1047,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 			getTimerService().setTimer(YellowOn_time_event_0, 500,
 					cycleStartTime);
 			getInterfaceTrafficLightImpl().setVarYellow(true);
+			getInterfacePedestrianImpl().setVarRequest(true);
 
 			nextStateIndex = 0;
 			stateVector[0] = State.YellowOn;
@@ -1082,8 +1075,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 	private void reactOff() {
 	}
 	private void reactYellowOn() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -1121,6 +1113,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 				getTimerService().setTimer(YellowOff_time_event_0, 500,
 						cycleStartTime);
 				getInterfaceTrafficLightImpl().setVarYellow(false);
+				getInterfacePedestrianImpl().setVarRequest(false);
 
 				nextStateIndex = 0;
 				stateVector[0] = State.YellowOff;
@@ -1131,8 +1124,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 
 	}
 	private void reactYellowOff() {
-		if (occuredEvents.contains(getDefaultInterfaceImpl()
-				.getEventKeypress2())) {
+		if (occuredEvents.contains(getDefaultInterfaceImpl().getEventOnOff())) {
 			//Handle exit of all possible states (of r1) at position 0...
 			switch (stateVector[0]) {
 
@@ -1170,6 +1162,7 @@ public class TrafficLightWaitingCycleBasedStatemachine
 				getTimerService().setTimer(YellowOn_time_event_0, 500,
 						cycleStartTime);
 				getInterfaceTrafficLightImpl().setVarYellow(true);
+				getInterfacePedestrianImpl().setVarRequest(true);
 
 				nextStateIndex = 0;
 				stateVector[0] = State.YellowOn;

+ 0 - 10
examples/org.yakindu.sct.example.trafficlight/src-gen/org/yakindu/sct/runtime/java/trafficlightwaiting/TrafficLightWaitingEventBasedStatemachine.java

@@ -1,13 +1,3 @@
-/**
-Copyright (c) 2011 committers of YAKINDU and others. 
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
- 
-Contributors:
-	committers of YAKINDU - initial API and implementation
- */
 package org.yakindu.sct.runtime.java.trafficlightwaiting;
 
 import java.util.LinkedList;

+ 140 - 0
examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoBase.java

@@ -0,0 +1,140 @@
+package org.yakindu.sct.examples.java.trafficlight;
+
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.LightweightSystem;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.yakindu.sct.runtime.java.trafficlightwaiting.TrafficLightWaitingCycleBasedStatemachine;
+
+/**
+ * This class cares about setting up the UI of the pesestrian crossing and delegates the state machine handling to the concrete subcasses.
+ * 
+ * @author terfloth
+ */
+public abstract class CrossingDemoBase {
+
+	protected TrafficLightWaitingCycleBasedStatemachine statemachine;
+	protected Shell shell;
+	protected Display display;
+	protected CrossingFigure crossing;
+	protected TrafficLightFigure trafficLightFigure;
+	protected PedestrianLightFigure pedestrianLightFigure;
+
+	public CrossingDemoBase() {
+		super();
+	}
+
+	
+	protected abstract void setUpAndRunStatemachine();
+	protected abstract void tearDownStatemachine();
+
+	protected abstract void readStatemachineOutput();
+
+	protected abstract void pedestrianRequestButtonClicked();
+	protected abstract void onOffButtonClicked();
+
+
+	public void runTrafficLight() {
+	
+		setUpAndRunStatemachine();
+		createUIContent();
+	
+		shell.open();
+		while (!shell.isDisposed()) {
+			// update traffic lights
+			readStatemachineOutput();
+	
+			crossing.repaint();
+	
+			if (!display.readAndDispatch()) {
+				display.sleep();
+			}
+		}
+		
+		tearDownStatemachine();
+	}
+
+
+	
+	protected void createUIContent() {
+		display = Display.getDefault();
+		shell = new Shell(display);
+		shell.setSize(400, 400);
+		shell.setText("Traffic Light Demo");
+		GridLayout shellLayout = new GridLayout();
+		shellLayout.numColumns = 1;
+		shell.setLayout(shellLayout);
+	
+		LightweightSystem lws = createLightweightsystem(shell);
+		createButtonComposite(statemachine, shell);
+	
+		crossing = new CrossingFigure();
+		lws.setContents(crossing);
+		trafficLightFigure = new TrafficLightFigure();
+		crossing.add(trafficLightFigure);
+		crossing.getLayoutManager().setConstraint(trafficLightFigure,
+				new Rectangle(275, 75, 35, 90));
+	
+		pedestrianLightFigure = new PedestrianLightFigure();
+		crossing.add(pedestrianLightFigure);
+		crossing.getLayoutManager().setConstraint(pedestrianLightFigure,
+				new Rectangle(50, 10, 70, 20));
+	}
+
+	protected LightweightSystem createLightweightsystem(Shell shell) {
+	
+		FigureCanvas canvas = new FigureCanvas(shell);
+		GridData canvasGridData = new GridData();
+		canvasGridData.horizontalAlignment = GridData.FILL;
+		canvasGridData.verticalAlignment = GridData.FILL;
+		canvasGridData.grabExcessVerticalSpace = true;
+		canvasGridData.grabExcessHorizontalSpace = true;
+		canvas.setLayoutData(canvasGridData);
+		LightweightSystem lws = new LightweightSystem(canvas);
+		return lws;
+	}
+
+	protected void createButtonComposite(final TrafficLightWaitingCycleBasedStatemachine statemachine, Shell shell) {
+		// create a composite to hold the buttons
+		Composite buttonComposite = new Composite(shell, SWT.NO_SCROLL);
+		GridData buttonCompositeGridData = new GridData();
+		buttonCompositeGridData.horizontalAlignment = GridData.FILL;
+		buttonCompositeGridData.grabExcessHorizontalSpace = true;
+		buttonComposite.setLayoutData(buttonCompositeGridData);
+		FillLayout buttonCompositeLayout = new FillLayout();
+		buttonCompositeLayout.type = SWT.HORIZONTAL;
+		buttonComposite.setLayout(new FillLayout());
+	
+		// create a button and event handlers
+		
+		Button pedestrianRequest = new Button(buttonComposite, SWT.PUSH);
+		pedestrianRequest.setText("pedestrian request");
+		pedestrianRequest.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(
+					final org.eclipse.swt.widgets.Event event) {
+				pedestrianRequestButtonClicked();
+			}
+
+		});
+		
+		Button onOff = new Button(buttonComposite, SWT.PUSH);
+		onOff.setText("on / off");
+		onOff.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(
+					final org.eclipse.swt.widgets.Event event) {
+				onOffButtonClicked();
+			}
+
+		});
+	}
+
+
+}

+ 38 - 112
examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoCycleBased.java

@@ -15,54 +15,25 @@ package org.yakindu.sct.examples.java.trafficlight;
  * 
  * @author a.nyssen - initial API and implementation
  * @author m.muehlbrandt - adaptions to new statemachine code.
+ * @author terfloth - refactoring
  */
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.LightweightSystem;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
 import org.yakindu.sct.runtime.java.TimerService;
 import org.yakindu.sct.runtime.java.trafficlightwaiting.TrafficLightWaitingCycleBasedStatemachine;
 
-public class CrossingDemoCycleBased {
+public class CrossingDemoCycleBased extends CrossingDemoBase {
 
+	
 	public static void main(String[] args) {
+		
+		new CrossingDemoCycleBased().runTrafficLight();
+	}
 
-		final TrafficLightWaitingCycleBasedStatemachine statemachine = new TrafficLightWaitingCycleBasedStatemachine();
-
-		// create display and shell
-		Display display = Display.getDefault();
-		Shell shell = new Shell(display);
-		shell.setSize(400, 400);
-		shell.setText("Traffic Light Demo");
-		GridLayout shellLayout = new GridLayout();
-		shellLayout.numColumns = 1;
-		shell.setLayout(shellLayout);
-
-		LightweightSystem lws = createLightweightsystem(shell);
-		createButtonComposite(statemachine, shell);
-
-		CrossingFigure crossing = new CrossingFigure();
-		lws.setContents(crossing);
-		final TrafficLightFigure tl = new TrafficLightFigure();
-		crossing.add(tl);
-		crossing.getLayoutManager().setConstraint(tl,
-				new Rectangle(275, 75, 35, 90));
-
-		final PedestrianLightFigure pl = new PedestrianLightFigure();
-		crossing.add(pl);
-		crossing.getLayoutManager().setConstraint(pl,
-				new Rectangle(50, 10, 70, 20));
-
+	
+	@Override
+	protected void setUpAndRunStatemachine() {
+		
+		statemachine = new TrafficLightWaitingCycleBasedStatemachine();
+		
 		Thread thread = new Thread() {
 			@Override
 			public void run() {
@@ -72,7 +43,6 @@ public class CrossingDemoCycleBased {
 				// implementation of a TimerHandler. It has to implement the
 				// ITimerHandler interface.
 				statemachine.setTimerService(new TimerService());
-				statemachine.init();
 				statemachine.enter();
 				while (!isInterrupted()) {
 					statemachine.runCycle();
@@ -82,87 +52,43 @@ public class CrossingDemoCycleBased {
 						interrupt();
 					}
 				}
-				// End TimerHandler and timing thread.
-				statemachine.getTimerService().cancel();
 			}
 		};
 		thread.start();
-		shell.open();
-		while (!shell.isDisposed()) {
-			// update traffic lights
-			tl.setRed(statemachine.getInterfaceTrafficLight().getVarRed());
-			tl.setYellow(statemachine.getInterfaceTrafficLight().getVarYellow());
-			tl.setGreen(statemachine.getInterfaceTrafficLight().getVarGreen());
-
-			pl.setWhite(statemachine.getInterfacePedestrian().getVarRequest());
-			pl.setRed(statemachine.getInterfacePedestrian().getVarRed());
-			pl.setGreen(statemachine.getInterfacePedestrian().getVarGreen());
+	}
 
-			crossing.repaint();
 
-			if (!display.readAndDispatch()) {
-				display.sleep();
-			}
-		}
-		thread.interrupt();
+	@Override
+	protected void tearDownStatemachine() {
+		// End TimerHandler and timing thread.
+		statemachine.getTimerService() .cancel();
 	}
 
-	private static LightweightSystem createLightweightsystem(Shell shell) {
 
-		FigureCanvas canvas = new FigureCanvas(shell);
-		GridData canvasGridData = new GridData();
-		canvasGridData.horizontalAlignment = GridData.FILL;
-		canvasGridData.verticalAlignment = GridData.FILL;
-		canvasGridData.grabExcessVerticalSpace = true;
-		canvasGridData.grabExcessHorizontalSpace = true;
-		canvas.setLayoutData(canvasGridData);
-		LightweightSystem lws = new LightweightSystem(canvas);
-		return lws;
+	@Override
+	protected void readStatemachineOutput() {
+		trafficLightFigure.setRed(statemachine.getInterfaceTrafficLight().getVarRed());
+		trafficLightFigure.setYellow(statemachine.getInterfaceTrafficLight().getVarYellow());
+		trafficLightFigure.setGreen(statemachine.getInterfaceTrafficLight().getVarGreen());
+	
+		pedestrianLightFigure.setWhite(statemachine.getInterfacePedestrian().getVarRequest());
+		pedestrianLightFigure.setRed(statemachine.getInterfacePedestrian().getVarRed());
+		pedestrianLightFigure.setGreen(statemachine.getInterfacePedestrian().getVarGreen());
 	}
 
-	private static void createButtonComposite(
-			final TrafficLightWaitingCycleBasedStatemachine statemachine,
-			Shell shell) {
-		// create a composite to hold the buttons
-		Composite buttonComposite = new Composite(shell, SWT.NO_SCROLL);
-		GridData buttonCompositeGridData = new GridData();
-		buttonCompositeGridData.horizontalAlignment = GridData.FILL;
-		buttonCompositeGridData.grabExcessHorizontalSpace = true;
-		buttonComposite.setLayoutData(buttonCompositeGridData);
-		FillLayout buttonCompositeLayout = new FillLayout();
-		buttonCompositeLayout.type = SWT.HORIZONTAL;
-		buttonComposite.setLayout(new FillLayout());
 
-		// create a button for each KEYPRESS event
-		Button[] button = new Button[2];
-		for (int i = 0; i < 2; i++) {
-			button[i] = new Button(buttonComposite, SWT.PUSH);
-			button[i].setText("key" + (i + 1));
-			final int j = i;
-			button[i].addListener(SWT.Selection, new Listener() {
-				public void handleEvent(
-						final org.eclipse.swt.widgets.Event event) {
+	@Override
+	protected void pedestrianRequestButtonClicked() {
+		statemachine.raisePedestrianRequest(); // raise event in statemachine
+	}
 
-					try {
-						Class<?> interfaceClass = statemachine
-								.getDefaultInterface().getClass();
-						interfaceClass.getDeclaredMethod(
-								"raiseKeypress" + (j + 1), new Class[0])
-								.invoke(statemachine.getDefaultInterface(),
-										new Object[0]);
-					} catch (IllegalAccessException e) {
-						e.printStackTrace();
-					} catch (IllegalArgumentException e) {
-						e.printStackTrace();
-					} catch (InvocationTargetException e) {
-						e.printStackTrace();
-					} catch (NoSuchMethodException e) {
-						e.printStackTrace();
-					} catch (SecurityException e) {
-						e.printStackTrace();
-					}
-				}
-			});
-		}
+
+	@Override
+	protected void onOffButtonClicked() {
+		statemachine.raiseOnOff(); // raise event in statemachine
 	}
+	
+	
+	
+	
 }

+ 29 - 110
examples/org.yakindu.sct.example.trafficlight/src/org/yakindu/sct/examples/java/trafficlight/CrossingDemoEventBased.java

@@ -16,134 +16,53 @@ package org.yakindu.sct.examples.java.trafficlight;
  * 
  * @author a.nyssen - initial API and implementation
  * @author m.muehlbrandt - adaptions to new statemachine code.
+ * @author terfloth - refactoring
  */
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.LightweightSystem;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
 import org.yakindu.sct.runtime.java.TimerService;
-import org.yakindu.sct.runtime.java.trafficlightwaiting.TrafficLightWaitingCycleBasedStatemachine;
 import org.yakindu.sct.runtime.java.trafficlightwaiting.TrafficLightWaitingEventBasedStatemachine;
 
-public class CrossingDemoEventBased {
+public class CrossingDemoEventBased extends CrossingDemoBase {
 
 	public static void main(String[] args) {
 
-		final TrafficLightWaitingEventBasedStatemachine statemachine = new TrafficLightWaitingEventBasedStatemachine();
-
-		// create display and shell
-		Display display = Display.getDefault();
-		Shell shell = new Shell(display);
-		shell.setSize(400, 400);
-		shell.setText("Traffic Light Demo");
-		GridLayout shellLayout = new GridLayout();
-		shellLayout.numColumns = 1;
-		shell.setLayout(shellLayout);
-
-		LightweightSystem lws = createLightweightsystem(shell);
-		createButtonComposite(statemachine, shell);
+		new CrossingDemoCycleBased().runTrafficLight();
+	}
 
-		CrossingFigure crossing = new CrossingFigure();
-		lws.setContents(crossing);
-		final TrafficLightFigure tl = new TrafficLightFigure();
-		crossing.add(tl);
-		crossing.getLayoutManager().setConstraint(tl,
-				new Rectangle(275, 75, 35, 90));
+	@Override
+	protected void setUpAndRunStatemachine() {
 
-		final PedestrianLightFigure pl = new PedestrianLightFigure();
-		crossing.add(pl);
-		crossing.getLayoutManager().setConstraint(pl,
-				new Rectangle(50, 10, 70, 20));
+		statemachine = new TrafficLightWaitingEventBasedStatemachine();
 
 		statemachine.setTimerService(new TimerService());
 		statemachine.enter();
-
-		shell.open();
-		while (!shell.isDisposed()) {
-			// update traffic lights
-			tl.setRed(statemachine.getInterfaceTrafficLight().getVarRed());
-			tl.setYellow(statemachine.getInterfaceTrafficLight().getVarYellow());
-			tl.setGreen(statemachine.getInterfaceTrafficLight().getVarGreen());
-
-			pl.setWhite(statemachine.getInterfacePedestrian().getVarRequest());
-			pl.setRed(statemachine.getInterfacePedestrian().getVarRed());
-			pl.setGreen(statemachine.getInterfacePedestrian().getVarGreen());
-
-			crossing.repaint();
-
-			if (!display.readAndDispatch()) {
-				display.sleep();
-			}
-		}
+	}
+	
+	@Override
+	protected void tearDownStatemachine() {
+		// End TimerHandler and timing thread.
 		statemachine.getTimerService().cancel();
 	}
 
-	private static LightweightSystem createLightweightsystem(Shell shell) {
+	@Override
+	protected void readStatemachineOutput() {
+		trafficLightFigure.setRed(statemachine.getInterfaceTrafficLight().getVarRed());
+		trafficLightFigure.setYellow(statemachine.getInterfaceTrafficLight().getVarYellow());
+		trafficLightFigure.setGreen(statemachine.getInterfaceTrafficLight().getVarGreen());
+	
+		pedestrianLightFigure.setWhite(statemachine.getInterfacePedestrian().getVarRequest());
+		pedestrianLightFigure.setRed(statemachine.getInterfacePedestrian().getVarRed());
+		pedestrianLightFigure.setGreen(statemachine.getInterfacePedestrian().getVarGreen());
+	}
 
-		FigureCanvas canvas = new FigureCanvas(shell);
-		GridData canvasGridData = new GridData();
-		canvasGridData.horizontalAlignment = GridData.FILL;
-		canvasGridData.verticalAlignment = GridData.FILL;
-		canvasGridData.grabExcessVerticalSpace = true;
-		canvasGridData.grabExcessHorizontalSpace = true;
-		canvas.setLayoutData(canvasGridData);
-		LightweightSystem lws = new LightweightSystem(canvas);
-		return lws;
+	@Override
+	protected void pedestrianRequestButtonClicked() {
+		statemachine.raisePedestrianRequest(); // raise event in statemachine
 	}
 
-	private static void createButtonComposite(
-			final TrafficLightWaitingCycleBasedStatemachine statemachine,
-			Shell shell) {
-		// create a composite to hold the buttons
-		Composite buttonComposite = new Composite(shell, SWT.NO_SCROLL);
-		GridData buttonCompositeGridData = new GridData();
-		buttonCompositeGridData.horizontalAlignment = GridData.FILL;
-		buttonCompositeGridData.grabExcessHorizontalSpace = true;
-		buttonComposite.setLayoutData(buttonCompositeGridData);
-		FillLayout buttonCompositeLayout = new FillLayout();
-		buttonCompositeLayout.type = SWT.HORIZONTAL;
-		buttonComposite.setLayout(new FillLayout());
+	@Override
+	protected void onOffButtonClicked() {
+		statemachine.raiseOnOff(); // raise event in statemachine
+	}
 
-		// create a button for each KEYPRESS event
-		Button[] button = new Button[2];
-		for (int i = 0; i < 2; i++) {
-			button[i] = new Button(buttonComposite, SWT.PUSH);
-			button[i].setText("key" + (i + 1));
-			final int j = i;
-			button[i].addListener(SWT.Selection, new Listener() {
-				public void handleEvent(
-						final org.eclipse.swt.widgets.Event event) {
 
-					try {
-						Class<?> interfaceClass = statemachine
-								.getDefaultInterface().getClass();
-						interfaceClass.getDeclaredMethod(
-								"raiseKeypress" + (j + 1), new Class[0])
-								.invoke(statemachine.getDefaultInterface(),
-										new Object[0]);
-					} catch (IllegalAccessException e) {
-						e.printStackTrace();
-					} catch (IllegalArgumentException e) {
-						e.printStackTrace();
-					} catch (InvocationTargetException e) {
-						e.printStackTrace();
-					} catch (NoSuchMethodException e) {
-						e.printStackTrace();
-					} catch (SecurityException e) {
-						e.printStackTrace();
-					}
-				}
-			});
-		}
-	}
 }