01: /*
02: * Created on 11-jan-2005
03: *
04: */
05: package org.drools.eclipse.wizard.dsl;
06:
07: import java.io.IOException;
08: import java.io.InputStream;
09:
10: import org.drools.eclipse.DroolsEclipsePlugin;
11: import org.eclipse.jface.viewers.IStructuredSelection;
12: import org.eclipse.swt.widgets.Composite;
13: import org.eclipse.ui.IWorkbench;
14: import org.eclipse.ui.IWorkbenchWindow;
15: import org.eclipse.ui.PartInitException;
16: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
17: import org.eclipse.ui.ide.IDE;
18:
19: /**
20: * A page to create a new Domain Specific Language configuration.
21: * There may be additional options here in future.
22: *
23: * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
24: * @author Michael Neale
25: */
26: public class NewDSLFilePage extends WizardNewFileCreationPage {
27:
28: private IWorkbench workbench;
29:
30: public NewDSLFilePage(IWorkbench workbench,
31: IStructuredSelection selection) {
32: super ("createDSLFilePage", selection);
33: setTitle("New DSL");
34: setDescription("Create a new Domain Specific Language configuration");
35: this .workbench = workbench;
36: }
37:
38: public void createControl(Composite parent) {
39: super .createControl(parent);
40: setPageComplete(true);
41: }
42:
43: public boolean finish() {
44: String fileName = getFileName();
45: if (!fileName.endsWith(".dsl")) {
46: setFileName(fileName + ".dsl");
47: }
48: org.eclipse.core.resources.IFile newFile = createNewFile();
49: if (newFile == null)
50: return false;
51: try {
52: IWorkbenchWindow dwindow = workbench
53: .getActiveWorkbenchWindow();
54: org.eclipse.ui.IWorkbenchPage page = dwindow
55: .getActivePage();
56: if (page != null)
57: IDE.openEditor(page, newFile, true);
58: } catch (PartInitException e) {
59: DroolsEclipsePlugin.log(e);
60: return false;
61: }
62: return true;
63: }
64:
65: protected InputStream getInitialContents() {
66: try {
67: return DroolsEclipsePlugin
68: .getDefault()
69: .getBundle()
70: .getResource(
71: "org/drools/eclipse/wizard/dsl/template.dsl")
72: .openStream();
73: } catch (IOException e) {
74: return null;
75: } catch (NullPointerException e) {
76: return null;
77: }
78: }
79:
80: }
|