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 217630
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceHyperlinkDetector.java (-1 / +1 lines)
Lines 24-30 Link Here
24
 */
24
 */
25
public class JavaStackTraceHyperlinkDetector extends AbstractHyperlinkDetector {
25
public class JavaStackTraceHyperlinkDetector extends AbstractHyperlinkDetector {
26
26
27
	private static final Pattern stackTracePattern = Pattern.compile("\\S*.{1}java:\\d*\\){1}",
27
	private static final Pattern stackTracePattern = Pattern.compile("\\S*\\.java:\\d*\\)",
28
			Pattern.CASE_INSENSITIVE);
28
			Pattern.CASE_INSENSITIVE);
29
29
30
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
30
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
(-)src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceFileHyperlink.java (-38 / +84 lines)
Lines 9-14 Link Here
9
package org.eclipse.mylyn.internal.java.ui;
9
package org.eclipse.mylyn.internal.java.ui;
10
10
11
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
15
import org.eclipse.core.runtime.jobs.Job;
12
import org.eclipse.debug.ui.IDebugModelPresentation;
16
import org.eclipse.debug.ui.IDebugModelPresentation;
13
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
17
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
14
import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction;
18
import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction;
Lines 20-25 Link Here
20
import org.eclipse.ui.IEditorInput;
24
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.progress.UIJob;
23
import org.eclipse.ui.texteditor.IDocumentProvider;
28
import org.eclipse.ui.texteditor.IDocumentProvider;
24
import org.eclipse.ui.texteditor.ITextEditor;
29
import org.eclipse.ui.texteditor.ITextEditor;
25
30
Lines 53-98 Link Here
53
58
54
	public void open() {
59
	public void open() {
55
60
56
		int lineNumber;
57
		try {
61
		try {
58
62
59
			String typeName = getTypeName();
63
			String typeName = getTypeName();
60
			lineNumber = getLineNumber();
64
			int lineNumber = getLineNumber();
61
65
62
			// documents start at 0
66
			// documents start at 0
63
			if (lineNumber > 0) {
67
			if (lineNumber > 0) {
64
				lineNumber--;
68
				lineNumber--;
65
			}
69
			}
66
			Object sourceElement = getSourceElement(typeName);
70
			
67
			if (sourceElement != null) {
71
			startSourceSearch(typeName, lineNumber);
68
				IDebugModelPresentation presentation = JDIDebugUIPlugin.getDefault().getModelPresentation();
72
			
69
				IEditorInput editorInput = presentation.getEditorInput(sourceElement);
70
				if (editorInput != null) {
71
					String editorId = presentation.getEditorId(editorInput, sourceElement);
72
					if (editorId != null) {
73
						IEditorPart editorPart = JDIDebugUIPlugin.getActivePage().openEditor(editorInput, editorId);
74
						if (editorPart instanceof ITextEditor && lineNumber >= 0) {
75
							ITextEditor textEditor = (ITextEditor) editorPart;
76
							IDocumentProvider provider = textEditor.getDocumentProvider();
77
							provider.connect(editorInput);
78
							IDocument document = provider.getDocument(editorInput);
79
							try {
80
								IRegion line = document.getLineInformation(lineNumber);
81
								textEditor.selectAndReveal(line.getOffset(), line.getLength());
82
							} catch (BadLocationException e1) {
83
								MessageDialog.openInformation(PlatformUI.getWorkbench()
84
										.getActiveWorkbenchWindow()
85
										.getShell(), "Open Type", "Line not found in type.");
86
							}
87
							provider.disconnect(editorInput);
88
						}
89
						return;
90
					}
91
				}
92
			}
93
			// did not find source
94
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Type",
95
					"Type could not be located.");
96
		} catch (CoreException e1) {
73
		} catch (CoreException e1) {
97
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Type",
74
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Type",
98
					"Failed to open type.");
75
					"Failed to open type.");
Lines 100-112 Link Here
100
		}
77
		}
101
78
102
	}
79
	}
80
	
81
	/**
82
	 * Starts a search for the type with the given name. Reports back to 'searchCompleted(...)'.
83
	 * 
84
	 * @param typeName the type to search for
85
	 */
86
	protected void startSourceSearch(final String typeName, final int lineNumber) {
87
		Job search = new Job("Searching...") {
88
			protected IStatus run(IProgressMonitor monitor) {
89
				try {
90
					// search for the type in the workspace
91
					Object result = OpenTypeAction.findTypeInWorkspace(typeName);
92
					searchCompleted(result, typeName, lineNumber, null);
93
				} catch (CoreException e) {
94
					searchCompleted(null, typeName, lineNumber, e.getStatus());
95
				}
96
				return Status.OK_STATUS;
97
			}
103
98
104
	// adapted from JavaStackTraceHyperlink
99
		};
105
	private Object getSourceElement(String typeName) throws CoreException {
100
		search.schedule();
106
		Object result = null;
101
	}
107
		result = OpenTypeAction.findTypeInWorkspace(typeName);
102
108
		// }
103
	protected void searchCompleted(final Object source, final String typeName, final int lineNumber, final IStatus status) {
109
		return result;
104
		UIJob job = new UIJob("link search complete") { //$NON-NLS-1$
105
			public IStatus runInUIThread(IProgressMonitor monitor) {
106
				if (source == null) {
107
					// did not find source
108
					MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Type",
109
							"Type could not be located.");
110
				} else {
111
					processSearchResult(source, typeName, lineNumber);
112
				}
113
				return Status.OK_STATUS;
114
			}
115
		};
116
		job.setSystem(true);
117
		job.schedule();
118
	}
119
120
	/**
121
	 * The search succeeded with the given result
122
	 * 
123
	 * @param source resolved source object for the search
124
	 * @param typeName type name searched for
125
	 * @param lineNumber line number on link
126
	 */
127
	protected void processSearchResult(Object source, String typeName, int lineNumber) {
128
		IDebugModelPresentation presentation = JDIDebugUIPlugin.getDefault().getModelPresentation();
129
		IEditorInput editorInput = presentation.getEditorInput(source);
130
		if (editorInput != null) {
131
			String editorId = presentation.getEditorId(editorInput, source);
132
			if (editorId != null) {
133
				try {
134
					IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorId);
135
					if (editorPart instanceof ITextEditor && lineNumber >= 0) {
136
						ITextEditor textEditor = (ITextEditor) editorPart;
137
						IDocumentProvider provider = textEditor.getDocumentProvider();
138
						provider.connect(editorInput);
139
						IDocument document = provider.getDocument(editorInput);
140
						try {
141
							IRegion line = document.getLineInformation(lineNumber);
142
							textEditor.selectAndReveal(line.getOffset(), line.getLength());
143
						} catch (BadLocationException e) {
144
							MessageDialog.openInformation(PlatformUI.getWorkbench()
145
									.getActiveWorkbenchWindow()
146
									.getShell(), "Open Type", "Line not found in type.");
147
						}
148
						provider.disconnect(editorInput);
149
					}
150
				} catch (CoreException e) {
151
					MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Type",
152
					"Failed to open type.");
153
				}
154
			}
155
		}
110
	}
156
	}
111
157
112
	// adapted from JavaStackTraceHyperlink
158
	// adapted from JavaStackTraceHyperlink

Return to bug 217630