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.HashMap;
027: import java.util.Map;
028: import java.util.regex.Matcher;
029: import java.util.regex.Pattern;
030:
031: import org.eclipse.jface.wizard.IWizardPage;
032: import org.eclipse.swt.SWT;
033: import org.eclipse.swt.events.ModifyEvent;
034: import org.eclipse.swt.events.ModifyListener;
035: import org.eclipse.swt.events.SelectionAdapter;
036: import org.eclipse.swt.events.SelectionEvent;
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.Label;
043: import org.eclipse.swt.widgets.Text;
044: import org.eclipse.ui.PlatformUI;
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.RecordTypeType;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.SSL;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.SSLMode;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
052:
053: public class TCPIPClientSettingsWizardPage extends PropertyWizardPage {
054: private Combo comboRecordType;
055: private Text textPort;
056:
057: private Text textHost;
058:
059: private Button sslButton;
060:
061: private Button advancedSettingButton;
062:
063: public Map<String, String> sslMap = new HashMap<String, String>();
064:
065: private boolean updateOperation = false;
066:
067: protected TCPIPClientSettingsWizardPage(String pageName) {
068: super (pageName);
069: setTitle(I18N.getString(Messages.TCPIP_CLIENT_TITLE));
070: setDescription(I18N
071: .getString(Messages.TCPIP_CLIENT_DESCRIPTION));
072: setDefaultSSLMapValues();
073: }
074:
075: public void createControl(Composite parent) {
076: final Composite topLevel = new Composite(parent, SWT.NONE);
077: topLevel.setVisible(false);
078: final GridLayout gridLayout = new GridLayout();
079: gridLayout.numColumns = 2;
080: gridLayout.horizontalSpacing = 10;
081: topLevel.setLayout(gridLayout);
082: topLevel.setLayoutData(new GridData(
083: GridData.VERTICAL_ALIGN_FILL
084: | GridData.HORIZONTAL_ALIGN_FILL));
085: topLevel.setFont(parent.getFont());
086: this .setControl(topLevel);
087:
088: final Label hostLabel = new Label(topLevel, SWT.NONE);
089: hostLabel.setText(I18N.getString(Messages.TCPIP_HOST));
090:
091: textHost = new Text(topLevel, SWT.BORDER);
092: textHost.addModifyListener(new ModifyListener() {
093: public void modifyText(ModifyEvent e) {
094: dialogChanged();
095: }
096: });
097: textHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
098: false));
099:
100: final Label portLabel = new Label(topLevel, SWT.NONE);
101: portLabel.setText(I18N.getString(Messages.TCPIP_PORT));
102:
103: textPort = new Text(topLevel, SWT.BORDER);
104: textPort.addModifyListener(new ModifyListener() {
105: public void modifyText(ModifyEvent e) {
106: dialogChanged();
107: }
108: });
109: textPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
110: false));
111: // since version 1.2.b -bug 400
112: // final Label label = new Label(topLevel, SWT.NONE);
113: // label.setVisible(false);
114: // label.setText(I18N.getString(Messages.REC_TYPE));
115: // comboRecordType = new Combo(topLevel, SWT.READ_ONLY);
116: // comboRecordType.setVisible(false);
117: // comboRecordType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
118: // comboRecordType.add("string");
119: // comboRecordType.add("xml");
120: // if (!this.getWizard().isUpdateOperation())
121: // comboRecordType.setText("string");
122: //
123: sslButton = new Button(topLevel, SWT.CHECK);
124: sslButton.addSelectionListener(new SelectionAdapter() {
125: public void widgetSelected(SelectionEvent e) {
126: if (sslButton.getSelection()) {
127: advancedSettingButton.setEnabled(true);
128: } else
129: advancedSettingButton.setEnabled(false);
130: dialogChanged();
131: }
132: });
133: sslButton.setText(I18N.getString(Messages.TCPIP_SSL));
134:
135: advancedSettingButton = new Button(topLevel, SWT.NONE);
136: advancedSettingButton.setEnabled(false);
137: advancedSettingButton.setText(I18N
138: .getString(Messages.TCPIP_ADVANCED_SETTINGS));
139: advancedSettingButton
140: .addSelectionListener(new SelectionAdapter() {
141: public void widgetSelected(SelectionEvent e) {
142: TCPIPClientSSLSettingsWizardPage dialog = new TCPIPClientSSLSettingsWizardPage(
143: PlatformUI.getWorkbench()
144: .getActiveWorkbenchWindow()
145: .getShell(), sslMap,
146: updateOperation);
147: dialog.open();
148: }
149: });
150: if (this .getWizard().isUpdateOperation()) {
151: updateOperation = true;
152: modelsToControl();
153: }
154:
155: dialogChanged();
156: }
157:
158: private void dialogChanged() {
159: if (textHost.getText().equals("")) {
160: setErrorMessage(I18N.getString(Messages.TCPIP_ERR_HOST_REQ));
161: setPageComplete(false);
162: return;
163: }
164:
165: if (!textPort.getText().equals("")) {
166: String recordPerMsg = textPort.getText();
167: Pattern pattern = Pattern.compile("[0-9]+");
168: Matcher matcher = pattern.matcher(recordPerMsg);
169: if (!matcher.matches()) {
170: setErrorMessage(I18N
171: .getString(Messages.TCPIP_ERR_PORT_NO));
172: setPageComplete(false);
173: return;
174: }
175: } else {
176: setErrorMessage(I18N.getString(Messages.TCPIP_ERR_PORT_REQ));
177: setPageComplete(false);
178: return;
179: }
180:
181: setErrorMessage(null);
182: setPageComplete(true);
183: }
184:
185: public IWizardPage getNextPage() {
186: if (this .getWizard().getMainPage().isConsumer()) {
187: return this .getWizard().getPage("ConsumerPage");
188: } else if (this .getWizard().getMainPage().isProvider()) {
189: return this .getWizard().getPage("ProviderPage");
190: }
191: return null;
192: }
193:
194: @Override
195: public void controlToModels() {
196: TCPIPPropertyWizard TCPIPWizard = (TCPIPPropertyWizard) this
197: .getWizard();
198: TCPIP model = TCPIPWizard.getModels();
199: if (model == null || model.getClient() == null) {
200: return;
201: }
202: model.getClient().setHost(textHost.getText());
203: model.getClient().setPort(textPort.getText());
204: if (sslButton.getSelection()) {
205: model.getClient().setUseSsl(true);
206: } else {
207: model.getClient().setUseSsl(false);
208: }
209: //since version 1.2.b -bug 400
210: //model.getProvider().setRecordType(RecordTypeType.getByName(comboRecordType
211: //.getText()));
212: //
213: if (sslButton.getSelection()) {
214:
215: SSL ssl = model.getClient().getSSL();
216: ssl.setSslProtocol(SSLMode.get(sslMap.get("sslProtocol")));
217: ssl.setAllowAnonymous(Boolean.parseBoolean(sslMap
218: .get("allowAnonymous")));
219: ssl.setUsePrivateKey(Boolean.parseBoolean(sslMap
220: .get("usePrivateKey")));
221: ssl.setKeyStoreFile(sslMap.get("keyStoreFile"));
222: ssl.setKeyStorePassword(sslMap.get("keyStorePassword"));
223: ssl.setAuthenticatePeer(new Boolean(sslMap.get(
224: "authenticateServer").toString()));
225: ssl.setUseDefaultTrustStore(Boolean.parseBoolean(sslMap
226: .get("useDefaultTrustStore")));
227: ssl.setTrustStoreFile(sslMap.get("trustStoreFile"));
228: ssl.setTrustStorePassword(sslMap.get("trustStorePassword"));
229: }
230: }
231:
232: @Override
233: public void modelsToControl() {
234: TCPIPPropertyWizard TCPIPWizard = (TCPIPPropertyWizard) this
235: .getWizard();
236: TCPIP model = TCPIPWizard.getModels();
237: if (model == null || model.getClient() == null) {
238: return;
239: }
240: if (model.getClient().getHost() != null)
241: textHost.setText(model.getClient().getHost());
242: else
243: textHost.setText("");
244: if (model.getClient().getPort() != null)
245: textPort.setText(model.getClient().getPort());
246: else
247: textPort.setText("");
248: sslButton.setSelection(model.getClient().isUseSsl());
249: if (sslButton.getSelection()) {
250: advancedSettingButton.setEnabled(true);
251: } else {
252: advancedSettingButton.setEnabled(false);
253: }
254:
255: //since version 1.2.b -bug 400
256: //comboRecordType.select(comboRecordType.indexOf(model.getProvider()
257: // .getRecordType().getLiteral()));
258: //
259: SSL ssl = model.getClient().getSSL();
260: sslMap.put("sslProtocol", ssl.getSslProtocol().getLiteral());
261: sslMap.put("allowAnonymous", Boolean.toString(ssl
262: .isAllowAnonymous()));
263: sslMap.put("usePrivateKey", Boolean.toString(ssl
264: .isUsePrivateKey()));
265: sslMap.put("keyStoreFile", ssl.getKeyStoreFile());
266: sslMap.put("keyStorePassword", ssl.getKeyStorePassword());
267: sslMap.put("authenticateServer", new Boolean(ssl
268: .isAuthenticatePeer()).toString());
269: sslMap.put("useDefaultTrustStore", Boolean.toString(ssl
270: .isUseDefaultTrustStore()));
271: sslMap.put("trustStoreFile", ssl.getTrustStoreFile());
272: sslMap.put("trustStorePassword", ssl.getTrustStorePassword());
273: }
274:
275: private void setDefaultSSLMapValues() {
276: sslMap.put("sslProtocol", "TLS");
277: sslMap.put("allowAnonymous", "true");
278: sslMap.put("usePrivateKey", "false");
279: sslMap.put("keyStoreFile", "");
280: sslMap.put("keyStorePassword", "");
281: sslMap.put("authenticateServer", "false");
282: sslMap.put("useDefaultTrustStore", "true");
283: sslMap.put("trustStoreFile", "");
284: sslMap.put("trustStorePassword", "");
285: }
286: }
|