本文整理汇总了Java中org.eclipse.jface.text.ITextSelection.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ITextSelection.isEmpty方法的具体用法?Java ITextSelection.isEmpty怎么用?Java ITextSelection.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.isEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
public void run()
{
VelocityEditor editor = (VelocityEditor) getTextEditor();
if (editor.fMouseListener.fActiveRegion != null)
{
// If the user is using the ctrl-alt mouse click feature, then
// goto the definition under the mouse, and not under the current cursor location
editor.gotoDefinition(editor.fMouseListener.fActiveRegion);
return;
}
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
if (!selection.isEmpty())
{
editor.gotoDefinition(new Region(selection.getOffset(), selection.getLength()));
}
}
示例2: isValidSelection
import org.eclipse.jface.text.ITextSelection; //导入方法依赖的package包/类
/**
* Returns if the current selection is valid, i.e. whether it is empty and
* the caret in the whitespace at the start of a line, or covers multiple
* lines.
*
* @return <code>true</code> if the selection is valid for an indent
* operation
*/
private boolean isValidSelection() {
ITextSelection selection = getSelection();
if (selection.isEmpty())
return false;
int offset = selection.getOffset();
int length = selection.getLength();
IDocument document = getDocument();
if (document == null)
return false;
try {
IRegion firstLine = document.getLineInformationOfOffset(offset);
int lineOffset = firstLine.getOffset();
// either the selection has to be empty and the caret in the WS at
// the line start
// or the selection has to extend over multiple lines
if (length == 0)
return document.get(lineOffset, offset - lineOffset).trim().length() == 0;
else
// return lineOffset + firstLine.getLength() < offset + length;
return false; // only enable for empty selections for now
} catch (BadLocationException e) {
}
return false;
}