Source Code Cross Referenced for JavaSearchResult.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » search » 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.search 
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.search;
011:
012:        import java.util.HashMap;
013:        import java.util.HashSet;
014:        import java.util.Map;
015:        import java.util.Set;
016:
017:        import org.eclipse.core.runtime.IAdaptable;
018:        import org.eclipse.core.runtime.IStatus;
019:        import org.eclipse.core.runtime.Status;
020:
021:        import org.eclipse.core.resources.IFile;
022:
023:        import org.eclipse.jface.resource.ImageDescriptor;
024:
025:        import org.eclipse.ui.IEditorPart;
026:
027:        import org.eclipse.search.ui.ISearchQuery;
028:        import org.eclipse.search.ui.text.AbstractTextSearchResult;
029:        import org.eclipse.search.ui.text.IEditorMatchAdapter;
030:        import org.eclipse.search.ui.text.IFileMatchAdapter;
031:        import org.eclipse.search.ui.text.Match;
032:        import org.eclipse.search.ui.text.MatchFilter;
033:
034:        import org.eclipse.jdt.core.IClassFile;
035:        import org.eclipse.jdt.core.ICompilationUnit;
036:        import org.eclipse.jdt.core.IJavaElement;
037:        import org.eclipse.jdt.core.IParent;
038:        import org.eclipse.jdt.core.JavaModelException;
039:
040:        import org.eclipse.jdt.ui.search.IMatchPresentation;
041:
042:        import org.eclipse.jdt.internal.ui.JavaPlugin;
043:
044:        public class JavaSearchResult extends AbstractTextSearchResult
045:                implements  IEditorMatchAdapter, IFileMatchAdapter {
046:
047:            private static final Match[] NO_MATCHES = new Match[0];
048:
049:            private final JavaSearchQuery fQuery;
050:            private final Map fElementsToParticipants;
051:
052:            public JavaSearchResult(JavaSearchQuery query) {
053:                fQuery = query;
054:                fElementsToParticipants = new HashMap();
055:                setActiveMatchFilters(JavaMatchFilter.getLastUsedFilters());
056:            }
057:
058:            public ImageDescriptor getImageDescriptor() {
059:                return fQuery.getImageDescriptor();
060:            }
061:
062:            public String getLabel() {
063:                return fQuery.getResultLabel(getMatchCount());
064:            }
065:
066:            public String getTooltip() {
067:                return getLabel();
068:            }
069:
070:            public Match[] computeContainedMatches(
071:                    AbstractTextSearchResult result, IEditorPart editor) {
072:                return computeContainedMatches(editor.getEditorInput());
073:            }
074:
075:            /* (non-Javadoc)
076:             * @see org.eclipse.search.ui.text.AbstractTextSearchResult#setMatchFilters(org.eclipse.search.ui.text.MatchFilter[])
077:             */
078:            public void setActiveMatchFilters(MatchFilter[] filters) {
079:                super .setActiveMatchFilters(filters);
080:                JavaMatchFilter.setLastUsedFilters(filters);
081:            }
082:
083:            /* (non-Javadoc)
084:             * @see org.eclipse.search.ui.text.AbstractTextSearchResult#getAllMatchFilters()
085:             */
086:            public MatchFilter[] getAllMatchFilters() {
087:                return JavaMatchFilter.allFilters(fQuery);
088:            }
089:
090:            public Match[] computeContainedMatches(
091:                    AbstractTextSearchResult result, IFile file) {
092:                return computeContainedMatches(file);
093:            }
094:
095:            private Match[] computeContainedMatches(IAdaptable adaptable) {
096:                IJavaElement javaElement = (IJavaElement) adaptable
097:                        .getAdapter(IJavaElement.class);
098:                Set matches = new HashSet();
099:                if (javaElement != null) {
100:                    collectMatches(matches, javaElement);
101:                }
102:                IFile file = (IFile) adaptable.getAdapter(IFile.class);
103:                if (file != null) {
104:                    collectMatches(matches, file);
105:                }
106:                if (!matches.isEmpty()) {
107:                    return (Match[]) matches.toArray(new Match[matches.size()]);
108:                }
109:                return NO_MATCHES;
110:            }
111:
112:            private void collectMatches(Set matches, IFile element) {
113:                Match[] m = getMatches(element);
114:                if (m.length != 0) {
115:                    for (int i = 0; i < m.length; i++) {
116:                        matches.add(m[i]);
117:                    }
118:                }
119:            }
120:
121:            private void collectMatches(Set matches, IJavaElement element) {
122:                Match[] m = getMatches(element);
123:                if (m.length != 0) {
124:                    for (int i = 0; i < m.length; i++) {
125:                        matches.add(m[i]);
126:                    }
127:                }
128:                if (element instanceof  IParent) {
129:                    IParent parent = (IParent) element;
130:                    try {
131:                        IJavaElement[] children = parent.getChildren();
132:                        for (int i = 0; i < children.length; i++) {
133:                            collectMatches(matches, children[i]);
134:                        }
135:                    } catch (JavaModelException e) {
136:                        // we will not be tracking these results
137:                    }
138:                }
139:            }
140:
141:            /* (non-Javadoc)
142:             * @see org.eclipse.search.ui.ISearchResultCategory#getFile(java.lang.Object)
143:             */
144:            public IFile getFile(Object element) {
145:                if (element instanceof  IJavaElement) {
146:                    IJavaElement javaElement = (IJavaElement) element;
147:                    ICompilationUnit cu = (ICompilationUnit) javaElement
148:                            .getAncestor(IJavaElement.COMPILATION_UNIT);
149:                    if (cu != null) {
150:                        return (IFile) cu.getResource();
151:                    } else {
152:                        IClassFile cf = (IClassFile) javaElement
153:                                .getAncestor(IJavaElement.CLASS_FILE);
154:                        if (cf != null)
155:                            return (IFile) cf.getResource();
156:                    }
157:                    return null;
158:                }
159:                if (element instanceof  IFile)
160:                    return (IFile) element;
161:                return null;
162:            }
163:
164:            /*
165:             * (non-Javadoc)
166:             * 
167:             * @see org.eclipse.search2.ui.text.IStructureProvider#isShownInEditor(org.eclipse.search2.ui.text.Match,
168:             *      org.eclipse.ui.IEditorPart)
169:             */
170:            public boolean isShownInEditor(Match match, IEditorPart editor) {
171:                Object element = match.getElement();
172:                if (element instanceof  IJavaElement) {
173:                    element = ((IJavaElement) element).getOpenable(); // class file or compilation unit 
174:                    return element != null
175:                            && element.equals(editor.getEditorInput()
176:                                    .getAdapter(IJavaElement.class));
177:                } else if (element instanceof  IFile) {
178:                    return element.equals(editor.getEditorInput().getAdapter(
179:                            IFile.class));
180:                }
181:                return false;
182:            }
183:
184:            /* (non-Javadoc)
185:             * @see org.eclipse.search.ui.ISearchResult#getQuery()
186:             */
187:            public ISearchQuery getQuery() {
188:                return fQuery;
189:            }
190:
191:            synchronized IMatchPresentation getSearchParticpant(Object element) {
192:                return (IMatchPresentation) fElementsToParticipants
193:                        .get(element);
194:            }
195:
196:            boolean addMatch(Match match, IMatchPresentation participant) {
197:                Object element = match.getElement();
198:                if (fElementsToParticipants.get(element) != null) {
199:                    // TODO must access the participant id / label to properly report the error.
200:                    JavaPlugin
201:                            .log(new Status(
202:                                    IStatus.WARNING,
203:                                    JavaPlugin.getPluginId(),
204:                                    0,
205:                                    "A second search participant was found for an element", null)); //$NON-NLS-1$
206:                    return false;
207:                }
208:                fElementsToParticipants.put(element, participant);
209:                addMatch(match);
210:                return true;
211:            }
212:
213:            public void removeAll() {
214:                synchronized (this ) {
215:                    fElementsToParticipants.clear();
216:                }
217:                super .removeAll();
218:            }
219:
220:            public void removeMatch(Match match) {
221:                synchronized (this ) {
222:                    if (getMatchCount(match.getElement()) == 1)
223:                        fElementsToParticipants.remove(match.getElement());
224:                }
225:                super .removeMatch(match);
226:            }
227:
228:            public IFileMatchAdapter getFileMatchAdapter() {
229:                return this ;
230:            }
231:
232:            public IEditorMatchAdapter getEditorMatchAdapter() {
233:                return this;
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.