1 7 8 9 package com.bull.eclipse.jonas.wizard; 10 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 14 import org.eclipse.core.resources.IWorkspace; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.jdt.core.IType; 19 import org.eclipse.jdt.core.jdom.DOMFactory; 20 import org.eclipse.jdt.core.jdom.IDOMMethod; 21 import org.eclipse.jdt.core.search.IJavaSearchScope; 22 import org.eclipse.jdt.core.search.SearchEngine; 23 import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog; 24 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 25 import org.eclipse.jface.wizard.WizardPage; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.events.SelectionListener; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Combo; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.List; 38 import org.eclipse.swt.widgets.Table; 39 import org.eclipse.swt.widgets.Text; 40 41 44 public class AddEjbMethodWizardPage extends WizardPage { 45 46 private Text signature; 47 private Text name; 48 private Text methodNameTxt; 49 private Text methodNameTxt0; 50 51 private Combo returnType; 52 private Combo parsType; 53 private Table parameters; 54 private IDOMMethod method; 55 private String methodType; 56 private String interfaceType; 57 private SearchEngine engine; 58 private IWorkspace workSpace; 59 private IJavaSearchScope scope; 60 private List lisTotPars; 61 private Combo lisPars; 62 private String methodPublic; 63 private String methodName; 64 65 private interface Selector { 66 67 public abstract void setSelection(Object obj); 68 } 69 70 private class TypeSelectionListener implements SelectionListener { 71 72 public void widgetSelected(SelectionEvent event) { 73 selector.setSelection(selection); 74 } 75 76 public void widgetDefaultSelected(SelectionEvent event) { 77 selector.setSelection(selection); 78 } 79 80 private Object selection; 81 private Selector selector; 82 83 public TypeSelectionListener( 84 Object newSelection, 85 Selector newSelector) { 86 selection = newSelection; 87 selector = newSelector; 88 } 89 } 90 91 public AddEjbMethodWizardPage(String pageName) { 92 93 super(pageName); 94 95 name = null; 96 signature = null; 97 returnType = null; 98 parsType = null; 99 parameters = null; 100 method = null; 101 methodType = "business"; 102 interfaceType = "remote"; 103 engine = new SearchEngine(); 104 workSpace = ResourcesPlugin.getWorkspace(); 105 scope = SearchEngine.createWorkspaceScope(); 106 setTitle("Add Business Methods .... "); 107 setDescription("Add New Business Methods"); 108 method = (new DOMFactory()).createMethod(); 109 methodPublic = "public"; 110 methodName = null; 111 } 112 113 public void createControl(Composite parent) { 114 Composite composite = new Composite(parent, 0); 115 int nColumns = 4; 116 GridLayout layout = new GridLayout(); 117 layout.numColumns = nColumns; 118 composite.setLayout(layout); 119 createMethodNameControls(composite, nColumns); 120 createMethodTypeSelectionControls(composite, nColumns); 121 createMethodPublicControls(composite, nColumns); 122 createReturnTypeControls(composite, nColumns); 123 createParameterControls(composite, nColumns); 124 setControl(composite); 125 } 126 127 protected void createMethodTypeSelectionControls( 128 Composite composite, 129 int nColumns) { 130 Selector methodTypeSelector = new Selector() { 131 132 public void setSelection(Object selected) { 133 methodType = (String ) selected; 134 135 methodNameTxt.setEnabled(methodType.equals("business")); 136 methodNameTxt0.setEnabled(methodType.equals("find")); 137 138 buildSignature(); 139 } 140 141 }; 142 Group ejbType = new Group(composite, 0); 143 ejbType.setLayout(new GridLayout()); 144 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); 145 ejbType.setLayoutData(gd); 147 ejbType.setText("Method Type"); 148 149 Group toto = new Group(ejbType, 0); 150 GridLayout layout = new GridLayout(); 151 layout.numColumns = nColumns; 152 153 toto.setLayout(layout); 154 155 158 gd.horizontalSpan = nColumns / 2; 159 160 Button intButton = new Button(toto, 16); 161 intButton.setText("Business Method"); 162 intButton.addSelectionListener( 163 new TypeSelectionListener("business", methodTypeSelector)); 164 165 (new Label(toto, 0)).setText("Name"); 166 gd = new GridData(100); 167 methodNameTxt = new Text(toto, 2048); 169 methodNameTxt.setLayoutData(gd); 170 methodNameTxt.addModifyListener(new ModifyListener() { 171 172 public void modifyText(ModifyEvent e) { 173 buildSignature(); 174 } 175 176 }); 177 178 Button fndButton = new Button(toto, 16); 179 fndButton.setText("Find"); 180 fndButton.addSelectionListener( 181 new TypeSelectionListener("find", methodTypeSelector)); 182 (new Label(toto, 0)).setText("Name"); 183 gd = new GridData(100); 184 methodNameTxt0 = new Text(toto, 2048); 186 methodNameTxt0.setLayoutData(gd); 187 methodNameTxt0.addModifyListener(new ModifyListener() { 188 189 public void modifyText(ModifyEvent e) { 190 buildSignature(); 191 } 192 193 }); 194 195 Button createButton = new Button(toto, 16); 196 createButton.setText("Create Method"); 197 createButton.addSelectionListener( 198 new TypeSelectionListener("create", methodTypeSelector)); 199 intButton.setSelection(true); 200 methodNameTxt.setEnabled(true); 201 methodNameTxt0.setEnabled(false); 202 203 } 204 205 protected void createMethodPublicControls( 206 Composite composite, 207 int nColumns) { 208 Selector methodTypeSelector = new Selector() { 209 210 public void setSelection(Object selected) { 211 methodPublic = (String ) selected; 212 buildSignature(); 213 } 214 215 }; 216 Group ejbType = new Group(composite, 0); 217 ejbType.setLayout(new GridLayout()); 218 GridData gd = new GridData(256); 219 gd.horizontalSpan = nColumns / 2; 220 ejbType.setLayoutData(gd); 221 ejbType.setText("Method Scope"); 222 223 Button priButton = new Button(ejbType, 16); 224 priButton.setText("Private"); 225 priButton.addSelectionListener( 226 new TypeSelectionListener("private", methodTypeSelector)); 227 228 Button pubButton = new Button(ejbType, 16); 229 pubButton.setText("Public"); 230 pubButton.addSelectionListener( 231 new TypeSelectionListener("public", methodTypeSelector)); 232 233 Button proButton = new Button(ejbType, 16); 234 proButton.setText("Protected"); 235 proButton.addSelectionListener( 236 new TypeSelectionListener("protected", methodTypeSelector)); 237 pubButton.setSelection(true); 238 } 239 240 private GridData buttonLayout(Button button) { 241 GridData data = new GridData(256); 242 data.heightHint = 20; 243 data.widthHint = 60; 244 return data; 245 } 246 247 protected void createMethodNameControls( 248 Composite composite, 249 int nColumns) { 250 GridLayout layout = new GridLayout(); 251 layout.numColumns = nColumns; 252 Composite methodNameGroup = new Composite(composite, 0); 253 methodNameGroup.setLayout(layout); 254 GridData gd = new GridData(768); 255 gd.horizontalSpan = nColumns; 256 methodNameGroup.setLayoutData(gd); 257 (new Label(methodNameGroup, 0)).setText("Method Signature"); 258 gd = new GridData(768); 259 gd.horizontalSpan = nColumns - 2; 260 name = new Text(methodNameGroup, 2048); 261 name.setLayoutData(gd); 262 263 } 264 265 protected void createReturnTypeControls( 266 Composite composite, 267 int nColumns) { 268 ArrayList primtypes = new ArrayList (); 269 270 primtypes.add("boolean"); 271 primtypes.add("byte"); 272 primtypes.add("char"); 273 primtypes.add("int"); 274 primtypes.add("long"); 275 primtypes.add("float"); 276 primtypes.add("double"); 277 278 primtypes.add("java.lang.Boolean"); 279 primtypes.add("java.lang.Character"); 280 primtypes.add("java.lang.Byte"); 281 primtypes.add("java.lang.Double"); 282 primtypes.add("java.lang.Float"); 283 primtypes.add("java.lang.FloatingDecimal"); 284 primtypes.add("java.lang.Integer"); 285 primtypes.add("java.lang.Long"); 286 primtypes.add("java.lang.Number"); 287 primtypes.add("java.lang.Short"); 288 primtypes.add("java.lang.String"); 289 primtypes.add("java.util.Collection"); 290 291 GridLayout layout = new GridLayout(); 292 layout.numColumns = nColumns; 293 Composite returnTypeGroup = new Composite(composite, 0); 294 returnTypeGroup.setLayout(layout); 295 GridData gd = new GridData(768); 296 gd.horizontalSpan = nColumns; 297 returnTypeGroup.setLayoutData(gd); 298 (new Label(returnTypeGroup, 0)).setText("Return Type"); 299 returnType = new Combo(returnTypeGroup, 2048); 300 gd = new GridData(768); 301 gd.horizontalSpan = nColumns - 3; 302 returnType.setLayoutData(gd); 303 returnType.add("void"); 304 for (Iterator iter = primtypes.iterator(); 305 iter.hasNext(); 306 returnType.add((String ) iter.next())); 307 returnType.addModifyListener(new ModifyListener() { 308 309 public void modifyText(ModifyEvent e) { 310 setErrorMessage(null); 311 setPageComplete(true); 312 buildSignature(); 313 } 314 315 }); 316 Button selectType = new Button(returnTypeGroup, 0); 317 selectType.setText("Browse"); 318 selectType.setLayoutData(buttonLayout(selectType)); 319 selectType.addSelectionListener(new SelectionListener() { 320 321 private void doEvent(SelectionEvent e) { 322 org.eclipse.swt.widgets.Shell parent = getShell(); 323 TypeSelectionDialog dialog = 324 new TypeSelectionDialog( 325 parent, 326 new ProgressMonitorDialog(parent), 327 6, 328 SearchEngine.createWorkspaceScope()); 329 dialog.setTitle("Select Type"); 330 dialog.setMessage("Select Type"); 331 if (dialog.open() != 0) { 332 return; 333 } else { 334 IType type = (IType) dialog.getResult()[0]; 335 returnType.setText(type.getFullyQualifiedName()); 336 return; 337 } 338 } 339 340 public void widgetSelected(SelectionEvent e) { 341 doEvent(e); 342 } 343 344 public void widgetDefaultSelected(SelectionEvent e) { 345 doEvent(e); 346 } 347 348 }); 349 } 350 351 protected void createParameterControls(Composite composite, int nColumns) { 352 353 GridLayout layout = new GridLayout(); 354 layout.numColumns = nColumns; 355 Group parametersGroup = new Group(composite, 0); 356 parametersGroup.setLayout(layout); 357 358 GridData gd = new GridData(768); 359 gd.horizontalSpan = nColumns; 360 parametersGroup.setLayoutData(gd); 361 parametersGroup.setText("Method Parameters"); 362 363 final Button clearButton = new Button(parametersGroup, 0); 364 final Button removeButton = new Button(parametersGroup, 0); 365 final Button addButton = new Button(parametersGroup, 0); 366 367 clearButton.setEnabled(false); 368 removeButton.setEnabled(false); 369 addButton.setEnabled(false); 370 371 (new Label(parametersGroup, 0)).setText("Param. Type"); 372 373 lisPars = new Combo(parametersGroup, 2052); 374 lisPars.addModifyListener(new ModifyListener() { 375 376 public void modifyText(ModifyEvent e) { 377 setErrorMessage(null); 378 setPageComplete(true); 379 addButton.setEnabled(!lisPars.getText().equals("")); 380 } 381 382 }); 383 384 gd = new GridData(768); 385 gd.horizontalSpan = nColumns; 386 lisPars.setLayoutData(gd); 387 388 clearButton.setText("Clear"); 389 clearButton.setLayoutData(buttonLayout(clearButton)); 390 clearButton.addSelectionListener(new SelectionListener() { 391 392 public void widgetSelected(SelectionEvent e) { 393 lisTotPars.removeAll(); 394 boolean bvis = (lisTotPars.getItemCount() != 0); 395 clearButton.setEnabled(bvis); 396 removeButton.setEnabled(bvis); 397 buildSignature(); 398 399 } 400 401 public void widgetDefaultSelected(SelectionEvent e) { 402 lisTotPars.removeAll(); 403 } 404 405 }); 406 407 removeButton.setText("Remove"); 408 removeButton.setLayoutData(buttonLayout(removeButton)); 409 removeButton.addSelectionListener(new SelectionListener() { 410 411 public void widgetSelected(SelectionEvent e) { 412 lisTotPars.remove(lisTotPars.getSelectionIndex()); 413 boolean bvis = (lisTotPars.getItemCount() != 0); 414 clearButton.setEnabled(bvis); 415 removeButton.setEnabled(bvis); 416 lisTotPars.setSelection(0); 417 buildSignature(); 418 419 } 420 421 public void widgetDefaultSelected(SelectionEvent e) { 422 } 423 424 }); 425 426 addButton.setText("Add"); 427 addButton.setLayoutData(buttonLayout(addButton)); 428 addButton.addSelectionListener(new SelectionListener() { 429 430 public void widgetSelected(SelectionEvent e) { 431 433 lisTotPars.add(lisPars.getText()); 435 clearButton.setEnabled(true); 436 removeButton.setEnabled(true); 437 String [] sel = new String [1]; 438 sel[0] = lisPars.getText(); 441 lisTotPars.setSelection(sel); 442 buildSignature(); 443 444 } 445 446 public void widgetDefaultSelected(SelectionEvent e) { 447 lisTotPars.add(lisPars.getItem(lisPars.getSelectionIndex())); 448 } 449 450 }); 451 lisTotPars = new List (parametersGroup, 2052); 452 gd = new GridData(768); 453 gd.horizontalSpan = nColumns - 1; 454 gd.verticalSpan = 3; 455 lisTotPars.setLayoutData(gd); 456 457 lisPars.add("boolean"); 459 lisPars.add("byte"); 460 lisPars.add("char"); 461 lisPars.add("int"); 462 lisPars.add("long"); 463 lisPars.add("float"); 464 lisPars.add("double"); 465 466 lisPars.add("java.lang.Boolean"); 467 lisPars.add("java.lang.Character"); 468 lisPars.add("java.lang.Byte"); 469 lisPars.add("java.lang.Double"); 470 lisPars.add("java.lang.Float"); 471 lisPars.add("java.lang.FloatingDecimal"); 472 lisPars.add("java.lang.Integer"); 473 lisPars.add("java.lang.Long"); 474 lisPars.add("java.lang.Number"); 475 lisPars.add("java.lang.Short"); 476 lisPars.add("java.lang.String"); 477 lisPars.add("java.util.Collection"); 478 479 clearButton.setEnabled(false); 480 removeButton.setEnabled(false); 481 } 482 483 public boolean isPageValid() { 484 return true; 485 } 486 487 protected void setStatus(IStatus status) { 488 setPageComplete(status.isOK()); 489 if (status.getSeverity() == 4) { 490 setErrorMessage(status.getMessage()); 491 } else { 492 setErrorMessage(null); 493 setMessage( 494 "OK".equals(status.getMessage()) ? null : status.getMessage()); 495 } 496 } 497 498 public String getMethodName() { 499 String s = name.getText(); 500 return name.getText(); 501 } 502 503 private void buildSignature() { 504 String msg = null; 505 String rt = ""; 506 if (returnType != null) 507 rt = 508 (!returnType.getText().equals("")) 509 ? returnType.getText() 510 : "??"; 511 512 String na = ""; String exc = ""; 514 515 if (methodType.equals("create")) { 516 exc = " throws CreateException"; 517 na = "ejbCreate"; 518 } 519 520 if (methodType.equals("find")) { 521 exc = " throws FinderException"; 522 na = methodNameTxt0.getText(); 523 na = na.equals("") ? "ejbFindxxx" : na; 524 } 526 527 if (methodType.equals("business")) { 528 exc = " throws Exception"; 529 String zz = methodNameTxt.getText(); 530 na = methodNameTxt.getText(); 531 na = na.equals("") ? "Foo " : na; 532 } 534 535 String spars = ""; 536 for (int i = 0; i < lisTotPars.getItemCount(); i++) { 537 if (i != 0) 538 spars += ", "; 539 spars += lisTotPars.getItem(i) + " par_" + i; 540 } 541 String s = 542 methodPublic + " " + rt + " " + na + "(" + spars + ")" + exc + ";"; 543 544 org.eclipse.core.runtime.IStatus status = new Status(4, "com.objectlearn.wlserver.integration.controlcenter", 4, "Return type is missign ..", new Exception ()); 546 if (rt.equals ("??")) 547 this.setStatus(status); 548 549 550 551 name.setText(s); 552 553 } 554 555 } 556 | Popular Tags |