KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.event.*;
30
31 import org.coach.idltree.*;
32 import org.coach.tracing.api.pi.TracingService;
33
34 public class InvokePanel extends JPanel implements ModelChangeListener {
35     TracingService tracingService;
36     
37     FlowLayout flowLayout1 = new FlowLayout(FlowLayout.LEFT);
38     JLabel targetLabel = new JLabel();
39     JButton invokeButton = new JButton();
40     IdlOperation method;
41     IdlModel model;
42     IdlModel replyModel;
43     private String JavaDoc[] methods;
44     private IdlOperation[] types;
45     org.omg.CORBA.Object JavaDoc ref;
46     JComboBox methodSelector = new JComboBox();
47     JCheckBox inheritenceCheckBox = new JCheckBox();
48     String JavaDoc id;
49     JFrame frm = new JFrame();
50     String JavaDoc facetName;
51     org.omg.CORBA.ORB JavaDoc orb;
52     MethodPanel methodPanel;
53
54     public InvokePanel() {
55         try {
56             jbInit();
57         }
58         catch(Exception JavaDoc ex) {
59             ex.printStackTrace();
60         }
61     }
62
63     public InvokePanel(MethodPanel mp, org.omg.CORBA.ORB JavaDoc orb) {
64         this();
65         this.methodPanel = mp;
66         this.orb = orb;
67 // replyModel = new IdlModel();
68
// methodPanel.setReply(replyModel);
69
}
70
71     public void setOperation(String JavaDoc id, String JavaDoc facetName, org.omg.CORBA.Object JavaDoc target) {
72         this.id = id;
73         this.facetName = facetName;
74         ref = target;
75         initMethods();
76     }
77         
78     private void initMethods() {
79         method = null;
80         methodSelector.removeAllItems();
81         try {
82             IdlInterface itf = new IdlInterface(id, false);
83             methods = itf.getOperations();
84             // create an array with all operations.
85
// could also create a cache table and fill it as needed
86
types = new IdlOperation[methods.length];
87             for (int i = 0; i < methods.length; i++) {
88                 types[i] = new IdlOperation(id, methods[i]);
89             }
90             for (int i = 0; i < methods.length; i++) {
91                 methodSelector.addItem(methods[i]);
92             }
93             if (methods.length > 0) {
94                 method = types[0];
95                 model = new IdlModel(method);
96             }
97             replyModel = null;
98         } catch (Exception JavaDoc e) {
99         }
100     }
101
102     private void jbInit() throws Exception JavaDoc {
103         targetLabel.setText("Methods");
104         this.setLayout(flowLayout1);
105
106         invokeButton.setText("invoke");
107         invokeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
108             public void actionPerformed(ActionEvent e) {
109                 invokeButton_actionPerformed(e);
110             }
111         });
112
113         methodSelector.addActionListener(new java.awt.event.ActionListener JavaDoc() {
114             public void actionPerformed(ActionEvent e) {
115                 methodSelector_actionPerformed(e);
116             }
117         });
118
119         inheritenceCheckBox.setText("show inherited");
120         inheritenceCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
121             public void actionPerformed(ActionEvent e) {
122                 inheritenceCheckBox_actionPerformed(e);
123             }
124         });
125
126         this.add(targetLabel, null);
127         this.add(methodSelector, null);
128         this.add(invokeButton, null);
129     }
130
131     public IdlModel getModel() {
132         return model;
133     }
134
135     public void modelChanged(ModelChangeEvent evt) {
136         model = evt.getModel();
137         method = (IdlOperation)model.getRoot();
138     }
139                 
140     void invokeButton_actionPerformed(ActionEvent e) {
141         if (tracingService == null) {
142             try {
143                 tracingService = org.coach.tracing.api.pi.TracingServiceHelper.narrow(org.objectweb.openccm.corba.TheORB.getORB().resolve_initial_references("TracingService"));
144                 tracingService.start();
145                 System.err.println("************ starting tracing service " + Thread.currentThread().getName());
146             } catch (Exception JavaDoc ex) {
147                 ex.printStackTrace();
148             }
149         }
150         if (ref == null) {
151             JOptionPane.showMessageDialog(null, "target not set!");
152         } else {
153             try {
154                 IdlReply reply = method.invoke(orb, ref);
155                 if (reply != null) {
156                     if (replyModel == null) {
157                         replyModel = new IdlModel(reply);
158                         methodPanel.setReply(replyModel);
159                     } else {
160                         replyModel.setRoot(reply);
161                         replyModel.reload();
162                     }
163                 }
164             } catch (Exception JavaDoc ex) {
165                 ex.printStackTrace();
166                 JOptionPane.showMessageDialog(null, ex.toString());
167             }
168         }
169     }
170
171     void methodSelector_actionPerformed(ActionEvent e) {
172         if (method != null) {
173             int idx = methodSelector.getSelectedIndex();
174             method = types[idx];
175             model.setRoot(method);
176             model.reload();
177             methodPanel.setOperation(model);
178             replyModel = null;
179         }
180     }
181
182     void inheritenceCheckBox_actionPerformed(ActionEvent e) {
183         initMethods();
184     }
185 }
186
Popular Tags