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.InputStream;
027:
028: import org.eclipse.core.resources.IFile;
029: import org.eclipse.jface.viewers.IStructuredSelection;
030: import org.eclipse.swt.SWT;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Event;
034: import org.eclipse.ui.IWorkbench;
035: import org.eclipse.ui.IWorkbenchPage;
036: import org.eclipse.ui.IWorkbenchWindow;
037: import org.eclipse.ui.PartInitException;
038: import org.eclipse.ui.ide.IDE;
039:
040: import com.bostechcorp.cbesb.common.i18n.I18N;
041: import com.bostechcorp.cbesb.common.i18n.Messages;
042: import com.bostechcorp.cbesb.common.util.etl.model.DriverModel;
043: import com.bostechcorp.cbesb.common.util.etl.xml.DriverFileGenerator;
044:
045: public class DriverManagerWizardPage extends WizardNewFileCreationPage {
046: private IWorkbench workbench;
047:
048: // widgets
049: private Button openFileCheckbox;
050:
051: // constants
052: private static int nameCounter = 1;
053:
054: /**
055: * Creates the page for the readme creation wizard.
056: *
057: * @param workbench
058: * the workbench on which the page should be created
059: * @param selection
060: * the current selection
061: */
062: public DriverManagerWizardPage(IWorkbench workbench,
063: IStructuredSelection selection) {
064: super ("NewDriverManagerWizard", selection); //$NON-NLS-1$
065: this .setTitle(I18N.getString(Messages.NEW_JDBC_DRIVER_FILE));
066: this .setDescription(I18N
067: .getString(Messages.NEW_JDBC_DRIVER_FILE_DES));
068: this .workbench = workbench;
069: }
070:
071: /**
072: * (non-Javadoc) Method declared on IDialogPage.
073: */
074: public void createControl(Composite parent) {
075: // inherit default container and name specification widgets
076: super .createControl(parent);
077: Composite composite = (Composite) getControl();
078:
079: this .setFileName("DriverFile" + nameCounter, "drv"); //$NON-NLS-1$ //$NON-NLS-2$
080: // open file for editing checkbox
081: openFileCheckbox = new Button(composite, SWT.CHECK);
082: openFileCheckbox.setText(I18N
083: .getString(Messages.IDE_OPEN_FILE_EDITOR));
084: openFileCheckbox.setSelection(true);
085: setPageComplete(validatePage(this .getContainerFullPath()
086: .toString(), "src/database/drivers"));
087:
088: }
089:
090: /**
091: * Creates a new file resource as requested by the user. If everything is OK
092: * then answer true. If not, false will cause the dialog to stay open.
093: *
094: * @return whether creation was successful
095: * @see MessageFormatCreationWizard#performFinish()
096: */
097: public boolean finish() {
098: // create the new file resource
099: IFile newFile = createNewFile("drv");
100:
101: if (newFile == null)
102: return false; // ie.- creation was unsuccessful
103:
104: // Since the file resource was created fine, open it for editing
105: // if requested by the user
106: DriverModel model = new DriverModel();
107: model.setName("");
108: model.setClassName("");
109: model.setURL("");
110:
111: DriverFileGenerator fg = new DriverFileGenerator(model, newFile
112: .getLocation().toOSString());
113: fg.write();
114: try {
115: if (openFileCheckbox.getSelection()) {
116: IWorkbenchWindow dwindow = workbench
117: .getActiveWorkbenchWindow();
118: IWorkbenchPage page = dwindow.getActivePage();
119: if (page != null) {
120: IDE.openEditor(page, newFile, true);
121: }
122: }
123: } catch (PartInitException e) {
124: e.printStackTrace();
125: return false;
126: }
127: nameCounter++;
128: return true;
129: }
130:
131: /**
132: * The <code>MessageFormatCreationWizardPage</code> implementation of this
133: * <code>WizardNewFileCreationPage</code> method generates sample headings
134: * for sections and subsections in the newly-created Readme file according
135: * to the selections of self's checkbox widgets
136: */
137: protected InputStream getInitialContents() {
138: return null;
139: }
140:
141: /**
142: * (non-Javadoc) Method declared on WizardNewFileCreationPage.
143: */
144: protected String getNewFileLabel() {
145: // Messages.IDE_MSGDEF_NAME
146: return "Driver file name"; //$NON-NLS-1$
147: }
148:
149: public void handleEvent(Event event) {
150: setPageComplete(validatePage(this .getContainerFullPath()
151: .toString(), "src/database/drivers"));
152: }
153: }
|