KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > Main


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: Main.java,v 1.4 2005/07/01 15:55:17 moroy Exp $
27 ====================================================================*/

28 package org.objectweb.openccm.explorer;
29
30 import org.objectweb.fractal.adl.ADLException;
31 import org.objectweb.fractal.adl.Factory;
32 import org.objectweb.fractal.adl.FactoryFactory;
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
36 import org.objectweb.fractal.util.Fractal;
37
38 import org.objectweb.openccm.corba.TheORB;
39 import org.objectweb.openccm.explorer.CORBA.ConsoleFactory;
40 import org.objectweb.openccm.explorer.menu.Menu;
41 import org.objectweb.openccm.explorer.menu.TreeDialogSingleton;
42 import org.objectweb.util.explorer.api.Tree;
43 import org.objectweb.util.explorer.context.api.ContextParser;
44 import org.objectweb.util.explorer.parser.api.ParserConfiguration;
45 import org.objectweb.util.explorer.swing.api.Explorer;
46 import org.objectweb.util.explorer.swing.api.StatusBar;
47 import org.objectweb.util.explorer.swing.api.ViewPanel;
48 import org.objectweb.util.explorer.swing.lib.DefaultTreePanel;
49
50 /** The java API's imports */
51 import java.awt.Dimension JavaDoc;
52 import java.awt.BorderLayout JavaDoc;
53 //import java.awt.HeadlessException;
54
import java.awt.event.WindowAdapter JavaDoc;
55 import java.awt.event.WindowEvent JavaDoc;
56 import javax.swing.JFrame JavaDoc;
57 import javax.swing.ImageIcon JavaDoc;
58 import java.net.URL JavaDoc;
59 import javax.swing.JSplitPane JavaDoc;
60
61 /**
62  * This class defines the main frame
63  *
64  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
65  * @version 0.1
66  */

67 public class Main extends JFrame JavaDoc {
68
69     /**
70      * Populates the tree
71      */

72     protected void populateTree(Tree tree) {
73
74         // Adds the name service into the initial context
75
try {
76             org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("NameService");
77             tree.addEntry("NameService", o, 2);
78         } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
79             // NS is not started
80
e1.printStackTrace();
81         } catch (org.omg.CORBA.TRANSIENT JavaDoc e1) {
82             // e1.printStackTrace();
83
// Ignore (throws when the NameService is not started)
84
}
85
86         // Adds the interface repository into the initial context
87
try {
88             org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("InterfaceRepository");
89             tree.addEntry("InterfaceRepository", o);
90         } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
91             // IR is not started
92
}
93
94         // Adds the trading service into the initial context
95
try {
96             org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("TradingService");
97             tree.addEntry("TradingService", o);
98         } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
99             // Trader is not started
100
} catch (org.omg.CORBA.TRANSIENT JavaDoc e1) {
101             // Ignore (throws when the TradingService is not started)
102
}
103
104     }
105
106     protected void initializeTreeDialog(Tree treeItf) {
107         try {
108             Component treeComponent = treeItf.duplicate();
109             Tree tree = (Tree)treeComponent.getFcInterface(Tree.TREE);
110 // tree.setNewBrowserProperty(treeConfiguration.getBrowserProperty());
111
// tree.setNewContextProperty(treeConfiguration.getContextProperty());
112

113             // Adds the name service into the initial context
114
try {
115                 org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("NameService");
116                 tree.addEntry("NameService", o, 2);
117             } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
118                 // Trader is not started
119
} catch (org.omg.CORBA.TRANSIENT JavaDoc e1) {
120                 // Ignore (throws when the TradingService is not started)
121
}
122
123             // Adds the trading service into the initial context
124
try {
125                 org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("TradingService");
126                 tree.addEntry("TradingService", o);
127             } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
128                 // NS is not strated
129
} catch (org.omg.CORBA.TRANSIENT JavaDoc e1) {
130                 // Ignore (throws when the NameService is not started)
131
}
132
133             // Adds the dci manager into the initial context
134
try {
135                 org.omg.CORBA.Object JavaDoc o = TheORB.getORB().resolve_initial_references("DCI");
136                 tree.addEntry("DCI Manager", o, 1);
137             } catch (org.omg.CORBA.ORBPackage.InvalidName JavaDoc e1) {
138                 // Trader is not started
139
} catch (org.omg.CORBA.TRANSIENT JavaDoc e1) {
140                 // Ignore (throws when the TradingService is not started)
141
}
142
143             TreeDialogSingleton.setInstance(treeComponent);
144         } catch (NoSuchInterfaceException e) {
145             ConsoleFactory.getDebugConsole().add(e.getMessage());
146         }
147     }
148
149     /** Returns an ImageIcon, or null if the path is invalid. */
150     protected static ImageIcon JavaDoc createIcon(String JavaDoc imageName) {
151         if (imageName != null) {
152             URL JavaDoc urlFile = null;
153             urlFile = Thread.currentThread().getContextClassLoader().getResource(imageName);
154             if(urlFile==null){
155                 try {
156                     urlFile = new URL JavaDoc(imageName);
157                 } catch (java.net.MalformedURLException JavaDoc e) {
158                     System.out.println(imageName + ": Malformed URL !");
159                 }
160             }
161             if(urlFile!=null){
162                 return new ImageIcon JavaDoc(urlFile);
163             }
164         }
165         return null;
166     }
167
168     /**
169      * Initializes the OpenCCM Browser frame
170      */

