1 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 51 import java.awt.Dimension ; 52 import java.awt.BorderLayout ; 53 import java.awt.event.WindowAdapter ; 55 import java.awt.event.WindowEvent ; 56 import javax.swing.JFrame ; 57 import javax.swing.ImageIcon ; 58 import java.net.URL ; 59 import javax.swing.JSplitPane ; 60 61 67 public class Main extends JFrame { 68 69 72 protected void populateTree(Tree tree) { 73 74 try { 76 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("NameService"); 77 tree.addEntry("NameService", o, 2); 78 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 79 e1.printStackTrace(); 81 } catch (org.omg.CORBA.TRANSIENT e1) { 82 } 85 86 try { 88 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("InterfaceRepository"); 89 tree.addEntry("InterfaceRepository", o); 90 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 91 } 93 94 try { 96 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("TradingService"); 97 tree.addEntry("TradingService", o); 98 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 99 } catch (org.omg.CORBA.TRANSIENT e1) { 101 } 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 113 try { 115 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("NameService"); 116 tree.addEntry("NameService", o, 2); 117 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 118 } catch (org.omg.CORBA.TRANSIENT e1) { 120 } 122 123 try { 125 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("TradingService"); 126 tree.addEntry("TradingService", o); 127 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 128 } catch (org.omg.CORBA.TRANSIENT e1) { 130 } 132 133 try { 135 org.omg.CORBA.Object o = TheORB.getORB().resolve_initial_references("DCI"); 136 tree.addEntry("DCI Manager", o, 1); 137 } catch (org.omg.CORBA.ORBPackage.InvalidName e1) { 138 } catch (org.omg.CORBA.TRANSIENT e1) { 140 } 142 143 TreeDialogSingleton.setInstance(treeComponent); 144 } catch (NoSuchInterfaceException e) { 145 ConsoleFactory.getDebugConsole().add(e.getMessage()); 146 } 147 } 148 149 150 protected static ImageIcon createIcon(String imageName) { 151 if (imageName != null) { 152 URL urlFile = null; 153 urlFile = Thread.currentThread().getContextClassLoader().getResource(imageName); 154 if(urlFile==null){ 155 try { 156 urlFile = new URL (imageName); 157 } catch (java.net.MalformedURLException e) { 158 System.out.println(imageName + ": Malformed URL !"); 159 } 160 } 161 if(urlFile!=null){ 162 return new ImageIcon (urlFile); 163 } 164 } 165 return null; 166 } 167 168 171 protected void init(String contextPropertyFile, String [] browserPropertyFile){ 172 try { 173 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 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 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 194 Menu menu = new Menu(this, explorer); 196 197 explorerItf.setMultipleRoles(true); 198 explorerItf.setCurrentRoles(new String []{"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 initializeTreeDialog(treeItf); 208 209 setJMenuBar(menu.getMenuBar()); 210 211 getContentPane().setLayout(new BorderLayout ()); 212 getContentPane().add(menu.getToolBar(),BorderLayout.NORTH); 213 getContentPane().add(new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, true, new DefaultTreePanel(explorerItf.getTree()), viewPanelItf.getViewPanel()), BorderLayout.CENTER); 214 getContentPane().add(statusBarItf.getStatusBar(),BorderLayout.SOUTH); 215 216 addWindowListener(new OpenCCMWindowListener(treeItf)); 218 pack(); 219 220 Dimension 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 e) { 235 System.err.println("ERROR: " + e.getMessage()); 236 System.exit(1); 237 } 238 } 239 240 243 public Main(String contextPropertyFile, String [] browserPropertyFile) { 244 245 super("OpenCCM Explorer"); 246 init(contextPropertyFile, browserPropertyFile); 247 248 } 249 250 253 protected class OpenCCMWindowListener extends WindowAdapter { 254 255 protected Tree treeItf_; 256 257 public OpenCCMWindowListener(Tree treeItf){ 258 treeItf_ = treeItf; 259 } 260 261 public void windowClosing(WindowEvent 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 |