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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
|
/*******************************************************************************
* Copyright (c) 2001, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.wizards;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Vector;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.part.PageBook;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;
import org.eclipse.wst.wsdl.ui.internal.util.ValidateHelper;
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
import org.eclipse.wst.xml.ui.internal.dialogs.UpdateListener;
public class WSDLNewFileOptionsPage extends WizardPage implements ModifyListener, UpdateListener, SelectionListener
{
protected Text targetNamespaceText;
protected Text prefixText;
protected boolean updatePortOpFieldBoolean = true;
protected PageBook protocolPageBook;
protected Combo protocolCombo;
protected Composite soapPage;
protected Composite httpPage;
protected Button docLitRadio;
protected Button rpcLitRadio;
protected Button rpcEncRadio;
protected Button httpGetRadio;
protected Button httpPostRadio;
// private BindingGenerator generator;
/**
* Constructor for WSDLNewFileOptionsPage.
* @param pageName
*/
public WSDLNewFileOptionsPage(String pageName)
{
super(pageName);
}
/**
* Constructor for WSDLNewFileOptionsPage.
* @param pageName
* @param title
* @param titleImage
*/
public WSDLNewFileOptionsPage(String pageName, String title, ImageDescriptor titleImage)
{
super(pageName, title, titleImage);
setDescription(WSDLEditorPlugin.getWSDLString("_UI_DESCRIPTION_NEW_WSDL_FILE")); //$NON-NLS-1$
}
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent)
{
Composite base = new Composite(parent, SWT.NONE);
WorkbenchHelp.setHelp(base, WSDLEditorPlugin.getWSDLString("_UI_HELP")); //$NON-NLS-1$
base.setLayout(new GridLayout());
// Group wsdlGroup = ViewUtility.createGroup(base, 2, "WSDL", false);
Composite wsdlGroup = new Composite(base, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
wsdlGroup.setLayout(layout);
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
wsdlGroup.setLayoutData(data);
GridData gd = (GridData)wsdlGroup.getLayoutData();
gd.grabExcessHorizontalSpace = true;
Label targetNamespace = new Label(wsdlGroup, SWT.LEFT);
targetNamespace.setText(WSDLEditorPlugin.getWSDLString("_UI_LABEL_TARGET_NAMESPACE")); //$NON-NLS-1$
GridData nsData = new GridData();
nsData.horizontalAlignment = GridData.FILL;
targetNamespace.setLayoutData(nsData);
targetNamespaceText = new Text(wsdlGroup, SWT.SINGLE | SWT.BORDER);
GridData textData = new GridData();
textData.horizontalAlignment = GridData.FILL;
textData.grabExcessHorizontalSpace = true;
textData.widthHint = 10;
targetNamespaceText.setLayoutData(textData);
targetNamespaceText.addModifyListener(this);
Label prefix = new Label(wsdlGroup, SWT.LEFT);
prefix.setText(WSDLEditorPlugin.getWSDLString("_UI_LABEL_PREFIX_WITH_COLON")); //$NON-NLS-1$\
GridData prefixData = new GridData();
prefixData.horizontalAlignment = GridData.FILL;
prefix.setLayoutData(prefixData);
prefixText = new Text(wsdlGroup, SWT.SINGLE | SWT.BORDER);
GridData prefixTextData = new GridData();
prefixTextData.horizontalAlignment = GridData.FILL;
prefixTextData.grabExcessHorizontalSpace = true;
prefixTextData.widthHint = 10;
prefixText.setLayoutData(prefixTextData);
prefixText.addModifyListener(this);
// XMLCatalog xmlCatalog = XMLCatalogRegistry.getInstance().lookupOrCreateXMLCatalog("default");
// SelectXMLCatalogIdPanel catalog = new SelectXMLCatalogIdPanel(base, xmlCatalog);
// Determine if the user wishes to create a skeleton WSDL. If yes, present the user with input fields.
createSkeletonCheckBox = new Button(base, SWT.CHECK);
createSkeletonCheckBox.setText(WSDLEditorPlugin.getWSDLString("_UI_LABEL_CREATE_WSDL_SKELETON"));
createSkeletonCheckBox.setSelection(true);
wsdlSkeletonGroup = new Composite(base, SWT.NONE);
GridLayout layout2 = new GridLayout();
layout2.numColumns = 2;
wsdlSkeletonGroup.setLayout(layout2);
GridData data2 = new GridData();
data2.verticalAlignment = GridData.FILL;
data2.horizontalAlignment = GridData.FILL;
wsdlSkeletonGroup.setLayoutData(data2);
createLabel(wsdlSkeletonGroup, WSDLEditorPlugin.getWSDLString("_UI_LABEL_BINDING_PROTOCOL"));
protocolCombo = new Combo(wsdlSkeletonGroup, SWT.READ_ONLY);
GridData dataC = new GridData();
dataC.horizontalAlignment = GridData.FILL;
dataC.grabExcessHorizontalSpace = true;
protocolCombo.setLayoutData(dataC);
protocolCombo.add(SOAP_PROTOCOL);
protocolCombo.add(HTTP_PROTOCOL);
protocolCombo.select(0);
protocolCombo.addModifyListener(this);
sepLabel = new Label(base, SWT.SEPARATOR | SWT.HORIZONTAL);
GridData sepData = new GridData();
sepData.horizontalAlignment = GridData.FILL;
sepData.grabExcessHorizontalSpace = true;
sepLabel.setLayoutData(sepData);
// Create PageBook and pages/controls for the PageBook
protocolPageBook = new PageBook(base, SWT.NONE);
///////////////////////// Soap Page
soapPage = new Composite(protocolPageBook, SWT.NONE);
GridLayout pbLayout = new GridLayout();
soapPage.setLayout(pbLayout);
GridData pbData = new GridData();
pbData.verticalAlignment = GridData.FILL;
pbData.horizontalAlignment = GridData.FILL;
soapPage.setLayoutData(pbData);
createLabel(soapPage, WSDLEditorPlugin.getWSDLString("_UI_LABEL_SOAP_BINDING_OPTIONS"));
docLitRadio = new Button(soapPage, SWT.RADIO);
rpcLitRadio = new Button(soapPage, SWT.RADIO);
rpcEncRadio = new Button(soapPage, SWT.RADIO);
docLitRadio.setText(SOAP_DOCUMENT_LITERAL);
rpcLitRadio.setText(SOAP_RPC_LITERAL);
rpcEncRadio.setText(SOAP_RPC_ENCODED);
docLitRadio.setSelection(true);
///////////////////////// Http Page
httpPage = new Composite(protocolPageBook, SWT.NONE);
pbLayout = new GridLayout();
httpPage.setLayout(pbLayout);
pbData = new GridData();
pbData.verticalAlignment = GridData.FILL;
pbData.horizontalAlignment = GridData.FILL;
httpPage.setLayoutData(pbData);
createLabel(httpPage, WSDLEditorPlugin.getWSDLString("_UI_LABEL_HTTP_BINDING_OPTIONS")); // Already Externalized
httpGetRadio = new Button(httpPage, SWT.RADIO);
httpPostRadio = new Button(httpPage, SWT.RADIO);
httpGetRadio.setText(HTTP_GET);
httpPostRadio.setText(HTTP_POST);
httpGetRadio.setSelection(true);
wsdlSkeletonGroup.setVisible(true);
sepLabel.setVisible(true);
protocolPageBook.showPage(soapPage);
protocolPageBook.setVisible(true);
////////////////////////// Add Selection Listeners
createSkeletonCheckBox.addSelectionListener(this);
// BindingProtocolComponentControl component = new BindingProtocolComponentControl(base, generator, false);
// component.initFields();
setControl(base);
}
private NewWSDLWizard getNewWSDLWizard()
{
return (NewWSDLWizard)getWizard();
}
private String computeDefaultDefinitionName()
{
String name = "DefaultName";
IPath path = getNewWSDLWizard().getNewFilePath();
if (path != null)
{
name = path.removeFileExtension().lastSegment().toString();
}
return name;
}
private String computeDefaultNamespaceName()
{
String namespace = WSDLEditorPlugin.getInstance().getPreferenceStore().getString(WSDLEditorPlugin.getWSDLString("_UI_PREF_PAGE_DEFAULT_TARGET_NAMESPACE"));
if (!namespace.endsWith("/")) {
namespace = namespace.concat("/");
}
IPath path = getNewWSDLWizard().getNewFilePath();
if (path != null)
{
namespace += path.removeFileExtension().toString() + "/";
}
return namespace;
}
public void setVisible(boolean visible)
{
super.setVisible(visible);
if (visible)
{
// prime the fields
targetNamespaceText.setText(computeDefaultNamespaceName());
prefixText.setText("tns");
}
}
public String getTargetNamespace()
{
return targetNamespaceText.getText();
}
public String getPrefix()
{
return prefixText.getText().trim();
}
public String getDefinitionName()
{
return computeDefaultDefinitionName();
}
public void modifyText(ModifyEvent e)
{
if (e.widget == targetNamespaceText)
{
startDelayedEvent(e);
}
else if (e.widget == prefixText)
{
setPageComplete(isPageComplete());
}
else if (e.widget == protocolCombo) {
// Update what page/control we show in the PageBook
if (protocolCombo.getText().equals("SOAP")) {
protocolPageBook.showPage(soapPage);
}
else if (protocolCombo.getText().equals("HTTP")) {
protocolPageBook.showPage(httpPage);
}
}
}
public void updateOccured(Object arg1, Object arg2)
{
setPageComplete(isPageComplete());
}
public boolean isPageComplete()
{
boolean ready = true;
setErrorMessage(null);
// so that the page doesn't immediately show up with an error
if (targetNamespaceText.getText().trim().equals(""))
{
if (ready)
{
setErrorMessage(null);
}
return false;
}
if (!validateTargetNamespace(targetNamespaceText.getText()))
{
ready = false;
}
return ready;
}
protected boolean validatePrefix(String prefix)
{
String errorMessage = ValidateHelper.checkXMLPrefix(prefix);
if (errorMessage == null || errorMessage.length() == 0)
{
return true;
}
return false;
}
protected boolean validateXMLName(String xmlName)
{
String errorMessage = ValidateHelper.checkXMLName(xmlName);
if (errorMessage == null || errorMessage.length() == 0)
{
return true;
}
setErrorMessage(errorMessage);
return false;
}
protected boolean validateTargetNamespace(String ns)
{
boolean test = true;
try
{
new URI(ns);
// URI testURI = new URI(ns);
// if (!testURI.isGenericURI())
// {
// setErrorMessage(WSDLEditorPlugin.getInstance().getWSDLString("_UI_ERROR_NAMESPACE_INVALID")); //$NON-NLS-1$
// test = false;
// }
}
catch (URISyntaxException e)
{
// String errorMessage = ValidateHelper.checkXMLName(ns);
// if (errorMessage == null || errorMessage.length() == 0)
// {
// test = true;
// }
// else
// {
setErrorMessage(WSDLEditorPlugin.getWSDLString("_UI_ERROR_NAMESPACE_INVALID")); //$NON-NLS-1$
test = false;
// }
}
return test;
}
/*
private boolean arePrefixesUniqueAndValid()
{
java.util.List infoList = namespaceInfo.getNamespaceInfoList();
java.util.List checkedList = namespaceInfo.getNamespaceCheckedList();
Vector prefixList = new Vector();
boolean test = true;
boolean isOneBlank = false;
String currentPrefix = prefixText.getText().trim();
if (currentPrefix.length() == 0)
{
isOneBlank = true;
}
else
{
if (validatePrefix(currentPrefix))
{
prefixList.add(currentPrefix);
}
else
{
setErrorMessage(WSDLEditorPlugin.getWSDLString("_UI_ERROR_PREFIX_IS_INVALID", currentPrefix)); //$NON-NLS-1$
return false;
}
}
for (int i = 0; i < infoList.size(); i++)
{
NamespaceInfo info = (NamespaceInfo)infoList.get(i);
if (((String)checkedList.get(i)).equals("true")) //$NON-NLS-1$
{
String aPrefix = info.prefix.trim();
if (aPrefix.length() > 0)
{
if (!prefixList.contains(aPrefix))
{
if (validatePrefix(aPrefix))
{
prefixList.add(aPrefix);
}
else
{
setErrorMessage(WSDLEditorPlugin.getWSDLString("_UI_ERROR_PREFIX_IS_INVALID", info.prefix)); //$NON-NLS-1$
test = false;
break;
}
}
else
{
setErrorMessage(WSDLEditorPlugin.getWSDLString("_UI_ERROR_PREFIX_IS_A_DUPLICATE", info.prefix)); //$NON-NLS-1$
test = false;
break;
}
}
else
{
if (!isOneBlank)
{
isOneBlank = true;
}
else
{
setErrorMessage(WSDLEditorPlugin.getWSDLString("_UI_ERROR_MORE_THAN_ONE_PREFIX_IS_BLANK")); //$NON-NLS-1$
test = false;
break;
}
}
}
}
return test;
}
*/
protected DelayedEvent delayedTask;
protected void startDelayedEvent(ModifyEvent e)
{
if (delayedTask == null || delayedTask.getEvent() == null)
{
delayedTask = new DelayedEvent();
delayedTask.setEvent(e);
Display.getDefault().timerExec(500, delayedTask);
}
else
{
ModifyEvent delayedEvent = delayedTask.getEvent();
if (e.widget == delayedEvent.widget)
{
// same event, just different data, delay new event
delayedTask.setEvent(null);
}
delayedTask = new DelayedEvent();
delayedTask.setEvent(e);
Display.getDefault().timerExec(500, delayedTask);
}
}
class DelayedEvent implements Runnable
{
protected ModifyEvent event;
/*
* @see Runnable#run()
*/
public void run()
{
if (event != null)
{
setPageComplete(isPageComplete());
event = null;
}
}
public ModifyEvent getEvent()
{
return event;
}
public void setEvent(ModifyEvent event)
{
this.event = event;
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
if (e.widget == createSkeletonCheckBox) {
if (createSkeletonCheckBox.getSelection()) {
wsdlSkeletonGroup.setVisible(true);
sepLabel.setVisible(true);
protocolPageBook.setVisible(true);
}
else {
wsdlSkeletonGroup.setVisible(false);
sepLabel.setVisible(false);
protocolPageBook.setVisible(false);
}
}
}
private static final String SOAP_PROTOCOL = "SOAP";
private static final String HTTP_PROTOCOL = "HTTP";
private static final String SOAP_RPC_ENCODED = WSDLEditorPlugin.getWSDLString("_UI_RADIO_RPC_ENCODED");
private static final String SOAP_RPC_LITERAL = WSDLEditorPlugin.getWSDLString("_UI_RADIO_RPC_LITERAL");
private static final String SOAP_DOCUMENT_LITERAL = WSDLEditorPlugin.getWSDLString("_UI_RADIO_DOCUMENT_LITERAL");
private static final String HTTP_POST = "HTTP POST";
private static final String HTTP_GET = "HTTP GET";
Composite wsdlSkeletonGroup;
Button createSkeletonCheckBox;
Label sepLabel;
private Label createLabel(Composite comp, String labelString) {
Label label = new Label(comp, SWT.LEFT);
label.setText(labelString);
GridData nsData = new GridData();
nsData.horizontalAlignment = GridData.FILL;
label.setLayoutData(nsData);
return label;
}
public Vector getNamespaceInfo() {
Vector namespaces = new Vector();
// Add Default Namespaces
NamespaceInfo info1 = new NamespaceInfo();
info1.prefix = "wsdl";
info1.uri = "http://schemas.xmlsoap.org/wsdl/";
namespaces.addElement(info1);
NamespaceInfo info8 = new NamespaceInfo();
info8.prefix = "xsd";
info8.uri = "http://www.w3.org/2001/XMLSchema";
namespaces.addElement(info8);
return namespaces;
}
public boolean getCreateSkeletonBoolean() {
return createSkeletonCheckBox.getSelection();
}
public String getProtocol() {
return protocolCombo.getText();
}
public Object[] getProtocolOptions() {
Object bool[] = new Boolean[3];
if (protocolCombo.getText().equals(SOAP_PROTOCOL)) {
if (docLitRadio.getSelection()) {
bool[0] = new Boolean(true);
}
else {
bool[0] = new Boolean(false);
}
if (rpcLitRadio.getSelection()) {
bool[2] = new Boolean(true);
}
else {
bool[2] = new Boolean(false);
}
}
else if (protocolCombo.getText().equals(HTTP_PROTOCOL)){
if (httpGetRadio.getSelection()) {
bool[0] = new Boolean(false);
}
else {
bool[0] = new Boolean(true);
}
}
return bool;
}
public boolean isSoapDocLiteralProtocol() {
if (getProtocol().equals(SOAP_PROTOCOL) && docLitRadio.getSelection()) {
return true;
}
else {
return false;
}
}
}
|