01: package org.drools.eclipse.rulebuilder.wizards;
02:
03: import java.io.ByteArrayInputStream;
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 rule using the Guided Editor.
17: */
18: public class NewBrlFileWizardPage extends WizardNewFileCreationPage {
19:
20: private static final String BRL_EXTENSION = ".brl";
21: private IWorkbench workbench;
22:
23: public NewBrlFileWizardPage(IWorkbench workbench,
24: IStructuredSelection selection) {
25: super ("createGuidedRuleFilePage", selection);
26: setTitle("RuleBuilder Editor File");
27: setDescription("This wizard creates a new file with *.brl extension that can be opened by a multi-page editor.");
28: this .workbench = workbench;
29: }
30:
31: public void createControl(Composite parent) {
32: super .createControl(parent);
33: setPageComplete(true);
34: }
35:
36: public boolean finish() {
37: String fileName = getFileName();
38: if (!fileName.endsWith(BRL_EXTENSION)) {
39: setFileName(fileName + BRL_EXTENSION);
40: }
41: org.eclipse.core.resources.IFile newFile = createNewFile();
42: if (newFile == null)
43: return false;
44: try {
45: IWorkbenchWindow dwindow = workbench
46: .getActiveWorkbenchWindow();
47: org.eclipse.ui.IWorkbenchPage page = dwindow
48: .getActivePage();
49: if (page != null)
50: IDE.openEditor(page, newFile, true);
51: } catch (PartInitException e) {
52: DroolsEclipsePlugin.log(e);
53: return false;
54: }
55: return true;
56: }
57:
58: protected InputStream getInitialContents() {
59: // return DroolsEclipsePlugin.getDefault().getBundle().getResource(
60: // "org/drools/eclipse/rulebuilder/wizards/template.brl").openStream();
61: String contents = "";
62: return new ByteArrayInputStream(contents.getBytes());
63: }
64:
65: }
|