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