01: package org.drools.eclipse.wizard.decisiontable;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05:
06: import org.drools.eclipse.DroolsEclipsePlugin;
07: import org.eclipse.jface.viewers.IStructuredSelection;
08: import org.eclipse.swt.widgets.Composite;
09: import org.eclipse.ui.IWorkbench;
10: import org.eclipse.ui.IWorkbenchWindow;
11: import org.eclipse.ui.PartInitException;
12: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
13: import org.eclipse.ui.ide.IDE;
14:
15: /**
16: * A page to create a new Decision table scaffolding based on a template.
17: *
18: * @author Michael Neale
19: */
20: public class NewDTFilePage extends WizardNewFileCreationPage {
21:
22: private static final String XLS_EXTENSION = ".xls";
23: private IWorkbench workbench;
24:
25: public NewDTFilePage(IWorkbench workbench,
26: IStructuredSelection selection) {
27: super ("createDTFilePage", selection);
28: setTitle("New Decision Table");
29: setDescription("Create a new Decision Table scaffolding.");
30: this .workbench = workbench;
31: }
32:
33: public void createControl(Composite parent) {
34: super .createControl(parent);
35: setPageComplete(true);
36: }
37:
38: public boolean finish() {
39: String fileName = getFileName();
40: if (!fileName.endsWith(XLS_EXTENSION)) {
41: setFileName(fileName + XLS_EXTENSION);
42: }
43: org.eclipse.core.resources.IFile newFile = createNewFile();
44: if (newFile == null)
45: return false;
46: try {
47: IWorkbenchWindow dwindow = workbench
48: .getActiveWorkbenchWindow();
49: org.eclipse.ui.IWorkbenchPage page = dwindow
50: .getActivePage();
51: if (page != null)
52: IDE.openEditor(page, newFile, true);
53: } catch (PartInitException e) {
54: DroolsEclipsePlugin.log(e);
55: return false;
56: }
57: return true;
58: }
59:
60: protected InputStream getInitialContents() {
61: try {
62: return DroolsEclipsePlugin
63: .getDefault()
64: .getBundle()
65: .getResource(
66: "org/drools/eclipse/wizard/decisiontable/template.xls")
67: .openStream();
68: } catch (IOException e) {
69: return null;
70: } catch (NullPointerException e) {
71: return null;
72: }
73: }
74:
75: }
|