本文整理汇总了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));
}
}
示例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) {
}
}
示例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);
}
}
}
}
}