Source Code Cross Referenced for MappingEditor.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » eclipse » dsl » editor » 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.dsl.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.eclipse.dsl.editor;
002:
003:        import org.drools.lang.dsl.DSLMappingEntry;
004:        import org.drools.lang.dsl.DSLMappingEntry.Section;
005:        import org.eclipse.jface.dialogs.TitleAreaDialog;
006:        import org.eclipse.swt.SWT;
007:        import org.eclipse.swt.layout.GridData;
008:        import org.eclipse.swt.layout.GridLayout;
009:        import org.eclipse.swt.widgets.Combo;
010:        import org.eclipse.swt.widgets.Composite;
011:        import org.eclipse.swt.widgets.Control;
012:        import org.eclipse.swt.widgets.Label;
013:        import org.eclipse.swt.widgets.Shell;
014:        import org.eclipse.swt.widgets.Text;
015:
016:        /**
017:         * This provides an editor for mapping language mappings.
018:         * This is preferable to in place editing, as it fits the usage pattern of read lots,
019:         * edit little.
020:         * 
021:         * This is a simple popup modal dialog.
022:         * 
023:         * @author Michael Neale
024:         */
025:        public class MappingEditor extends TitleAreaDialog {
026:
027:            private static final int SCOPE_KEYWORD = 0;
028:            private static final int SCOPE_WHEN = 1;
029:            private static final int SCOPE_THEN = 2;
030:            private static final int SCOPE_ALL = 3;
031:
032:            private static final String SCOPE_STR_KEYWORD = "keyword";
033:            private static final String SCOPE_STR_WHEN = "condition";
034:            private static final String SCOPE_STR_THEN = "consequence";
035:            private static final String SCOPE_STR_ALL = "*";
036:
037:            private Text exprText;
038:            private Text mappingText;
039:            private Text objText;
040:            private Combo scopeCombo;
041:            private boolean cancelled;
042:
043:            private DSLMappingEntry model;
044:
045:            protected MappingEditor(Shell parent) {
046:                super (parent);
047:            }
048:
049:            /**
050:             * Pass in a NLMapping item for display/edits.
051:             * Changes will be applied to this object only if the user clicks OK.
052:             */
053:            public void setNLMappingItem(DSLMappingEntry item) {
054:                model = item;
055:                setSection(model.getSection());
056:                exprText.setText(model.getMappingKey() == null ? "" : model
057:                        .getMappingKey());
058:                mappingText.setText(model.getMappingValue() == null ? ""
059:                        : model.getMappingValue());
060:                objText.setText(model.getMetaData().getMetaData() == null ? ""
061:                        : model.getMetaData().getMetaData());
062:            }
063:
064:            private void setSection(Section section) {
065:                if (section == DSLMappingEntry.CONDITION) {
066:                    scopeCombo.select(SCOPE_WHEN);
067:                } else if (section == DSLMappingEntry.CONSEQUENCE) {
068:                    scopeCombo.select(SCOPE_THEN);
069:                } else if (section == DSLMappingEntry.ANY) {
070:                    scopeCombo.select(SCOPE_ALL);
071:                } else if (section == DSLMappingEntry.KEYWORD) {
072:                    scopeCombo.select(SCOPE_KEYWORD);
073:                } else {
074:                    throw new IllegalArgumentException("Unknown scope type: "
075:                            + section);
076:                }
077:            }
078:
079:            private Section getSection(String sectionStr) {
080:                DSLMappingEntry.Section section = DSLMappingEntry.ANY;
081:                if (SCOPE_STR_KEYWORD.equals(sectionStr)) {
082:                    section = DSLMappingEntry.KEYWORD;
083:                } else if (SCOPE_STR_WHEN.equals(sectionStr)) {
084:                    section = DSLMappingEntry.CONDITION;
085:                } else if (SCOPE_STR_THEN.equals(sectionStr)) {
086:                    section = DSLMappingEntry.CONSEQUENCE;
087:                }
088:                return section;
089:            }
090:
091:            protected void cancelPressed() {
092:                this .cancelled = true;
093:                super .cancelPressed();
094:            }
095:
096:            protected void okPressed() {
097:                this .cancelled = false;
098:                this .model.setMappingKey(this .exprText.getText());
099:                this .model.setMappingValue(this .mappingText.getText());
100:                this .model.setSection(this 
101:                        .getSection(this .scopeCombo.getText()));
102:                this .model
103:                        .setMetaData(new DSLMappingEntry.DefaultDSLEntryMetaData(
104:                                this .objText.getText()));
105:                super .okPressed();
106:            }
107:
108:            /** This will tell if the user cancelled the edit */
109:            public boolean isCancelled() {
110:                return cancelled;
111:            }
112:
113:            protected Control createDialogArea(Composite parent) {
114:
115:                //set the overall layout
116:                GridLayout gridLayout = new GridLayout();
117:                gridLayout.marginHeight = 10;
118:                gridLayout.verticalSpacing = 10;
119:                gridLayout.marginWidth = 10;
120:                gridLayout.numColumns = 2;
121:                parent.setLayout(gridLayout);
122:
123:                //setup fields
124:                createExpressionField(parent);
125:                createMappingField(parent);
126:                createObjectField(parent);
127:                createScopeField(parent);
128:
129:                // create the top level composite wrapper
130:                Composite composite = new Composite(parent, SWT.NONE);
131:                GridLayout layout = new GridLayout();
132:                layout.marginHeight = 10;
133:                layout.marginWidth = 10;
134:                layout.verticalSpacing = 10;
135:                composite.setLayout(layout);
136:                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
137:                composite.setFont(parent.getFont());
138:
139:                return composite;
140:            }
141:
142:            private void createMappingField(Composite parent) {
143:                Label mappingLbl = new Label(parent, SWT.NONE);
144:                mappingLbl.setText("Rule mapping:");
145:                mappingLbl.setFont(parent.getFont());
146:                mappingLbl.setLayoutData(new GridData(
147:                        GridData.HORIZONTAL_ALIGN_END));
148:
149:                mappingText = new Text(parent, SWT.BORDER);
150:                GridData data = new GridData();
151:                data.widthHint = 450;
152:                data.horizontalAlignment = GridData.FILL;
153:                data.grabExcessHorizontalSpace = true;
154:                mappingText.setLayoutData(data);
155:
156:                mappingText
157:                        .setToolTipText("Enter the rule language mapping that the \nlanguage item will be translated to."
158:                                + " Use the named variables (holes) \nthat you specify in the language expression above.");
159:
160:            }
161:
162:            private void createExpressionField(Composite parent) {
163:                Label exprLbl = new Label(parent, SWT.NONE);
164:                exprLbl.setText("Language expression:");
165:                exprLbl.setFont(parent.getFont());
166:                exprLbl.setLayoutData(new GridData(
167:                        GridData.HORIZONTAL_ALIGN_END));
168:
169:                exprText = new Text(parent, SWT.BORDER);
170:                GridData data = new GridData();
171:                data.widthHint = 450;
172:                data.horizontalAlignment = GridData.FILL;
173:                data.grabExcessHorizontalSpace = true;
174:                exprText.setLayoutData(data);
175:                exprText
176:                        .setToolTipText("Enter the language expression that you want to use in a rule.\n"
177:                                + "Use curly brackets to mark 'holes' where the values will be extracted\n"
178:                                + "from in the rule source. "
179:                                + "Such as: Person has a name of {name} \n"
180:                                + "This will then parse the rule source to extract the data out of \n"
181:                                + "the place where {name} would appear.");
182:            }
183:
184:            private void createObjectField(Composite parent) {
185:                Label objectLbl = new Label(parent, SWT.NONE);
186:                objectLbl.setText("Object:");
187:                objectLbl.setFont(parent.getFont());
188:                objectLbl.setLayoutData(new GridData(
189:                        GridData.HORIZONTAL_ALIGN_END));
190:
191:                objText = new Text(parent, SWT.BORDER);
192:                GridData data = new GridData();
193:                data.widthHint = 450;
194:                data.horizontalAlignment = GridData.FILL;
195:                data.grabExcessHorizontalSpace = true;
196:                objText.setLayoutData(data);
197:
198:                objText.setToolTipText("Enter the name of the object.");
199:
200:            }
201:
202:            private void createScopeField(Composite parent) {
203:
204:                //type
205:                Label scopeLbl = new Label(parent, SWT.NONE);
206:                scopeLbl.setText("Scope:");
207:                scopeLbl.setFont(parent.getFont());
208:                scopeLbl.setLayoutData(new GridData(
209:                        GridData.HORIZONTAL_ALIGN_END));
210:
211:                scopeCombo = new Combo(parent, SWT.READ_ONLY);
212:
213:                scopeCombo.add(SCOPE_STR_KEYWORD, SCOPE_KEYWORD);
214:                scopeCombo.add(SCOPE_STR_WHEN, SCOPE_WHEN);
215:                scopeCombo.add(SCOPE_STR_THEN, SCOPE_THEN);
216:                scopeCombo.add(SCOPE_STR_ALL, SCOPE_ALL);
217:
218:                scopeCombo.select(SCOPE_ALL); //the default
219:
220:                scopeCombo.setLayoutData(new GridData(
221:                        GridData.HORIZONTAL_ALIGN_BEGINNING));
222:                scopeCombo.setFont(parent.getFont());
223:                scopeCombo
224:                        .setToolTipText("This specifies what part of the rule the expression applies. Indicating '*' means global.");
225:
226:            }
227:
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.