1 26 package org.objectweb.openccm.explorer.menu; 27 28 import java.awt.Component ; 29 import java.awt.Dimension ; 30 import java.io.BufferedReader ; 31 import java.io.File ; 32 import java.io.FileReader ; 33 34 import javax.swing.ImageIcon ; 35 36 import org.objectweb.util.explorer.swing.gui.api.DialogAction; 37 import org.objectweb.util.explorer.swing.gui.api.DialogBox; 38 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox; 39 import org.objectweb.util.explorer.swing.gui.lib.TreeBox; 40 import org.omg.CORBA.ORB ; 41 42 49 public class LoadIORFileAction 50 extends AbstractMenuAction 51 implements DialogAction { 52 53 59 60 protected org.objectweb.util.explorer.swing.gui.lib.LabelBox name_ = null; 61 62 63 protected org.objectweb.util.explorer.swing.gui.lib.FileChooserBox iorFile_ = null; 64 65 66 protected TreeBox treeBox_ = null; 67 68 74 77 public LoadIORFileAction(String nom, ImageIcon image, String desc, Integer mnemonic, org.objectweb.fractal.api.Component tree, Component parent) { 78 super(nom, image, desc, mnemonic, tree); 79 } 80 81 87 90 protected void createBox(DialogBox dialogBox) { 91 name_ = new org.objectweb.util.explorer.swing.gui.lib.LabelBox("Object's name"); 92 dialogBox.addElementBox(name_); 93 iorFile_ = new org.objectweb.util.explorer.swing.gui.lib.FileChooserBox("IOR file",JFileChooserSingleton.getInstance(OpenCCMBrowserConstants.IOR_FILE_CHOOSER),false); 94 dialogBox.addElementBox(iorFile_); 95 treeBox_ = new TreeBox(TreeDialogSingleton.getInstance(),false); 96 treeBox_.setPreferredSize(new Dimension (350, 150)); 97 dialogBox.addElementBox(treeBox_); 98 } 99 100 106 109 public void actionPerformed(java.awt.event.ActionEvent ae) { 110 DialogBox dialogBox = new DefaultDialogBox("Adds a CORBA object"); 111 createBox(dialogBox); 112 dialogBox.setValidateAction(this); 113 dialogBox.show(); 114 } 115 116 122 125 public void executeAction() throws Exception { 126 File file = iorFile_.getFile(); 127 Object selectedObject = treeBox_.getObject(); 128 org.omg.CORBA.Object object = null; 129 if (file != null) { 130 String ior = null; 131 try { 132 BufferedReader in = new BufferedReader (new FileReader (file)); 133 ior = in.readLine(); 134 } catch (java.io.FileNotFoundException err) { 135 System.out.println(file + " : File not found !"); 136 } catch (java.io.IOException err) { 137 System.out.println(file + " : Error while reading !"); 138 } 139 if (ior != null && ior.startsWith("IOR:")) { 140 ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 141 object = orb.string_to_object(ior); 142 } 143 } else if (selectedObject != null) { 144 try { 145 object = (org.omg.CORBA.Object ) selectedObject; 146 } catch (ClassCastException e1) { 147 throw new Exception ("You must select a org.omg.CORBA.Object \n Found : " + selectedObject.getClass().getName()); 148 } 149 } 150 if (object != null) 151 treeItf_.addEntry(name_.getLabel(), object); 152 else 153 throw new Exception ("The object to bind is missing !"); 154 } 155 156 } 157 | Popular Tags |