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.swt.SWT;
027: import org.eclipse.swt.events.ModifyEvent;
028: import org.eclipse.swt.events.ModifyListener;
029: import org.eclipse.swt.layout.GridData;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Combo;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Label;
034: import org.eclipse.swt.widgets.Text;
035: import org.eclipse.ui.PlatformUI;
036: import org.eclipse.ui.part.FileEditorInput;
037:
038: import com.bostechcorp.cbesb.common.i18n.I18N;
039: import com.bostechcorp.cbesb.common.i18n.Messages;
040: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ComponentFlowEditorElement;
041:
042: public abstract class PropertyWizardPageMain extends PropertyWizardPage {
043:
044: protected Combo comboCCSL;
045:
046: protected Text textDescription;
047:
048: protected Text textName;
049:
050: abstract boolean isConsumer();
051:
052: abstract boolean isProvider();
053:
054: abstract public String getComponentName();
055:
056: abstract public void createControl(Composite parent);
057:
058: Composite topLevel = null;
059:
060: protected PropertyWizardPageMain(String pageName) {
061: super (pageName);
062: }
063:
064: public void createSubControl(Composite parent, int numColumn) {
065:
066: topLevel = new Composite(parent, SWT.NONE);
067: final GridLayout gridLayout = new GridLayout();
068: gridLayout.verticalSpacing = 10;
069: gridLayout.numColumns = numColumn;
070: topLevel.setLayout(gridLayout);
071: topLevel.setLayoutData(new GridData(
072: GridData.VERTICAL_ALIGN_FILL
073: | GridData.HORIZONTAL_ALIGN_FILL));
074: topLevel.setFont(parent.getFont());
075: this .setControl(topLevel);
076:
077: Label useCclsLabel;
078:
079: final Label labelName = new Label(topLevel, SWT.NONE);
080: labelName.setText(I18N.getString(Messages.NAME_WIZ));
081:
082: textName = new Text(topLevel, SWT.BORDER);
083: GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true,
084: false);
085: gridData.horizontalSpan = numColumn - 1;
086: textName.setLayoutData(gridData);
087: // textDescription.addModifyListener(this);
088:
089: if (!this .getWizard().isUpdateOperation()) {
090: int num = WizardUtil.modelExistNum(this .getWizard()
091: .getModels());
092: if (num == 0) {
093: textName.setText(getComponentName());
094:
095: } else {
096: textName.setText(getComponentName() + "_"
097: + String.valueOf(num));
098: }
099: } else {
100: textName.setText(getComponentName());
101:
102: }
103: textName.addModifyListener(new ModifyListener() {
104: public void modifyText(ModifyEvent e) {
105:
106: dialogChanged();
107:
108: }
109: });
110: final Label labelDescription = new Label(topLevel, SWT.NONE);
111: labelDescription.setText(I18N.getString(Messages.DES_WIZ));
112:
113: textDescription = new Text(topLevel, SWT.BORDER);
114: final GridData gridData_1 = new GridData(SWT.FILL, SWT.CENTER,
115: true, false);
116: gridData_1.widthHint = 400;
117: gridData_1.horizontalSpan = numColumn - 1;
118: textDescription.setLayoutData(gridData);
119: useCclsLabel = new Label(topLevel, SWT.NONE);
120: useCclsLabel.setText(I18N.getString(Messages.USE_CCSL));
121:
122: comboCCSL = new Combo(topLevel, SWT.READ_ONLY);
123: comboCCSL.setLayoutData(gridData);
124: comboCCSL.setItems(new String[] { "true", "false" });
125: if (!this .getWizard().isUpdateOperation())
126: comboCCSL.setText("true");
127:
128: comboCCSL.addModifyListener(new ModifyListener() {
129:
130: public void modifyText(ModifyEvent e) {
131:
132: dialogChanged();
133: }
134: });
135: }
136:
137: protected void dialogChanged() {
138:
139: if (textName.getText().equals("")) {
140: updateStatus(I18N.getString(Messages.NAME_REQ));
141: setPageComplete(false);
142: return;
143: } else if (WizardUtil.nameExist(textName.getText(), this
144: .getWizard().getModels())) {
145: updateStatus(I18N.getString(Messages.NAME_DUP));
146: setPageComplete(false);
147: return;
148: } else if (WizardUtil.nameInstallerExist(textName.getText())) {
149: updateStatus(I18N.getString(Messages.NAME_FOR));
150: setPageComplete(false);
151: return;
152: }
153: setPageComplete(true);
154: updateStatus(null);
155: }
156:
157: protected void updateStatus(String message) {
158: setErrorMessage(message);
159: }
160:
161: public void controlToModels() {
162: PropertyWizard wizard = this .getWizard();
163:
164: ComponentFlowEditorElement element = wizard.getModels();
165:
166: try {
167: element.setName(textName.getText());
168: if (!textName.getText().equals("")) {
169: element.setServiceName(textName.getText() + "_Service");
170: element.setInterfaceName(textName.getText()
171: + "_Interface");
172: }
173:
174: element.setDescription(textDescription.getText());
175:
176: if (comboCCSL.getText().equals("true"))
177: element.setUseCCSL(true);
178: else
179: element.setUseCCSL(false);
180:
181: } catch (Exception e) {
182: e.printStackTrace();
183: }
184: ;
185: }
186:
187: public void modelsToControl() {
188:
189: PropertyWizard wizard = this .getWizard();
190: ComponentFlowEditorElement element = wizard.getModels();
191: if (element.getName() != null)
192: textName.setText(element.getName());
193: else
194: textName.setText("");
195:
196: if (element.getDescription() != null)
197: textDescription.setText(element.getDescription());
198: else
199: textDescription.setText("");
200:
201: if (element.getUseCCSL())
202: comboCCSL.select(0);
203: else
204: comboCCSL.select(1);
205:
206: }
207:
208: public Combo getComboCCSL() {
209: return comboCCSL;
210: }
211:
212: public Text getTextName() {
213: return textName;
214: }
215:
216: public void setTextName(Text textName) {
217: this .textName = textName;
218: }
219:
220: public boolean isUseCCSL() {
221: return comboCCSL.getText().equals("true");
222: }
223:
224: public String getProjectName() {
225: FileEditorInput editorInput = (FileEditorInput) PlatformUI
226: .getWorkbench().getActiveWorkbenchWindow()
227: .getActivePage().getActiveEditor().getEditorInput();
228:
229: String projectName = editorInput.getFile().getProject()
230: .getName();
231: return projectName;
232: }
233: }
|