Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 244353 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java (-9 / +130 lines)
Lines 8-26 Link Here
8
8
9
package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks;
9
package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks;
10
10
11
import java.util.ArrayList;
12
import java.util.List;
13
11
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
17
import org.eclipse.core.runtime.Status;
15
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.core.runtime.jobs.Job;
16
import org.eclipse.debug.ui.IDebugModelPresentation;
19
import org.eclipse.debug.ui.IDebugModelPresentation;
20
import org.eclipse.jdt.core.IJavaProject;
21
import org.eclipse.jdt.core.IPackageFragment;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.search.IJavaSearchConstants;
24
import org.eclipse.jdt.core.search.SearchEngine;
25
import org.eclipse.jdt.core.search.SearchMatch;
26
import org.eclipse.jdt.core.search.SearchParticipant;
27
import org.eclipse.jdt.core.search.SearchPattern;
28
import org.eclipse.jdt.core.search.SearchRequestor;
17
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
29
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18
import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction;
30
import org.eclipse.jdt.internal.ui.JavaUIMessages;
31
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
32
import org.eclipse.jdt.ui.JavaElementLabelProvider;
33
import org.eclipse.jdt.ui.JavaElementLabels;
34
import org.eclipse.jdt.ui.JavaUI;
35
import org.eclipse.jface.dialogs.IDialogConstants;
19
import org.eclipse.jface.dialogs.MessageDialog;
36
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.text.IRegion;
37
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.jface.text.hyperlink.IHyperlink;
38
import org.eclipse.jface.text.hyperlink.IHyperlink;
39
import org.eclipse.jface.viewers.ArrayContentProvider;
40
import org.eclipse.jface.viewers.StyledString;
22
import org.eclipse.ui.IEditorInput;
41
import org.eclipse.ui.IEditorInput;
23
import org.eclipse.ui.PlatformUI;
42
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.dialogs.ListDialog;
24
import org.eclipse.ui.progress.UIJob;
44
import org.eclipse.ui.progress.UIJob;
25
45
26
/**
46
/**
Lines 28-33 Link Here
28
 * 
48
 * 
29
 * @author Rob Elves
49
 * @author Rob Elves
30
 * @author Jingwe Ou
50
 * @author Jingwe Ou
51
 * @author David Green fix bug 244352
31
 */
52
 */
32
public class JavaResourceHyperlink implements IHyperlink {
53
public class JavaResourceHyperlink implements IHyperlink {
33
54
Lines 68-75 Link Here
68
			protected IStatus run(IProgressMonitor monitor) {
89
			protected IStatus run(IProgressMonitor monitor) {
69
				try {
90
				try {
70
					// search for the type in the workspace
91
					// search for the type in the workspace
71
					Object result = OpenTypeAction.findTypeInWorkspace(typeName);
92
72
					searchCompleted(result, typeName, null);
93
					final List<IType> results = new ArrayList<IType>();
94
95
					SearchRequestor collector = new SearchRequestor() {
96
						@Override
97
						public void acceptSearchMatch(SearchMatch match) throws CoreException {
98
							Object element = match.getElement();
99
							if (element instanceof IType) {
100
								results.add((IType) element);
101
							}
102
						}
103
					};
104
105
					// do a case-sensitive search for the class name see bug 244352
106
107
					SearchEngine engine = new SearchEngine();
108
					SearchPattern pattern = SearchPattern.createPattern(typeName, IJavaSearchConstants.TYPE,
109
							IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH
110
									| SearchPattern.R_CASE_SENSITIVE);
111
					engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
112
							SearchEngine.createWorkspaceScope(), collector, monitor);
113
114
					searchCompleted(results, typeName, null);
115
73
				} catch (CoreException e) {
116
				} catch (CoreException e) {
74
					searchCompleted(null, typeName, e.getStatus());
117
					searchCompleted(null, typeName, e.getStatus());
75
				}
118
				}
Lines 80-96 Link Here
80
		search.schedule();
123
		search.schedule();
81
	}
124
	}
82
125
83
	protected void searchCompleted(final Object source, final String typeName, final IStatus status) {
126
	protected void searchCompleted(final List<IType> sources, final String typeName, final IStatus status) {
84
		UIJob job = new UIJob("link search complete") { //$NON-NLS-1$
127
		UIJob job = new UIJob("link search complete") { //$NON-NLS-1$
85
			@Override
128
			@Override
86
			public IStatus runInUIThread(IProgressMonitor monitor) {
129
			public IStatus runInUIThread(IProgressMonitor monitor) {
87
				if (source == null) {
130
				if (sources.size() > 1) {
88
					// did not find source
131
					openTypeDialog(sources, typeName);
89
					MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
90
							"Open Type", "Type could not be located.");
91
				} else {
132
				} else {
92
					processSearchResult(source, typeName);
133
					IType type = sources.get(0);
134
135
					if (type == null) {
136
						// did not find source
137
						MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
138
								"Open Type", "Type could not be located.");
139
					} else {
140
						processSearchResult(type, typeName);
141
					}
93
				}
142
				}
143
94
				return Status.OK_STATUS;
144
				return Status.OK_STATUS;
95
			}
145
			}
96
		};
146
		};
Lines 123-126 Link Here
123
			}
