--- /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.g2d.diagram.participant;\r
+\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.Heartbeat;\r
+import org.simantics.g2d.participant.TimeParticipant;\r
+import org.simantics.scenegraph.g2d.events.TimeEvent;\r
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
+\r
+/**\r
+ * This participant sends time events to Heartbeat element handlers.\r
+ * \r
+ * @See {@link Heartbeat}\r
+ * @author Toni Kalajainen\r
+ */\r
+public class ElementHeartbeater extends AbstractDiagramParticipant {\r
+\r
+ @Dependency TimeParticipant time;\r
+\r
+ @Override\r
+ public void addedToContext(ICanvasContext ctx) {\r
+ super.addedToContext(ctx);\r
+ time.registerForEvents(getClass());\r
+ }\r
+\r
+ @Override\r
+ public void removedFromContext(ICanvasContext ctx) {\r
+ time.unregisterForEvents(getClass());\r
+ super.removedFromContext(ctx);\r
+ }\r
+\r
+ @EventHandler(priority = 0)\r
+ public boolean handleHeartbeat(TimeEvent te) {\r
+ IDiagram d = diagram;\r
+ if (d==null) return false;\r
+ for (IElement e : d.getSnapshot())\r
+ {\r
+ for (Heartbeat hb : e.getElementClass().getItemsByClass(Heartbeat.class))\r
+ hb.heartbeat(e, te.time, te.interval, getContext());\r
+ }\r
+ return false;\r
+ }\r
+\r
+}\r