Source Code Cross Referenced for NewRulePackagePage.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » eclipse » wizard » rule » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » drolls Rule Engine » org.drools.eclipse.wizard.rule 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 11-jan-2005
003:         *
004:         */
005:        package org.drools.eclipse.wizard.rule;
006:
007:        import java.io.IOException;
008:        import java.io.InputStream;
009:
010:        import org.drools.eclipse.DroolsEclipsePlugin;
011:        import org.eclipse.jface.viewers.IStructuredSelection;
012:        import org.eclipse.swt.SWT;
013:        import org.eclipse.swt.layout.GridData;
014:        import org.eclipse.swt.layout.GridLayout;
015:        import org.eclipse.swt.widgets.Button;
016:        import org.eclipse.swt.widgets.Combo;
017:        import org.eclipse.swt.widgets.Composite;
018:        import org.eclipse.swt.widgets.Label;
019:        import org.eclipse.swt.widgets.Text;
020:        import org.eclipse.ui.IWorkbench;
021:        import org.eclipse.ui.IWorkbenchWindow;
022:        import org.eclipse.ui.PartInitException;
023:        import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
024:        import org.eclipse.ui.ide.IDE;
025:
026:        /**
027:         * A page to create a new .drl package/package file.
028:         * There is only one page for this wizard, its very simple.
029:         * 
030:         * Enhancements may be made to allow configuration of semantic languages, DSLs (locate a DSL) and other 
031:         * package level options.
032:         * 
033:         * @author Michael Neale
034:         * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
035:         */
036:        public class NewRulePackagePage extends WizardNewFileCreationPage {
037:
038:            private static final int TYPE_RULE = 1;
039:            private static final int TYPE_PACKAGE = 0;
040:            private IWorkbench workbench;
041:            private Combo ruleFileType;
042:            private Button expander;
043:            private Button function;
044:            private Text packageName;
045:
046:            public NewRulePackagePage(IWorkbench workbench,
047:                    IStructuredSelection selection) {
048:                super ("createDRLFilePage", selection);
049:                setTitle("New Rules File");
050:                setDescription("Create a new rules file (drl)");
051:                this .workbench = workbench;
052:            }
053:
054:            public void createControl(Composite parent) {
055:                super .createControl(parent);
056:                setPageComplete(true);
057:                super 
058:                        .setMessage("Hint: Press CTRL+SPACE when editing rules to get content sensitive assistance/popups.");
059:            }
060:
061:            protected void createAdvancedControls(Composite parent) {
062:                Composite container = new Composite(parent, SWT.NONE);
063:                final GridLayout layout = new GridLayout();
064:                layout.numColumns = 2;
065:                container.setLayout(layout);
066:                setControl(container);
067:
068:                //setup the controls.
069:                createType(container);
070:                createDSL(container);
071:                createFunctions(container);
072:                createPackageName(container);
073:
074:                super .createAdvancedControls(parent);
075:            }
076:
077:            private void createPackageName(Composite container) {
078:                //package name
079:                Label pack = new Label(container, SWT.NONE);
080:                pack.setText("Rule package name:");
081:                pack.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
082:                pack.setFont(this .getFont());
083:                packageName = new Text(container, SWT.BORDER);
084:                packageName
085:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
086:                packageName.setToolTipText("Rules require a namespace.");
087:                packageName.setFont(this .getFont());
088:            }
089:
090:            private void createFunctions(Composite container) {
091:                //function
092:                Label func = new Label(container, SWT.NONE);
093:                func.setText("Use functions:");
094:                func.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
095:                func.setFont(this .getFont());
096:                function = new Button(container, SWT.CHECK);
097:                function.setSelection(false);
098:                function.setLayoutData(new GridData(
099:                        GridData.HORIZONTAL_ALIGN_BEGINNING));
100:                function
101:                        .setToolTipText("Functions are methods you embed in your rule source.");
102:            }
103:
104:            private void createDSL(Composite container) {
105:                //expander
106:                Label exp = new Label(container, SWT.NONE);
107:                exp.setText("Use a DSL:");
108:                exp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
109:                exp.setFont(this .getFont());
110:                expander = new Button(container, SWT.CHECK);
111:                expander.setSelection(false);
112:                expander.setLayoutData(new GridData(
113:                        GridData.HORIZONTAL_ALIGN_BEGINNING));
114:                expander
115:                        .setToolTipText("Domain Specific Language: allows you to create your own domain specific languages\n for use in rules.");
116:            }
117:
118:            private void createType(Composite container) {
119:                //type
120:                Label type = new Label(container, SWT.NONE);
121:                type.setText("Type of rule resource:");
122:                type.setFont(this .getFont());
123:                type.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
124:                ruleFileType = new Combo(container, SWT.READ_ONLY);
125:                ruleFileType.add("New DRL (rule package)", TYPE_PACKAGE);
126:                ruleFileType.add("New Rule (individual rule)", TYPE_RULE);
127:                ruleFileType.select(0);
128:                ruleFileType.setLayoutData(new GridData(
129:                        GridData.FILL_HORIZONTAL));
130:                ruleFileType.setFont(this .getFont());
131:
132:            }
133:
134:            public boolean finish() {
135:                if (!validate()) {
136:                    return false;
137:                }
138:                String fileName = getFileName();
139:                String extension = expander.getSelection() ? ".dslr" : ".drl";
140:                if (!fileName.endsWith(extension)) {
141:                    setFileName(fileName + extension);
142:                }
143:                org.eclipse.core.resources.IFile newFile = createNewFile();
144:                if (newFile == null)
145:                    return false;
146:                try {
147:                    IWorkbenchWindow dwindow = workbench
148:                            .getActiveWorkbenchWindow();
149:                    org.eclipse.ui.IWorkbenchPage page = dwindow
150:                            .getActivePage();
151:                    if (page != null)
152:                        IDE.openEditor(page, newFile, true);
153:                } catch (PartInitException e) {
154:                    DroolsEclipsePlugin.log(e);
155:                    return false;
156:                }
157:                return true;
158:            }
159:
160:            private boolean validate() {
161:                if (this .packageName.getText() == null
162:                        || packageName.getText().equals("")) {
163:                    setErrorMessage("You must provide a rule package name");
164:                    return false;
165:                } else {
166:                    return true;
167:                }
168:            }
169:
170:            protected InputStream getInitialContents() {
171:
172:                try {
173:
174:                    DRLGenerator gen = new DRLGenerator();
175:                    if (this .ruleFileType.getSelectionIndex() == TYPE_RULE) {
176:                        InputStream template = getTemplate("org/drools/eclipse/wizard/rule/new_rule.drl.template");
177:                        return gen.generateRule(this .packageName.getText(),
178:                                template);
179:                    } else {
180:                        InputStream template = getTemplate("org/drools/eclipse/wizard/rule/new_package.drl.template");
181:                        return gen.generatePackage(this .packageName.getText(),
182:                                function.getSelection(), expander
183:                                        .getSelection(), template);
184:                    }
185:                } catch (IOException e) {
186:                    return null;
187:                } catch (NullPointerException e) {
188:                    return null;
189:                }
190:            }
191:
192:            private InputStream getTemplate(String templatePath)
193:                    throws IOException {
194:                return DroolsEclipsePlugin.getDefault().getBundle()
195:                        .getResource(templatePath).openStream();
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.