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.SelectionAdapter;
029: import org.eclipse.swt.events.SelectionEvent;
030: import org.eclipse.swt.layout.GridData;
031: import org.eclipse.swt.layout.GridLayout;
032: import org.eclipse.swt.widgets.Button;
033: import org.eclipse.swt.widgets.Composite;
034: import org.eclipse.swt.widgets.Group;
035:
036: import com.bostechcorp.cbesb.common.i18n.I18N;
037: import com.bostechcorp.cbesb.common.i18n.Messages;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.File;
039: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RoleType;
040:
041: public class FilePropertyWizardMainPage extends PropertyWizardPageMain {
042:
043: private Button buttonRead;
044:
045: private Button buttonWrite;
046:
047: protected FilePropertyWizardMainPage(String pageName) {
048: super (pageName);
049: setTitle(I18N.getString(Messages.FILE_PRO_WIZ));// "Choose
050:
051: setDescription(I18N.getString(Messages.FILE_PRO_WIZ_DES));
052: }
053:
054: public void createControl(Composite parent) {
055:
056: super .createSubControl(parent, 2);
057:
058: final Group modeGroup = new Group(topLevel, SWT.NONE);
059: modeGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
060: false, false, 2, 1));
061: modeGroup.setText(I18N.getString(Messages.MODE));
062: final GridLayout gridLayout = new GridLayout();
063: gridLayout.horizontalSpacing = 200;
064: gridLayout.numColumns = 2;
065: modeGroup.setLayout(gridLayout);
066:
067: buttonRead = new Button(modeGroup, SWT.CHECK);
068: buttonRead.addSelectionListener(new SelectionAdapter() {
069: public void widgetSelected(final SelectionEvent e) {
070: // canFlipToNextPage();
071: dialogChanged();
072: }
073: });
074: buttonRead.setText(I18N.getString(Messages.READ));
075:
076: buttonWrite = new Button(modeGroup, SWT.CHECK);
077: buttonWrite.addSelectionListener(new SelectionAdapter() {
078: public void widgetSelected(final SelectionEvent e) {
079: canFlipToNextPage();
080: dialogChanged();
081: }
082: });
083: buttonWrite.setText(I18N.getString(Messages.WRITE));
084:
085: if (this .getWizard().isUpdateOperation()) {
086: modelsToControl();
087: }
088:
089: dialogChanged();
090:
091: }
092:
093: protected void dialogChanged() {
094: if (WizardUtil.whetherUseValidation == false) {
095: setPageComplete(true);
096: return;
097: }
098: if (buttonRead != null && buttonWrite != null) {
099: if (!buttonRead.getSelection()
100: && !buttonWrite.getSelection()) {
101: updateStatus(I18N.getString(Messages.MODE_SEL_TIP));
102: setPageComplete(false);
103: return;
104:
105: }
106: }
107: super .dialogChanged();
108: }
109:
110: public boolean isPageComplete() {
111: if (buttonRead != null && buttonWrite != null) {
112: return (buttonRead.getSelection() || buttonWrite
113: .getSelection());
114: }
115: return false;
116: }
117:
118: public IWizardPage getNextPage() {
119: if (buttonRead.getSelection()) {
120: // Go to the normal next page
121:
122: return super .getNextPage();
123: } else if (buttonWrite.getSelection()) {
124:
125: return getWizard().getPage("PageStep6");
126: }
127:
128: return super .getNextPage();
129: }
130:
131: public Button getButtonRead() {
132: return buttonRead;
133: }
134:
135: public void setButtonRead(Button buttonRead) {
136: this .buttonRead = buttonRead;
137: }
138:
139: public Button getButtonWrite() {
140: return buttonWrite;
141: }
142:
143: public void setButtonWrite(Button buttonWrite) {
144: this .buttonWrite = buttonWrite;
145: }
146:
147: @Override
148: public void controlToModels() {
149: super .controlToModels();
150:
151: FilePropertyWizard fileWizard = (FilePropertyWizard) this
152: .getWizard();
153: File models = fileWizard.getModels();
154: if (models == null)
155: return;
156: try {
157:
158: if (buttonRead.getSelection()
159: && !buttonWrite.getSelection()) {
160: models.setRole(RoleType.get(RoleType.CONSUMER));
161:
162: } else if (buttonWrite.getSelection()
163: && !buttonRead.getSelection()) {
164: models.setRole(RoleType.get(RoleType.PROVIDER));
165: } else if (buttonRead.getSelection()
166: && buttonWrite.getSelection()) {
167: models.setRole(RoleType.get(RoleType.BOTH));
168: }
169: if (buttonRead.getSelection()) {
170: if (!textName.getText().equals(""))
171: models.getConsumer().setEndPointName(
172: getConsumerEndpointName());
173:
174: }
175:
176: if (buttonWrite.getSelection()) {
177: if (!textName.getText().equals(""))
178: models.getProvider().setEndPointName(
179: getProviderEndpointName());
180:
181: }
182:
183: } catch (Exception e) {
184: e.printStackTrace();
185: }
186: }
187:
188: @Override
189: public void modelsToControl() {
190:
191: super .modelsToControl();
192:
193: FilePropertyWizard fileWizard = (FilePropertyWizard) this
194: .getWizard();
195: if (!fileWizard.isUpdateOperation())
196: return;
197: try {
198: File models = fileWizard.getModels();
199:
200: int modeType = models.getRole().getValue();
201:
202: if (modeType == RoleType.CONSUMER) {
203: buttonRead.setSelection(true);
204: buttonWrite.setSelection(false);
205: } else if (modeType == RoleType.PROVIDER) {
206: buttonRead.setSelection(false);
207: buttonWrite.setSelection(true);
208: } else if (modeType == RoleType.BOTH) {
209: buttonRead.setSelection(true);
210: buttonWrite.setSelection(true);
211: }
212: } catch (Exception e) {
213: e.printStackTrace();
214: }
215: }
216:
217: @Override
218: boolean isConsumer() {
219: return buttonRead.getSelection();
220: }
221:
222: @Override
223: boolean isProvider() {
224: return buttonWrite.getSelection();
225: }
226:
227: @Override
228: public String getComponentName() {
229: return "File";
230: }
231:
232: public String getConsumerEndpointName() {
233: return textName.getText() + "_Input";
234: }
235:
236: public String getProviderEndpointName() {
237: return textName.getText() + "_Ouput";
238: }
239:
240: }
|