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.dialogs.IDialogPage;
031: import org.eclipse.jface.viewers.IStructuredSelection;
032: import org.eclipse.swt.SWT;
033: import org.eclipse.swt.widgets.Button;
034: import org.eclipse.swt.widgets.Composite;
035: import org.eclipse.swt.widgets.Event;
036: import org.eclipse.ui.IWorkbench;
037: import org.eclipse.ui.IWorkbenchPage;
038: import org.eclipse.ui.IWorkbenchWindow;
039: import org.eclipse.ui.PartInitException;
040: import org.eclipse.ui.ide.IDE;
041:
042: import com.bostechcorp.cbesb.common.util.etl.xml.DSMWriter;
043: import com.bostechcorp.cbesb.common.i18n.I18N;
044: import com.bostechcorp.cbesb.common.i18n.Messages;
045: import com.bostechcorp.cbesb.common.util.etl.model.AbstractMessageModel.DataSourceModelTypeEnum;
046: import com.bostechcorp.cbesb.ui.util.MsgUtil;
047:
048: /**
049: * The "New" wizard page allows setting the container for the new file as well
050: * as the file name. The page will only accept file name without the extension
051: * OR with the extension that matches the expected one (mpe).
052: */
053:
054: public class DataSourceMapperMainPage extends WizardNewFileCreationPage {
055: private IWorkbench workbench;
056:
057: // widgets
058: private Button openFileCheckbox;
059:
060: // constants
061: private static int nameCounter = 1;
062:
063: String selectProjectName = "";
064:
065: /*
066: * private Text targetfileNameText; private Text sourcefileNameText; private
067: * IFile file; private ISelection selection; private String sourcefilePath =
068: * ""; private String targetfilePath = "";
069: */
070: /**
071: * Creates the page for the readme creation wizard.
072: *
073: * @param workbench
074: * the workbench on which the page should be created
075: * @param selection
076: * the current selection
077: */
078: public DataSourceMapperMainPage(IWorkbench workbench,
079: IStructuredSelection selection) {
080: super ("NewDataSourceMapperWizard", selection);
081: setTitle(I18N.getString(Messages.NEW_DATA_SOURCE_MAPPER_FILE));
082: setDescription(I18N
083: .getString(Messages.NEW_DATA_SOURCE_MAPPER_FILE_DES));
084: this .workbench = workbench;
085: }
086:
087: /**
088: * @see IDialogPage#createControl(Composite)
089: */
090: public void createControl(Composite parent) {
091: // inherit default container and name specification widgets
092: super .createControl(parent);
093: Composite composite = (Composite) getControl();
094:
095: this .setFileName("DataSourceMapper" + nameCounter, "dsm"); //$NON-NLS-1$ //$NON-NLS-2$
096:
097: // open file for editing checkbox
098: openFileCheckbox = new Button(composite, SWT.CHECK);
099: openFileCheckbox.setText(I18N
100: .getString(Messages.IDE_OPEN_FILE_DONE)); //$NON-NLS-1$
101: openFileCheckbox.setSelection(true);
102:
103: setPageComplete(validatePage(this .getContainerFullPath()
104: .toString(), "src/database/dataSourceMaps"));
105: }
106:
107: /**
108: * Creates a new file resource as requested by the user. If everything is OK
109: * then answer true. If not, false will cause the dialog to stay open.
110: * @param name
111: * @param dbfile
112: *
113: * @return whether creation was successful
114: * @see MessageFormatCreationWizard#performFinish()
115: */
116: //
117: public boolean finish(String connectionFile, String modelType,
118: String name) {
119: // create the new file resource
120: IFile newFile = createNewFile("dsm");
121: if (newFile == null)
122: return false; // ie.- creation was unsuccessful
123:
124: String fileDsmName = newFile.getLocation().toString().replace(
125: "\\", "/");
126:
127: // TODO:Fill the default text
128: try {
129: if (openFileCheckbox.getSelection()) {
130: IWorkbenchWindow dwindow = this .workbench
131: .getActiveWorkbenchWindow();
132: IWorkbenchPage page = dwindow.getActivePage();
133: String dbfile = connectionFile.replace(".dbc", ".dbd");
134: if (page != null) {
135: DSMWriter.createNewDSMFile(fileDsmName,
136: connectionFile, dbfile,
137: DataSourceModelTypeEnum.valueOf(modelType),
138: name);
139: IDE.openEditor(page, newFile, true);
140: }
141: }
142: } catch (PartInitException e) {
143: MsgUtil.warningMsg(e.toString());
144: e.printStackTrace();
145: return false;
146: } catch (IOException e) {
147: MsgUtil.warningMsg(e.toString());
148: e.printStackTrace();
149: return false;
150: }
151: nameCounter++;
152: return true;
153: }
154:
155: /**
156: * The <code>MessageFormatCreationWizardPage</code> implementation of this
157: * <code>WizardNewFileCreationPage</code> method generates sample headings
158: * for sections and subsections in the newly-created Readme file according
159: * to the selections of self's checkbox widgets
160: */
161: protected InputStream getInitialContents() {
162: return null;
163: }
164:
165: @Override
166: public boolean canFlipToNextPage() {
167: // TODO Auto-generated method stub
168: return super
169: .canFlipToNextPagebyName("src/database/dataSourceMaps");
170: }
171:
172: public void handleEvent(Event event) {
173: String containerPath = this .getContainerFullPath().toString();
174: setPageComplete(validatePage(containerPath,
175: "src/database/dataSourceMaps"));
176: if (((DataSourceMapperSecondPage) this .getNextPage())
177: .getTextName() != null)
178: ((DataSourceMapperSecondPage) this .getNextPage())
179: .getTextName().setText(this .getFileName());
180: if (containerPath.lastIndexOf("/") == 0) {
181: selectProjectName = containerPath.substring(1);
182: } else {
183: selectProjectName = containerPath.substring(1,
184: containerPath.indexOf("/", 1));
185: }
186: }
187:
188: public String getSelectProjectName() {
189: return selectProjectName;
190: }
191: }
|