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.GridData;
034: import org.eclipse.swt.layout.GridLayout;
035: import org.eclipse.swt.widgets.Button;
036: import org.eclipse.swt.widgets.Combo;
037: import org.eclipse.swt.widgets.Composite;
038: import org.eclipse.swt.widgets.Group;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Text;
041: import org.eclipse.ui.PlatformUI;
042: import org.eclipse.ui.part.FileEditorInput;
043:
044: import com.bostechcorp.cbesb.common.i18n.I18N;
045: import com.bostechcorp.cbesb.common.i18n.Messages;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBR;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.CBRType;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
049: import com.bostechcorp.cbesb.ui.util.MsgUtil;
050: import com.bostechcorp.cbesb.ui.util.ProjectUtil;
051: import com.bostechcorp.cbesb.ui.util.browser.CustomCodeBrowseDialog;
052:
053: public class CBRPropertyWizardPageMain extends
054: ServiceEngineWizardPageMain {
055:
056: private Text textDelimiter;
057:
058: private Text textExpression;
059:
060: private Combo comboType;
061:
062: private Text textIndex;
063:
064: private Text textScriptClass;
065:
066: private Combo comboScriptEngine;
067:
068: private Text textFixedLength;
069:
070: private Text textFixedOffset;
071:
072: private Composite compositeNull;
073:
074: private Group compositeScript;
075:
076: private Group compositeXPath;
077:
078: private Group compositeCSV;
079:
080: private Group compositeFixed;
081:
082: private Composite compositeMain;
083:
084: private StackLayout stackLayout;
085:
086: protected CBRPropertyWizardPageMain(String pageName) {
087: super (pageName);
088: setTitle(I18N.getString(Messages.CBR_PRO_WIZ));// "Choose
089: setDescription(I18N.getString(Messages.PAGE_MAIN_DES));
090: }
091:
092: public void createControl(Composite parent) {
093:
094: super .createSubControl(parent, 2);
095:
096: final Label typeLabel = new Label(topLevel, SWT.NONE);
097: typeLabel.setLayoutData(new GridData());
098: typeLabel.setText(I18N.getString(Messages.TRX_TYPE));
099:
100: comboType = new Combo(topLevel, SWT.READ_ONLY);
101: comboType.setItems(new String[] { "fixed", "CSV", "hl7", "x12",
102: "xpath", "script" });
103: comboType.setVisibleItemCount(6);
104: if (!this .getWizard().isUpdateOperation())
105: comboType.setText("fixed");
106: comboType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
107: true, false));
108:
109: compositeMain = new Composite(topLevel, SWT.NONE);
110: final GridData gridData_4 = new GridData(SWT.FILL, SWT.FILL,
111: false, false, 2, 1);
112: compositeMain.setLayoutData(gridData_4);
113: stackLayout = new StackLayout();
114: stackLayout.marginHeight = 10;
115: compositeMain.setLayout(stackLayout);
116:
117: compositeFixed = new Group(compositeMain, SWT.NONE);
118: compositeFixed.setText(I18N.getString(Messages.FIX_GROUP));
119: final GridLayout gridLayout_1 = new GridLayout();
120: gridLayout_1.numColumns = 2;
121: compositeFixed.setLayout(gridLayout_1);
122: compositeFixed.setLayoutData(new GridData(
123: GridData.VERTICAL_ALIGN_FILL
124: | GridData.HORIZONTAL_ALIGN_FILL));
125:
126: final Label fixedOffsetLabel = new Label(compositeFixed,
127: SWT.NONE);
128: fixedOffsetLabel.setText(I18N.getString(Messages.FIX_OFFSET));
129:
130: textFixedOffset = new Text(compositeFixed, SWT.BORDER);
131: textFixedOffset.addModifyListener(new ModifyListener() {
132: public void modifyText(final ModifyEvent e) {
133: dialogChanged();
134: }
135: });
136:
137: final GridData gridData_3 = new GridData(SWT.FILL, SWT.CENTER,
138: true, false);
139: textFixedOffset.setLayoutData(gridData_3);
140:
141: final Label fixedLengthLabel = new Label(compositeFixed,
142: SWT.NONE);
143: fixedLengthLabel.setText(I18N.getString(Messages.FIX_LEN));
144:
145: textFixedLength = new Text(compositeFixed, SWT.BORDER);
146: textFixedLength.setLayoutData(new GridData(SWT.FILL,
147: SWT.CENTER, true, false));
148: textFixedLength.addModifyListener(new ModifyListener() {
149: public void modifyText(final ModifyEvent e) {
150: dialogChanged();
151: }
152: });
153:
154: compositeCSV = new Group(compositeMain, SWT.NONE);
155: compositeCSV.setText(I18N.getString(Messages.CSV_GROUP));
156: final GridLayout gridLayout_4 = new GridLayout();
157: gridLayout_4.numColumns = 2;
158: compositeCSV.setLayout(gridLayout_4);
159:
160: final Label dilimiterLabel = new Label(compositeCSV, SWT.NONE);
161: dilimiterLabel.setText(I18N.getString(Messages.DELIMITER));
162:
163: textDelimiter = new Text(compositeCSV, SWT.BORDER);
164: if (!this .getWizard().isUpdateOperation())
165: textDelimiter.setText(",");
166: textDelimiter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
167: true, false));
168: textDelimiter.addModifyListener(new ModifyListener() {
169: public void modifyText(final ModifyEvent e) {
170: dialogChanged();
171: }
172: });
173:
174: final Label indexLabel = new Label(compositeCSV, SWT.NONE);
175: indexLabel.setText(I18N.getString(Messages.INDEX));
176:
177: textIndex = new Text(compositeCSV, SWT.BORDER);
178: textIndex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
179: true, false));
180: textIndex.addModifyListener(new ModifyListener() {
181: public void modifyText(final ModifyEvent e) {
182: dialogChanged();
183: }
184: });
185:
186: compositeXPath = new Group(compositeMain, SWT.NONE);
187: compositeXPath.setText(I18N.getString(Messages.XPATH_GROUP));
188: final GridLayout gridLayout_3 = new GridLayout();
189: gridLayout_3.numColumns = 2;
190: compositeXPath.setLayout(gridLayout_3);
191:
192: final Label extenssionLabel = new Label(compositeXPath,
193: SWT.NONE);
194: extenssionLabel.setText(I18N.getString(Messages.EXPRE));
195:
196: textExpression = new Text(compositeXPath, SWT.BORDER);
197: textExpression.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
198: true, false));
199: textExpression.addModifyListener(new ModifyListener() {
200: public void modifyText(final ModifyEvent e) {
201: dialogChanged();
202: }
203: });
204:
205: compositeScript = new Group(compositeMain, SWT.NONE);
206: final GridLayout gridLayout_5 = new GridLayout();
207: gridLayout_5.numColumns = 3;
208: compositeScript.setLayout(gridLayout_5);
209: compositeScript.setText(I18N.getString(Messages.SCR_GROUP));
210:
211: final Label scriptEngineLabel = new Label(compositeScript,
212: SWT.NONE);
213: scriptEngineLabel.setText(I18N.getString(Messages.SCR_ENG));
214:
215: comboScriptEngine = new Combo(compositeScript, SWT.BORDER
216: | SWT.READ_ONLY);
217: final GridData gridData_5 = new GridData(SWT.FILL, SWT.CENTER,
218: true, false, 2, 1);
219: comboScriptEngine.setLayoutData(gridData_5);
220: comboScriptEngine.setItems(new String[] { "Groovy", "Java" });
221: if (!this .getWizard().isUpdateOperation())
222: comboScriptEngine.setText("Groovy");
223: comboScriptEngine.addModifyListener(new ModifyListener() {
224:
225: public void modifyText(ModifyEvent e) {
226:
227: textScriptClass.setText("");
228: }
229: });
230:
231: comboType.addSelectionListener(new SelectionAdapter() {
232: public void widgetSelected(final SelectionEvent e) {
233: comboTypeChange();
234: }
235: });
236:
237: compositeNull = new Composite(compositeMain, SWT.NONE);
238: final GridLayout gridLayout_2 = new GridLayout();
239: gridLayout_2.marginTop = 10;
240: compositeNull.setLayout(gridLayout_2);
241:
242: // Button browseMethod;
243:
244: final Button browseClass;
245:
246: final Label scriptClassLabel = new Label(compositeScript,
247: SWT.NONE);
248: scriptClassLabel.setText(I18N.getString(Messages.SCR_CLASS));
249:
250: textScriptClass = new Text(compositeScript, SWT.READ_ONLY
251: | SWT.BORDER);
252: final GridData gridData_6 = new GridData(SWT.FILL, SWT.CENTER,
253: true, false);
254: textScriptClass.setLayoutData(gridData_6);
255: textScriptClass.addModifyListener(new ModifyListener() {
256: public void modifyText(final ModifyEvent e) {
257: dialogChanged();
258: }
259: });
260: browseClass = new Button(compositeScript, SWT.NONE);
261: browseClass.setLayoutData(new GridData());
262: browseClass.setText(I18N.getString(Messages.MDL_COMMON_BROWSE));
263:
264: browseClass.addSelectionListener(new SelectionAdapter() {
265:
266: public void widgetSelected(SelectionEvent e) {
267:
268: FileEditorInput editorInput = (FileEditorInput) PlatformUI
269: .getWorkbench().getActiveWorkbenchWindow()
270: .getActivePage().getActiveEditor()
271: .getEditorInput();
272:
273: String projectName = editorInput.getFile().getProject()
274: .getName();
275:
276: if (comboScriptEngine.getText() != "") {
277: CustomCodeBrowseDialog customCodeBrowseDialog = new CustomCodeBrowseDialog(
278: ComponentFlowEditorDiagramEditorPlugin
279: .getInstance(), comboScriptEngine
280: .getShell(), I18N
281: .getString(Messages.IDE_FILE_SEL),
282: ProjectUtil.getRelatedProject(projectName),
283: comboScriptEngine.getText(), "trxID",
284: textScriptClass);
285:
286: customCodeBrowseDialog.open();
287: } else {
288: MsgUtil
289: .warningMsg("Please choose the ScriptEngine frist.");
290: return;
291: }
292: }
293:
294: });
295:
296: stackLayout.topControl = compositeFixed;
297:
298: if (this .getWizard().isUpdateOperation()) {
299: modelsToControl();
300: }
301:
302: dialogChanged();
303: }
304:
305: protected void dialogChanged() {
306: if (WizardUtil.whetherUseValidation == false) {
307: setPageComplete(true);
308: return;
309: }
310: if (comboType.getText().equals("fixed")) {
311: if (textFixedOffset.getText().equals("")) {
312: updateStatus(I18N.getString(Messages.FIX_OFFSET_REQ));
313: setPageComplete(false);
314: return;
315: } else if (!WizardUtil.isNumber(textFixedOffset.getText())) {
316: updateStatus(I18N.getString(Messages.FIX_OFFSET_INT));
317: setPageComplete(false);
318: return;
319: } else if (textFixedLength.getText().equals("")) {
320: updateStatus(I18N.getString(Messages.FIX_LEN_REQ));
321: setPageComplete(false);
322: return;
323: } else if (!WizardUtil.isNumber(textFixedLength.getText())) {
324: updateStatus(I18N.getString(Messages.FIX_LEN_INT));
325: setPageComplete(false);
326: return;
327: }
328: } else if (comboType.getText().equals("CSV")) {
329: if (textDelimiter.getText().equals("")) {
330: updateStatus(I18N.getString(Messages.DEL_REQ));
331: setPageComplete(false);
332: return;
333: } else if (textIndex.getText().equals("")) {
334: updateStatus(I18N.getString(Messages.IND_REQ));
335: setPageComplete(false);
336: return;
337: } else if (!WizardUtil.isNumber(textIndex.getText())) {
338: updateStatus(I18N.getString(Messages.IND_INT));
339: setPageComplete(false);
340: return;
341: }
342: } else if (comboType.getText().equals("script")) {
343: if (textScriptClass.getText().equals("")) {
344: updateStatus(I18N.getString(Messages.CLA_REQ));
345: setPageComplete(false);
346: return;
347: }
348: }
349: super .dialogChanged();
350: }
351:
352: public IWizardPage getNextPage() {
353: if (comboCCSL.getText().equals("true")) {
354: return super .getNextPage();
355: }
356: return null;
357: }
358:
359: @Override
360: public void controlToModels() {
361:
362: super .controlToModels();
363:
364: CBRPropertyWizard CBRWizard = (CBRPropertyWizard) this
365: .getWizard();
366: CBR models = CBRWizard.getModels();
367: if (models == null)
368: return;
369: try {
370:
371: models.setType(CBRType.get(comboType.getText()
372: .toLowerCase()));
373:
374: models.setDelimiter(textDelimiter.getText());
375: models.setExpression(textExpression.getText());
376: models.setFixedLength(textFixedLength.getText());
377: models.setFixedOffset(textFixedOffset.getText());
378: models.setIndex(textIndex.getText());
379: models.setScriptClass(textScriptClass.getText());
380: models.setScriptEngine(comboScriptEngine.getText());
381: } catch (Exception e) {
382: e.printStackTrace();
383: }
384: }
385:
386: @Override
387: public void modelsToControl() {
388: super .modelsToControl();
389:
390: CBRPropertyWizard CBRWizard = (CBRPropertyWizard) this
391: .getWizard();
392: CBR models = CBRWizard.getModels();
393:
394: if (models.getDelimiter() != null)
395: textDelimiter.setText(models.getDelimiter());
396: else
397: textDelimiter.setText("");
398:
399: if (models.getExpression() != null)
400: textExpression.setText(models.getExpression());
401: else
402: textExpression.setText("");
403:
404: if (models.getFixedLength() != null)
405: textFixedLength.setText(models.getFixedLength());
406: else
407: textFixedLength.setText("");
408:
409: if (models.getFixedOffset() != null)
410: textFixedOffset.setText(models.getFixedOffset());
411: else
412: textFixedOffset.setText("");
413:
414: if (models.getIndex() != null)
415: textIndex.setText(models.getIndex());
416: else
417: textIndex.setText("");
418:
419: if (models.getScriptEngine() != null)
420: comboScriptEngine.setText(models.getScriptEngine());
421: else
422: comboScriptEngine.setText("");
423:
424: if (models.getScriptClass() != null)
425: textScriptClass.setText(models.getScriptClass());
426: else
427: textScriptClass.setText("");
428:
429: // if (CBRWizard.getModels().getScriptMethod() != null)
430: // textScriptMethod.setText(CBRWizard.getModels().getScriptMethod());
431: // else
432: // textScriptMethod.setText("");
433:
434: if (models.getType().getLiteral().equalsIgnoreCase("fixed")) {
435: comboType.select(0);
436: } else if (models.getType().getLiteral()
437: .equalsIgnoreCase("CSV")) {
438: comboType.select(1);
439: } else if (models.getType().getLiteral()
440: .equalsIgnoreCase("hl7")) {
441: comboType.select(2);
442: } else if (models.getType().getLiteral()
443: .equalsIgnoreCase("x12")) {
444: comboType.select(3);
445: } else if (models.getType().getLiteral().equalsIgnoreCase(
446: "xpath")) {
447: comboType.select(4);
448: } else if (models.getType().getLiteral().equalsIgnoreCase(
449: "script")) {
450: comboType.select(5);
451: }
452: comboTypeChange();
453:
454: }
455:
456: public void comboTypeChange() {
457: if (comboType.getText().equals("fixed")) {
458: stackLayout.topControl = compositeFixed;
459: compositeMain.layout();
460: } else if (comboType.getText().equals("CSV")) {
461: stackLayout.topControl = compositeCSV;
462: compositeMain.layout();
463: } else if (comboType.getText().equals("xpath")) {
464: stackLayout.topControl = compositeXPath;
465: compositeMain.layout();
466: } else if (comboType.getText().equals("script")) {
467: stackLayout.topControl = compositeScript;
468: compositeMain.layout();
469: } else {
470: stackLayout.topControl = compositeNull;
471: compositeMain.layout();
472: }
473: dialogChanged();
474: }
475:
476: @Override
477: public String getComponentName() {
478: return "CBR";
479: }
480:
481: }
|