1 26 27 package org.objectweb.openccm.explorer.Components; 28 29 import java.awt.Dimension ; 30 import java.awt.GridLayout ; 31 import java.awt.event.ActionEvent ; 32 33 import javax.swing.JOptionPane ; 34 import javax.swing.JPanel ; 35 import javax.swing.JScrollPane ; 36 37 38 import org.objectweb.fractal.api.Component; 39 import org.objectweb.fractal.api.NoSuchInterfaceException; 40 import org.objectweb.openccm.explorer.CORBA.ConsoleFactory; 41 import org.objectweb.openccm.explorer.menu.TreeDialogSingleton; 42 import org.objectweb.util.explorer.api.Entry; 43 import org.objectweb.util.explorer.api.MenuItem; 44 import org.objectweb.util.explorer.api.MenuItemTreeView; 45 import org.objectweb.util.explorer.api.Tree; 46 import org.objectweb.util.explorer.api.TreeView; 47 import org.objectweb.util.explorer.swing.api.Explorer; 48 49 import org.omg.Components.CCMObject; 50 import org.omg.Components.FacetDescription; 51 import org.omg.Components.ReceptacleDescription; 52 53 60 public class ConnectAction 61 implements MenuItem { 62 63 public int getStatus(TreeView arg0){ 64 return MenuItem.ENABLED_STATUS; 65 } 66 67 public void actionPerformed(MenuItemTreeView e) throws Exception { 68 69 ReceptacleContainer rc = (ReceptacleContainer) e.getSelectedObject(); 70 ReceptacleDescription receptacle = rc.getReceptacle(); 71 CCMObject component = rc.getComponent(); 72 73 Component tree = TreeDialogSingleton.getInstance(); 74 try { 75 Explorer explorerItf = (Explorer)tree.getFcInterface(Explorer.EXPLORER); 76 Tree treeItf = (Tree)tree.getFcInterface(Tree.TREE); 77 JPanel treePanel = new JPanel (); 78 treePanel.setLayout(new GridLayout (1, 0)); 79 treePanel.setPreferredSize(new Dimension (450, 350)); 80 treePanel.add(new JScrollPane (explorerItf.getTree())); 81 ActionEvent ae = (ActionEvent )e.getEvent(); 82 int result = JOptionPane.showOptionDialog((java.awt.Component )ae.getSource(), treePanel, "Select a facet", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); 83 if (result == 0) { 84 Entry entry = treeItf.getSelectedEntry(); 85 if (entry != null) { 86 Object object = entry.getValue(); 87 if (object != null) { 88 org.omg.CORBA.Object obj_ref = null; 89 if (object instanceof org.omg.CORBA.Object ) { 90 obj_ref = (org.omg.CORBA.Object ) object; 91 } else if (object instanceof FacetDescription) { 92 obj_ref = ((FacetDescription)object).facet_ref; 93 } else { 94 throw new Exception ("CORBA object expected !"); 95 } 96 if (component != null && receptacle != null && obj_ref != null) { 97 component.connect(receptacle.name, obj_ref); 98 } 99 } 100 } 101 } 102 } catch (NoSuchInterfaceException e1) { 103 ConsoleFactory.getDebugConsole().add(e1.getMessage()); 104 } 105 } 106 107 } 108 | Popular Tags |