1 /*
2 * Created on 24.mar.2003
3 *
4 */
5 package net.sf.panoptes.view.configurator;
6
7 import java.io.StringWriter;
8 import java.io.Writer;
9 import java.util.HashMap;
10
11 import org.apache.commons.jelly.JellyContext;
12 import org.apache.commons.jelly.XMLOutput;
13 import org.eclipse.swt.layout.FillLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16
17 import net.sf.panoptes.controller.MainController;
18 import net.sf.panoptes.model.component.Component;
19 import net.sf.panoptes.model.node.Node;
20 import net.sf.panoptes.model.node.NodeUpdateEvent;
21
22 /***
23 *
24 *
25 * @author Dag Liodden
26 * @version 0.1
27 */
28 public class JellyConfigurator extends NodeConfigurator {
29
30 private Component component = null;
31 /***
32 * The Jelly context to run in
33 */
34 final JellyContext context = new JellyContext();
35
36 public JellyConfigurator(MainController controller, Composite parent, int style, HashMap attributes) {
37 super(controller, parent, style, attributes);
38 setLayout(new FillLayout());
39 }
40
41 public void execJelly() {
42 /***
43 * Dispose of old widgets
44 */
45 Control[] widgets = getChildren();
46 for (int i = 0; i < widgets.length; i++)
47 widgets[i].dispose();
48
49 String script = (String) getAttribute("script");
50 if (script == null) {
51 getController().displayError("Jelly Execution failed", "No script associated with this component.");
52 }
53
54 try {
55 context.setVariable("container", this);
56 context.setVariable("component", component);
57
58 Writer output = new StringWriter(0);
59 XMLOutput xmlOutput = XMLOutput.createXMLOutput(output); // Why do I need this?
60 long startTime = System.currentTimeMillis();
61 context.runScript(script, xmlOutput);
62 System.out.println("Jelly execution time:" + (System.currentTimeMillis() - startTime));
63
64 } catch (Exception e) {
65 getController().displayError("Jelly Execution failed", e.getMessage(), e);
66 }
67 }
68
69 /* (non-Javadoc)
70 * @see net.sf.panoptes.view.configurator.NodeConfigurator#setNode(net.sf.panoptes.model.node.Node)
71 */
72 public void setNode(Node node) {
73 component = (Component) node;
74 execJelly();
75 }
76
77 /* (non-Javadoc)
78 * @see net.sf.panoptes.view.configurator.NodeConfigurator#refresh()
79 */
80 public void refresh() {
81 }
82
83 /* (non-Javadoc)
84 * @see net.sf.panoptes.model.node.NodeUpdateListener#nodeUpdated(net.sf.panoptes.model.node.NodeUpdateEvent)
85 */
86 public void nodeUpdated(NodeUpdateEvent event) {
87
88 }
89
90 }
This page was automatically generated by Maven