01: package org.drools.eclipse.flow.ruleflow;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.io.InputStream;
20:
21: import org.eclipse.jface.viewers.IStructuredSelection;
22: import org.eclipse.swt.widgets.Composite;
23: import org.eclipse.ui.IWorkbench;
24: import org.eclipse.ui.IWorkbenchWindow;
25: import org.eclipse.ui.PartInitException;
26: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
27: import org.eclipse.ui.ide.IDE;
28:
29: /**
30: * Page for creating a new RuleFlow file.
31: *
32: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
33: */
34: public class NewRuleFlowFilePage extends WizardNewFileCreationPage {
35:
36: private IWorkbench workbench;
37:
38: public NewRuleFlowFilePage(IWorkbench workbench,
39: IStructuredSelection selection) {
40: super ("createRuleFlowPage", selection);
41: setTitle("Create RuleFlow File");
42: setDescription("Create a new RuleFlow file");
43: this .workbench = workbench;
44: }
45:
46: public void createControl(Composite parent) {
47: super .createControl(parent);
48: setPageComplete(true);
49: }
50:
51: public boolean finish() {
52: String fileName = getFileName();
53: if (!fileName.endsWith(".rf")) {
54: setFileName(fileName + ".rf");
55: }
56: org.eclipse.core.resources.IFile newFile = createNewFile();
57: if (newFile == null)
58: return false;
59: try {
60: IWorkbenchWindow dwindow = workbench
61: .getActiveWorkbenchWindow();
62: org.eclipse.ui.IWorkbenchPage page = dwindow
63: .getActivePage();
64: if (page != null)
65: IDE.openEditor(page, newFile, true);
66: } catch (PartInitException e) {
67: e.printStackTrace();
68: return false;
69: }
70: return true;
71: }
72:
73: protected InputStream getInitialContents() {
74: String s = "org/drools/eclipse/flow/ruleflow/SampleRuleFlow.rf.template";
75: return getClass().getClassLoader().getResourceAsStream(s);
76: }
77: }
|