1 /*
2 * Created on 09.mar.2003
3 *
4 */
5 package net.sf.panoptes.controller;
6
7 import java.io.FileInputStream;
8 import java.util.Iterator;
9
10 import net.sf.panoptes.controller.digester.ComponentFactory;
11 import net.sf.panoptes.controller.digester.SymLinkFactory;
12 import net.sf.panoptes.controller.digester.ComponentGroupNodeFactory;
13 import net.sf.panoptes.controller.digester.ComponentQueryFactory;
14 import net.sf.panoptes.controller.digester.ConfiguratorFactory;
15 import net.sf.panoptes.controller.digester.LoggerFactory;
16 import net.sf.panoptes.model.node.Node;
17 import net.sf.panoptes.model.node.NodeUpdateEvent;
18 import net.sf.panoptes.model.node.NodeUpdateListener;
19 import net.sf.panoptes.model.node.RootNode;
20 import net.sf.panoptes.view.MainWindow;
21 import net.sf.panoptes.view.configurator.NodeConfigurator;
22
23 import org.apache.commons.digester.Digester;
24 import org.apache.commons.digester.FactoryCreateRule;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.core.runtime.Status;
27 import org.eclipse.jface.dialogs.ErrorDialog;
28 import org.eclipse.swt.widgets.Display;
29
30 /***
31 * Main controller for Panoptes.
32 *
33 * @author Dag Liodden
34 * @version 0.1
35 */
36 public class MainController implements NodeUpdateListener {
37
38
39 private MainWindow mainWindow;
40
41 private RootNode rootNode;
42 private Node currentNode = null;
43
44 private MBeanConnectionController mbeanController;
45
46 public MainController() {
47 mbeanController = new MBeanConnectionController(this);
48 rootNode = new RootNode();
49
50 /***
51 * Populate the rootnode
52 */
53 try {
54 Digester digester = new Digester();
55 FileInputStream in = new FileInputStream("src/etc/panoptes-config.xml");
56 digester.addFactoryCreate("*/logger", new LoggerFactory(this, rootNode.getLoggerRepository(), rootNode.getComponentRegistry()));
57 digester.push(rootNode);
58 digester.addRule("*/group", new FactoryCreateRule(ComponentGroupNodeFactory.class));
59 digester.addFactoryCreate("*/symlink", new SymLinkFactory(rootNode.getComponentRegistry()));
60 digester.addFactoryCreate("*/component-query", new ComponentQueryFactory(rootNode.getComponentRegistry()));
61 digester.addFactoryCreate("*/component", new ComponentFactory(rootNode.getComponentRegistry()));
62 digester.addFactoryCreate("*/configurator", new ConfiguratorFactory(rootNode.getConfigRegistry()));
63 digester.parse(in);
64
65 } catch (Exception e) {
66 System.out.println("Unable to initialized - exiting.");
67 e.printStackTrace();
68 System.exit(0);
69 }
70
71 mainWindow = new MainWindow(this, rootNode);
72 }
73
74 /***
75 * @return MainWindow
76 */
77 public MainWindow getMainWindow() {
78 return mainWindow;
79 }
80
81 /***
82 * @return RootNode
83 */
84 public RootNode getRootNode() {
85 return rootNode;
86 }
87
88
89 /***
90 * Displays an error message.
91 *
92 * @param title
93 * @param message
94 */
95 public void displayError(String title, String message) {
96 displayError(title, message, null);
97 }
98
99 /***
100 * Displays an error message with a cause.
101 *
102 * @param title
103 * @param message
104 * @param exception
105 */
106 public void displayError(String title, String message, Throwable exception) {
107 if (message == null) message = "No message";
108 ErrorDialog dialog = new ErrorDialog(mainWindow.getShell(), title, message, new Status(Status.ERROR, " ", Status.OK, message, exception), IStatus.ERROR);
109 dialog.setBlockOnOpen(true);
110 dialog.open();
111 }
112
113 /***
114 *
115 */
116 public MBeanConnectionController getMBeanConnectionController() {
117 return mbeanController;
118 }
119
120 /* (non-Javadoc)
121 * @see net.sf.panoptes.model.node.NodeUpdateListener#nodeUpdated(net.sf.panoptes.model.node.NodeUpdateEvent)
122 */
123 public void nodeUpdated(final NodeUpdateEvent event) {
124 Display.getDefault().syncExec(new Runnable() {
125 public void run() {
126 for (Iterator i = mainWindow.getCurrentConfigurators().iterator(); i.hasNext(); ) {
127 ((NodeConfigurator) i.next()).nodeUpdated(event);
128 }
129 }
130 });
131 }
132
133 /***
134 * @return
135 */
136 public Node getCurrentNode() {
137 return currentNode;
138 }
139
140 /***
141 * @param node
142 */
143 public void setCurrentNode(Node node) {
144 if (currentNode != null) currentNode.removeUpdateListener(this);
145 currentNode = node;
146 currentNode.addUpdateListener(this);
147 }
148
149 }
This page was automatically generated by Maven