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.ide.wizards;
025:
026: import java.io.IOException;
027: import java.io.InputStream;
028:
029: import org.eclipse.core.resources.IFile;
030: import org.eclipse.jface.viewers.IStructuredSelection;
031: import org.eclipse.swt.SWT;
032: import org.eclipse.swt.layout.GridData;
033: import org.eclipse.swt.widgets.Button;
034: import org.eclipse.swt.widgets.Combo;
035: import org.eclipse.swt.widgets.Composite;
036: import org.eclipse.swt.widgets.Event;
037: import org.eclipse.swt.widgets.Label;
038: import org.eclipse.ui.IWorkbench;
039: import org.eclipse.ui.IWorkbenchPage;
040: import org.eclipse.ui.IWorkbenchWindow;
041: import org.eclipse.ui.PartInitException;
042: import org.eclipse.ui.ide.IDE;
043:
044: import com.bostechcorp.cbesb.common.util.etl.xml.ExecConfigWriter;
045: import com.bostechcorp.cbesb.common.i18n.I18N;
046: import com.bostechcorp.cbesb.common.i18n.Messages;
047: import com.bostechcorp.cbesb.common.util.etl.model.execconfig.ExecConfigModel;
048: import com.bostechcorp.cbesb.common.util.etl.model.execconfig.ModelTypeEnum;
049: import com.bostechcorp.cbesb.common.util.etl.model.execconfig.TransactionMode;
050: import com.bostechcorp.cbesb.ui.util.MsgUtil;
051:
052: public class ETLConfigWizardPage extends WizardNewFileCreationPage {
053: private IWorkbench workbench;
054:
055: // widgets
056: private Button openFileCheckbox;
057:
058: private Combo typeCombo;
059:
060: // constants
061: private static int nameCounter = 1;
062:
063: /**
064: * Creates the page for the readme creation wizard.
065: *
066: * @param workbench
067: * the workbench on which the page should be created
068: * @param selection
069: * the current selection
070: */
071: public ETLConfigWizardPage(IWorkbench workbench,
072: IStructuredSelection selection) {
073: super ("NewConfigWizard", selection); //$NON-NLS-1$
074: this .setTitle(I18N.getString(Messages.NEW_ETL_CONFIG_FILE));
075: this .setDescription(I18N
076: .getString(Messages.NEW_ETL_CONFIG_FILE_DES));
077: this .workbench = workbench;
078: }
079:
080: /**
081: * (non-Javadoc) Method declared on IDialogPage.
082: */
083: public void createControl(Composite parent) {
084: // inherit default container and name specification widgets
085: super .createControl(parent);
086: Composite composite = (Composite) getControl();
087:
088: this .setFileName("ETLconfigfile" + nameCounter, "ecf"); //$NON-NLS-1$ //$NON-NLS-2$
089: Label label = new Label(composite, SWT.NONE);
090: final GridData gridData = new GridData();
091: gridData.horizontalSpan = 5;
092: label.setLayoutData(gridData);
093: label.setText(I18N.getString(Messages.WIZARD_ROLE));
094: // Combo for MDL version choice
095: typeCombo = new Combo(composite, SWT.READ_ONLY);
096: typeCombo.setLayoutData(new GridData(
097: GridData.HORIZONTAL_ALIGN_FILL));
098: typeCombo.add("Consumer");
099: typeCombo.add("Provider");
100: typeCombo.select(0);
101: // open file for editing checkbox
102: openFileCheckbox = new Button(composite, SWT.CHECK);
103: openFileCheckbox.setText(I18N
104: .getString(Messages.IDE_OPEN_FILE_EDITOR));
105: openFileCheckbox.setSelection(true);
106: openFileCheckbox.setText(I18N
107: .getString(Messages.IDE_OPEN_FILE_EDITOR));
108: setPageComplete(validatePage(this .getContainerFullPath()
109: .toString(), "src/etl/ExecConfig"));
110:
111: }
112:
113: /**
114: * Creates a new file resource as requested by the user. If everything is OK
115: * then answer true. If not, false will cause the dialog to stay open.
116: *
117: * @return whether creation was successful
118: * @see MessageFormatCreationWizard#performFinish()
119: */
120: public boolean finish() {
121: // create the new file resource
122: IFile newFile = createNewFile("ecf");
123:
124: if (newFile == null)
125: return false; // ie.- creation was unsuccessful
126:
127: // Since the file resource was created fine, open it for editing
128: // if requested by the user
129: ExecConfigModel configModel = new ExecConfigModel();
130: if (typeCombo.getText().equals("Consumer")) {
131: configModel.setModelType(ModelTypeEnum.SelectOnly);
132: TransactionMode transactionMode = new TransactionMode();
133: transactionMode.setMode("Batch with AutoCommit off");
134: transactionMode.setValue("");
135: configModel.setTransactionMode(transactionMode);
136: } else {
137: TransactionMode transactionMode = new TransactionMode();
138: transactionMode.setMode("Single");
139: transactionMode.setValue("");
140: configModel.setModelType(ModelTypeEnum.Insert);
141: configModel.setTransactionMode(transactionMode);
142: }
143: ExecConfigWriter fg = new ExecConfigWriter();
144: try {
145: fg.writeToFile(configModel, newFile.getLocation()
146: .toOSString());
147: } catch (IOException e1) {
148: MsgUtil.warningMsg(e1.toString());
149: e1.printStackTrace();
150: }
151: try {
152: if (openFileCheckbox.getSelection()) {
153: IWorkbenchWindow dwindow = workbench
154: .getActiveWorkbenchWindow();
155: IWorkbenchPage page = dwindow.getActivePage();
156: if (page != null) {
157: IDE.openEditor(page, newFile, true);
158: }
159: }
160: } catch (PartInitException e) {
161: e.printStackTrace();
162: return false;
163: }
164: nameCounter++;
165: return true;
166: }
167:
168: /**
169: * The <code>MessageFormatCreationWizardPage</code> implementation of this
170: * <code>WizardNewFileCreationPage</code> method generates sample headings
171: * for sections and subsections in the newly-created Readme file according
172: * to the selections of self's checkbox widgets
173: */
174: protected InputStream getInitialContents() {
175: return null;
176: }
177:
178: /**
179: * (non-Javadoc) Method declared on WizardNewFileCreationPage.
180: */
181: protected String getNewFileLabel() {
182: // Messages.IDE_MSGDEF_NAME
183: return "Config file name"; //$NON-NLS-1$
184: }
185:
186: public void handleEvent(Event event) {
187: setPageComplete(validatePage(this .getContainerFullPath()
188: .toString(), "src/etl/ExecConfig"));
189: }
190: }
|