001: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra;
002:
003: import org.eclipse.jface.wizard.WizardPage;
004: import org.eclipse.swt.SWT;
005: import org.eclipse.swt.events.ModifyEvent;
006: import org.eclipse.swt.events.ModifyListener;
007: import org.eclipse.swt.events.SelectionAdapter;
008: import org.eclipse.swt.events.SelectionEvent;
009: import org.eclipse.swt.events.SelectionListener;
010: import org.eclipse.swt.graphics.Image;
011: import org.eclipse.swt.layout.GridData;
012: import org.eclipse.swt.layout.GridLayout;
013: import org.eclipse.swt.widgets.Button;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.swt.widgets.Group;
016: import org.eclipse.swt.widgets.Label;
017: import org.eclipse.swt.widgets.Table;
018: import org.eclipse.swt.widgets.TableColumn;
019: import org.eclipse.swt.widgets.TableItem;
020: import org.eclipse.swt.widgets.Text;
021: import org.eclipse.jface.viewers.ILabelProviderListener;
022: import org.eclipse.jface.viewers.IStructuredContentProvider;
023: import org.eclipse.jface.viewers.ITableLabelProvider;
024: import org.eclipse.jface.viewers.TableViewer;
025: import org.eclipse.jface.viewers.Viewer;
026:
027: import com.bostechcorp.cbesb.common.i18n.I18N;
028: import com.bostechcorp.cbesb.common.i18n.Messages;
029: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.models.ServiceOperation;
030:
031: public class WSEditorPage extends WizardPage {
032:
033: private Button inOnlyButton;
034: private Button updateButton;
035: private Table table;
036: private Button removeButton;
037: private Button addButton;
038: private Button inoutButton;
039: private ImageCombo combo_2;
040: private ImageCombo combo_1;
041: private Text text_3;
042: private Text text_2;
043: private Text text_1;
044: private Text text;
045:
046: private TableViewer viewer;
047: private Object[] content;
048:
049: // private final static String OPERATION_NAME_PROPERTY="operationName";
050: // private final static String OPERATION_INPUT_NAME_PROPERTY="operationInputName";
051: // private final static String OPERATION_INPUT_TYPE_PROPERTY="operationInputType";
052: // private final static String OPERATION_OUTPUT_NAME_PROPERTY="operationOutputName";
053: // private final static String OPERATION_OUTPUT_TYPE_PROPERTY="operationOutputType";
054:
055: /**
056: * Create the wizard
057: */
058: public WSEditorPage() {
059: super ("wizardPage");
060: this .setTitle(I18N.getString(Messages.WSDL_EDIT_PAGE));
061: this .setDescription(I18N
062: .getString(Messages.WSDL_EDIT_PAGE_DESCRIPTION));
063: }
064:
065: /**
066: * @param pageName
067: */
068: public WSEditorPage(String pageName) {
069: super (pageName);
070: this .setTitle(I18N.getString(Messages.WSDL_EDIT_PAGE));
071: this .setDescription(I18N
072: .getString(Messages.WSDL_EDIT_PAGE_DESCRIPTION));
073: }
074:
075: /**
076: * Create contents of the wizard
077: * @param parent
078: */
079: public void createControl(Composite parent) {
080: Composite container = new Composite(parent, SWT.NULL);
081: final GridLayout gridLayout = new GridLayout();
082: gridLayout.numColumns = 2;
083: container.setLayout(gridLayout);
084: //
085: setControl(container);
086:
087: final Label webServiceNameLabel = new Label(container, SWT.NONE);
088: webServiceNameLabel.setText(I18N
089: .getString(Messages.WEB_SERVICE_NAME));
090:
091: text = new Text(container, SWT.BORDER);
092: text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
093: false));
094: text.setText(getWizard().getModel().getWsName());
095:
096: final Group operationDetailsGroup = new Group(container,
097: SWT.NONE);
098: operationDetailsGroup.setText(I18N
099: .getString(Messages.OPERATION_DETAILS));
100: operationDetailsGroup.setLayoutData(new GridData(SWT.FILL,
101: SWT.FILL, false, false, 2, 1));
102: final GridLayout gridLayout_1 = new GridLayout();
103: gridLayout_1.numColumns = 4;
104: operationDetailsGroup.setLayout(gridLayout_1);
105:
106: final Label operationNameLabel = new Label(
107: operationDetailsGroup, SWT.NONE);
108: operationNameLabel.setLayoutData(new GridData(SWT.FILL,
109: SWT.CENTER, false, false));
110: operationNameLabel.setText(I18N.getString(Messages.OPERATION));
111:
112: text_1 = new Text(operationDetailsGroup, SWT.BORDER);
113: final GridData gridData = new GridData(SWT.FILL, SWT.CENTER,
114: true, false);
115: gridData.widthHint = 226;
116: text_1.setLayoutData(gridData);
117:
118: inOnlyButton = new Button(operationDetailsGroup, SWT.RADIO);
119: inOnlyButton.addSelectionListener(new SelectionAdapter() {
120: public void widgetSelected(final SelectionEvent e) {
121: checkMEP();
122: }
123:
124: });
125: inOnlyButton.setSelection(true);
126: inOnlyButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
127: false, false));
128: inOnlyButton.setText("In Only");
129:
130: inoutButton = new Button(operationDetailsGroup, SWT.RADIO);
131: inoutButton.addSelectionListener(new SelectionAdapter() {
132: public void widgetSelected(final SelectionEvent e) {
133: checkMEP();
134: }
135: });
136: inoutButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
137: false, false));
138: inoutButton.setText("In-Out");
139: new Label(operationDetailsGroup, SWT.NONE);
140:
141: final Label nameLabel = new Label(operationDetailsGroup,
142: SWT.NONE);
143: nameLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
144: false, false));
145: nameLabel.setText(I18N.getString(Messages.MESSAGE_NAME));
146:
147: final Label typeLabel = new Label(operationDetailsGroup,
148: SWT.NONE);
149: typeLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
150: false, false, 2, 1));
151: typeLabel.setText(I18N.getString(Messages.MESSAGE_TYPE));
152:
153: final Label inputMessageLabel = new Label(
154: operationDetailsGroup, SWT.NONE);
155: inputMessageLabel.setLayoutData(new GridData(SWT.FILL,
156: SWT.CENTER, false, false));
157: inputMessageLabel.setText(I18N
158: .getString(Messages.INPUT_MESSAGE));
159:
160: text_2 = new Text(operationDetailsGroup, SWT.BORDER);
161: text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
162: false));
163:
164: combo_1 = new ImageCombo(operationDetailsGroup, SWT.NONE);
165: //combo_1.setEditable(false);
166: combo_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
167: false, 2, 1));
168:
169: final Label outputMessageLabel = new Label(
170: operationDetailsGroup, SWT.NONE);
171: outputMessageLabel.setLayoutData(new GridData(SWT.FILL,
172: SWT.CENTER, false, false));
173: outputMessageLabel.setText(I18N
174: .getString(Messages.OUTPUT_MESSAGE));
175:
176: text_3 = new Text(operationDetailsGroup, SWT.BORDER);
177: text_3.setEnabled(false);
178: text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
179: false));
180:
181: combo_2 = new ImageCombo(operationDetailsGroup, SWT.NONE);
182: //combo_2.setEditable(false);
183: combo_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
184: false, 2, 1));
185:
186: final Group operationsGroup = new Group(container, SWT.NONE);
187: operationsGroup.setText(I18N.getString(Messages.OPERATIONS));
188: operationsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
189: true, true, 2, 1));
190: final GridLayout gridLayout_2 = new GridLayout();
191: gridLayout_2.numColumns = 2;
192: operationsGroup.setLayout(gridLayout_2);
193:
194: table = new Table(operationsGroup, SWT.FULL_SELECTION
195: | SWT.BORDER);
196: table.addSelectionListener(new SelectionAdapter() {
197: public void widgetSelected(final SelectionEvent e) {
198: sincronizeTableItem();
199: checkRemove();
200: checkUpdate();
201: }
202: });
203: table.setLinesVisible(true);
204: table.setHeaderVisible(true);
205: table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
206: true, 1, 3));
207:
208: final TableColumn newColumnTableColumn = new TableColumn(table,
209: SWT.NONE);
210: newColumnTableColumn.setWidth(100);
211: newColumnTableColumn.setText(I18N
212: .getString(Messages.OPERATION_NAME));
213:
214: final TableColumn newColumnTableColumn_1 = new TableColumn(
215: table, SWT.NONE);
216: newColumnTableColumn_1.setWidth(100);
217: newColumnTableColumn_1.setText(I18N
218: .getString(Messages.INPUT_MESSAGE_NAME));
219:
220: final TableColumn newColumnTableColumn_2 = new TableColumn(
221: table, SWT.NONE);
222: newColumnTableColumn_2.setWidth(100);
223: newColumnTableColumn_2.setText(I18N
224: .getString(Messages.INPUT_MESSAGE_TYPE));
225:
226: final TableColumn newColumnTableColumn_3 = new TableColumn(
227: table, SWT.NONE);
228: newColumnTableColumn_3.setWidth(100);
229: newColumnTableColumn_3.setText(I18N
230: .getString(Messages.OUTPUT_MESSAGE_NAME));
231:
232: final TableColumn newColumnTableColumn_4 = new TableColumn(
233: table, SWT.NONE);
234: newColumnTableColumn_4.setWidth(100);
235: newColumnTableColumn_4.setText(I18N
236: .getString(Messages.OUTPUT_MESSAGE_TYPE));
237:
238: table.setLinesVisible(true);
239: table.setHeaderVisible(true);
240:
241: viewer = new TableViewer(table);
242: attachContentProvider(viewer);
243: attachLabelProviderTable(viewer);
244: content = getWizard().getModel().getOperations().toArray();
245: viewer.setInput(content);
246: //
247: addButton = new Button(operationsGroup, SWT.NONE);
248:
249: addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
250: false, false));
251: addButton.setText(I18N.getString(Messages.ADD));
252:
253: updateButton = new Button(operationsGroup, SWT.NONE);
254: updateButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
255: false, false));
256: updateButton.setText(I18N.getString(Messages.UPDATE));
257:
258: removeButton = new Button(operationsGroup, SWT.NONE);
259: removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
260: false, false));
261: removeButton.setText(I18N.getString(Messages.REMOVE));
262:
263: // Some listeners
264:
265: //Listen for text modification in whole page
266: ModifyListener modifyListener = new ModifyListener() {
267: public void modifyText(ModifyEvent e) {
268: checkAdd();
269: checkFinish();
270: }
271: };
272:
273: text.addModifyListener(modifyListener);
274: text_1.addModifyListener(modifyListener);
275: text_2.addModifyListener(modifyListener);
276: text_3.addModifyListener(modifyListener);
277:
278: combo_1.addModifyListener(modifyListener);
279: combo_2.addModifyListener(modifyListener);
280:
281: //Listen for wadd/remove buttons
282:
283: SelectionListener selectionAdapterAdd = new SelectionListener() {
284: public void widgetDefaultSelected(SelectionEvent e) {//reloadOperationList();
285: }
286:
287: public void widgetSelected(SelectionEvent e) {
288: ServiceOperation operation = new ServiceOperation();
289: operation.setOperationName(text_1.getText());
290: operation.setInputType(combo_1.getText());
291: operation.setInputMessageName(text_2.getText());
292: //test wether it is a type or element
293: if (isTypeElement(combo_1.getItem(combo_1
294: .getSelectionIndex()))) {
295: operation.setInputTypeElement(true);
296: } else {
297: operation.setInputTypeElement(false);
298: }
299:
300: if (inoutButton.getSelection()) {
301: operation.setOutMessage(true);
302: operation.setOutputType(combo_2.getText());
303: operation.setOutputMessageName(text_3.getText());
304: //test wether it is a type or element
305: if (isTypeElement(combo_2.getItem(combo_2
306: .getSelectionIndex()))) {
307: operation.setOutputTypeElement(true);
308: } else {
309: operation.setOutputTypeElement(false);
310: }
311: } else {
312: operation.setOutMessage(false);
313: }
314: getWizard().getModel().addOperation(operation);
315: reloadOperationList();
316: checkFinish();
317: }
318: };
319: addButton.addSelectionListener(selectionAdapterAdd);
320:
321: SelectionListener selectionAdapterRemove = new SelectionListener() {
322: public void widgetDefaultSelected(SelectionEvent e) {//reloadOperationList();
323: }
324:
325: public void widgetSelected(SelectionEvent e) {
326: TableItem oper[] = table.getSelection();
327: for (TableItem item : oper) {
328: getWizard().getModel().removeOperation(
329: item.getData());
330: }
331: reloadOperationList();
332: checkUpdate();
333: checkFinish();
334: }
335: };
336: removeButton.addSelectionListener(selectionAdapterRemove);
337:
338: SelectionListener selectionAdapterUpdate = new SelectionListener() {
339:
340: public void widgetDefaultSelected(SelectionEvent e) {
341: }
342:
343: public void widgetSelected(SelectionEvent e) {
344: TableItem oper[] = table.getSelection();
345: if (oper[0] != null) {
346: ServiceOperation operation = (ServiceOperation) oper[0]
347: .getData();
348: operation.setOperationName(text_1.getText());
349: operation.setInputType(combo_1.getText());
350: operation.setInputMessageName(text_2.getText());
351: //test wether it is a type or element
352: if (isTypeElement(combo_1.getItem(combo_1
353: .getSelectionIndex()))) {
354: operation.setInputTypeElement(true);
355: } else {
356: operation.setInputTypeElement(false);
357: }
358:
359: if (inoutButton.getSelection()) {
360: operation.setOutMessage(true);
361: operation.setOutputType(combo_2.getText());
362: operation
363: .setOutputMessageName(text_3.getText());
364: //test wether it is a type or element
365: if (isTypeElement(combo_2.getItem(combo_2
366: .getSelectionIndex()))) {
367: operation.setOutputTypeElement(true);
368: } else {
369: operation.setOutputTypeElement(false);
370: }
371: } else {
372: operation.setOutMessage(false);
373: operation.setOutputType("");
374: operation.setOutputMessageName("");
375: }
376: }
377: reloadOperationList();
378: getUpdateButton().setEnabled(false);
379: //checkFinish();
380: }
381: };
382:
383: updateButton.addSelectionListener(selectionAdapterUpdate);
384: getWizard().getImportPage().populateCombos();
385: sincronizeTableItem();
386: checkAdd();
387: checkRemove();
388: checkUpdate();
389: checkFinish();
390: }
391:
392: protected boolean isTypeElement(TableItem item) {
393: if (item != null)
394: if (item.getImage().equals(
395: SchemaImportPage.elementTypeImage))
396: return true;
397: return false;
398: }
399:
400: protected void checkMEP() {
401: if (inOnlyButton.getSelection()) {
402: text_3.setEnabled(false);
403: combo_2.setEnabled(false);
404: } else {
405: text_3.setEnabled(true);
406: combo_2.setEnabled(true);
407: }
408: }
409:
410: protected void sincronizeTableItem() {
411: TableItem[] selection = table.getItems();
412: if (selection.length > 0)
413: if (selection[0] != null) {
414: ServiceOperation op = (ServiceOperation) selection[0]
415: .getData();
416: text_1.setText(op.getOperationName());
417: text_2.setText(op.getInputMessageName());
418: combo_1.setText(op.getInputType());
419: if (op.hasOutMessage()) {
420: text_3.setText(op.getOutputMessageName());
421: combo_2.setText(op.getOutputType());
422: getInoutButton().setSelection(true);
423: getInOnlyButton().setSelection(false);
424: checkMEP();
425: } else {
426: text_3.setText("");
427: combo_2.setText("");
428: getInoutButton().setSelection(false);
429: getInOnlyButton().setSelection(true);
430: checkMEP();
431: }
432: getAddButton().setEnabled(false);
433: }
434: //getUpdateButton().setEnabled(true);
435: }
436:
437: // private void attachCellEditorsTable(
438: // final TableViewer viewer,
439: // Composite parent)
440: // {
441: // viewer.setCellModifier(new ICellModifier()
442: // {
443: // public boolean canModify(Object element, String property)
444: // {
445: // return true;
446: // }
447: //
448: // public Object getValue(Object element, String property)
449: // {
450: // if (OPERATION_NAME_PROPERTY.equals(property))
451: // return ((ServiceOperation) element).getOperationName();
452: // else if (OPERATION_INPUT_NAME_PROPERTY.equals(property))
453: // return ((ServiceOperation) element).getInputMessageName();
454: // else if (OPERATION_INPUT_TYPE_PROPERTY.equals(property))
455: // return ((ServiceOperation) element).getInputType();
456: // else if (OPERATION_OUTPUT_NAME_PROPERTY.equals(property))
457: // return ((ServiceOperation) element).getOutputMessageName();
458: // else if (OPERATION_OUTPUT_TYPE_PROPERTY.equals(property))
459: // return ((ServiceOperation) element).getOutputType();
460: // }
461: //
462: // public void modify(Object element, String property, Object value)
463: // {
464: // TableItem tableItem = (TableItem) element;
465: // ServiceOperation data = (ServiceOperation) tableItem.getData();
466: // // checkPageError(data);
467: // if (value != null)
468: // if (OPERATION_NAME_PROPERTY.equals(property))
469: // data.setOperationName(value.toString());
470: // else if (OPERATION_INPUT_NAME_PROPERTY.equals(property))
471: // data.setInputMessageName(value.toString());
472: // else if (OPERATION_INPUT_TYPE_PROPERTY.equals(property))
473: // data.setInputMessageType(value.toString());
474: // else if (OPERATION_OUTPUT_NAME_PROPERTY.equals(property))
475: // data.setOutputMessageName(value.toString());
476: // else if (OPERATION_OUTPUT_TYPE_PROPERTY.equals(property))
477: // data.setOutputType(value.toString());
478: // viewer.refresh();
479: // }
480: // });
481: //
482: // pageNameEditor = new TextCellEditor(parent);
483: //
484: // viewer.setCellEditors(new CellEditor[]
485: // { pageNameEditor, new TextCellEditor(parent) });
486: //
487: // viewer.setColumnProperties(new String[]
488: // { NAME_PROPERTY, DESCRIPTION_PROPERTY });
489: // }
490: //
491: private void attachLabelProviderTable(TableViewer viewer) {
492: viewer.setLabelProvider(new ITableLabelProvider() {
493:
494: public Image getColumnImage(Object element, int columnIndex) {
495: return null;
496: }
497:
498: public String getColumnText(Object element, int columnIndex) {
499: switch (columnIndex) {
500: case 0:
501: return ((ServiceOperation) element)
502: .getOperationName();
503: case 1:
504: return ((ServiceOperation) element)
505: .getInputMessageName();
506: case 2:
507: return ((ServiceOperation) element).getInputType();
508: case 3:
509: return ((ServiceOperation) element)
510: .getOutputMessageName();
511: case 4:
512: return ((ServiceOperation) element).getOutputType();
513: default:
514: return "Invalid column: " + columnIndex;
515: }
516: }
517:
518: public void addListener(ILabelProviderListener listener) {
519: }
520:
521: public void dispose() {
522: }
523:
524: public boolean isLabelProperty(Object element,
525: String property) {
526: return false;
527: }
528:
529: public void removeListener(ILabelProviderListener listener) {
530: }
531: });
532: }
533:
534: private void attachContentProvider(TableViewer viewer) {
535: viewer.setContentProvider(new IStructuredContentProvider() {
536: public Object[] getElements(Object inputElement) {
537: return (Object[]) inputElement;
538: // return ((List) inputElement).toArray();
539: }
540:
541: public void dispose() {
542: }
543:
544: public void inputChanged(Viewer viewer, Object oldInput,
545: Object newInput) {
546: }
547: });
548: }
549:
550: public ImageCombo getCombo_1() {
551: return combo_1;
552: }
553:
554: public ImageCombo getCombo_2() {
555: return combo_2;
556: }
557:
558: @Override
559: public NewWSDLWizard getWizard() {
560: return ((NewWSDLWizard) super .getWizard());
561: }
562:
563: private void reloadOperationList() {
564: content = getWizard().getModel().getOperations().toArray();
565: viewer.setInput(content);
566: }
567:
568: private void checkAdd() {
569: getAddButton().setEnabled(false);
570: if (text_1.getText().equals("")) {
571: setErrorMessage(I18N.getString(Messages.OPERATION_NULL));
572: //setPageComplete(false);
573: return;
574: } else if (text_2.getText().equals("")) {
575: setErrorMessage(I18N.getString(Messages.IMPUT_MESSAGE_NULL));
576: //setPageComplete(false);
577: return;
578: } else if (combo_1.getText().equals("")) {
579: setErrorMessage(I18N.getString(Messages.INPUT_TYPE_NULL));
580: //setPageComplete(false);
581: return;
582: }
583: ;
584: if (getInoutButton().getSelection()) {
585: if (text_3.getText().equals("")) {
586: setErrorMessage(I18N
587: .getString(Messages.OUTPUT_MESSAGE_NULL));
588: //setPageComplete(false);
589: return;
590: } else if (text_3.getText().equals("")) {
591: setErrorMessage(I18N
592: .getString(Messages.OUTPUT_TYPE_NULL));
593: //setPageComplete(false);
594: return;
595: }
596: }
597: getAddButton().setEnabled(true);
598: setErrorMessage(null);
599: }
600:
601: private void checkUpdate() {
602: checkAdd();
603: checkRemove();
604:
605: //getUpdateButton().setEnabled(false);
606: getUpdateButton().setEnabled(
607: getAddButton().getEnabled()
608: && getRemoveButton().getEnabled());
609: //setErrorMessage(null);
610: }
611:
612: private void checkRemove() {
613: getRemoveButton().setEnabled(false);
614: if (table.getSelection().length > 0) {
615: getRemoveButton().setEnabled(true);
616: }
617: }
618:
619: private void checkFinish() {
620: if (text.getText().equals("")) {
621: setErrorMessage(I18N
622: .getString(Messages.WEB_SERVICE_NAME_NULL));
623: setPageComplete(false);
624: return;
625: } else if (table.getItemCount() == 0) {
626: setErrorMessage(I18N.getString(Messages.OPERATION_PROVIDED));
627: setPageComplete(false);
628: return;
629: }
630: setErrorMessage(null);
631: setPageComplete(true);
632: }
633:
634: protected Button getInoutButton() {
635: return inoutButton;
636: }
637:
638: protected Button getAddButton() {
639: return addButton;
640: }
641:
642: protected Button getRemoveButton() {
643: return removeButton;
644: }
645:
646: public Table getTable() {
647: return table;
648: }
649:
650: protected Button getUpdateButton() {
651: return updateButton;
652: }
653:
654: protected Button getInOnlyButton() {
655: return inOnlyButton;
656: }
657:
658: public Text getText() {
659: return text;
660: }
661: }
|