1 2 5 14 package org.jacorb.trading.client.offers; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.io.*; 19 import java.util.*; 20 import org.omg.CORBA.ORB ; 21 import org.omg.CosTrading.*; 22 import org.omg.CosTrading.RegisterPackage.*; 23 import org.omg.CosTradingRepos.*; 24 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*; 25 import org.jacorb.trading.client.util.*; 26 27 28 public class ConstraintDialog 29 extends Dialog 30 implements ActionListener, Runnable 31 { 32 private Choice m_types; 33 private TextField m_constraint; 34 private Button m_ok; 35 private Button m_cancel; 36 private Label m_status; 37 private Register m_register; 38 private ServiceTypeRepository m_repos; 39 private Vector m_listeners = new Vector(); 40 private String m_actionCommand; 41 42 43 public ConstraintDialog(Frame f, Register reg) 44 { 45 super(f, "Withdraw", false); 46 47 m_register = reg; 48 org.omg.CORBA.Object obj = reg.type_repos(); 49 m_repos = ServiceTypeRepositoryHelper.narrow(obj); 50 51 createContents(); 52 pack(); 53 54 addWindowListener( 55 new WindowAdapter() 56 { 57 public void windowClosing(WindowEvent e) 58 { 59 cancel(); 60 } 61 } 62 ); 63 64 Point parentLoc = getParent().getLocation(); 65 setLocation(parentLoc.x + 30, parentLoc.y + 30); 66 } 67 68 69 protected void createContents() 70 { 71 Panel panel = new Panel(); 72 panel.setLayout(new GridBagLayout()); 73 74 Panel typesPanel = new Panel(); 75 typesPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); 76 typesPanel.add(new Label("Service type", Label.LEFT)); 77 78 m_types = new Choice(); 79 loadTypes(m_types); 80 typesPanel.add(m_types); 81 82 Constrain.constrain(panel, typesPanel, 0, 0, 2, 1, 83 GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 84 1.0, 0.0, 5, 10, 0, 10); 85 86 Constrain.constrain(panel, new Label("Constraint", Label.LEFT), 0, 1, 2, 1, 87 GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, 88 5, 10, 0, 10); 89 90 m_constraint = new TextField(50); 91 m_constraint.setEditable(true); 92 Constrain.constrain(panel, m_constraint, 0, 2, 2, 1, 93 GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1.0, 0.0, 94 0, 10, 0, 10); 95 96 m_ok = new Button("OK"); 97 m_ok.setActionCommand("ok"); 98 m_ok.addActionListener(this); 99 Constrain.constrain(panel, m_ok, 0, 3, 1, 1, 100 GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, 101 10, 10, 0, 0, 30, 3); 102 103 m_cancel = new Button("Cancel"); 104 m_cancel.setActionCommand("cancel"); 105 m_cancel.addActionListener(this); 106 Constrain.constrain(panel, m_cancel, 1, 3, 1, 1, 107 GridBagConstraints.NONE, GridBagConstraints.NORTHEAST, 0.0, 0.0, 108 10, 0, 0, 10, 10, 3); 109 110 m_status = new Label("", Label.LEFT); 111 Constrain.constrain(panel, m_status, 0, 4, 2, 1, 112 GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1.0, 0.0, 113 5, 10, 5, 10); 114 115 add(panel); 116 } 117 118 119 public void addActionListener(ActionListener l) 120 { 121 m_listeners.addElement(l); 122 } 123 124 125 public void removeActionListener(ActionListener l) 126 { 127 m_listeners.removeElement(l); 128 } 129 130 131 public void setActionCommand(String command) 132 { 133 m_actionCommand = command; 134 } 135 136 137 public void actionPerformed(ActionEvent e) 138 { 139 if (e.getActionCommand().equals("ok")) 140 ok(); 141 else if (e.getActionCommand().equals("cancel")) 142 cancel(); 143 } 144 145 146 protected void ok() 147 { 148 new Thread (this).start(); 149 } 150 151 152 protected void cancel() 153 { 154 setVisible(false); 155 } 156 157 158 public void run() 159 { 160 try { 161 showStatus("Withdrawing offers..."); 162 m_ok.setEnabled(false); 163 m_cancel.setEnabled(false); 164 165 String type = m_types.getSelectedItem(); 166 String constraint = m_constraint.getText(); 167 168 m_register.withdraw_using_constraint(type, constraint); 169 170 setVisible(false); 171 notifyListeners(); 172 clearStatus(); 173 } 174 catch (IllegalServiceType e) { 175 showStatus("Illegal service type '" + e.type + "'"); 176 } 177 catch (UnknownServiceType e) { 178 showStatus("Unknown service type '" + e.type + "'"); 179 } 180 catch (IllegalConstraint e) { 181 showStatus("Illegal constraint"); 182 } 183 catch (NoMatchingOffers e) { 184 showStatus("No matching offers found"); 185 } 186 finally { 187 m_ok.setEnabled(true); 189 m_cancel.setEnabled(true); 190 } 191 } 192 193 194 protected void notifyListeners() 195 { 196 ActionEvent evt = 197 new ActionEvent(this, ActionEvent.ACTION_PERFORMED, m_actionCommand); 198 199 Enumeration e = m_listeners.elements(); 200 while (e.hasMoreElements()) { 201 ActionListener l = (ActionListener)e.nextElement(); 202 l.actionPerformed(evt); 203 } 204 } 205 206 207 protected void showStatus(String message) 208 { 209 m_status.setText(message); 210 } 211 212 213 protected void clearStatus() 214 { 215 m_status.setText(""); 216 } 217 218 219 protected void loadTypes(Choice choice) 220 { 221 choice.removeAll(); 222 String [] types; 223 SpecifiedServiceTypes whichTypes = new SpecifiedServiceTypes(); 224 whichTypes.__default(); 227 228 types = m_repos.list_types(whichTypes); 229 QuickSort.sort(types); 230 for (int i = 0; i < types.length; i++) 231 choice.add(types[i]); 232 } 233 } 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | Popular Tags |