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.GridData;
033: import org.eclipse.swt.layout.GridLayout;
034: import org.eclipse.swt.widgets.Button;
035: import org.eclipse.swt.widgets.Combo;
036: import org.eclipse.swt.widgets.Composite;
037: import org.eclipse.swt.widgets.Group;
038: import org.eclipse.swt.widgets.Label;
039: import org.eclipse.swt.widgets.Text;
040: import org.eclipse.ui.PlatformUI;
041: import org.eclipse.ui.part.FileEditorInput;
042:
043: import com.bostechcorp.cbesb.common.i18n.I18N;
044: import com.bostechcorp.cbesb.common.i18n.Messages;
045: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ConnectionModeType;
046: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RoleType;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.TCPIP;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
049: import com.bostechcorp.cbesb.ui.util.ProjectUtil;
050: import com.bostechcorp.cbesb.ui.util.browser.CustomCodeBrowseDialog;
051:
052: public class TCPIPPropertyWizardMainPage extends PropertyWizardPageMain {
053:
054: private Text textProcotolHandler;
055:
056: private Button clientButton;
057:
058: private Button serverButton;
059:
060: private Button consumerButton;
061:
062: private Button providerButton;
063:
064: private String className = "";
065:
066: protected TCPIPPropertyWizardMainPage(String pageName) {
067: super (pageName);
068: setTitle(I18N.getString(Messages.TCPIP_WIZARD_TITLE));
069: setDescription(I18N
070: .getString(Messages.TCPIP_WIZARD_DESCRIPTION));
071: }
072:
073: public void createControl(Composite parent) {
074: super .createSubControl(parent, 2);
075:
076: final Composite composite = new Composite(topLevel, SWT.NONE);
077: composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
078: false, false, 3, 1));
079: final GridLayout gridLayout_1 = new GridLayout();
080: gridLayout_1.marginWidth = 0;
081: gridLayout_1.numColumns = 3;
082: composite.setLayout(gridLayout_1);
083:
084: final Label proLabel = new Label(composite, SWT.NONE);
085: proLabel.setText(I18N
086: .getString(Messages.TCPIP_PROCOTOL_HANDLER));
087:
088: textProcotolHandler = new Text(composite, SWT.BORDER);
089: final GridData gridData_3 = new GridData(SWT.FILL, SWT.CENTER,
090: true, false);
091: gridData_3.widthHint = 288;
092: textProcotolHandler.setLayoutData(gridData_3);
093: textProcotolHandler.addModifyListener(new ModifyListener() {
094: public void modifyText(ModifyEvent e) {
095: dialogChanged();
096: }
097: });
098:
099: final Button procotolHandlerButton = new Button(composite,
100: SWT.NONE);
101: final GridData gridData_4 = new GridData(SWT.FILL, SWT.CENTER,
102: false, false);
103: gridData_4.widthHint = 59;
104: procotolHandlerButton.setLayoutData(gridData_4);
105: procotolHandlerButton.setText(I18N
106: .getString(Messages.TCPIP_BROWSE));
107: addBrowseListerner(procotolHandlerButton, textProcotolHandler);
108:
109: final Group modeGroup = new Group(topLevel, SWT.NONE);
110: modeGroup.setText(I18N.getString(Messages.TCPIP_MODE));
111: modeGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
112: false, false, 3, 1));
113: final GridLayout gridLayout_2 = new GridLayout();
114: gridLayout_2.horizontalSpacing = 150;
115: gridLayout_2.verticalSpacing = 0;
116: gridLayout_2.numColumns = 2;
117: gridLayout_2.marginWidth = 0;
118: modeGroup.setLayout(gridLayout_2);
119:
120: serverButton = new Button(modeGroup, SWT.RADIO);
121: serverButton.setSelection(true);
122: serverButton.setLayoutData(new GridData());
123: serverButton.setText(I18N.getString(Messages.TCPIP_SERVER));
124:
125: clientButton = new Button(modeGroup, SWT.RADIO);
126: clientButton.setText(I18N.getString(Messages.TCPIP_CLIENT));
127:
128: final Group roleGroup = new Group(topLevel, SWT.NONE);
129: roleGroup.setText(I18N.getString(Messages.TCPIP_ROLE));
130: roleGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
131: false, false, 3, 1));
132: final GridLayout gridLayout_3 = new GridLayout();
133: gridLayout_3.horizontalSpacing = 140;
134: gridLayout_3.numColumns = 2;
135: gridLayout_3.marginWidth = 0;
136: roleGroup.setLayout(gridLayout_3);
137:
138: consumerButton = new Button(roleGroup, SWT.RADIO);
139: consumerButton.setSelection(true);
140: consumerButton.setText(I18N.getString(Messages.TCPIP_CONSUMER));
141: consumerButton.addSelectionListener(new SelectionAdapter() {
142: public void widgetSelected(SelectionEvent e) {
143: setMaxClients();
144: }
145: });
146:
147: providerButton = new Button(roleGroup, SWT.RADIO);
148: providerButton.setText(I18N.getString(Messages.TCPIP_PROVIDER));
149: providerButton.addSelectionListener(new SelectionAdapter() {
150: public void widgetSelected(SelectionEvent e) {
151: setMaxClients();
152: }
153: });
154:
155: if (this .getWizard().isUpdateOperation()) {
156: modelsToControl();
157: }
158:
159: dialogChanged();
160: }
161:
162: private void setMaxClients() {
163: if (consumerButton.getSelection()) {
164: ((TCPIPServerSettingsWizardPage) this .getWizard().getPage(
165: "ServerPage")).getText().setText("20");
166: ((TCPIPServerSettingsWizardPage) this .getWizard().getPage(
167: "ServerPage")).getText().setEnabled(true);
168: }
169: if (providerButton.getSelection()) {
170: ((TCPIPServerSettingsWizardPage) this .getWizard().getPage(
171: "ServerPage")).getText().setText("1");
172: ((TCPIPServerSettingsWizardPage) this .getWizard().getPage(
173: "ServerPage")).getText().setEnabled(false);
174: }
175: }
176:
177: public void addBrowseListerner(final Button browseClass,
178: final Text classText) {
179: browseClass.addSelectionListener(new SelectionAdapter() {
180:
181: public void widgetSelected(SelectionEvent e) {
182: FileEditorInput editorInput = (FileEditorInput) PlatformUI
183: .getWorkbench().getActiveWorkbenchWindow()
184: .getActivePage().getActiveEditor()
185: .getEditorInput();
186: String projectName = editorInput.getFile().getProject()
187: .getName();
188: CustomCodeBrowseDialog customCodeBrowseDialog = new CustomCodeBrowseDialog(
189: ComponentFlowEditorDiagramEditorPlugin
190: .getInstance(), browseClass.getShell(),
191: I18N.getString(Messages.IDE_FILE_SEL),
192: ProjectUtil.getRelatedProject(projectName),
193: "Java", "TCPIP", classText);
194:
195: customCodeBrowseDialog.open();
196: className = customCodeBrowseDialog.getClassName();
197: }
198: });
199: }
200:
201: protected void dialogChanged() {
202: if (WizardUtil.whetherUseValidation == false) {
203: setPageComplete(true);
204: return;
205: }
206:
207: if (textProcotolHandler.getText().equals("")) {
208: setErrorMessage(I18N
209: .getString(Messages.TCPIP_PROTOCOL_HANDLER_REQ));
210: setPageComplete(false);
211: return;
212: }
213:
214: super .dialogChanged();
215: }
216:
217: public IWizardPage getNextPage() {
218: if (clientButton.getSelection()) {
219: return this .getWizard().getPage("ClientPage");
220: } else if (serverButton.getSelection()) {
221: return this .getWizard().getPage("ServerPage");
222: }
223: return null;
224: }
225:
226: @Override
227: public void controlToModels() {
228: super .controlToModels();
229:
230: TCPIPPropertyWizard TCPIPWizard = (TCPIPPropertyWizard) this
231: .getWizard();
232: TCPIP model = TCPIPWizard.getModels();
233: if (model == null) {
234: return;
235: }
236:
237: model.setProtocolHandlerDescription(textProcotolHandler
238: .getText());
239: model.setProtocolHandler(className);
240:
241: if (serverButton.getSelection()) {
242: model.setConnectionMode(ConnectionModeType.SERVER_LITERAL);
243: } else if (clientButton.getSelection()) {
244: model.setConnectionMode(ConnectionModeType.CLIENT_LITERAL);
245: }
246:
247: if (consumerButton.getSelection()) {
248: model.setRole(RoleType.CONSUMER_LITERAL);
249: model.getConsumer().setEndPointName(model.getName());
250: } else if (providerButton.getSelection()) {
251: model.setRole(RoleType.PROVIDER_LITERAL);
252: model.getProvider().setEndPointName(model.getName());
253:
254: }
255: }
256:
257: @Override
258: public void modelsToControl() {
259: super .modelsToControl();
260:
261: TCPIPPropertyWizard TCPIPWizard = (TCPIPPropertyWizard) this
262: .getWizard();
263: TCPIP model = TCPIPWizard.getModels();
264: if (model == null)
265: return;
266:
267: if (model.getProtocolHandlerDescription() != null) {
268: textProcotolHandler.setText(model
269: .getProtocolHandlerDescription());
270: } else {
271: if (model.getProtocolHandler() != null) {
272: textProcotolHandler.setText(model.getProtocolHandler());
273: } else {
274: textProcotolHandler.setText("");
275: }
276: }
277:
278: if (model.getProtocolHandler() != null) {
279: className = model.getProtocolHandler();
280: } else {
281: className = "";
282: }
283:
284: if (model.getConnectionMode().toString().equalsIgnoreCase(
285: "server")) {
286: serverButton.setSelection(true);
287: clientButton.setSelection(false);
288: } else {
289: serverButton.setSelection(false);
290: clientButton.setSelection(true);
291: }
292:
293: if (model.getRole().toString().equalsIgnoreCase("consumer")) {
294: providerButton.setSelection(false);
295: consumerButton.setSelection(true);
296: } else {
297: consumerButton.setSelection(false);
298: providerButton.setSelection(true);
299: }
300: }
301:
302: public Button getConsumerButton() {
303: return consumerButton;
304: }
305:
306: public Button getProviderButton() {
307: return providerButton;
308: }
309:
310: @Override
311: boolean isConsumer() {
312: return consumerButton.getSelection();
313: }
314:
315: @Override
316: boolean isProvider() {
317: return providerButton.getSelection();
318: }
319:
320: @Override
321: public String getComponentName() {
322: return "TCPIP";
323: }
324:
325: }
|