KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 package org.objectweb.openccm.explorer.Components;
28
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
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 /**
54  * The class allows to connect a facet to a receptacle.
55  *
56  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
57  *
58  * @version 0.1
59  */

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 JavaDoc {
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 JavaDoc treePanel = new JPanel JavaDoc();
78             treePanel.setLayout(new GridLayout JavaDoc(1, 0));
79             treePanel.setPreferredSize(new Dimension JavaDoc(450, 350));
80             treePanel.add(new JScrollPane JavaDoc(explorerItf.getTree()));
81             ActionEvent JavaDoc ae = (ActionEvent JavaDoc)e.getEvent();
82             int result = JOptionPane.showOptionDialog((java.awt.Component JavaDoc)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 JavaDoc object = entry.getValue();
87                     if (object != null) {
88                         org.omg.CORBA.Object JavaDoc obj_ref = null;
89                         if (object instanceof org.omg.CORBA.Object JavaDoc) {
90                             obj_ref = (org.omg.CORBA.Object JavaDoc) object;
91                         } else if (object instanceof FacetDescription) {
92                             obj_ref = ((FacetDescription)object).facet_ref;
93                         } else {
94                             throw new Exception JavaDoc("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