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:
028: import org.eclipse.jface.wizard.IWizardPage;
029: import org.eclipse.swt.SWT;
030: import org.eclipse.swt.events.ModifyEvent;
031: import org.eclipse.swt.events.ModifyListener;
032: import org.eclipse.swt.events.SelectionAdapter;
033: import org.eclipse.swt.events.SelectionEvent;
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.Shell;
041: import org.eclipse.swt.widgets.Text;
042: import org.eclipse.ui.PlatformUI;
043: import org.eclipse.ui.part.FileEditorInput;
044:
045: import com.bostechcorp.cbesb.common.i18n.I18N;
046: import com.bostechcorp.cbesb.common.i18n.Messages;
047: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.DefaultMepType;
048: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RoleType;
049: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Scheduler;
050: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Script;
051: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ScriptType;
052: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
053: import com.bostechcorp.cbesb.ui.util.ProjectUtil;
054: import com.bostechcorp.cbesb.ui.util.browser.CustomCodeBrowseDialog;
055:
056: public class ScriptPropertyWizardPageMain extends
057: PropertyWizardPageMain {
058:
059: private Combo comboMEP;
060:
061: private Combo comboType;
062:
063: private Combo comboRole;
064:
065: private Text textClass;
066:
067: private SchedulerGroup tiggerMethodGroup;
068:
069: private HashMap<String, Object> detailMap = new HashMap<String, Object>();
070:
071: protected ScriptPropertyWizardPageMain(String pageName) {
072: super (pageName);
073: setTitle(I18N.getString(Messages.SCRIPT_TITLE));// "Choose
074: setDescription(I18N.getString(Messages.WIZARD_ENTER_TIP));
075: }
076:
077: public void createControl(Composite parent) {
078:
079: super .createSubControl(parent, 3);
080:
081: final Label fixedOffsetLabel = new Label(topLevel, SWT.NONE);
082: fixedOffsetLabel.setText(I18N.getString(Messages.WIZARD_TYPE));
083:
084: comboType = new Combo(topLevel, SWT.READ_ONLY);
085:
086: comboType.setItems(new String[] { "Groovy", "Java" });
087: comboType.addModifyListener(new ModifyListener() {
088:
089: public void modifyText(ModifyEvent e) {
090:
091: if (textClass != null)
092: textClass.setText("");
093: }
094: });
095: final GridData gridData_4 = new GridData(SWT.FILL, SWT.CENTER,
096: true, false, 2, 1);
097: gridData_4.widthHint = 287;
098: comboType.setLayoutData(gridData_4);
099: if (!this .getWizard().isUpdateOperation())
100: comboType.setText("Groovy");
101:
102: final Label typeLabel = new Label(topLevel, SWT.NONE);
103: typeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
104: false, false));
105: typeLabel.setText(I18N.getString(Messages.WIZARD_MEP));
106:
107: comboMEP = new Combo(topLevel, SWT.READ_ONLY);
108: comboMEP.setEnabled(false);
109: comboMEP.setItems(new String[] { "in-only", "in-out",
110: "reliablein" });
111: if (!this .getWizard().isUpdateOperation())
112: comboMEP.setText("in-out");
113:
114: final GridData gridData_5 = new GridData(SWT.FILL, SWT.CENTER,
115: true, false, 2, 1);
116: gridData_5.widthHint = 313;
117: comboMEP.setLayoutData(gridData_5);
118:
119: final Label dilimiterLabel = new Label(topLevel, SWT.NONE);
120: dilimiterLabel.setText(I18N.getString(Messages.CCSL_CLASS));
121:
122: textClass = new Text(topLevel, SWT.READ_ONLY | SWT.BORDER);
123: final GridData gridData_3 = new GridData(SWT.FILL, SWT.CENTER,
124: true, false);
125: gridData_3.widthHint = 261;
126: textClass.setLayoutData(gridData_3);
127: textClass.addModifyListener(new ModifyListener() {
128: public void modifyText(ModifyEvent e) {
129:
130: dialogChanged();
131: }
132: });
133:
134: final Button buttonBrowser = new Button(topLevel, SWT.NONE);
135: buttonBrowser.addSelectionListener(new SelectionAdapter() {
136:
137: public void widgetSelected(final SelectionEvent e) {
138:
139: FileEditorInput editorInput = (FileEditorInput) PlatformUI
140: .getWorkbench().getActiveWorkbenchWindow()
141: .getActivePage().getActiveEditor()
142: .getEditorInput();
143: String projectName = editorInput.getFile().getProject()
144: .getName();
145:
146: Shell shell = PlatformUI.getWorkbench()
147: .getActiveWorkbenchWindow().getShell();
148: CustomCodeBrowseDialog dialog = new CustomCodeBrowseDialog(
149: ComponentFlowEditorDiagramEditorPlugin
150: .getInstance(), buttonBrowser
151: .getShell(), I18N
152: .getString(Messages.IDE_FILE_SEL),
153: ProjectUtil.getRelatedProject(projectName),
154: comboType.getText(), "script", textClass);
155: dialog.open();
156: }
157: });
158: final GridData gridData_6 = new GridData(SWT.FILL, SWT.FILL,
159: false, false);
160: gridData_6.widthHint = 94;
161: buttonBrowser.setLayoutData(gridData_6);
162: buttonBrowser.setText(I18N.getString(Messages.WIZARD_BROWSE));
163:
164: final Label scriptEngineLabel = new Label(topLevel, SWT.NONE);
165: scriptEngineLabel.setText(I18N.getString(Messages.WIZARD_ROLE));
166:
167: comboRole = new Combo(topLevel, SWT.READ_ONLY);
168: comboRole.setItems(new String[] { "consumer", "provider" });
169: comboRole.setText("provider");
170: final GridData gridData_7 = new GridData(SWT.FILL, SWT.CENTER,
171: true, false, 2, 1);
172: gridData_7.widthHint = 297;
173: comboRole.setLayoutData(gridData_7);
174:
175: if (this .getWizard().isUpdateOperation()) {
176: modelsToControl();
177: }
178:
179: tiggerMethodGroup = new SchedulerGroup(topLevel, SWT.NONE, I18N
180: .getString(Messages.SCRIPT_TRIGGER_TIME), "1000",
181: detailMap, this .getWizard().isUpdateOperation());
182:
183: tiggerMethodGroup.setLayoutData(new GridData(SWT.FILL,
184: SWT.CENTER, false, false, 3, 1));
185:
186: tiggerMethodGroup.setVisible(false);
187:
188: if (this .getWizard().isUpdateOperation()) {
189: if (comboRole.getText().equalsIgnoreCase("consumer")) {
190: tiggerMethodGroup.setVisible(true);
191: }
192: }
193:
194: comboRole.addSelectionListener(new SelectionAdapter() {
195: public void widgetSelected(SelectionEvent e) {
196: if (comboRole.getText().equalsIgnoreCase("consumer")) {
197: tiggerMethodGroup.setVisible(true);
198: comboMEP.setEnabled(true);
199: } else {
200: tiggerMethodGroup.setVisible(false);
201: comboMEP.setEnabled(false);
202: comboMEP.select(1);
203: }
204: }
205: });
206:
207: dialogChanged();
208: }
209:
210: protected void dialogChanged() {
211: if (WizardUtil.whetherUseValidation == false) {
212: setPageComplete(true);
213: return;
214: }
215: if (textClass.getText().equals("")) {
216: updateStatus(I18N
217: .getString(Messages.CCSL_ERROR_CLASS_REQUIRE));
218: setPageComplete(false);
219: return;
220: }
221: super .dialogChanged();
222: }
223:
224: public IWizardPage getNextPage() {
225: if (isUseCCSL()) {
226: if (this .isConsumer())
227: return getWizard().getCcslConsumerPage();
228: else
229: return this .getWizard().getCcslProviderPage();
230: }
231:
232: return null;
233: }
234:
235: @Override
236: public void controlToModels() {
237:
238: super .controlToModels();
239:
240: ScriptPropertyWizard ScriptWizard = (ScriptPropertyWizard) this
241: .getWizard();
242: Script models = ScriptWizard.getModels();
243: if (models == null)
244: return;
245: try {
246:
247: models.setClass_(textClass.getText());
248: models.setRole(RoleType.getByName(comboRole.getText()));
249: models.getConsumer().setDefaultMep(
250: DefaultMepType.get(comboMEP.getText()));
251:
252: models.setType(ScriptType.get(comboType.getText()));
253:
254: if (comboRole.getText().equalsIgnoreCase("consumer")) {
255:
256: if (tiggerMethodGroup != null)
257: tiggerMethodGroup.controlToModel();
258: models.setUseScheduler(new Boolean((String) detailMap
259: .get("useschedule")));
260: if (new Boolean((String) detailMap.get("useschedule")))
261: models.setScheduler((Scheduler) detailMap
262: .get("scheduler"));
263: else
264: models.setTriggerTime((String) detailMap
265: .get("scaninterval"));
266:
267: comboMEP.setEnabled(true);
268: models.getConsumer().setEndPointName(models.getName());
269: } else {
270: models.getProvider().setEndPointName(models.getName());
271: }
272:
273: } catch (Exception e) {
274: e.printStackTrace();
275: }
276: ;
277: }
278:
279: @Override
280: public void modelsToControl() {
281:
282: super .modelsToControl();
283:
284: ScriptPropertyWizard ScriptWizard = (ScriptPropertyWizard) this
285: .getWizard();
286: Script models = ScriptWizard.getModels();
287:
288: comboRole.select(comboRole.indexOf(models.getRole()
289: .getLiteral()));
290:
291: if (comboRole.getText().equalsIgnoreCase("consumer")) {
292: Scheduler scheduler = models.getScheduler();
293: Scheduler newScheduler = scheduler;
294: detailMap.put("scheduler", newScheduler);
295: detailMap.put("useschedule", new Boolean(models
296: .isUseScheduler()).toString());
297: detailMap.put("scaninterval", models.getTriggerTime());
298: comboMEP.setEnabled(true);
299: }
300:
301: comboCCSL.select(comboCCSL.indexOf(models.getUseCCSL()
302: .toString()));
303: comboMEP.select(comboMEP.indexOf(models.getConsumer()
304: .getDefaultMep().getLiteral()));
305: comboType.select(comboType.indexOf(models.getType()
306: .getLiteral()));
307:
308: if (models.getClass_() != null)
309: textClass.setText(models.getClass_());
310: else
311: textClass.setText("");
312:
313: }
314:
315: @Override
316: boolean isConsumer() {
317:
318: return comboRole.getText().equalsIgnoreCase("consumer");
319: }
320:
321: @Override
322: boolean isProvider() {
323: return comboRole.getText().equalsIgnoreCase("provider");
324: }
325:
326: @Override
327: public String getComponentName() {
328: return "Script";
329: }
330:
331: }
|