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.events.ModifyEvent;
029: import org.eclipse.swt.events.ModifyListener;
030: import org.eclipse.swt.events.SelectionAdapter;
031: import org.eclipse.swt.events.SelectionEvent;
032: import org.eclipse.swt.layout.FillLayout;
033:
034: import org.eclipse.swt.layout.GridData;
035: import org.eclipse.swt.layout.GridLayout;
036: import org.eclipse.swt.widgets.Button;
037: import org.eclipse.swt.widgets.Combo;
038: import org.eclipse.swt.widgets.Composite;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Text;
041:
042: import com.bostechcorp.cbesb.common.i18n.I18N;
043: import com.bostechcorp.cbesb.common.i18n.Messages;
044: import com.bostechcorp.cbesb.common.util.SystemCharacterEncoding;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DestinationStyleType;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMS;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.JMSProvider;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ReadStyleType;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RecordTypeType;
050:
051: public class JMSPropertyWizardPageProviderProperty extends
052: PropertyWizardPage {
053:
054: private Button jmsSelectorButton;
055: private Text expression_text;
056: private Text textReplyDestinationName;
057:
058: private Text textRecordsPerMessage;
059:
060: private Combo comboRecordType;
061:
062: private Combo comboReadStyle;
063:
064: private Combo comboWriteCharset;
065:
066: private Combo comboWriteStyle;
067:
068: private Text textTargetName;
069:
070: private Combo comboDestinationStyle;
071:
072: private Text textJNDIFactoryName;
073:
074: private Text textJNDIUrl;
075:
076: private Text textJNDIFactory;
077:
078: private Label recordsPerMessageLabel;
079:
080: private Label replyDestinationNameLabel;
081:
082: private Label recordTypeLabel;
083:
084: private Label readStyleLabel;
085:
086: /*private Label enableQueryLabel;
087:
088: private Combo enableQuery;
089:
090: private Label queryExpressionLabel;
091:
092: private Text queryExpression;*/
093:
094: protected JMSPropertyWizardPageProviderProperty(String pageName) {
095: super (pageName);
096: setTitle(I18N.getString(Messages.JMS_PROVIDER));// "Choose
097: setDescription(I18N.getString(Messages.WIZARD_ENTER_TIP));
098: }
099:
100: public void createControl(Composite parent) {
101:
102: Composite topLevel = new Composite(parent, SWT.NONE);
103: topLevel.setLayout(new FillLayout(SWT.VERTICAL));
104: topLevel.setLayoutData(new GridData(
105: GridData.VERTICAL_ALIGN_FILL
106: | GridData.HORIZONTAL_ALIGN_FILL));
107: topLevel.setFont(parent.getFont());
108: this .setControl(topLevel);
109:
110: final Composite composite = new Composite(topLevel, SWT.NONE);
111: final GridLayout gridLayout = new GridLayout();
112: gridLayout.numColumns = 2;
113: composite.setLayout(gridLayout);
114:
115: final Label jndiInitialContextLabel = new Label(composite,
116: SWT.NONE);
117: jndiInitialContextLabel.setText(I18N
118: .getString(Messages.JMS_JNDI_FACTORY));
119:
120: textJNDIFactory = new Text(composite, SWT.BORDER);
121: if (!this .getWizard().isUpdateOperation())
122: textJNDIFactory
123: .setText("com.sun.jndi.fscontext.RefFSContextFactory");
124: textJNDIFactory.setLayoutData(new GridData(SWT.FILL,
125: SWT.CENTER, true, false));
126:
127: final Label jndiProviderUrlLabel = new Label(composite,
128: SWT.NONE);
129: jndiProviderUrlLabel.setText(I18N
130: .getString(Messages.JMS_PROVIDER_URL));
131:
132: textJNDIUrl = new Text(composite, SWT.BORDER);
133: if (!this .getWizard().isUpdateOperation())
134: textJNDIUrl.setText("file:/C:/CBESB/JndiDir");
135: textJNDIUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
136: true, false));
137:
138: final Label jndiConnectionFactoryLabel = new Label(composite,
139: SWT.NONE);
140: jndiConnectionFactoryLabel.setText(I18N
141: .getString(Messages.JMS_JNDI_FACTORY_NAME));
142:
143: textJNDIFactoryName = new Text(composite, SWT.BORDER);
144: textJNDIFactoryName.setLayoutData(new GridData(SWT.FILL,
145: SWT.CENTER, true, false));
146: textJNDIFactoryName.addModifyListener(new ModifyListener() {
147: public void modifyText(ModifyEvent e) {
148: dialogChanged();
149: }
150: });
151:
152: final Label oDestinationStyleLabel = new Label(composite,
153: SWT.NONE);
154: oDestinationStyleLabel.setText(I18N
155: .getString(Messages.JMS_DESTINATION_STYLE));
156:
157: comboDestinationStyle = new Combo(composite, SWT.READ_ONLY);
158: comboDestinationStyle
159: .setItems(new String[] { "queue", "topic" });
160: comboDestinationStyle.setLayoutData(new GridData(SWT.FILL,
161: SWT.CENTER, true, false));
162: if (!this .getWizard().isUpdateOperation())
163: comboDestinationStyle.setText("queue");
164: final Label oTargetDestinationLabel = new Label(composite,
165: SWT.NONE);
166: oTargetDestinationLabel.setText(I18N
167: .getString(Messages.JMS_TARGET_DESTINATION_NAME));
168:
169: textTargetName = new Text(composite, SWT.BORDER);
170: textTargetName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
171: true, false));
172: textTargetName.addModifyListener(new ModifyListener() {
173: public void modifyText(ModifyEvent e) {
174: dialogChanged();
175: }
176: });
177:
178: final Label writeStyleLabel = new Label(composite, SWT.NONE);
179: writeStyleLabel.setText(I18N.getString(Messages.WRI_STYLE));
180:
181: comboWriteStyle = new Combo(composite, SWT.READ_ONLY);
182: comboWriteStyle.setItems(new String[] { "raw", "newline" });
183: if (!this .getWizard().isUpdateOperation())
184: comboWriteStyle.setText("raw");
185: comboWriteStyle.setLayoutData(new GridData(SWT.FILL,
186: SWT.CENTER, true, false));
187:
188: final Label characterSetLabel = new Label(composite, SWT.NONE);
189: characterSetLabel.setText(I18N.getString(Messages.CHAR_SET));
190:
191: comboWriteCharset = new Combo(composite, SWT.DROP_DOWN);
192: // comboWriteCharset.setItems(new String[] {"SYSTEM_DEFAULT",
193: // "ISO_8859_1", "USASCII", "UTF_8", "UTF_16BE", "UTF_16LE",
194: // "windows_1252", "EUC_JP", "Shift_JIS", "Big5", "Big5_HKSCS"});
195: comboWriteCharset.setItems(SystemCharacterEncoding
196: .getSupportedCharacterSets());
197:
198: comboWriteCharset.setText("SYSTEM_DEFAULT");
199: comboWriteCharset.setLayoutData(new GridData(SWT.FILL,
200: SWT.CENTER, true, false));
201:
202: readStyleLabel = new Label(composite, SWT.NONE);
203: readStyleLabel.setText(I18N.getString(Messages.READ_STYLE));
204:
205: comboReadStyle = new Combo(composite, SWT.READ_ONLY);
206: comboReadStyle.setItems(new String[] { "raw", "newline" });
207: comboReadStyle.setText("raw");
208: comboReadStyle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
209: true, false));
210:
211: recordTypeLabel = new Label(composite, SWT.NONE);
212: recordTypeLabel.setText(I18N.getString(Messages.REC_TYPE));
213:
214: comboRecordType = new Combo(composite, SWT.READ_ONLY);
215: comboRecordType.setItems(new String[] { "string", "xml",
216: "binary" });
217: comboRecordType.setText("string");
218: comboRecordType.setLayoutData(new GridData(SWT.FILL,
219: SWT.CENTER, true, false));
220:
221: recordsPerMessageLabel = new Label(composite, SWT.NONE);
222: recordsPerMessageLabel.setText(I18N
223: .getString(Messages.REC_PER_MES));
224:
225: textRecordsPerMessage = new Text(composite, SWT.BORDER);
226: textRecordsPerMessage.setLayoutData(new GridData(SWT.FILL,
227: SWT.CENTER, true, false));
228: textRecordsPerMessage.addModifyListener(new ModifyListener() {
229: public void modifyText(ModifyEvent e) {
230: dialogChanged();
231: }
232: });
233: textRecordsPerMessage.setText("0");
234:
235: replyDestinationNameLabel = new Label(composite, SWT.NONE);
236: replyDestinationNameLabel.setText(I18N
237: .getString(Messages.JMS_REPLY_DESTINATION_NAME));
238:
239: textReplyDestinationName = new Text(composite, SWT.BORDER);
240: textReplyDestinationName.setLayoutData(new GridData(SWT.FILL,
241: SWT.CENTER, true, false));
242:
243: jmsSelectorButton = new Button(composite, SWT.CHECK);
244: jmsSelectorButton.addSelectionListener(new SelectionAdapter() {
245: public void widgetSelected(final SelectionEvent e) {
246: expression_text.setEditable(getJmsSelectorButton()
247: .getSelection());
248: }
249: });
250: jmsSelectorButton.setText(I18N.getString(Messages.ENABLEQUERY));
251:
252: expression_text = new Text(composite, SWT.BORDER);
253: expression_text.setEditable(false);
254: expression_text.setLayoutData(new GridData(SWT.FILL,
255: SWT.CENTER, true, false));
256:
257: if (this .getWizard().isUpdateOperation()) {
258: modelsToControl();
259: } else {
260: if (((JMSPropertyWizardPageMain) super .getWizard()
261: .getMainPage()).isReliableDelivery()) {
262: defaultSettingForReliableDel();
263: }
264: }
265:
266: dialogChanged();
267: }
268:
269: public void defaultSettingForReliableDel() {
270: textJNDIFactory
271: .setText("org.apache.activemq.jndi.ActiveMQInitialContextFactory");
272: textJNDIUrl.setText("tcp://localhost:61616");
273: textJNDIFactoryName.setText("ConnectionFactory");
274: comboDestinationStyle.select(0);
275: String projectName = this .getWizard().getMainPage()
276: .getProjectName();
277: String modelName = this .getWizard().getMainPage().getTextName()
278: .getText();
279: textTargetName.setText("dynamicQueues/" + projectName + "_"
280: + modelName + "_request");
281: comboReadStyle.select(0);
282: comboRecordType.select(0);
283: textRecordsPerMessage.setText("0");
284: textReplyDestinationName.setText("dynamicQueues/" + projectName
285: + "_" + modelName + "_reply");
286:
287: }
288:
289: public void defaultSettingForNonReliableDel() {
290: textJNDIFactory
291: .setText("com.sun.jndi.fscontext.RefFSContextFactory");
292: textJNDIUrl.setText("file:/C:/CBESB/JndiDir");
293: textJNDIFactoryName.setText("");
294: comboDestinationStyle.select(0);
295: textTargetName.setText("");
296: comboReadStyle.select(0);
297: comboRecordType.select(0);
298: textRecordsPerMessage.setText("0");
299:
300: }
301:
302: private void dialogChanged() {
303: if (WizardUtil.whetherUseValidation == false) {
304: setPageComplete(true);
305: return;
306: }
307: if (textJNDIFactoryName.getText().equals("")) {
308: updateStatus(I18N
309: .getString(Messages.JMS_JNDI_FACTORY_NAME_REQUIRE));
310: setPageComplete(false);
311: return;
312: } else if (textTargetName.getText().equals("")) {
313: updateStatus(I18N
314: .getString(Messages.JMS_JNDI_TARGET_DESTINATION_NAME_REQUIRE));
315: setPageComplete(false);
316: return;
317: } else {
318: String recordPerMsg = textRecordsPerMessage.getText();
319: if (!WizardUtil.isNumber(recordPerMsg)) {
320: updateStatus(I18N
321: .getString(Messages.JMS_RECORDS_PER_MESSAGE_INTEGER));
322: setPageComplete(false);
323: return;
324: }
325: }
326:
327: setPageComplete(true);
328: updateStatus(null);
329: }
330:
331: private void updateStatus(String message) {
332: setErrorMessage(message);
333: }
334:
335: @Override
336: public void controlToModels() {
337:
338: JMSPropertyWizard JMSWizard = (JMSPropertyWizard) this
339: .getWizard();
340:
341: if (JMSWizard.getModels() == null)
342: return;
343: try {
344: JMSProvider jmsProvider = JMSWizard.getModels()
345: .getJmsProvider();
346: jmsProvider.setDestinationStyle(DestinationStyleType
347: .getByName(comboDestinationStyle.getText()));
348: jmsProvider
349: .setJndiConnectionFactoryName(textJNDIFactoryName
350: .getText());
351: jmsProvider.setJndiInitialContextFactory(textJNDIFactory
352: .getText());
353: jmsProvider.setJndiProviderUrl(textJNDIUrl.getText());
354: jmsProvider.setTargetDestinationName(textTargetName
355: .getText());
356: jmsProvider.setWriteStyle(ReadStyleType
357: .getByName(comboWriteStyle.getText()));
358: jmsProvider.setCharset(comboWriteCharset.getText());
359: jmsProvider.setReadStyle(ReadStyleType
360: .getByName(comboReadStyle.getText()));
361: jmsProvider.setRecordsPerMessage(textRecordsPerMessage
362: .getText());
363: jmsProvider.setRecordType(RecordTypeType
364: .getByName(comboRecordType.getText()));
365: jmsProvider
366: .setReplyDestinationName(textReplyDestinationName
367: .getText());
368:
369: jmsProvider.setEnableQuery(getJmsSelectorButton()
370: .getSelection());
371: jmsProvider.setQueryExpression(expression_text.getText());
372:
373: if (((JMSPropertyWizardPageMain) super .getWizard()
374: .getMainPage()).isReliableDelivery())
375: jmsProvider.setSaveMetaData(true);
376: else
377: jmsProvider.setSaveMetaData(false);
378:
379: } catch (Exception e) {
380: e.printStackTrace();
381: }
382:
383: }
384:
385: public IWizardPage getNextPage() {
386: if (this .getWizard().getMainPage().isConsumer()) {
387: if (this .getWizard().getMainPage().isUseCCSL()) {
388:
389: return super .getWizard().getCcslConsumerPage();
390: }
391: }
392: if (this .getWizard().getMainPage().isUseCCSL()) {
393:
394: return super .getWizard().getCcslProviderPage();
395: }
396:
397: return null;
398: }
399:
400: @Override
401: public void modelsToControl() {
402:
403: JMSPropertyWizard JMSWizard = (JMSPropertyWizard) this
404: .getWizard();
405: if (!JMSWizard.isUpdateOperation())
406: return;
407: try {
408: JMS models = JMSWizard.getModels();
409: comboWriteStyle.select(comboWriteStyle.indexOf(models
410: .getJmsProvider().getWriteStyle().getName()));
411: comboDestinationStyle.select(comboDestinationStyle
412: .indexOf(models.getJmsProvider()
413: .getDestinationStyle().getLiteral()));
414: comboWriteCharset.select(comboWriteCharset.indexOf(models
415: .getJmsProvider().getCharset()));
416: if (models.getJmsProvider().getJndiConnectionFactoryName() != null)
417: textJNDIFactoryName.setText(models.getJmsProvider()
418: .getJndiConnectionFactoryName());
419: else
420: textJNDIFactoryName.setText("");
421:
422: if (models.getJmsProvider().getJndiInitialContextFactory() != null)
423: textJNDIFactory.setText(models.getJmsProvider()
424: .getJndiInitialContextFactory());
425: else
426: textJNDIFactory.setText("");
427:
428: if (models.getJmsProvider().getJndiProviderUrl() != null)
429: textJNDIUrl.setText(models.getJmsProvider()
430: .getJndiProviderUrl());
431: else
432: textJNDIUrl.setText("");
433:
434: if (models.getJmsProvider().getRecordsPerMessage() != null)
435: textRecordsPerMessage.setText(models.getJmsProvider()
436: .getRecordsPerMessage());
437: else
438: textRecordsPerMessage.setText("");
439:
440: if (models.getJmsProvider().getTargetDestinationName() != null)
441: textTargetName.setText(models.getJmsProvider()
442: .getTargetDestinationName());
443: else
444: textTargetName.setText("");
445:
446: comboReadStyle.select(comboReadStyle.indexOf(models
447: .getJmsProvider().getReadStyle().getLiteral()));
448: textRecordsPerMessage.setText(models.getJmsProvider()
449: .getRecordsPerMessage());
450: comboRecordType.select(comboRecordType.indexOf(models
451: .getJmsProvider().getRecordType().getLiteral()));
452: textReplyDestinationName.setText(models.getJmsProvider()
453: .getReplyDestinationName());
454:
455: getJmsSelectorButton().setSelection(
456: models.getJmsProvider().isEnableQuery());
457: expression_text.setEditable(models.getJmsProvider()
458: .isEnableQuery());
459: expression_text.setText(models.getJmsProvider()
460: .getQueryExpression());
461:
462: } catch (Exception e) {
463: e.printStackTrace();
464: }
465: }
466:
467: public Button getJmsSelectorButton() {
468: return jmsSelectorButton;
469: }
470: }
|