Source Code Cross Referenced for CodeTemplateSourceViewerConfiguration.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » preferences » 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.preferences 
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.preferences;
011:
012:        import java.util.Iterator;
013:
014:        import org.eclipse.swt.SWT;
015:        import org.eclipse.swt.graphics.Color;
016:        import org.eclipse.swt.graphics.RGB;
017:        import org.eclipse.swt.widgets.Shell;
018:
019:        import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
020:        import org.eclipse.jface.preference.IPreferenceStore;
021:        import org.eclipse.jface.preference.PreferenceConverter;
022:
023:        import org.eclipse.jface.text.BadLocationException;
024:        import org.eclipse.jface.text.DefaultInformationControl;
025:        import org.eclipse.jface.text.IDocument;
026:        import org.eclipse.jface.text.IInformationControl;
027:        import org.eclipse.jface.text.IInformationControlCreator;
028:        import org.eclipse.jface.text.IRegion;
029:        import org.eclipse.jface.text.ITextHover;
030:        import org.eclipse.jface.text.ITextViewer;
031:        import org.eclipse.jface.text.contentassist.ContentAssistant;
032:        import org.eclipse.jface.text.contentassist.IContentAssistant;
033:        import org.eclipse.jface.text.source.ISourceViewer;
034:        import org.eclipse.jface.text.templates.TemplateContextType;
035:        import org.eclipse.jface.text.templates.TemplateVariableResolver;
036:
037:        import org.eclipse.ui.texteditor.ITextEditor;
038:
039:        import org.eclipse.jdt.ui.PreferenceConstants;
040:        import org.eclipse.jdt.ui.text.IColorManager;
041:        import org.eclipse.jdt.ui.text.IJavaPartitions;
042:        import org.eclipse.jdt.ui.text.JavaTextTools;
043:
044:        import org.eclipse.jdt.internal.ui.JavaPlugin;
045:        import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
046:        import org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
047:        import org.eclipse.jdt.internal.ui.text.template.preferences.TemplateVariableProcessor;
048:
049:        public class CodeTemplateSourceViewerConfiguration extends
050:                SimpleJavaSourceViewerConfiguration {
051:
052:            private static class TemplateVariableTextHover implements 
053:                    ITextHover {
054:
055:                private TemplateVariableProcessor fProcessor;
056:
057:                /**
058:                 * @param processor the template variable processor
059:                 */
060:                public TemplateVariableTextHover(
061:                        TemplateVariableProcessor processor) {
062:                    fProcessor = processor;
063:                }
064:
065:                /* (non-Javadoc)
066:                 * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
067:                 */
068:                public String getHoverInfo(ITextViewer textViewer,
069:                        IRegion subject) {
070:                    try {
071:                        IDocument doc = textViewer.getDocument();
072:                        int offset = subject.getOffset();
073:                        if (offset >= 2 && "${".equals(doc.get(offset - 2, 2))) { //$NON-NLS-1$
074:                            String varName = doc.get(offset, subject
075:                                    .getLength());
076:                            TemplateContextType contextType = fProcessor
077:                                    .getContextType();
078:                            if (contextType != null) {
079:                                Iterator iter = contextType.resolvers();
080:                                while (iter.hasNext()) {
081:                                    TemplateVariableResolver var = (TemplateVariableResolver) iter
082:                                            .next();
083:                                    if (varName.equals(var.getType())) {
084:                                        return var.getDescription();
085:                                    }
086:                                }
087:                            }
088:                        }
089:                    } catch (BadLocationException e) {
090:                    }
091:                    return null;
092:                }
093:
094:                /* (non-Javadoc)
095:                 * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
096:                 */
097:                public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
098:                    if (textViewer != null) {
099:                        return JavaWordFinder.findWord(
100:                                textViewer.getDocument(), offset);
101:                    }
102:                    return null;
103:                }
104:
105:            }
106:
107:            private final TemplateVariableProcessor fProcessor;
108:
109:            public CodeTemplateSourceViewerConfiguration(
110:                    IColorManager colorManager, IPreferenceStore store,
111:                    ITextEditor editor, TemplateVariableProcessor processor) {
112:                super (colorManager, store, editor,
113:                        IJavaPartitions.JAVA_PARTITIONING, false);
114:                fProcessor = processor;
115:            }
116:
117:            /*
118:             * @see SourceViewerConfiguration#getContentAssistant(ISourceViewer)
119:             */
120:            public IContentAssistant getContentAssistant(
121:                    ISourceViewer sourceViewer) {
122:
123:                IPreferenceStore store = JavaPlugin.getDefault()
124:                        .getPreferenceStore();
125:                JavaTextTools textTools = JavaPlugin.getDefault()
126:                        .getJavaTextTools();
127:                IColorManager manager = textTools.getColorManager();
128:
129:                ContentAssistant assistant = new ContentAssistant();
130:                assistant.setContentAssistProcessor(fProcessor,
131:                        IDocument.DEFAULT_CONTENT_TYPE);
132:                // Register the same processor for strings and single line comments to get code completion at the start of those partitions.
133:                assistant.setContentAssistProcessor(fProcessor,
134:                        IJavaPartitions.JAVA_STRING);
135:                assistant.setContentAssistProcessor(fProcessor,
136:                        IJavaPartitions.JAVA_CHARACTER);
137:                assistant.setContentAssistProcessor(fProcessor,
138:                        IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
139:                assistant.setContentAssistProcessor(fProcessor,
140:                        IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
141:                assistant.setContentAssistProcessor(fProcessor,
142:                        IJavaPartitions.JAVA_DOC);
143:
144:                assistant.enableAutoInsert(store
145:                        .getBoolean(PreferenceConstants.CODEASSIST_AUTOINSERT));
146:                assistant
147:                        .enableAutoActivation(store
148:                                .getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION));
149:                assistant
150:                        .setAutoActivationDelay(store
151:                                .getInt(PreferenceConstants.CODEASSIST_AUTOACTIVATION_DELAY));
152:                assistant
153:                        .setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
154:                assistant
155:                        .setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
156:                assistant
157:                        .setInformationControlCreator(new IInformationControlCreator() {
158:                            public IInformationControl createInformationControl(
159:                                    Shell parent) {
160:                                return new DefaultInformationControl(parent,
161:                                        SWT.NONE, new HTMLTextPresenter(true));
162:                            }
163:                        });
164:
165:                Color background = getColor(store,
166:                        PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND,
167:                        manager);
168:                assistant.setContextInformationPopupBackground(background);
169:                assistant.setContextSelectorBackground(background);
170:                assistant.setProposalSelectorBackground(background);
171:
172:                Color foreground = getColor(store,
173:                        PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND,
174:                        manager);
175:                assistant.setContextInformationPopupForeground(foreground);
176:                assistant.setContextSelectorForeground(foreground);
177:                assistant.setProposalSelectorForeground(foreground);
178:
179:                return assistant;
180:            }
181:
182:            private Color getColor(IPreferenceStore store, String key,
183:                    IColorManager manager) {
184:                RGB rgb = PreferenceConverter.getColor(store, key);
185:                return manager.getColor(rgb);
186:            }
187:
188:            /*
189:             * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
190:             * @since 2.1
191:             */
192:            public ITextHover getTextHover(ISourceViewer sourceViewer,
193:                    String contentType, int stateMask) {
194:                return new TemplateVariableTextHover(fProcessor);
195:            }
196:
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.