1 2 5 14 package org.jacorb.trading.client.typemgr; 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.CosTradingRepos.*; 23 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*; 24 import org.jacorb.trading.client.util.*; 25 26 27 public class AddTypeDialog extends Dialog implements ActionListener 28 { 29 private TextArea m_description; 30 private Button m_ok; 31 private Button m_clear; 32 private Button m_cancel; 33 private Label m_status; 34 private ServiceTypeRepository m_repos; 35 private Vector m_listeners = new Vector(); 36 private String m_actionCommand; 37 38 39 public AddTypeDialog(Frame f, ServiceTypeRepository repos) 40 { 41 super(f, "Add Service Type", false); 42 43 m_repos = repos; 44 45 createContents(); 46 pack(); 47 48 addWindowListener( 49 new WindowAdapter() 50 { 51 public void windowClosing(WindowEvent e) 52 { 53 cancel(); 54 } 55 } 56 ); 57 58 Point parentLoc = getParent().getLocation(); 59 setLocation(parentLoc.x + 30, parentLoc.y + 30); 60 61 m_description.setText( 63 "service YourService : BaseService {\n" + 64 " interface YourInterface;\n" + 65 " mandatory readonly property sequence<string> myprop;\n" + 66 "};\n"); 67 } 68 69 70 protected void createContents() 71 { 72 Panel panel = new Panel(); 73 panel.setLayout(new GridBagLayout()); 74 75 Constrain.constrain(panel, new Label("Description", Label.LEFT), 76 0, 0, 3, 1, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 77 0.0, 0.0, 5, 10, 0, 10); 78 m_description = new TextArea(10, 50); 79 m_description.setEditable(true); 80 Constrain.constrain(panel, m_description, 0, 1, 3, 1, 81 GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST, 1.0, 1.0, 82 0, 10, 0, 10); 83 84 m_ok = new Button("OK"); 85 m_ok.setActionCommand("ok"); 86 m_ok.addActionListener(this); 87 Constrain.constrain(panel, m_ok, 0, 2, 1, 1, 88 GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, 89 10, 10, 0, 0, 30, 3); 90 91 m_clear = new Button("Clear"); 92 m_clear.setActionCommand("clear"); 93 m_clear.addActionListener(this); 94 Constrain.constrain(panel, m_clear, 1, 2, 1, 1, 95 GridBagConstraints.NONE, GridBagConstraints.CENTER, 0.0, 0.0, 96 10, 0, 0, 0, 20, 3); 97 98 m_cancel = new Button("Cancel"); 99 m_cancel.setActionCommand("cancel"); 100 m_cancel.addActionListener(this); 101 Constrain.constrain(panel, m_cancel, 2, 2, 1, 1, 102 GridBagConstraints.NONE, GridBagConstraints.NORTHEAST, 0.0, 0.0, 103 10, 0, 0, 10, 10, 3); 104 105 m_status = new Label("", Label.LEFT); 106 Constrain.constrain(panel, m_status, 0, 3, 2, 1, 107 GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST, 1.0, 0.0, 108 5, 10, 5, 10); 109 110 add(panel); 111 } 112 113 114 public void addActionListener(ActionListener l) 115 { 116 m_listeners.addElement(l); 117 } 118 119 120 public void removeActionListener(ActionListener l) 121 { 122 m_listeners.removeElement(l); 123 } 124 125 126 public void setActionCommand(String command) 127 { 128 m_actionCommand = command; 129 } 130 131 132 public void actionPerformed(ActionEvent e) 133 { 134 if (e.getActionCommand().equals("ok")) 135 ok(); 136 else if (e.getActionCommand().equals("clear")) 137 m_description.setText(""); 138 else if (e.getActionCommand().equals("cancel")) 139 cancel(); 140 } 141 142 143 protected void ok() 144 { 145 try { 146 String text = m_description.getText(); 147 148 StringReader reader = new StringReader(text); 149 Parser parser = new Parser(); 150 parser.parse(reader); 151 152 m_repos.add_type(parser.getName(), parser.getInterface(), 153 parser.getProperties(), parser.getSuperTypes()); 154 155 setVisible(false); 156 notifyListeners(); 157 } 158 catch (ParserException e) { 159 showStatus("Line " + e.getLine() + ": " + e.getMessage()); 160 } 161 catch (IllegalServiceType e) { 162 showStatus("Illegal service type '" + e.type + "'"); 163 } 164 catch (UnknownServiceType e) { 165 showStatus("Unknown service type '" + e.type + "'"); 166 } 167 catch (IllegalPropertyName e) { 168 showStatus("Illegal property name '" + e.name + "'"); 169 } 170 catch (DuplicatePropertyName e) { 171 showStatus("Duplicate property name '" + e.name + "'"); 172 } 173 catch (ServiceTypeExists e) { 174 showStatus("Service type '" + e.name + "' already exists"); 175 } 176 catch (DuplicateServiceTypeName e) { 177 showStatus("Duplicate super type '" + e.name + "'"); 178 } 179 catch (InterfaceTypeMismatch e) { 180 showStatus("Interface type mismatch between " + e.derived_service + 181 " and " + e.base_service); 182 } 183 catch (ValueTypeRedefinition e) { 184 showStatus("Value type redefinition in " + e.type_1 + 185 " for property '" + e.definition_1.name + "'"); 186 } 187 } 188 189 190 protected void cancel() 191 { 192 setVisible(false); 193 } 194 195 196 protected void notifyListeners() 197 { 198 ActionEvent evt = 199 new ActionEvent(this, ActionEvent.ACTION_PERFORMED, m_actionCommand); 200 201 Enumeration e = m_listeners.elements(); 202 while (e.hasMoreElements()) { 203 ActionListener l = (ActionListener)e.nextElement(); 204 l.actionPerformed(evt); 205 } 206 } 207 208 209 protected void showStatus(String message) 210 { 211 m_status.setText(message); 212 } 213 214 215 protected void clearStatus() 216 { 217 m_status.setText(""); 218 } 219 } 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | Popular Tags |