1 26 package org.objectweb.openccm.explorer.Components; 27 28 import java.awt.Component ; 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 import org.objectweb.openccm.explorer.menu.TreeDialogSingleton; 38 import org.objectweb.util.explorer.api.Entry; 39 import org.objectweb.util.explorer.api.MenuItem; 40 import org.objectweb.util.explorer.api.MenuItemTreeView; 41 import org.objectweb.util.explorer.api.Tree; 42 import org.objectweb.util.explorer.api.TreeView; 43 import org.objectweb.util.explorer.swing.api.Explorer; 44 45 import org.omg.Components.CCMObject; 46 import org.omg.Components.ConsumerDescription; 47 import org.omg.Components.PublisherDescription; 48 49 57 public class SubscribesAction 58 implements MenuItem { 59 60 63 public int getStatus(TreeView arg0){ 64 return MenuItem.ENABLED_STATUS; 65 } 66 67 70 public void actionPerformed(MenuItemTreeView e) throws Exception { 71 72 PublisherContainer pc = (PublisherContainer) e.getSelectedObject(); 73 PublisherDescription publisher = pc.getPublisher(); 74 CCMObject component = pc.getComponent(); 75 76 org.objectweb.fractal.api.Component tree = TreeDialogSingleton.getInstance(); 77 Explorer explorerItf = (Explorer)tree.getFcInterface(Explorer.EXPLORER); 78 Tree treeItf = (Tree)tree.getFcInterface(Tree.TREE); 79 80 JPanel treePanel = new JPanel (); 81 treePanel.setLayout(new GridLayout (1, 0)); 82 treePanel.setPreferredSize(new Dimension (450, 350)); 83 treePanel.add(new JScrollPane (explorerItf.getTree())); 84 ActionEvent ae = (ActionEvent )e.getEvent(); 85 int result = JOptionPane.showOptionDialog((Component ) ae.getSource(), treePanel, "Select a consumer", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); 86 if (result == 0) { 87 Entry entry = treeItf.getSelectedEntry(); 88 if (entry != null) { 89 Object object = entry.getValue();; 90 if (object != null) { 91 try{ 92 ConsumerDescription consumer = (ConsumerDescription)object; 93 if (component != null && publisher != null && consumer != null) { 94 component.subscribe(publisher.name, consumer.consumer); 95 } 96 } catch (ClassCastException e1) { 97 throw new Exception ("ConsumerDescription expected !"); 98 } 99 } 100 } 101 } 102 } 103 104 } 105 | Popular Tags |