Source Code Cross Referenced for PositionBasedCompletionProposal.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » text » template » contentassist » 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 » jdt » org.eclipse.jdt.internal.ui.text.template.contentassist 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 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.jdt.internal.ui.text.template.contentassist;
011:
012:        import org.eclipse.core.runtime.Assert;
013:
014:        import org.eclipse.swt.graphics.Image;
015:        import org.eclipse.swt.graphics.Point;
016:
017:        import org.eclipse.jface.text.BadLocationException;
018:        import org.eclipse.jface.text.DocumentEvent;
019:        import org.eclipse.jface.text.IDocument;
020:        import org.eclipse.jface.text.ITextViewer;
021:        import org.eclipse.jface.text.Position;
022:        import org.eclipse.jface.text.contentassist.ICompletionProposal;
023:        import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
024:        import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
025:        import org.eclipse.jface.text.contentassist.IContextInformation;
026:
027:        /**
028:         * An enhanced implementation of the <code>ICompletionProposal</code> interface implementing all the extension interfaces.
029:         * It uses a position to track its replacement offset and length. The position must be set up externally.
030:         */
031:        public class PositionBasedCompletionProposal implements 
032:                ICompletionProposal, ICompletionProposalExtension,
033:                ICompletionProposalExtension2 {
034:
035:            /** The string to be displayed in the completion proposal popup */
036:            private String fDisplayString;
037:            /** The replacement string */
038:            private String fReplacementString;
039:            /** The replacement position. */
040:            private Position fReplacementPosition;
041:            /** The cursor position after this proposal has been applied */
042:            private int fCursorPosition;
043:            /** The image to be displayed in the completion proposal popup */
044:            private Image fImage;
045:            /** The context information of this proposal */
046:            private IContextInformation fContextInformation;
047:            /** The additional info of this proposal */
048:            private String fAdditionalProposalInfo;
049:
050:            /**
051:             * Creates a new completion proposal based on the provided information.  The replacement string is
052:             * considered being the display string too. All remaining fields are set to <code>null</code>.
053:             *
054:             * @param replacementString the actual string to be inserted into the document
055:             * @param replacementPosition the position of the text to be replaced
056:             * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
057:             */
058:            public PositionBasedCompletionProposal(String replacementString,
059:                    Position replacementPosition, int cursorPosition) {
060:                this (replacementString, replacementPosition, cursorPosition,
061:                        null, null, null, null);
062:            }
063:
064:            /**
065:             * Creates a new completion proposal. All fields are initialized based on the provided information.
066:             *
067:             * @param replacementString the actual string to be inserted into the document
068:             * @param replacementPosition the position of the text to be replaced
069:             * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
070:             * @param image the image to display for this proposal
071:             * @param displayString the string to be displayed for the proposal
072:             * @param contextInformation the context information associated with this proposal
073:             * @param additionalProposalInfo the additional information associated with this proposal
074:             */
075:            public PositionBasedCompletionProposal(String replacementString,
076:                    Position replacementPosition, int cursorPosition,
077:                    Image image, String displayString,
078:                    IContextInformation contextInformation,
079:                    String additionalProposalInfo) {
080:                Assert.isNotNull(replacementString);
081:                Assert.isTrue(replacementPosition != null);
082:
083:                fReplacementString = replacementString;
084:                fReplacementPosition = replacementPosition;
085:                fCursorPosition = cursorPosition;
086:                fImage = image;
087:                fDisplayString = displayString;
088:                fContextInformation = contextInformation;
089:                fAdditionalProposalInfo = additionalProposalInfo;
090:            }
091:
092:            /*
093:             * @see ICompletionProposal#apply(IDocument)
094:             */
095:            public void apply(IDocument document) {
096:                try {
097:                    document.replace(fReplacementPosition.getOffset(),
098:                            fReplacementPosition.getLength(),
099:                            fReplacementString);
100:                } catch (BadLocationException x) {
101:                    // ignore
102:                }
103:            }
104:
105:            /*
106:             * @see ICompletionProposal#getSelection(IDocument)
107:             */
108:            public Point getSelection(IDocument document) {
109:                return new Point(fReplacementPosition.getOffset()
110:                        + fCursorPosition, 0);
111:            }
112:
113:            /*
114:             * @see ICompletionProposal#getContextInformation()
115:             */
116:            public IContextInformation getContextInformation() {
117:                return fContextInformation;
118:            }
119:
120:            /*
121:             * @see ICompletionProposal#getImage()
122:             */
123:            public Image getImage() {
124:                return fImage;
125:            }
126:
127:            /*
128:             * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
129:             */
130:            public String getDisplayString() {
131:                if (fDisplayString != null)
132:                    return fDisplayString;
133:                return fReplacementString;
134:            }
135:
136:            /*
137:             * @see ICompletionProposal#getAdditionalProposalInfo()
138:             */
139:            public String getAdditionalProposalInfo() {
140:                return fAdditionalProposalInfo;
141:            }
142:
143:            /*
144:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
145:             */
146:            public void apply(ITextViewer viewer, char trigger, int stateMask,
147:                    int offset) {
148:                apply(viewer.getDocument());
149:            }
150:
151:            /*
152:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
153:             */
154:            public void selected(ITextViewer viewer, boolean smartToggle) {
155:            }
156:
157:            /*
158:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
159:             */
160:            public void unselected(ITextViewer viewer) {
161:            }
162:
163:            /*
164:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
165:             */
166:            public boolean validate(IDocument document, int offset,
167:                    DocumentEvent event) {
168:                try {
169:                    String content = document.get(fReplacementPosition
170:                            .getOffset(), offset
171:                            - fReplacementPosition.getOffset());
172:                    if (fReplacementString.startsWith(content))
173:                        return true;
174:                } catch (BadLocationException e) {
175:                    // ignore concurrently modified document
176:                }
177:                return false;
178:            }
179:
180:            /*
181:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#apply(org.eclipse.jface.text.IDocument, char, int)
182:             */
183:            public void apply(IDocument document, char trigger, int offset) {
184:                // not called any more
185:            }
186:
187:            /*
188:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#isValidFor(org.eclipse.jface.text.IDocument, int)
189:             */
190:            public boolean isValidFor(IDocument document, int offset) {
191:                // not called any more
192:                return false;
193:            }
194:
195:            /*
196:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getTriggerCharacters()
197:             */
198:            public char[] getTriggerCharacters() {
199:                return null;
200:            }
201:
202:            /*
203:             * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getContextInformationPosition()
204:             */
205:            public int getContextInformationPosition() {
206:                return fReplacementPosition.getOffset();
207:            }
208:
209:        }
w__w_w.___j_a_v__a___2___s__.c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.