1 package pl.caltha.forms.internal.ui.actions;
2
3 import org.xml.sax.Attributes;
4
5 import pl.caltha.forms.ConstructionException;
6 import pl.caltha.forms.internal.model.InstanceImpl;
7 import pl.caltha.forms.internal.ui.ActionEvent;
8 import pl.caltha.forms.internal.ui.ActionNode;
9 import pl.caltha.forms.internal.ui.Node;
10 import pl.caltha.forms.internal.ui.UI;
11 import pl.caltha.forms.internal.util.Util;
12
13 /*** Toggle action for switch/case and form/page elements.
14 *
15 * @author <a href="mailto:zwierzem@ngo.pl">Damian Gajda</a>
16 * @version $Id: Dispatch.java,v 1.1 2005/01/19 06:55:32 pablo Exp $
17 */
18 public class Dispatch extends pl.caltha.forms.internal.ui.Action
19 {
20 public Dispatch(String type, Attributes atts)
21 throws ConstructionException
22 {
23 super(type, atts);
24 eventName = Util.getSAXAttributeVal(atts, "name");
25 targetNodeId = Util.getSAXAttributeVal(atts, "target");
26 bubbles = Util.createBooleanAttribute(atts, "bubbles", true);
27 cancelable = Util.createBooleanAttribute(atts, "cancelable", true);
28 }
29
30 private ActionNode targetNode;
31
32 private String eventName;
33 private String targetNodeId;
34 private boolean bubbles;
35 private boolean cancelable;
36
37 /*** This method performs the action, ie. dispatches an event
38 * to a given target.
39 */
40 public void execute(UI ui, InstanceImpl instance, ActionEvent evt)
41 {
42 targetNode.dispatchEvent(ui, instance, new ActionEvent(eventName, (Node)(targetNode)));
43 }
44
45
46
47
48 /*** Inits a dispatch action node - connects a referenced <code>target</code>
49 * element..
50 * @throws ConstructionException Thrown on initialisation errors
51 */
52 protected void init(UI ui)
53 throws ConstructionException
54 {
55 super.init(ui);
56 targetNode = (ActionNode)(getNodeById(ui, targetNodeId));
57 }
58 }