本文整理匯總了Java中org.eclipse.ui.IViewSite.getSelectionProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java IViewSite.getSelectionProvider方法的具體用法?Java IViewSite.getSelectionProvider怎麽用?Java IViewSite.getSelectionProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.ui.IViewSite
的用法示例。
在下文中一共展示了IViewSite.getSelectionProvider方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getServersViewSelection
import org.eclipse.ui.IViewSite; //導入方法依賴的package包/類
/**
* If the Servers view is available and it contains a selection, the
* corresponding structured selection is returned. In any other case,
* including the Servers view being unavailable, either because it is not
* installed or it is closed, null is returned.
* @return structured selection in the Servers view, if the Servers view is
* open and available, or null otherwise
*/
public static IStructuredSelection getServersViewSelection() {
IViewRegistry registry = PlatformUI.getWorkbench().getViewRegistry();
String serversViewID = SERVERS_VIEW_ID;
// fast check to verify that the servers View is available.
IViewDescriptor serversViewDescriptor = registry.find(serversViewID);
if (serversViewDescriptor != null) {
// Granular null checks required as any of the workbench components
// may not be available at some given point in time (e.g., during
// start/shutdown)
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage != null) {
IViewReference[] references = activePage.getViewReferences();
if (references != null) {
IViewPart serversViewPart = null;
for (IViewReference reference : references) {
if (serversViewID.equals(reference.getId())) {
serversViewPart = reference.getView(true);
break;
}
}
if (serversViewPart != null) {
IViewSite viewSite = serversViewPart.getViewSite();
if (viewSite != null) {
ISelectionProvider selectionProvider = viewSite.getSelectionProvider();
if (selectionProvider != null) {
ISelection selection = selectionProvider.getSelection();
if (selection instanceof IStructuredSelection) {
return (IStructuredSelection) selection;
}
}
}
}
}
}
}
}
return null;
}