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


Java IEditorSite.getSelectionProvider方法代碼示例

本文整理匯總了Java中org.eclipse.ui.IEditorSite.getSelectionProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java IEditorSite.getSelectionProvider方法的具體用法?Java IEditorSite.getSelectionProvider怎麽用?Java IEditorSite.getSelectionProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.ui.IEditorSite的用法示例。


在下文中一共展示了IEditorSite.getSelectionProvider方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setStatusLineMessage

import org.eclipse.ui.IEditorSite; //導入方法依賴的package包/類
/**
 * Tries to set the given message on the workbench's status line. This is a
 * best effort method which fails to set the status line if there is no
 * active editor present from where the statuslinemanager can be looked up.
 * 
 * @param msg
 *            The message to be shown on the status line
 */
public static void setStatusLineMessage(final String msg) {
	IStatusLineManager statusLineManager = null;
	ISelectionProvider selectionService = null;

	// First try to get the StatusLineManager from the IViewPart and only
	// resort back to the editor if a view isn't active right now.
	final IWorkbenchPart workbenchPart = getActiveWindow().getActivePage().getActivePart();
	if (workbenchPart instanceof IViewPart) {
		final IViewPart viewPart = (IViewPart) workbenchPart;
		statusLineManager = viewPart.getViewSite().getActionBars().getStatusLineManager();
		selectionService = viewPart.getViewSite().getSelectionProvider();
	} else if (getActiveEditor() != null) {
		final IEditorSite editorSite = getActiveEditor().getEditorSite();
		statusLineManager = editorSite.getActionBars().getStatusLineManager();
		selectionService = editorSite.getSelectionProvider();
	}

	if (statusLineManager != null && selectionService != null) {
		statusLineManager.setMessage(msg);
		selectionService.addSelectionChangedListener(new StatusLineMessageEraser(statusLineManager,
				selectionService));
	}
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:32,代碼來源:UIHelper.java

示例2: run

import org.eclipse.ui.IEditorSite; //導入方法依賴的package包/類
/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
	try {
		// get editor
		IEditorPart editorPart = VariantSyncPlugin.getDefault()
				.getWorkbench().getActiveWorkbenchWindow().getActivePage()
				.getActiveEditor();

		if (editorPart instanceof AbstractTextEditor) {
			int offset = 0;
			int length = 0;
			String selectedText = null;
			IEditorSite iEditorSite = editorPart.getEditorSite();
			if (iEditorSite != null) {
				// get selection provider
				ISelectionProvider selectionProvider = iEditorSite
						.getSelectionProvider();
				if (selectionProvider != null) {
					ISelection iSelection = selectionProvider
							.getSelection();
					// offset
					offset = ((ITextSelection) iSelection).getOffset();
					if (!iSelection.isEmpty()) {
						selectedText = ((ITextSelection) iSelection)
								.getText();
						// length
						length = ((ITextSelection) iSelection).getLength();
						MessageDialog.openInformation(shell,
								"Do Something Menu", "Length: " + length
										+ "    Offset: " + offset + "\n"
										+ "Content: " + selectedText);
					}
				}
			}

		}
	} catch (Exception e) {
	}
}
 
開發者ID:1Tristan,項目名稱:VariantSync,代碼行數:42,代碼來源:CodeEditorAction.java

示例3: handleSelection

import org.eclipse.ui.IEditorSite; //導入方法依賴的package包/類
@Override
protected void handleSelection(String feature) {
	IEditorPart editorPart = VariantSyncPlugin.getDefault().getWorkbench()
			.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	if (editorPart instanceof AbstractTextEditor) {
		int startLine = 0;
		int endLine = 0;
		int offset = 0;
		int length = 0;
		String selectedText = null;
		IEditorSite iEditorSite = editorPart.getEditorSite();
		if (iEditorSite != null) {
			ISelectionProvider selectionProvider = iEditorSite
					.getSelectionProvider();
			if (selectionProvider != null) {
				ISelection iSelection = selectionProvider.getSelection();
				if (!iSelection.isEmpty()) {
					selectedText = ((ITextSelection) iSelection).getText();
					startLine = ((ITextSelection) iSelection)
							.getStartLine();
					endLine = ((ITextSelection) iSelection).getEndLine();
					offset = ((ITextSelection) iSelection).getOffset();
					length = ((ITextSelection) iSelection).getLength();
					String title = iEditorSite.getPage().getActiveEditor()
							.getTitle();
					IFile file = (IFile) editorPart.getEditorInput()
							.getAdapter(IFile.class);
					IPath path = file.getRawLocation().makeAbsolute();
					// MarkerInformation mi = new MarkerInformation(0,
					// startLine, endLine, offset, length);
					// IMarker marker = null;
					try {
						CodeMarkerFactory.createMarker(String.valueOf(0),
								file, offset, offset + length, feature,
								CodeHighlighting.YELLOW);
					} catch (CoreException e) {
						e.printStackTrace();
					}
					// System.out
					// .println("\nOOOOOOOOOOOOOOOO OFFSET OOOOOOOOOOOOOOOO = "
					// + offset + ", " + length);
					// MarkerHandler.getInstance().addMarker(mi, marker,
					// file,
					// feature);

					controller.addFeatureMapping(feature, title,
							JavaElements.CODE_FRAGMENT, path, selectedText,
							startLine, endLine, offset);
				}
			}
		}

	}
}
 
開發者ID:1Tristan,項目名稱:VariantSync,代碼行數:55,代碼來源:CodeEditorMapping.java


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