當前位置: 首頁>>代碼示例>>Java>>正文


Java IViewSite.getSelectionProvider方法代碼示例

本文整理匯總了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;
}
 
開發者ID:eclipse,項目名稱:cft,代碼行數:59,代碼來源:CFUiUtil.java


注:本文中的org.eclipse.ui.IViewSite.getSelectionProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。