1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 [] methods; 44 private IdlOperation[] types; 45 org.omg.CORBA.Object ref; 46 JComboBox methodSelector = new JComboBox(); 47 JCheckBox inheritenceCheckBox = new JCheckBox(); 48 String id; 49 JFrame frm = new JFrame(); 50 String facetName; 51 org.omg.CORBA.ORB orb; 52 MethodPanel methodPanel; 53 54 public InvokePanel() { 55 try { 56 jbInit(); 57 } 58 catch(Exception ex) { 59 ex.printStackTrace(); 60 } 61 } 62 63 public InvokePanel(MethodPanel mp, org.omg.CORBA.ORB orb) { 64 this(); 65 this.methodPanel = mp; 66 this.orb = orb; 67 } 70 71 public void setOperation(String id, String facetName, org.omg.CORBA.Object 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 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 e) { 99 } 100 } 101 102 private void jbInit() throws Exception { 103 targetLabel.setText("Methods"); 104 this.setLayout(flowLayout1); 105 106 invokeButton.setText("invoke"); 107 invokeButton.addActionListener(new java.awt.event.ActionListener () { 108 public void actionPerformed(ActionEvent e) { 109 invokeButton_actionPerformed(e); 110 } 111 }); 112 113 methodSelector.addActionListener(new java.awt.event.ActionListener () { 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 () { 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 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 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 |