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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.contentassist;
011:
012:        import org.eclipse.swt.events.DisposeEvent;
013:        import org.eclipse.swt.events.DisposeListener;
014:        import org.eclipse.swt.events.FocusEvent;
015:        import org.eclipse.swt.events.FocusListener;
016:        import org.eclipse.swt.widgets.Combo;
017:        import org.eclipse.swt.widgets.Control;
018:        import org.eclipse.swt.widgets.Text;
019:
020:        import org.eclipse.core.commands.AbstractHandler;
021:        import org.eclipse.core.commands.ExecutionEvent;
022:        import org.eclipse.core.commands.ExecutionException;
023:        import org.eclipse.core.commands.IHandler;
024:
025:        import org.eclipse.jface.bindings.TriggerSequence;
026:        import org.eclipse.jface.contentassist.AbstractControlContentAssistSubjectAdapter;
027:        import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter;
028:        import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
029:        import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter;
030:        import org.eclipse.jface.viewers.ILabelProvider;
031:        import org.eclipse.jface.viewers.LabelProvider;
032:
033:        import org.eclipse.ui.PlatformUI;
034:        import org.eclipse.ui.handlers.IHandlerActivation;
035:        import org.eclipse.ui.handlers.IHandlerService;
036:        import org.eclipse.ui.internal.texteditor.NLSUtility;
037:        import org.eclipse.ui.keys.IBindingService;
038:        import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
039:
040:        /**
041:         * A content assistant handler which handles the key binding and
042:         * the cue for a {@link org.eclipse.jface.text.contentassist.ContentAssistant}
043:         * and its subject adapter.
044:         *
045:         * @since 3.0
046:         * @deprecated As of 3.2, replaced by JFace field assist support
047:         */
048:        public class ContentAssistHandler {
049:            /**
050:             * The target control.
051:             */
052:            private Control fControl;
053:            /**
054:             * The content assist subject adapter.
055:             */
056:            private AbstractControlContentAssistSubjectAdapter fContentAssistSubjectAdapter;
057:            /**
058:             * The content assistant.
059:             */
060:            private SubjectControlContentAssistant fContentAssistant;
061:            /**
062:             * The currently installed FocusListener, or <code>null</code> iff none installed.
063:             * This is also used as flag to tell whether content assist is enabled
064:             */
065:            private FocusListener fFocusListener;
066:            /**
067:             * The currently installed IHandlerActivation, or <code>null</code> iff none installed.
068:             */
069:            private IHandlerActivation fHandlerActivation;
070:
071:            /**
072:             * Creates a new {@link ContentAssistHandler} for the given {@link Combo}.
073:             * Only a single {@link ContentAssistHandler} may be installed on a {@link Combo} instance.
074:             * Content Assist is enabled by default.
075:             *
076:             * @param combo target combo
077:             * @param contentAssistant a configured content assistant
078:             * @return a new {@link ContentAssistHandler}
079:             */
080:            public static ContentAssistHandler createHandlerForCombo(
081:                    Combo combo, SubjectControlContentAssistant contentAssistant) {
082:                return new ContentAssistHandler(combo,
083:                        new ComboContentAssistSubjectAdapter(combo),
084:                        contentAssistant);
085:            }
086:
087:            /**
088:             * Creates a new {@link ContentAssistHandler} for the given {@link Text}.
089:             * Only a single {@link ContentAssistHandler} may be installed on a {@link Text} instance.
090:             * Content Assist is enabled by default.
091:             *
092:             * @param text target text
093:             * @param contentAssistant a configured content assistant
094:             * @return a new {@link ContentAssistHandler}
095:             */
096:            public static ContentAssistHandler createHandlerForText(Text text,
097:                    SubjectControlContentAssistant contentAssistant) {
098:                return new ContentAssistHandler(text,
099:                        new TextContentAssistSubjectAdapter(text),
100:                        contentAssistant);
101:            }
102:
103:            /**
104:             * Internal constructor.
105:             *
106:             * @param control target control
107:             * @param subjectAdapter content assist subject adapter
108:             * @param contentAssistant content assistant
109:             */
110:            private ContentAssistHandler(Control control,
111:                    AbstractControlContentAssistSubjectAdapter subjectAdapter,
112:                    SubjectControlContentAssistant contentAssistant) {
113:                fControl = control;
114:                fContentAssistant = contentAssistant;
115:                fContentAssistSubjectAdapter = subjectAdapter;
116:                setEnabled(true);
117:                fControl.addDisposeListener(new DisposeListener() {
118:                    public void widgetDisposed(DisposeEvent e) {
119:                        setEnabled(false);
120:                    }
121:                });
122:            }
123:
124:            /**
125:             * @return <code>true</code> iff content assist is enabled
126:             */
127:            public boolean isEnabled() {
128:                return fFocusListener != null;
129:            }
130:
131:            /**
132:             * Controls enablement of content assist.
133:             * When enabled, a cue is shown next to the focused field
134:             * and the affordance hover shows the shortcut.
135:             *
136:             * @param enable enable content assist iff true
137:             */
138:            public void setEnabled(boolean enable) {
139:                if (enable == isEnabled())
140:                    return;
141:
142:                if (enable)
143:                    enable();
144:                else
145:                    disable();
146:            }
147:
148:            /**
149:             * Enable content assist.
150:             */
151:            private void enable() {
152:                if (!fControl.isDisposed()) {
153:                    fContentAssistant.install(fContentAssistSubjectAdapter);
154:                    installCueLabelProvider();
155:                    installFocusListener();
156:                    if (fControl.isFocusControl())
157:                        activateHandler();
158:                }
159:            }
160:
161:            /**
162:             * Disable content assist.
163:             */
164:            private void disable() {
165:                if (!fControl.isDisposed()) {
166:                    fContentAssistant.uninstall();
167:                    fContentAssistSubjectAdapter
168:                            .setContentAssistCueProvider(null);
169:                    fControl.removeFocusListener(fFocusListener);
170:                    fFocusListener = null;
171:                    if (fHandlerActivation != null)
172:                        deactivateHandler();
173:                }
174:            }
175:
176:            /**
177:             * Create and install the {@link LabelProvider} for fContentAssistSubjectAdapter.
178:             */
179:            private void installCueLabelProvider() {
180:                ILabelProvider labelProvider = new LabelProvider() {
181:                    /*
182:                     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
183:                     */
184:                    public String getText(Object element) {
185:                        IBindingService bindingService = (IBindingService) PlatformUI
186:                                .getWorkbench().getAdapter(
187:                                        IBindingService.class);
188:                        TriggerSequence[] activeBindings = bindingService
189:                                .getActiveBindingsFor(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
190:                        if (activeBindings.length == 0)
191:                            return ContentAssistMessages.ContentAssistHandler_contentAssistAvailable;
192:                        return NLSUtility
193:                                .format(
194:                                        ContentAssistMessages.ContentAssistHandler_contentAssistAvailableWithKeyBinding,
195:                                        activeBindings[0].format());
196:                    }
197:                };
198:                fContentAssistSubjectAdapter
199:                        .setContentAssistCueProvider(labelProvider);
200:            }
201:
202:            /**
203:             * Create fFocusListener and install it on fControl.
204:             */
205:            private void installFocusListener() {
206:                fFocusListener = new FocusListener() {
207:                    public void focusGained(final FocusEvent e) {
208:                        if (fHandlerActivation == null)
209:                            activateHandler();
210:                    }
211:
212:                    public void focusLost(FocusEvent e) {
213:                        if (fHandlerActivation != null)
214:                            deactivateHandler();
215:                    }
216:                };
217:                fControl.addFocusListener(fFocusListener);
218:            }
219:
220:            /**
221:             * Create and register fHandlerSubmission.
222:             */
223:            private void activateHandler() {
224:                IHandlerService handlerService = (IHandlerService) PlatformUI
225:                        .getWorkbench().getAdapter(IHandlerService.class);
226:                if (handlerService == null)
227:                    return;
228:
229:                IHandler handler = new AbstractHandler() {
230:                    public Object execute(ExecutionEvent event)
231:                            throws ExecutionException {
232:                        if (ContentAssistHandler.this .isEnabled()) // don't call AbstractHandler#isEnabled()!
233:                            fContentAssistant.showPossibleCompletions();
234:                        return null;
235:                    }
236:                };
237:                fHandlerActivation = handlerService
238:                        .activateHandler(
239:                                ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS,
240:                                handler);
241:            }
242:
243:            /**
244:             * Unregister the {@link IHandlerActivation} from the shell.
245:             */
246:            private void deactivateHandler() {
247:                IHandlerService handlerService = (IHandlerService) PlatformUI
248:                        .getWorkbench().getAdapter(IHandlerService.class);
249:                if (handlerService != null)
250:                    handlerService.deactivateHandler(fHandlerActivation);
251:                fHandlerActivation = null;
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.