Source Code Cross Referenced for TemplateVariableProcessor.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » texteditor » templates » 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 » IDE Eclipse » ui workbench » org.eclipse.ui.texteditor.templates 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.texteditor.templates;
011:
012:        import java.util.ArrayList;
013:        import java.util.Collections;
014:        import java.util.Comparator;
015:        import java.util.Iterator;
016:        import java.util.List;
017:
018:        import org.eclipse.jface.text.ITextViewer;
019:        import org.eclipse.jface.text.contentassist.ICompletionProposal;
020:        import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
021:        import org.eclipse.jface.text.contentassist.IContextInformation;
022:        import org.eclipse.jface.text.contentassist.IContextInformationValidator;
023:        import org.eclipse.jface.text.templates.TemplateContextType;
024:        import org.eclipse.jface.text.templates.TemplateVariableResolver;
025:
026:        /**
027:         * A content assist processor for template variables.
028:         * <p>
029:         * This class should not be used by clients and may become package visible in
030:         * the future.
031:         * </p>
032:         *
033:         * @since 3.0
034:         */
035:        final class TemplateVariableProcessor implements 
036:                IContentAssistProcessor {
037:
038:            private static Comparator fgTemplateVariableProposalComparator = new Comparator() {
039:                public int compare(Object arg0, Object arg1) {
040:                    TemplateVariableProposal proposal0 = (TemplateVariableProposal) arg0;
041:                    TemplateVariableProposal proposal1 = (TemplateVariableProposal) arg1;
042:
043:                    return proposal0.getDisplayString().compareTo(
044:                            proposal1.getDisplayString());
045:                }
046:
047:                /*
048:                 * @see java.lang.Object#equals(java.lang.Object)
049:                 */
050:                public boolean equals(Object arg0) {
051:                    return false;
052:                }
053:
054:                /*
055:                 * Returns Object#hashCode.
056:                 * @see java.lang.Object#hashCode()
057:                 */
058:                public int hashCode() {
059:                    return super .hashCode();
060:                }
061:            };
062:
063:            /** the context type */
064:            private TemplateContextType fContextType;
065:
066:            /**
067:             * Sets the context type.
068:             *
069:             * @param contextType the context type for this processor
070:             */
071:            public void setContextType(TemplateContextType contextType) {
072:                fContextType = contextType;
073:            }
074:
075:            /**
076:             * Returns the context type.
077:             *
078:             * @return the context type
079:             */
080:            public TemplateContextType getContextType() {
081:                return fContextType;
082:            }
083:
084:            /*
085:             * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
086:             */
087:            public ICompletionProposal[] computeCompletionProposals(
088:                    ITextViewer viewer, int documentOffset) {
089:
090:                if (fContextType == null)
091:                    return null;
092:
093:                List proposals = new ArrayList();
094:
095:                String text = viewer.getDocument().get();
096:                int start = getStart(text, documentOffset);
097:                int end = documentOffset;
098:
099:                String string = text.substring(start, end);
100:                String prefix = (string.length() >= 2) ? string.substring(2)
101:                        : null;
102:
103:                int offset = start;
104:                int length = end - start;
105:
106:                for (Iterator iterator = fContextType.resolvers(); iterator
107:                        .hasNext();) {
108:                    TemplateVariableResolver variable = (TemplateVariableResolver) iterator
109:                            .next();
110:
111:                    if (prefix == null || variable.getType().startsWith(prefix))
112:                        proposals.add(new TemplateVariableProposal(variable,
113:                                offset, length, viewer));
114:                }
115:
116:                Collections.sort(proposals,
117:                        fgTemplateVariableProposalComparator);
118:                return (ICompletionProposal[]) proposals
119:                        .toArray(new ICompletionProposal[proposals.size()]);
120:            }
121:
122:            /* Guesses the start position of the completion */
123:            private int getStart(String string, int end) {
124:                int start = end;
125:
126:                if (start >= 1 && string.charAt(start - 1) == '$')
127:                    return start - 1;
128:
129:                while ((start != 0)
130:                        && Character.isUnicodeIdentifierPart(string
131:                                .charAt(start - 1)))
132:                    start--;
133:
134:                if (start >= 2 && string.charAt(start - 1) == '{'
135:                        && string.charAt(start - 2) == '$')
136:                    return start - 2;
137:
138:                return end;
139:            }
140:
141:            /*
142:             * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
143:             */
144:            public IContextInformation[] computeContextInformation(
145:                    ITextViewer viewer, int documentOffset) {
146:                return null;
147:            }
148:
149:            /*
150:             * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
151:             */
152:            public char[] getCompletionProposalAutoActivationCharacters() {
153:                return new char[] { '$' };
154:            }
155:
156:            /*
157:             * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
158:             */
159:            public char[] getContextInformationAutoActivationCharacters() {
160:                return null;
161:            }
162:
163:            /*
164:             * @see IContentAssistProcessor#getErrorMessage()
165:             */
166:            public String getErrorMessage() {
167:                return null;
168:            }
169:
170:            /*
171:             * @see IContentAssistProcessor#getContextInformationValidator()
172:             */
173:            public IContextInformationValidator getContextInformationValidator() {
174:                return null;
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.