|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004, 2007 Mylyn project committers and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
*******************************************************************************/ |
| 8 |
|
| 9 |
package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; |
| 10 |
|
| 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; |
| 16 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
| 17 |
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| 18 |
import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction; |
| 19 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 20 |
import org.eclipse.jface.text.IRegion; |
| 21 |
import org.eclipse.jface.text.hyperlink.IHyperlink; |
| 22 |
import org.eclipse.ui.IEditorInput; |
| 23 |
import org.eclipse.ui.PlatformUI; |
| 24 |
import org.eclipse.ui.progress.UIJob; |
| 25 |
|
| 26 |
/** |
| 27 |
* Truncated class of JavaStackTraceFileHyperlink, open a hyperlink using OpenTypeAction |
| 28 |
* |
| 29 |
* @author Rob Elves |
| 30 |
* @author Jingwe Ou |
| 31 |
*/ |
| 32 |
public class JavaResourceHyperlink implements IHyperlink { |
| 33 |
|
| 34 |
private final IRegion region; |
| 35 |
|
| 36 |
private final String typeName; |
| 37 |
|
| 38 |
public JavaResourceHyperlink(IRegion region, String typeName) { |
| 39 |
this.region = region; |
| 40 |
this.typeName = typeName; |
| 41 |
} |
| 42 |
|
| 43 |
public IRegion getHyperlinkRegion() { |
| 44 |
return region; |
| 45 |
} |
| 46 |
|
| 47 |
public String getHyperlinkText() { |
| 48 |
return "Open " + typeName; |
| 49 |
} |
| 50 |
|
| 51 |
public String getTypeLabel() { |
| 52 |
return null; |
| 53 |
} |
| 54 |
|
| 55 |
public void open() { |
| 56 |
startSourceSearch(typeName); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Starts a search for the type with the given name. Reports back to 'searchCompleted(...)'. |
| 61 |
* |
| 62 |
* @param typeName |
| 63 |
* the type to search for |
| 64 |
*/ |
| 65 |
protected void startSourceSearch(final String typeName) { |
| 66 |
Job search = new Job("Searching...") { |
| 67 |
@Override |
| 68 |
protected IStatus run(IProgressMonitor monitor) { |
| 69 |
try { |
| 70 |
// search for the type in the workspace |
| 71 |
Object result = OpenTypeAction.findTypeInWorkspace(typeName); |
| 72 |
searchCompleted(result, typeName, null); |
| 73 |
} catch (CoreException e) { |
| 74 |
searchCompleted(null, typeName, e.getStatus()); |
| 75 |
} |
| 76 |
return Status.OK_STATUS; |
| 77 |
} |
| 78 |
|
| 79 |
}; |
| 80 |
search.schedule(); |
| 81 |
} |
| 82 |
|
| 83 |
protected void searchCompleted(final Object source, final String typeName, final IStatus status) { |
| 84 |
UIJob job = new UIJob("link search complete") { //$NON-NLS-1$ |
| 85 |
@Override |
| 86 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
| 87 |
if (source == null) { |
| 88 |
// did not find source |
| 89 |
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 90 |
"Open Type", "Type could not be located."); |
| 91 |
} else { |
| 92 |
processSearchResult(source, typeName); |
| 93 |
} |
| 94 |
return Status.OK_STATUS; |
| 95 |
} |
| 96 |
}; |
| 97 |
job.setSystem(true); |
| 98 |
job.schedule(); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* The search succeeded with the given result |
| 103 |
* |
| 104 |
* @param source |
| 105 |
* resolved source object for the search |
| 106 |
* @param typeName |
| 107 |
* type name searched for |
| 108 |
*/ |
| 109 |
protected void processSearchResult(Object source, String typeName) { |
| 110 |
IDebugModelPresentation presentation = JDIDebugUIPlugin.getDefault().getModelPresentation(); |
| 111 |
IEditorInput editorInput = presentation.getEditorInput(source); |
| 112 |
if (editorInput != null) { |
| 113 |
String editorId = presentation.getEditorId(editorInput, source); |
| 114 |
if (editorId != null) { |
| 115 |
try { |
| 116 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, |
| 117 |
editorId); |
| 118 |
|
| 119 |
} catch (CoreException e) { |
| 120 |
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
| 121 |
"Open Type", "Failed to open type."); |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |