Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 110182 Details for
Bug 244353
java class hyperlink detection should provide multiple options when multiple results are found for a class name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
a patch pops up a dialog for multiple hyperlinks
clipboard.txt (text/plain), 7.19 KB, created by
Jingwen 'Owen' Ou
on 2008-08-17 20:45:04 EDT
(
hide
)
Description:
a patch pops up a dialog for multiple hyperlinks
Filename:
MIME Type:
Creator:
Jingwen 'Owen' Ou
Created:
2008-08-17 20:45:04 EDT
Size:
7.19 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.sandbox.ui >Index: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/sandbox/org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java,v >retrieving revision 1.1 >diff -u -r1.1 JavaResourceHyperlink.java >--- src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java 23 Jul 2008 23:24:41 -0000 1.1 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java 18 Aug 2008 00:44:01 -0000 >@@ -8,19 +8,39 @@ > > package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; > >+import java.util.ArrayList; >+import java.util.List; >+ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.debug.ui.IDebugModelPresentation; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.search.IJavaSearchConstants; >+import org.eclipse.jdt.core.search.SearchEngine; >+import org.eclipse.jdt.core.search.SearchMatch; >+import org.eclipse.jdt.core.search.SearchParticipant; >+import org.eclipse.jdt.core.search.SearchPattern; >+import org.eclipse.jdt.core.search.SearchRequestor; > import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; >-import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction; >+import org.eclipse.jdt.internal.ui.JavaUIMessages; >+import org.eclipse.jdt.internal.ui.util.ExceptionHandler; >+import org.eclipse.jdt.ui.JavaElementLabelProvider; >+import org.eclipse.jdt.ui.JavaElementLabels; >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.text.IRegion; > import org.eclipse.jface.text.hyperlink.IHyperlink; >+import org.eclipse.jface.viewers.ArrayContentProvider; >+import org.eclipse.jface.viewers.StyledString; > import org.eclipse.ui.IEditorInput; > import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.dialogs.ListDialog; > import org.eclipse.ui.progress.UIJob; > > /** >@@ -28,6 +48,7 @@ > * > * @author Rob Elves > * @author Jingwe Ou >+ * @author David Green fix bug 244352 > */ > public class JavaResourceHyperlink implements IHyperlink { > >@@ -68,8 +89,30 @@ > protected IStatus run(IProgressMonitor monitor) { > try { > // search for the type in the workspace >- Object result = OpenTypeAction.findTypeInWorkspace(typeName); >- searchCompleted(result, typeName, null); >+ >+ final List<IType> results = new ArrayList<IType>(); >+ >+ SearchRequestor collector = new SearchRequestor() { >+ @Override >+ public void acceptSearchMatch(SearchMatch match) throws CoreException { >+ Object element = match.getElement(); >+ if (element instanceof IType) { >+ results.add((IType) element); >+ } >+ } >+ }; >+ >+ // do a case-sensitive search for the class name see bug 244352 >+ >+ SearchEngine engine = new SearchEngine(); >+ SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE, >+ IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH >+ | SearchPattern.R_CASE_SENSITIVE); >+ engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, >+ SearchEngine.createWorkspaceScope(), collector, monitor); >+ >+ searchCompleted(results, typeName, null); >+ > } catch (CoreException e) { > searchCompleted(null, typeName, e.getStatus()); > } >@@ -80,17 +123,24 @@ > search.schedule(); > } > >- protected void searchCompleted(final Object source, final String typeName, final IStatus status) { >+ protected void searchCompleted(final List<IType> sources, final String typeName, final IStatus status) { > UIJob job = new UIJob("link search complete") { //$NON-NLS-1$ > @Override > public IStatus runInUIThread(IProgressMonitor monitor) { >- if (source == null) { >- // did not find source >- MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), >- "Open Type", "Type could not be located."); >+ if (sources.size() > 1) { >+ openTypeDialog(sources, typeName); > } else { >- processSearchResult(source, typeName); >+ IType type = sources.get(0); >+ >+ if (type == null) { >+ // did not find source >+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), >+ "Open Type", "Type could not be located."); >+ } else { >+ processSearchResult(type, typeName); >+ } > } >+ > return Status.OK_STATUS; > } > }; >@@ -123,4 +173,75 @@ > } > } > } >+ >+ private void openTypeDialog(final List<IType> sources, final String typeName) { >+ ListDialog dialog = new ListDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); >+ dialog.setInput(sources.toArray()); >+ dialog.setContentProvider(new ArrayContentProvider()); >+ dialog.setLabelProvider(new JavaElementLabelProvider() { >+ @Override >+ public StyledString getStyledText(Object element) { >+ IType type = (IType) element; >+ StyledString styledString = super.getStyledText(type); >+ >+ IPackageFragment fragment = type.getPackageFragment(); >+ if (fragment != null) { >+ styledString.append(JavaElementLabels.CONCAT_STRING); >+ styledString.append(super.getText(fragment)); >+ } >+ >+ IJavaProject project = type.getJavaProject(); >+ if (project != null) { >+ styledString.append(JavaElementLabels.CONCAT_STRING); >+ styledString.append(super.getText(project)); >+ } >+ >+ return styledString; >+ } >+ >+ @Override >+ public String getText(Object element) { >+ IType type = (IType) element; >+ StringBuilder builder = new StringBuilder(); >+ builder.append(super.getText(type)); >+ >+ IPackageFragment fragment = type.getPackageFragment(); >+ if (fragment != null) { >+ builder.append(JavaElementLabels.CONCAT_STRING); >+ builder.append(super.getText(fragment)); >+ } >+ >+ IJavaProject project = type.getJavaProject(); >+ if (project != null) { >+ builder.append(JavaElementLabels.CONCAT_STRING); >+ builder.append(super.getText(project)); >+ } >+ >+ return builder.toString(); >+ } >+ }); >+ >+ dialog.setTitle("Open Hyperlink"); >+ dialog.setMessage("More than one types are detected, please select one:"); >+ dialog.setHelpAvailable(false); >+ >+ int result = dialog.open(); >+ if (result != IDialogConstants.OK_ID) { >+ return; >+ } >+ >+ Object[] types = dialog.getResult(); >+ if (types != null && types.length > 0) { >+ IType type = null; >+ for (Object type2 : types) { >+ type = (IType) type2; >+ try { >+ JavaUI.openInEditor(type, true, true); >+ } catch (CoreException x) { >+ ExceptionHandler.handle(x, JavaUIMessages.OpenTypeAction_errorTitle, >+ JavaUIMessages.OpenTypeAction_errorMessage); >+ } >+ } >+ } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 244353
: 110182 |
110183
|
110184
|
110190
|
110763
|
113061