KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > componentBrowser > MethodPanel


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 /***************************************************************************/
25 package org.coach.actor.componentBrowser;
26
27 import java.awt.*;
28 import javax.swing.*;
29 import org.coach.idltree.*;
30 import org.coach.util.IorPrinter;
31 import org.omg.Components.*;
32
33 public class MethodPanel extends JPanel implements ObjectListener {
34     MethodFrame methodFrame;
35     JPanel treePanel;
36     JPanel emptyReply = new JPanel();
37     IdlTreePanel operationTree;
38     JScrollPane operationScrollPane;
39     IdlTreePanel replyTree;
40     JScrollPane replyScrollPane;
41     InvokePanel invokePanel;
42     org.omg.CORBA.ORB JavaDoc orb;
43     
44     public MethodPanel() {
45         try {
46             this.setLayout(new BorderLayout());
47         }
48         catch(Exception JavaDoc ex) {
49             ex.printStackTrace();
50         }
51     }
52
53     public MethodPanel(MethodFrame mf, String JavaDoc id, String JavaDoc facetName, org.omg.CORBA.Object JavaDoc target, org.omg.CORBA.ORB JavaDoc orb) {
54         this();
55         this.orb = orb;
56         this.methodFrame = mf;
57         invokePanel = new InvokePanel(this, orb);
58         invokePanel.setOperation(id, facetName, target);
59         treePanel = new JPanel();
60         treePanel.setLayout(new GridLayout(1,2));
61         setOperation(invokePanel.getModel());
62         this.add(treePanel, BorderLayout.CENTER);
63         this.add(invokePanel, BorderLayout.SOUTH);
64     }
65     
66     public void setReply(IdlModel replyModel) {
67         replyTree = new IdlTreePanel(replyModel);
68         replyTree.addObjectListener(this);
69         replyScrollPane = new JScrollPane(replyTree);
70         treePanel.remove(emptyReply);
71         treePanel.add(replyScrollPane);
72         treePanel.repaint();
73         repaint();
74         methodFrame.pack();
75     }
76
77     public void setOperation(IdlModel operationModel) {
78         treePanel.removeAll();
79         operationTree = new IdlTreePanel(operationModel);
80         operationTree.addModelListener(invokePanel);
81         operationScrollPane = new JScrollPane(operationTree);
82         treePanel.add(operationScrollPane);
83         clearReply();
84         methodFrame.pack();
85     }
86     
87     public void clearReply() {
88         replyTree = null;
89         replyScrollPane = null;
90         treePanel.add(emptyReply);
91         treePanel.repaint();
92         repaint();
93     }
94         
95     /**
96      * This method is called when a user double clicks on an IOR in the reply tree
97      */

98     public void objectAction(String JavaDoc ior) {
99         try {
100             IorPrinter iorPrinter = new IorPrinter(ior);
101             String JavaDoc id = iorPrinter.getTypeId();
102             org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(ior);
103             try {
104                 // if the corba object is a component, start the component browser
105
CCMObject c = CCMObjectHelper.narrow(obj);
106 // ComponentBrowser cb = new ComponentBrowser(this, orb, c.getName(), c);
107
// ComponentBrowser cb = new ComponentBrowser(this, orb, "component name?", c);
108
invokePanel.setOperation(id, "", obj);
109                   setOperation(invokePanel.getModel());
110 //MethodFrame mf = new MethodFrame(this, id, "", obj, orb);
111
} catch (Exception JavaDoc ex) {
112                 // else, start the facet browser
113
// MethodFrame mf = new MethodFrame(this, id, "", obj, orb);
114
invokePanel.setOperation(id, "", obj);
115                   setOperation(invokePanel.getModel());
116             }
117         } catch (Exception JavaDoc e) {
118             e.printStackTrace();
119         }
120     }
121 }
Popular Tags