KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > Components > ConnectConsumerAction


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 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 package org.objectweb.openccm.explorer.Components;
27
28 import java.awt.Component JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.GridLayout JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32
33 import javax.swing.JOptionPane JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.JScrollPane JavaDoc;
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.EmitterDescription;
48
49 /**
50  * This items allows to subscribe a consumer to a publisher
51  * (<code>::Components::CCMObject::subscribe</code> called).
52  *
53  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
54  *
55  * @version 0.1
56  */

57 public class ConnectConsumerAction
58   implements MenuItem
59 {
60
61     /* (non-Javadoc)
62      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
63      */

64     public int getStatus(TreeView arg0){
65         return MenuItem.ENABLED_STATUS;
66     }
67
68     /* (non-Javadoc)
69      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
70      */

71     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
72         EmitterContainer ec = (EmitterContainer) e.getSelectedObject();
73         EmitterDescription emitter = ec.getEmitter();
74         CCMObject component = ec.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 JavaDoc treePanel = new JPanel JavaDoc();
81         treePanel.setLayout(new GridLayout JavaDoc(1, 0));
82         treePanel.setPreferredSize(new Dimension JavaDoc(450, 350));
83         treePanel.add(new JScrollPane JavaDoc(explorerItf.getTree()));
84         ActionEvent JavaDoc ae = (ActionEvent JavaDoc)e.getEvent();
85         int result = JOptionPane.showOptionDialog((Component JavaDoc) 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 JavaDoc object = entry.getValue();
90                 if (object != null) {
91                     System.err.println(object);
92                     ConsumerDescription consumer = (ConsumerDescription) object;
93                     if (component != null && emitter != null && consumer != null) {
94                         component.connect_consumer(emitter.name, consumer.consumer);
95                     }
96                 }
97             }
98         }
99     }
100
101 }
102
Popular Tags