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 java.util.regex.Matcher;
027: import java.util.regex.Pattern;
028:
029: import org.eclipse.jface.wizard.IWizardPage;
030: import org.eclipse.swt.SWT;
031: import org.eclipse.swt.events.ModifyEvent;
032: import org.eclipse.swt.events.ModifyListener;
033: import org.eclipse.swt.layout.GridData;
034: import org.eclipse.swt.layout.GridLayout;
035: import org.eclipse.swt.widgets.Combo;
036: import org.eclipse.swt.widgets.Composite;
037: import org.eclipse.swt.widgets.Label;
038: import org.eclipse.swt.widgets.Text;
039:
040: import com.bostechcorp.cbesb.common.i18n.I18N;
041: import com.bostechcorp.cbesb.common.i18n.Messages;
042: import com.bostechcorp.cbesb.common.util.SystemCharacterEncoding;
043: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.FileConsumer;
044: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ReadStyleType;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RecordTypeType;
046:
047: public class FilePropertyWizardPageReadFilePath extends
048: PropertyWizardPage {
049:
050: private Combo comboCharacterSet;
051:
052: private Text textRecordPerMsg;
053:
054: private Combo comboRecordType;
055:
056: private Combo comboReadStyle;
057:
058: protected FilePropertyWizardPageReadFilePath(String pageName) {
059: super (pageName);
060: setTitle(I18N.getString(Messages.READ_MODE_PRO));// "Choose
061: setDescription(I18N.getString(Messages.PAGE_READ_PATH_DES));
062: }
063:
064: public void createControl(Composite parent) {
065:
066: Composite topLevel = new Composite(parent, SWT.NONE);
067: final GridLayout gridLayout = new GridLayout();
068: gridLayout.numColumns = 2;
069: topLevel.setLayout(gridLayout);
070: topLevel.setLayoutData(new GridData(
071: GridData.VERTICAL_ALIGN_FILL
072: | GridData.HORIZONTAL_ALIGN_FILL));
073: topLevel.setFont(parent.getFont());
074: this .setControl(topLevel);
075:
076: final Label labelReadStyle = new Label(topLevel, SWT.NONE);
077: labelReadStyle.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
078: false, false));
079: labelReadStyle.setText(I18N.getString(Messages.READ_STYLE));
080:
081: comboReadStyle = new Combo(topLevel, SWT.READ_ONLY);
082: comboReadStyle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
083: true, false));
084: comboReadStyle.add("raw");
085: comboReadStyle.add("newline");
086: if (!this .getWizard().isUpdateOperation())
087: comboReadStyle.setText("raw");
088:
089: final Label labelRecordType = new Label(topLevel, SWT.NONE);
090: labelRecordType.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
091: false, false));
092: labelRecordType.setText(I18N.getString(Messages.REC_TYPE));
093:
094: comboRecordType = new Combo(topLevel, SWT.READ_ONLY);
095: comboRecordType.setLayoutData(new GridData(SWT.FILL,
096: SWT.CENTER, true, false));
097: comboRecordType.add("string");
098: comboRecordType.add("xml");
099: comboRecordType.add("binary");
100: if (!this .getWizard().isUpdateOperation())
101: comboRecordType.setText("string");
102:
103: final Label labelRecordsPerMsg = new Label(topLevel, SWT.NONE);
104: labelRecordsPerMsg.setLayoutData(new GridData(SWT.FILL,
105: SWT.FILL, false, false));
106: labelRecordsPerMsg
107: .setText(I18N.getString(Messages.REC_PER_MES));
108:
109: textRecordPerMsg = new Text(topLevel, SWT.BORDER);
110: if (!this .getWizard().isUpdateOperation())
111: textRecordPerMsg.setText("0");
112: textRecordPerMsg.setLayoutData(new GridData(SWT.FILL,
113: SWT.CENTER, true, false));
114: textRecordPerMsg.addModifyListener(new ModifyListener() {
115:
116: public void modifyText(ModifyEvent e) {
117:
118: dialogChanged();
119: }
120:
121: });
122:
123: final Label labelCharacterSet = new Label(topLevel, SWT.NONE);
124: labelCharacterSet.setLayoutData(new GridData(SWT.FILL,
125: SWT.FILL, false, false));
126: labelCharacterSet.setText(I18N.getString(Messages.CHAR_SET));
127:
128: comboCharacterSet = new Combo(topLevel, SWT.READ_ONLY);
129:
130: comboCharacterSet.setLayoutData(new GridData(SWT.FILL,
131: SWT.CENTER, true, false));
132:
133: comboCharacterSet.setItems(SystemCharacterEncoding
134: .getSupportedCharacterSets());
135:
136: if (!this .getWizard().isUpdateOperation())
137: comboCharacterSet.setText("SYSTEM_DEFAULT");
138:
139: if (this .getWizard().isUpdateOperation()) {
140: modelsToControl();
141: }
142:
143: }
144:
145: private void dialogChanged() {
146:
147: if (WizardUtil.whetherUseValidation == false) {
148: setPageComplete(true);
149: return;
150: }
151: if (!textRecordPerMsg.getText().equals("")) {
152: String recordPerMsg = textRecordPerMsg.getText();
153: Pattern pattern = Pattern.compile("[0-9]+");
154: Matcher matcher = pattern.matcher(recordPerMsg);
155: if (!matcher.matches()) {
156: updateState(I18N.getString(Messages.REC_PER_MES_INT));
157: setPageComplete(false);
158: return;
159: }
160: }
161: updateState(null);
162: setPageComplete(true);
163: }
164:
165: private void updateState(String message) {
166: setErrorMessage(message);
167: }
168:
169: @Override
170: public void controlToModels() {
171:
172: FilePropertyWizard fileWizard = (FilePropertyWizard) this
173: .getWizard();
174: if (fileWizard.getModels() == null)
175: return;
176: try {
177: FileConsumer fileConsumer = fileWizard.getModels()
178: .getFileConsumer();
179: fileConsumer.setReadStyle(ReadStyleType
180: .getByName(comboReadStyle.getText()));
181: fileConsumer.setRecordType(RecordTypeType
182: .getByName(comboRecordType.getText()));
183: fileConsumer.setRecordsPerMessage(textRecordPerMsg
184: .getText());
185:
186: fileConsumer.setCharset(comboCharacterSet.getText());
187:
188: } catch (Exception e) {
189: e.printStackTrace();
190: }
191: }
192:
193: public IWizardPage getNextPage() {
194:
195: return super .getNextPage();
196: }
197:
198: @Override
199: public void modelsToControl() {
200:
201: FilePropertyWizard fileWizard = (FilePropertyWizard) this
202: .getWizard();
203: if (!fileWizard.isUpdateOperation())
204: return;
205: try {
206:
207: FileConsumer fileConsumer = fileWizard.getModels()
208: .getFileConsumer();
209: comboReadStyle.select(comboReadStyle.indexOf(fileConsumer
210: .getReadStyle().getLiteral()));
211: comboRecordType.select(comboRecordType.indexOf(fileConsumer
212: .getRecordType().getLiteral()));
213:
214: if (fileConsumer.getRecordsPerMessage() != null)
215: textRecordPerMsg.setText(fileConsumer
216: .getRecordsPerMessage());
217: else
218: textRecordPerMsg.setText("");
219:
220: comboCharacterSet.select(comboCharacterSet
221: .indexOf(fileConsumer.getCharset()));
222: } catch (Exception e) {
223: e.printStackTrace();
224: }
225: }
226: }
|