173
			}
124
		}
174
		}
125
	}
175
	}
176
177
	private void openTypeDialog(final List<IType> sources, final String typeName) {
178
		ListDialog dialog = new ListDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
179
		dialog.setInput(sources.toArray());
180
		dialog.setContentProvider(new ArrayContentProvider());
181
		dialog.setLabelProvider(new JavaElementLabelProvider() {
182
			@Override
183
			public StyledString getStyledText(Object element) {
184
				IType type = (IType) element;
185
				StyledString styledString = super.getStyledText(type);
186
187
				IPackageFragment fragment = type.getPackageFragment();
188
				if (fragment != null) {
189
					styledString.append(JavaElementLabels.CONCAT_STRING);
190
					styledString.append(super.getText(fragment));
191
				}
192
193
				IJavaProject project = type.getJavaProject();
194
				if (project != null) {
195
					styledString.append(JavaElementLabels.CONCAT_STRING);
196
					styledString.append(super.getText(project));
197
				}
198
199
				return styledString;
200
			}
201
202
			@Override
203
			public String getText(Object element) {
204
				IType type = (IType) element;
205
				StringBuilder builder = new StringBuilder();
206
				builder.append(super.getText(type));
207
208
				IPackageFragment fragment = type.getPackageFragment();
209
				if (fragment != null) {
210
					builder.append(JavaElementLabels.CONCAT_STRING);
211
					builder.append(super.getText(fragment));
212
				}
213
214
				IJavaProject project = type.getJavaProject();
215
				if (project != null) {
216
					builder.append(JavaElementLabels.CONCAT_STRING);
217
					builder.append(super.getText(project));
218
				}
219
220
				return builder.toString();
221
			}
222
		});
223
224
		dialog.setTitle("Open Hyperlink");
225
		dialog.setMessage("More than one types are detected, please select one:");
226
		dialog.setHelpAvailable(false);
227
228
		int result = dialog.open();
229
		if (result != IDialogConstants.OK_ID) {
230
			return;
231
		}
232
233
		Object[] types = dialog.getResult();
234
		if (types != null && types.length > 0) {
235
			IType type = null;
236
			for (Object type2 : types) {
237
				type = (IType) type2;
238
				try {
239
					JavaUI.openInEditor(type, true, true);
240
				} catch (CoreException x) {
241
					ExceptionHandler.handle(x, JavaUIMessages.OpenTypeAction_errorTitle,
242
							JavaUIMessages.OpenTypeAction_errorMessage);
243
				}
244
			}
245
		}
246
	}
126
}
247
}

Return to bug 244353