]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementHeartbeater.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / participant / ElementHeartbeater.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.diagram.participant;
13
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;
22
23 /**
24  * This participant sends time events to Heartbeat element handlers.
25  * 
26  * @See {@link Heartbeat}
27  * @author Toni Kalajainen
28  */
29 public class ElementHeartbeater extends AbstractDiagramParticipant {
30
31     @Dependency TimeParticipant time;
32
33     @Override
34     public void addedToContext(ICanvasContext ctx) {
35         super.addedToContext(ctx);
36         time.registerForEvents(getClass());
37     }
38
39     @Override
40     public void removedFromContext(ICanvasContext ctx) {
41                 time.unregisterForEvents(getClass());
42         super.removedFromContext(ctx);
43     }
44
45     @EventHandler(priority = 0)
46     public boolean handleHeartbeat(TimeEvent te) {
47         IDiagram d = diagram;
48         if (d==null) return false;
49         for (IElement e : d.getSnapshot())
50         {
51             for (Heartbeat hb : e.getElementClass().getItemsByClass(Heartbeat.class))
52                 hb.heartbeat(e, te.time, te.interval, getContext());
53         }
54         return false;
55     }
56
57 }