001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards;
025:
026: import org.eclipse.jface.wizard.IWizardPage;
027: import org.eclipse.swt.SWT;
028: import org.eclipse.swt.custom.StackLayout;
029: import org.eclipse.swt.events.ModifyEvent;
030: import org.eclipse.swt.events.ModifyListener;
031: import org.eclipse.swt.events.SelectionAdapter;
032: import org.eclipse.swt.events.SelectionEvent;
033: import org.eclipse.swt.layout.FillLayout;
034: import org.eclipse.swt.layout.FormAttachment;
035: import org.eclipse.swt.layout.FormData;
036: import org.eclipse.swt.layout.FormLayout;
037: import org.eclipse.swt.layout.GridData;
038: import org.eclipse.swt.layout.GridLayout;
039: import org.eclipse.swt.widgets.Button;
040: import org.eclipse.swt.widgets.Combo;
041: import org.eclipse.swt.widgets.Composite;
042: import org.eclipse.swt.widgets.Group;
043: import org.eclipse.swt.widgets.Label;
044: import org.eclipse.swt.widgets.Text;
045:
046: import com.bostechcorp.cbesb.common.i18n.I18N;
047: import com.bostechcorp.cbesb.common.i18n.Messages;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTP;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FTPScriptModeType;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RoleType;
052:
053: public class FTPPropertyWizardPageMain extends PropertyWizardPageMain {
054:
055: private Text textDescription_1;
056:
057: private Text textName_1;
058:
059: private Button buttonWrite;
060:
061: private Button buttonRead;
062:
063: private Button baseModeButton;
064:
065: private Button advanceModeButton;
066:
067: private StackLayout stackLayout;
068:
069: private Composite baseComposite;
070:
071: private Composite advaceComposite;
072:
073: private Composite topLevel;
074:
075: private Composite composite;
076:
077: protected FTPPropertyWizardPageMain(String pageName) {
078: super (pageName);
079: setTitle(I18N.getString(Messages.FTP_PRO_WIZ));// "Choose
080: setDescription(I18N.getString(Messages.FILE_PRO_WIZ_DES));
081: }
082:
083: public void createControl(Composite parent) {
084:
085: topLevel = new Composite(parent, SWT.NONE);
086: final GridLayout gridLayout_4 = new GridLayout();
087: gridLayout_4.verticalSpacing = 15;
088: topLevel.setLayout(gridLayout_4);
089: topLevel.setLayoutData(new GridData(
090: GridData.VERTICAL_ALIGN_FILL
091: | GridData.HORIZONTAL_ALIGN_FILL));
092: topLevel.setFont(parent.getFont());
093: this .setControl(topLevel);
094:
095: final Group scriptModeGroup = new Group(topLevel, SWT.NONE);
096: scriptModeGroup.setLayoutData(new GridData(SWT.FILL,
097: SWT.CENTER, true, false));
098: final GridLayout gridLayout_3 = new GridLayout();
099: gridLayout_3.horizontalSpacing = 200;
100: gridLayout_3.numColumns = 2;
101: scriptModeGroup.setLayout(gridLayout_3);
102: scriptModeGroup.setText(I18N.getString(Messages.MODE));
103:
104: baseModeButton = new Button(scriptModeGroup, SWT.RADIO);
105:
106: baseModeButton.setText(I18N.getString(Messages.BASE_MODE));
107:
108: baseModeButton.addSelectionListener(new SelectionAdapter() {
109: public void widgetSelected(SelectionEvent e) {
110: stackLayout.topControl = baseComposite;
111: composite.layout();
112: dialogChanged();
113: }
114: });
115:
116: advanceModeButton = new Button(scriptModeGroup, SWT.RADIO);
117: advanceModeButton.setText(I18N.getString(Messages.SCR_MODE));
118:
119: advanceModeButton.addSelectionListener(new SelectionAdapter() {
120: public void widgetSelected(SelectionEvent e) {
121: stackLayout.topControl = advaceComposite;
122: composite.layout();
123: dialogChanged();
124: }
125: });
126:
127: composite = new Composite(topLevel, SWT.NONE);
128: composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
129: true, false));
130: stackLayout = new StackLayout();
131: composite.setLayout(stackLayout);
132:
133: baseComposite = new Composite(composite, SWT.NONE);
134: baseComposite.setLayout(new FillLayout());
135:
136: final Group baseModeGroup = new Group(baseComposite, SWT.NONE);
137: final GridLayout gridLayout_2 = new GridLayout();
138: gridLayout_2.numColumns = 2;
139: baseModeGroup.setLayout(gridLayout_2);
140: baseModeGroup.setText(I18N.getString(Messages.BASE_MODE));
141:
142: Group modeGroup;
143:
144: final Label labelName = new Label(baseModeGroup, SWT.NONE);
145: labelName.setText(I18N.getString(Messages.NAME_WIZ));
146:
147: textName = new Text(baseModeGroup, SWT.BORDER);
148: final GridData gridData_3 = new GridData(SWT.FILL, SWT.CENTER,
149: true, false);
150: gridData_3.widthHint = 394;
151: textName.setLayoutData(gridData_3);
152: textName.setText("FTP");
153: if (!this .getWizard().isUpdateOperation()) {
154: int num = WizardUtil.modelExistNum(this .getWizard()
155: .getModels());
156: if (num == 0) {
157: } else {
158: textName.setText("FTP_" + num);
159: }
160: }
161: textName.addModifyListener(new ModifyListener() {
162: public void modifyText(ModifyEvent e) {
163: dialogChanged();
164: }
165: });
166:
167: textName.addModifyListener(new ModifyListener() {
168: public void modifyText(ModifyEvent e) {
169: dialogChanged();
170: }
171: });
172:
173: final Label labelDescription = new Label(baseModeGroup,
174: SWT.NONE);
175: labelDescription.setText(I18N.getString(Messages.DES_WIZ));
176:
177: textDescription = new Text(baseModeGroup, SWT.BORDER);
178: final GridData gridData_2 = new GridData(SWT.FILL, SWT.CENTER,
179: true, false);
180: gridData_2.widthHint = 71;
181: textDescription.setLayoutData(gridData_2);
182:
183: final Label useCclsLabel = new Label(baseModeGroup, SWT.NONE);
184: useCclsLabel.setText(I18N.getString(Messages.USE_CCSL));
185:
186: comboCCSL = new Combo(baseModeGroup, SWT.READ_ONLY);
187: comboCCSL.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
188: true, false));
189: comboCCSL.setItems(new String[] { "true", "false" });
190: if (!this .getWizard().isUpdateOperation())
191: comboCCSL.setText("true");
192: modeGroup = new Group(baseModeGroup, SWT.NONE);
193: modeGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
194: false, false, 2, 1));
195: final GridLayout gridLayout = new GridLayout();
196: gridLayout.numColumns = 2;
197: gridLayout.marginHeight = 10;
198: gridLayout.horizontalSpacing = 200;
199: modeGroup.setLayout(gridLayout);
200: modeGroup.setText(I18N.getString(Messages.MODE));
201:
202: buttonRead = new Button(modeGroup, SWT.CHECK);
203: buttonRead.addSelectionListener(new SelectionAdapter() {
204: public void widgetSelected(SelectionEvent e) {
205: dialogChanged();
206:
207: }
208: });
209: buttonRead.setText(I18N.getString(Messages.READ));
210:
211: buttonWrite = new Button(modeGroup, SWT.CHECK);
212: buttonWrite.setText(I18N.getString(Messages.WRITE));
213: buttonWrite.addSelectionListener(new SelectionAdapter() {
214: public void widgetSelected(SelectionEvent e) {
215: dialogChanged();
216:
217: }
218: });
219:
220: advaceComposite = new Composite(composite, SWT.NONE);
221: advaceComposite.setLayout(new GridLayout());
222:
223: final Group advanceModeGroup = new Group(advaceComposite,
224: SWT.NONE);
225: advanceModeGroup.setLayoutData(new GridData(SWT.FILL,
226: SWT.CENTER, true, false));
227: final GridLayout gridLayout_1 = new GridLayout();
228: gridLayout_1.numColumns = 2;
229: advanceModeGroup.setLayout(gridLayout_1);
230: advanceModeGroup.setText(I18N.getString(Messages.SCR_MODE));
231:
232: final Label labelName_1 = new Label(advanceModeGroup, SWT.NONE);
233: labelName_1.setText(I18N.getString(Messages.NAME_WIZ));
234:
235: textName_1 = new Text(advanceModeGroup, SWT.BORDER);
236: final GridData gridData_1 = new GridData(SWT.FILL, SWT.CENTER,
237: true, false);
238: gridData_1.widthHint = 380;
239: textName_1.setLayoutData(gridData_1);
240: if (!this .getWizard().isUpdateOperation())
241: textName_1.setText("FTP");
242:
243: final Label labelDescription_1 = new Label(advanceModeGroup,
244: SWT.NONE);
245: labelDescription_1.setText(I18N.getString(Messages.DES_WIZ));
246:
247: textDescription_1 = new Text(advanceModeGroup, SWT.BORDER);
248: final GridData gridData = new GridData(SWT.FILL, SWT.CENTER,
249: true, false);
250: gridData.widthHint = 316;
251: textDescription_1.setLayoutData(gridData);
252:
253: textName_1.addModifyListener(new ModifyListener() {
254: public void modifyText(ModifyEvent e) {
255: dialogChanged();
256: }
257: });
258: stackLayout.topControl = baseComposite;
259:
260: if (this .getWizard().isUpdateOperation()) {
261: modelsToControl();
262: } else {
263: baseModeButton.setSelection(true);
264: stackLayout.topControl = baseComposite;
265: }
266:
267: dialogChanged();
268:
269: }
270:
271: //The ftp wizard can't invoke super.dialogChanged
272: protected void dialogChanged() {
273: if (WizardUtil.whetherUseValidation == false) {
274: setPageComplete(true);
275: return;
276: }
277: if (baseModeButton.getSelection()) {
278: if (textName.getText().equals("")) {
279: updateStatus(I18N.getString(Messages.NAME_REQ));
280: setPageComplete(false);
281: return;
282: } else if (WizardUtil.nameExist(textName.getText(), this
283: .getWizard().getModels())) {
284: updateStatus(I18N.getString(Messages.NAME_DUP));
285: setPageComplete(false);
286: return;
287: } else if (WizardUtil
288: .nameInstallerExist(textName.getText())) {
289: updateStatus(I18N.getString(Messages.NAME_FOR));
290: setPageComplete(false);
291: return;
292: } else if (!buttonRead.getSelection()
293: && !buttonWrite.getSelection()) {
294: updateStatus(I18N.getString(Messages.MODE_SEL_TIP));
295: setPageComplete(false);
296: return;
297: }
298: } else if (advanceModeButton.getSelection()) {
299: if (textName_1.getText().equals("")) {
300: updateStatus(I18N.getString(Messages.NAME_REQ));
301: setPageComplete(false);
302: return;
303: }
304: } else if (WizardUtil.nameInstallerExist(textName.getText())) {
305: updateStatus(I18N.getString(Messages.NAME_FOR));
306: setPageComplete(false);
307: return;
308: }
309: setPageComplete(true);
310: updateStatus(null);
311: }
312:
313: public IWizardPage getNextPage() {
314: if (advanceModeButton.getSelection()) {
315:
316: return null;
317: } else if (baseModeButton.getSelection()
318: && buttonRead.getSelection()) {
319:
320: return super .getNextPage();
321: } else if (baseModeButton.getSelection()
322: && buttonWrite.getSelection()) {
323:
324: return this .getWizard().getPage("WriteServerInformation");
325: }
326:
327: return null;
328: }
329:
330: public void setButtonRead(Button buttonRead) {
331: this .buttonRead = buttonRead;
332: }
333:
334: public void setButtonWrite(Button buttonWrite) {
335: this .buttonWrite = buttonWrite;
336: }
337:
338: //The ftp wizard can't invoke super.controlToModels
339:
340: public void controlToModels() {
341:
342: FTPPropertyWizard FTPWizard = (FTPPropertyWizard) this
343: .getWizard();
344: FTP models = FTPWizard.getModels();
345: if (models == null)
346: return;
347: try {
348: if (baseModeButton.getSelection()) {
349: models.setName(textName.getText());
350: models.setScriptMode(FTPScriptModeType.BASE_LITERAL);
351: if (!textName.getText().equals("")) {
352: models.setServiceName(textName.getText()
353: + "_Service");
354: models.setInterfaceName(textName.getText()
355: + "_Interface");
356: }
357:
358: models.setDescription(textDescription.getText());
359:
360: if (comboCCSL.getText().equals("true"))
361: models.setUseCCSL(true);
362: else if (comboCCSL.getText().equals("false"))
363: models.setUseCCSL(false);
364:
365: if (buttonRead.getSelection()
366: && !buttonWrite.getSelection()) {
367: models.setRole(RoleType.get(RoleType.CONSUMER));
368: models.getFtpBase().getFtpConsumer()
369: .setEndPointName(
370: textName.getText() + "_Input");
371:
372: } else if (buttonWrite.getSelection()
373: && !buttonRead.getSelection()) {
374: models.setRole(RoleType.get(RoleType.PROVIDER));
375: models.getFtpBase().getFtpProvider()
376: .setEndPointName(
377: textName.getText() + "_Output");
378: } else if (buttonRead.getSelection()
379: && buttonWrite.getSelection()) {
380: models.setRole(RoleType.get(RoleType.BOTH));
381: models.getFtpBase().getFtpConsumer()
382: .setEndPointName(
383: textName.getText() + "_Input");
384:
385: models.getFtpBase().getFtpProvider()
386: .setEndPointName(
387: textName.getText() + "_Output");
388: }
389: if (buttonRead.getSelection()) {
390: if (!textName.getText().equals(""))
391: models.getFtpBase().getFtpConsumer()
392: .setEndPointName(
393: textName.getText() + "_Input");
394:
395: }
396:
397: if (buttonWrite.getSelection()) {
398: if (!textName.getText().equals(""))
399: models.getFtpBase().getFtpProvider()
400: .setEndPointName(
401: textName.getText() + "_Ouput");
402:
403: }
404: } else if (advanceModeButton.getSelection()) {
405: models.setName(textName_1.getText());
406: models.setScriptMode(FTPScriptModeType.BASE_LITERAL);
407: if (!textName_1.getText().equals("")) {
408: models.setServiceName(textName_1.getText()
409: + "_Service");
410: models.setInterfaceName(textName_1.getText()
411: + "_Interface");
412: }
413:
414: models.setDescription(textDescription_1.getText());
415:
416: models.setScriptMode(FTPScriptModeType.SCRIPT_LITERAL);
417: models.setRole(RoleType.get(RoleType.PROVIDER));
418: }
419:
420: } catch (Exception e) {
421: e.printStackTrace();
422: }
423: }
424:
425: // The ftp wizard can't invoke super.modelsToControl
426:
427: @Override
428: public void modelsToControl() {
429:
430: FTPPropertyWizard FTPWizard = (FTPPropertyWizard) this
431: .getWizard();
432: try {
433: if (FTPWizard.getModels().getScriptMode().getLiteral()
434: .equals("base")) {
435: baseModeButton.setSelection(true);
436: topLevel.layout();
437:
438: if (FTPWizard.getModels().getName() != null)
439: textName.setText(FTPWizard.getModels().getName());
440: else
441: textName.setText("");
442:
443: if (FTPWizard.getModels().getDescription() != null)
444: textDescription.setText(FTPWizard.getModels()
445: .getDescription());
446: else
447: textDescription.setText("");
448:
449: int modeType = FTPWizard.getModels().getRole()
450: .getValue();
451:
452: if (modeType == RoleType.CONSUMER) {
453: buttonRead.setSelection(true);
454: buttonWrite.setSelection(false);
455: } else if (modeType == RoleType.PROVIDER) {
456: buttonRead.setSelection(false);
457: buttonWrite.setSelection(true);
458: } else if (modeType == RoleType.BOTH) {
459: buttonRead.setSelection(true);
460: buttonWrite.setSelection(true);
461: }
462: comboCCSL.select(comboCCSL.indexOf(FTPWizard
463: .getModels().getUseCCSL().toString()));
464: } else {
465: advanceModeButton.setSelection(true);
466: stackLayout.topControl = advaceComposite;
467: topLevel.layout();
468: if (FTPWizard.getModels().getName() != null)
469: textName_1.setText(FTPWizard.getModels().getName());
470: else
471: textName_1.setText("");
472:
473: if (FTPWizard.getModels().getDescription() != null)
474: textDescription_1.setText(FTPWizard.getModels()
475: .getDescription());
476: else
477: textDescription_1.setText("");
478: // String mepType =
479: // FTPWizard.getModels().getFtpAdvance().getDefaultMep().getLiteral();
480: }
481:
482: }
483:
484: catch (Exception e) {
485: e.printStackTrace();
486: }
487: }
488:
489: public Button getAdvanceModeButton() {
490: return advanceModeButton;
491: }
492:
493: public void setAdvanceModeButton(Button advanceModeButton) {
494: this .advanceModeButton = advanceModeButton;
495: }
496:
497: public Button getButtonRead() {
498: return buttonRead;
499: }
500:
501: public Button getButtonWrite() {
502: return buttonWrite;
503: }
504:
505: @Override
506: boolean isConsumer() {
507: return buttonRead.getSelection();
508: }
509:
510: @Override
511: boolean isProvider() {
512:
513: return buttonWrite.getSelection();
514: }
515:
516: @Override
517: public String getComponentName() {
518:
519: return "FTP";
520: }
521:
522: }
|