1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.diagram.participant;
14 import org.simantics.g2d.canvas.ICanvasContext;
15 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
16 import org.simantics.g2d.diagram.IDiagram;
17 import org.simantics.g2d.element.IElement;
18 import org.simantics.g2d.element.handler.Heartbeat;
19 import org.simantics.g2d.participant.TimeParticipant;
20 import org.simantics.scenegraph.g2d.events.TimeEvent;
21 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
24 * This participant sends time events to Heartbeat element handlers.
26 * @See {@link Heartbeat}
27 * @author Toni Kalajainen
29 public class ElementHeartbeater extends AbstractDiagramParticipant {
31 @Dependency TimeParticipant time;
34 public void addedToContext(ICanvasContext ctx) {
35 super.addedToContext(ctx);
36 time.registerForEvents(getClass());
40 public void removedFromContext(ICanvasContext ctx) {
41 time.unregisterForEvents(getClass());
42 super.removedFromContext(ctx);
45 @EventHandler(priority = 0)
46 public boolean handleHeartbeat(TimeEvent te) {
48 if (d==null) return false;
49 for (IElement e : d.getSnapshot())
51 for (Heartbeat hb : e.getElementClass().getItemsByClass(Heartbeat.class))
52 hb.heartbeat(e, te.time, te.interval, getContext());