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


001:        package org.drools.eclipse.dsl.editor.completion;
002:
003:        import java.io.BufferedReader;
004:        import java.io.IOException;
005:        import java.io.StringReader;
006:        import java.util.Iterator;
007:        import java.util.List;
008:
009:        import org.drools.eclipse.DroolsPluginImages;
010:        import org.drools.eclipse.dsl.editor.DSLAdapter;
011:        import org.drools.eclipse.dsl.editor.DSLRuleEditor;
012:        import org.drools.eclipse.editors.AbstractRuleEditor;
013:        import org.drools.eclipse.editors.completion.RuleCompletionProcessor;
014:        import org.drools.eclipse.editors.completion.RuleCompletionProposal;
015:        import org.drools.lang.Location;
016:        import org.eclipse.swt.graphics.Image;
017:
018:        /**
019:         * For handling DSL rules.
020:         * 
021:         * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
022:         */
023:        public class DSLRuleCompletionProcessor extends RuleCompletionProcessor {
024:
025:            private static final Image DSL_ICON = DroolsPluginImages
026:                    .getImage(DroolsPluginImages.DSL_EXPRESSION);
027:
028:            public DSLRuleCompletionProcessor(AbstractRuleEditor editor) {
029:                super (editor);
030:            }
031:
032:            protected DSLRuleEditor getDSLRuleEditor() {
033:                return (DSLRuleEditor) getEditor();
034:            }
035:
036:            protected void addRHSCompletionProposals(List list,
037:                    int documentOffset, String prefix, String backText,
038:                    String conditions, String consequence) {
039:                // super.addRHSCompletionProposals(list, documentOffset, prefix, backText, conditions, consequence);
040:                DSLAdapter adapter = getDSLRuleEditor().getDSLAdapter();
041:                if (adapter != null) {
042:                    List dslConsequences = adapter.getDSLTree()
043:                            .getConsequenceChildrenList(prefix, true);
044:                    addDSLProposals(list, documentOffset, prefix,
045:                            dslConsequences);
046:                }
047:            }
048:
049:            protected void addLHSCompletionProposals(List list,
050:                    int documentOffset, Location location, String prefix,
051:                    String backText) {
052:                // super.addLHSCompletionProposals(list, documentOffset, location, prefix, backText);
053:                DSLAdapter adapter = getDSLRuleEditor().getDSLAdapter();
054:                if (adapter != null) {
055:                    String lastobj = this .getLastNonDashLine(backText);
056:                    String last = this .getLastLine(backText);
057:                    // we have to check if the last line is when. if it is we set
058:                    // the last line to zero length string
059:                    if (last.equals("when")) {
060:                        last = "";
061:                        lastobj = "*";
062:                    }
063:                    // pass the last string in the backText to getProposals
064:                    List dslConditions = this .getProposals(adapter, lastobj,
065:                            last);
066:                    // if we couldn't find any matches, we add the list from
067:                    // the DSLAdapter so that there's something
068:                    if (dslConditions.size() == 0) {
069:                        dslConditions.addAll(adapter.listConditionItems());
070:                    }
071:                    addDSLProposals(list, documentOffset, prefix, dslConditions);
072:                }
073:            }
074:
075:            private void addDSLProposals(final List list, int documentOffset,
076:                    final String prefix, List dslItems) {
077:                Iterator iterator = dslItems.iterator();
078:                while (iterator.hasNext()) {
079:                    String consequence = (String) iterator.next();
080:                    RuleCompletionProposal p = new RuleCompletionProposal(
081:                            documentOffset - prefix.length(), prefix.length(),
082:                            consequence);
083:                    p.setImage(DSL_ICON);
084:                    list.add(p);
085:                }
086:            }
087:
088:            /**
089:             * because of how the backText works, we need to get the last line, so that
090:             * we can pass it to the DSLUtility
091:             * 
092:             * @param backText
093:             * @return
094:             */
095:            public String getLastLine(String backText) {
096:                BufferedReader breader = new BufferedReader(new StringReader(
097:                        backText));
098:                String last = "";
099:                String line = null;
100:                try {
101:                    while ((line = breader.readLine()) != null) {
102:                        // only if the line has text do we set last to it
103:                        if (line.length() > 0) {
104:                            last = line;
105:                        }
106:                    }
107:                } catch (IOException e) {
108:                    // TODO need to log this.
109:                    // I'm leaving this for mic_hat, so he has something to do
110:                }
111:                // now that all the conditions for a single object are on the same line
112:                // we need to check for the left parenthesis
113:                if (last.indexOf("(") > -1) {
114:                    last = last.substring(last.lastIndexOf("(") + 1);
115:                }
116:                // if the string has a comma "," we get the substring starting from
117:                // the index after the last comma
118:                if (last.indexOf(",") > -1) {
119:                    last = last.substring(last.lastIndexOf(",") + 1);
120:                }
121:                // if the line ends with right parenthesis, we change it to zero length
122:                // string
123:                if (last.endsWith(")")) {
124:                    last = "";
125:                }
126:                return last;
127:            }
128:
129:            /**
130:             * Returns the last line that doesn't start with a dash
131:             * 
132:             * @param backText
133:             * @return
134:             */
135:            public String getLastNonDashLine(String backText) {
136:                BufferedReader breader = new BufferedReader(new StringReader(
137:                        backText));
138:                String last = "";
139:                String line = null;
140:                try {
141:                    while ((line = breader.readLine()) != null) {
142:                        // there may be blank lines, so we trim first
143:                        line = line.trim();
144:                        // only if the line has text do we set last to it
145:                        if (line.length() > 0 && !line.startsWith("-")) {
146:                            last = line;
147:                        }
148:                    }
149:                } catch (IOException e) {
150:                    // TODO need to log this.
151:                    // I'm leaving this for mic_hat, so he has something to do
152:                }
153:                if (last.indexOf("(") > -1 && !last.endsWith(")")) {
154:                    last = last.substring(0, last.indexOf("("));
155:                } else if (last.indexOf("(") > -1 && last.endsWith(")")) {
156:                    last = "";
157:                }
158:                return last;
159:            }
160:
161:            /**
162:             * The DSLTree is configurable. It can either return just the child of the
163:             * last token found, or it can traverse the tree and generate all the
164:             * combinations beneath the last matching node. TODO I don't know how to add
165:             * configuration to the editor, so it needs to be hooked up to the
166:             * configuration for the editor later.
167:             * 
168:             * @param last
169:             * @return
170:             */
171:            protected List getProposals(DSLAdapter adapter, String obj,
172:                    String last) {
173:                if (last.length() == 0) {
174:                    last = " ";
175:                }
176:                return adapter.getDSLTree().getChildrenList(obj, last, true);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.