下面列出了怎么用org.eclipse.ui.part.IShowInTarget的API类实例代码及写法,或者点击链接到github查看源代码。
public Object getAdapter(Class key) {
if (key == IShowInSource.class) {
return getShowInSource();
}
if (key == IShowInTargetList.class) {
return new IShowInTargetList() {
public String[] getShowInTargetIds() {
return new String[] { JavaUI.ID_PACKAGES };
}
};
}
if (key == IShowInTarget.class) {
return getShowInTarget();
}
return null;
}
/**
* Returns the <code>IShowInTarget</code> for this view.
*
* @return the {@link IShowInTarget}
*/
protected IShowInTarget getShowInTarget() {
return new IShowInTarget() {
public boolean show(ShowInContext context) {
ISelection sel= context.getSelection();
if (sel instanceof ITextSelection) {
ITextSelection tsel= (ITextSelection) sel;
int offset= tsel.getOffset();
IJavaElement element= fEditor.getElementAt(offset);
if (element != null) {
setSelection(new StructuredSelection(element));
return true;
}
} else if (sel instanceof IStructuredSelection) {
setSelection(sel);
return true;
}
return false;
}
};
}
protected IShowInTarget getShowInTarget() {
return new IShowInTarget() {
@Override
public boolean show(ShowInContext context) {
StructureElement structureElement = getStructureElementFor(context.getSelection());
if(structureElement != null) {
setSelection(new StructuredSelection(structureElement));
return true;
}
return false;
}
};
}
/**
* Opens the editor for the file located at the given path and reveal the selection.
*
* @param path
* @param selection
*/
public static void openAndReveal(IPath path, ISelection selection) {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IFile file = root.getFile(path);
final IEditorPart editor = openEditor(file);
if (editor instanceof IShowInTarget) {
IShowInTarget showIn = (IShowInTarget) editor;
showIn.show(new ShowInContext(null, selection));
}
}
@Override
public Object getAdapter(Class adapter) {
if (adapter == IShowInTarget.class) {
return this;
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if(adapter == IShowInTarget.class) {
return (T) getShowInTarget();
}
return null;
}
public JsonContentOutlinePage(IDocumentProvider documentProvider, IShowInTarget showInTarget) {
super();
this.documentProvider = documentProvider;
this.showInTarget = showInTarget;
}