171     protected void init(String JavaDoc contextPropertyFile, String JavaDoc[] browserPropertyFile){
172         try {
173             // Creates a Fractal Explorer instance.
174
Factory f = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
175             Component explorer = (Component)f.newComponent("org.objectweb.openccm.explorer.SwingCCMExplorer",null);
176             Fractal.getLifeCycleController(explorer).startFc();
177
178             // Loads the configuration file.
179
ParserConfiguration parser = (ParserConfiguration)explorer.getFcInterface(ParserConfiguration.PARSER_CONFIGURATION);
180             for (int i = 0; i < browserPropertyFile.length; i++) {
181                 parser.addPropertyFile(browserPropertyFile[i]);
182             }
183             parser.parse();
184
185             // Loads the context configuration file.
186
ContextParser cParser = (ContextParser)explorer.getFcInterface(ContextParser.CONTEXT_PARSER);
187             cParser.parse(contextPropertyFile);
188             
189             Explorer explorerItf = (Explorer)explorer.getFcInterface(Explorer.EXPLORER);
190             Tree treeItf = (Tree)explorer.getFcInterface(Tree.TREE);
191             
192             //setIconImage(createIcon("icons/tools.png").getImage());
193

194             // Creates the menu
195
Menu menu = new Menu(this, explorer);
196             
197             explorerItf.setMultipleRoles(true);
198             explorerItf.setCurrentRoles(new String JavaDoc[]{"user view","Deployment administrator","Components administrator","CORBA Administrator","CosNaming administrator"});
199             explorerItf.setMenuBar(menu.getMenuBar());
200             explorerItf.setToolBar(menu.getToolBar());
201             populateTree(treeItf);
202             
203             ViewPanel viewPanelItf = (ViewPanel)explorer.getFcInterface(ViewPanel.VIEW_PANEL);
204             StatusBar statusBarItf = (StatusBar)explorer.getFcInterface(StatusBar.STATUS_BAR);
205             
206             // Initializes the tree using in JDialog Boxes,
207
initializeTreeDialog(treeItf);
208
209             setJMenuBar(menu.getMenuBar());
210
211             getContentPane().setLayout(new BorderLayout JavaDoc());
212             getContentPane().add(menu.getToolBar(),BorderLayout.NORTH);
213             getContentPane().add(new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT, true, new DefaultTreePanel(explorerItf.getTree()), viewPanelItf.getViewPanel()), BorderLayout.CENTER);
214             getContentPane().add(statusBarItf.getStatusBar(),BorderLayout.SOUTH);
215
216             //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
217
addWindowListener(new OpenCCMWindowListener(treeItf));
218             pack();
219
220             // Centers the frame
221
Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
222             setLocation((screenSize.width - getWidth()) / 2, (screenSize.height - getHeight()) / 2);
223
224             setVisible(true);
225         } catch (ADLException e) {
226             System.err.println("ERROR: " + e.getMessage());
227             System.exit(1);
228         } catch (IllegalLifeCycleException e) {
229             System.err.println("ERROR: " + e.getMessage());
230             System.exit(1);
231         } catch (NoSuchInterfaceException e) {
232             System.err.println("ERROR: " + e.getMessage());
233             System.exit(1);
234         } catch (Exception JavaDoc e) {
235             System.err.println("ERROR: " + e.getMessage());
236             System.exit(1);
237         }
238     }
239
240     /**
241      * Default constructor
242      */

243     public Main(String JavaDoc contextPropertyFile, String JavaDoc[] browserPropertyFile) {
244
245         super("OpenCCM Explorer");
246         init(contextPropertyFile, browserPropertyFile);
247
248     }
249
250     /**
251      * Class to manage the window actions
252      */

253     protected class OpenCCMWindowListener extends WindowAdapter JavaDoc{
254         
255         protected Tree treeItf_;
256         
257         public OpenCCMWindowListener(Tree treeItf){
258             treeItf_ = treeItf;
259         }
260         
261         public void windowClosing(WindowEvent JavaDoc e) {
262             treeItf_.close();
263             ConsoleFactory.getDebugConsole().add("Shutting the ORB down\n");
264             TheORB.shutdown(false);
265             ConsoleFactory.getDebugConsole().add("Destroying the ORB\n");
266             TheORB.destroy();
267             System.exit(0);
268         }
269         
270     }
271
272 }
273
Popular Tags