本文整理匯總了Java中org.eclipse.jface.text.TextSelection.getOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java TextSelection.getOffset方法的具體用法?Java TextSelection.getOffset怎麽用?Java TextSelection.getOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.TextSelection
的用法示例。
在下文中一共展示了TextSelection.getOffset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: commentSelection
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public void commentSelection(TextSelection selection, IDocument doc){
if (selection.getLength() > 0) {
try {
int offset;
offset = selection.getOffset();
doc.replace(offset, 0, commentBegin);
offset += selection.getLength() + commentBegin.length();
doc.replace(offset, 0, commentEnd);
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
}
示例2: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
markSpec = getMark();
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
editor = (FluentMkEditor) edPart;
doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
cpos = editor.getCursorOffset();
if (len == 0) beg = cpos;
try {
if (samePartition(beg, len)) {
toggle(beg, len);
}
} catch (BadLocationException e) {}
}
}
}
return null;
}
示例3: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart edPart = HandlerUtil.getActiveEditor(event);
if (edPart instanceof FluentMkEditor) {
FluentMkEditor editor = (FluentMkEditor) edPart;
IDocument doc = editor.getDocument();
if (doc != null) {
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof TextSelection) {
TextSelection tsel = (TextSelection) sel;
int beg = tsel.getOffset();
int len = tsel.getLength();
switch (checkPartition(doc, beg, len)) {
case NONE:
addComment(doc, beg, len);
break;
case SAME:
removeComment(doc, beg);
break;
}
}
}
}
return null;
}
示例4: run
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void run() {
IXtextDocument document = editor.getDocument();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
TextSelection textSelection = (TextSelection) selection;
if (textSelection.getLength()==0) {
IRegion region = matcher.match(document, textSelection.getOffset());
if (region != null) {
if (region.getOffset()+1==textSelection.getOffset()) {
editor.selectAndReveal(region.getOffset()+region.getLength(),0);
} else {
editor.selectAndReveal(region.getOffset()+1,0);
}
}
}
}
}
示例5: setSelectedElementField
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
protected void setSelectedElementField() {
ISelectionProvider selectionProvider = getSelectionProvider();
if(selectionProvider == null) {
return; // Can happen during dispose
}
ISelection selection = selectionProvider.getSelection();
if(selection instanceof TextSelection) {
TextSelection textSelection = (TextSelection) selection;
int caretOffset = textSelection.getOffset();
SourceFileStructure structure;
try {
structure = getSourceStructure();
} catch(CommonException e) {
return;
}
if(structure != null) {
StructureElement selectedElement = structure.getStructureElementAt(caretOffset);
selectedElementField.setFieldValue(selectedElement);
}
}
}
示例6: getCurrentKey
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public String getCurrentKey() {
ITextEditor textEditor = getEditor();
if (textEditor.getSelectionProvider().getSelection() instanceof TextSelection) {
TextSelection selection = (TextSelection) textEditor.getSelectionProvider().getSelection();
int selectionStart = selection.getOffset();
String content = getContent();
int start = 0, end = 0;
// Extract the bounds of the line containing the selection
for (start = selectionStart; start > 0 && content.charAt(start-1) != '\n'; start--);
for (end = start; end < content.length()-1 && content.charAt(end+1) != '=' && content.charAt(end+1) != '\n'; end++);
String line = content.substring(start, end+1).trim();
return line;
}
return null;
}
示例7: formatAndBoxComment
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
private void formatAndBoxComment()
throws org.eclipse.jface.text.BadLocationException {
if (formatComment()) {
// Need to recompute things that were changed by executing
// formatComment.
text = doc.get();
selection = (TextSelection) selectionProvider.getSelection();
offset = selection.getOffset();
boxComment();
}
return;
}
示例8: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if ( editor instanceof AtlEditorExt ) {
AtlEditorExt atlEditor = (AtlEditorExt) editor;
IFile file = (IFile) atlEditor.getUnderlyingResource();
AnalysisResult r = AnalysisIndex.getInstance().getAnalysisOrLoad(file);
if ( r == null )
return null;
ISelection s = HandlerUtil.getCurrentSelection(event);
if ( s instanceof TextSelection ) {
TextSelection ts = (TextSelection) s;
int offset = ts.getOffset();
IDocument doc = atlEditor.getViewer().getDocument();
LocatedElement found = WorkbenchUtil.getElementFromOffset(offset, r.getATLModel(), doc);
if ( found != null ) {
Binding binding = ATLUtils.getContainer(found, Binding.class);
MatchedRule mr = ATLUtils.getContainer(found, MatchedRule.class);
if ( binding != null ) {
showDialog(HandlerUtil.getActiveShell(event), binding, r);
} else if ( mr != null ){
showDialog(HandlerUtil.getActiveShell(event), mr, r);
}
}
}
}
return null;
}
示例9: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public @Nullable Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
if (!(editorPart instanceof RustEditor)) {
return null;
}
RustEditor editor = (RustEditor) editorPart;
TextSelection sel = (TextSelection) editor.getSelectionProvider().getSelection();
int startLine = sel.getStartLine();
Optional<IDocument> docOpt = editor.getDocumentOpt();
if (!docOpt.isPresent()) {
return null;
}
IDocument doc = docOpt.get();
try {
int startOffset = doc.getLineOffset(startLine);
int endOffset = sel.getOffset() + sel.getLength();
int len = endOffset - startOffset;
String text = doc.get(startOffset, len);
if (text.matches("^(//(.*)(\\r?\\n|\\r))*//.*$")) {
// remove comments
text = text.substring(2).replaceAll("(\\r?\\n|\\r)//", "$1");
} else {
// add comments
text = "//" + text.replaceAll("(\\r?\\n|\\r)", "$1//");
}
doc.replace(startOffset, len, text);
// select new text
editor.selectAndReveal(startOffset, text.length());
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return null;
}
示例10: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public Object execute(ExecutionEvent event) throws ExecutionException {
TLAEditor editor;
editor = EditorUtil.getTLAEditorWithFocus();
// gets the editor to which command applies
if (editor == null) {
return null;
}
doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
text = doc.get();
selectionProvider = editor.getSelectionProvider();
selection = (TextSelection) selectionProvider.getSelection();
offset = selection.getOffset();
RightMargin = Activator.getDefault().getPreferenceStore().getInt(
EditorPreferencePage.EDITOR_RIGHT_MARGIN);
if (offset < 0) {
return null;
}
try {
lineInfo = doc.getLineInformationOfOffset(offset);
String cmd = event.getCommand().getId();
if (cmd.equals(startBoxedCommentId)) {
startBoxedComment();
} else if (cmd.equals(boxCommentId)) {
boxComment();
} else if (cmd.equals(formatAndBoxCommentId)) {
formatAndBoxComment();
} else if (cmd.equals(unboxCommentId)) {
unboxComment();
} else if (cmd.equals(formatCommentId)) {
formatComment();
} else {
Activator.getDefault().logInfo("Unrecognized boxing command.");
}
} catch (org.eclipse.jface.text.BadLocationException e) {
Activator.getDefault().logError("Error executing comment-boxing command", e);
// just do nothing
}
// free the space. (Probably not worth doing.)
doc = null;
text = null;
selectionProvider = null;
selection = null;
lineInfo = null;
return null;
}
示例11: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public Object execute(ExecutionEvent event) throws ExecutionException
{ TLAEditor editor ;
editor = EditorUtil.getTLAEditorWithFocus() ; // gets the editor to which command applies
if (editor == null) {
return null;
}
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); // gets document being edited.
selectionProvider = editor.getSelectionProvider() ;
TextSelection selection = (TextSelection) selectionProvider.getSelection();
offset = selection.getOffset();
if (offset < 0){
return null;
}
try {
lineInfo = doc.getLineInformationOfOffset(offset);
String cmd = event.getCommand().getId();
int repeatVal =
CommandPrefixDigitHandler.getAndResetRepeatValue(editor);
while (repeatVal > 0)
{
repeatVal-- ;
if (cmd.equals(charRightId))
{
charRight();
} else if (cmd.equals(charLeftId))
{
charLeft();
} else
{
System.out.println("Unrecognized command.");
System.out.println(cmd);
}
}
} catch (org.eclipse.jface.text.BadLocationException e) {
return null;
}
return null;
}
示例12: execute
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
.getNCLEditor();
TextSelection selection = (TextSelection) editor.getSelectionProvider()
.getSelection();
IDocument doc = editor.getInputDocument();
String commentBegin = "<!--";
String commentEnd = "-->";
// TODO: Check if the line is already commented. If it is uncomment the
// line(off
if (selection.getLength() > 0) {
try {
int offset;
int line = selection.getStartLine();
offset = doc.getLineOffset(line);
String rest = doc.get(offset, selection.getOffset() - offset);
int index = rest.indexOf(commentBegin);
if (index != -1){
doc.replace(offset + index, commentBegin.length(), "");
line = selection.getEndLine();
offset = doc.getLineOffset(line) + doc.getLineLength(line);
rest = doc.get (selection.getOffset() + selection.getLength() -
commentBegin.length(), offset);
index = rest.indexOf(commentEnd);
if (index != -1)
doc.replace(selection.getOffset() + selection.getLength() -
commentBegin.length() + index, commentEnd.length(), "");
return null;
}
offset = selection.getOffset();
doc.replace(offset, 0, commentBegin);
offset += selection.getLength() + commentBegin.length();
doc.replace(offset, 0, commentEnd);
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
return null;
}
示例13: run
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@Override
public void run(IAction action) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
NCLEditor editor = ((NCLMultiPageEditor) page.getActiveEditor())
.getNCLEditor();
TextSelection selection = (TextSelection) editor.getSelectionProvider()
.getSelection();
IDocument doc = editor.getInputDocument();
String commentBegin = "<!--";
String commentEnd = "-->";
int startLine = selection.getStartLine();
int endLine = selection.getEndLine();
if (selection.getLength() > 0) {
try {
int offset;
offset = selection.getOffset();
IRegion region = doc.getLineInformationOfOffset(offset);
String text = doc.get(doc.getLineOffset(startLine), offset - region.getOffset());
int index = text.lastIndexOf(commentBegin);
if (index != -1)
doc.replace(doc.getLineOffset(startLine) + index, commentBegin.length(), "");
else{
text = selection.getText();
index = text.indexOf(commentBegin);
doc.replace(offset + index, commentBegin.length(), "");
}
offset += selection.getLength();
region = doc.getLineInformationOfOffset(offset);
text = doc.get(offset, doc.getLineLength(endLine) - (offset - region.getOffset()) );
index = text.indexOf(commentEnd);
if (index != -1)
doc.replace(offset, commentEnd.length(), "");
else{
text = selection.getText();
index = text.lastIndexOf(commentEnd);
if (index != -1)
doc.replace(selection.getOffset() + index, commentEnd.length(), "");
}
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
// TODO: Comment the range!
System.out.println("Comment the range!");
}
return;
}
示例14: run
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
@SuppressWarnings("restriction")
@Override
public void run(IAction action) {
TextSelection textSelection = CodeMarkerFactory.getTextSelection();
TreeSelection treeSelection = CodeMarkerFactory.getTreeSelection();
MappingElement map = null;
if (textSelection != null) {
IFile file = (IFile) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getActiveEditor().getEditorInput().getAdapter(IFile.class);
int startLine = textSelection.getStartLine();
int endLine = textSelection.getEndLine();
int offset = textSelection.getOffset();
MarkerHandler.getInstance().removeMarker(file, startLine, endLine);
map = new MappingElement("", file.getName(),
JavaElements.CODE_FRAGMENT, file.getFullPath().toString(),
textSelection.getText(), startLine, endLine, offset);
} else if (treeSelection != null) {
String elementName;
IPath elementPath;
JavaElements elementType = null;
IProject project;
Object selectedElement = treeSelection.getFirstElement();
IJavaProject javaProject = null;
org.eclipse.jdt.internal.core.JavaElement element = null;
if (selectedElement instanceof org.eclipse.jdt.internal.core.PackageFragment) {
element = ((org.eclipse.jdt.internal.core.PackageFragment) treeSelection
.getFirstElement());
elementType = JavaElements.PACKAGE;
IJavaElement[] children = null;
try {
children = element.getChildren();
} catch (JavaModelException e1) {
e1.printStackTrace();
}
for (IJavaElement child : children) {
deleteMarkersOfFile(child.getResource());
}
} else if (selectedElement instanceof org.eclipse.jdt.internal.core.CompilationUnit) {
element = ((org.eclipse.jdt.internal.core.CompilationUnit) treeSelection
.getFirstElement());
elementType = JavaElements.CLASS;
deleteMarkersOfFile(element.getResource());
} else if (selectedElement instanceof org.eclipse.jdt.internal.core.SourceType) {
element = ((org.eclipse.jdt.internal.core.SourceType) treeSelection
.getFirstElement());
elementType = JavaElements.CLASS;
deleteMarkersOfFile(element.getResource());
} else if (selectedElement instanceof org.eclipse.jdt.internal.core.SourceMethod) {
element = ((org.eclipse.jdt.internal.core.SourceMethod) treeSelection
.getFirstElement());
elementType = JavaElements.METHOD;
// not yet implemented
}
javaProject = element.getJavaProject();
elementPath = element.getPath();
elementName = element.getElementName();
project = javaProject.getProject();
map = new MappingElement("", elementName, elementType,
elementPath.toString(), project.getLocation().toFile()
.getAbsolutePath());
}
ControllerHandler.getInstance().getFeatureController()
.removeMapping(map);
}
示例15: getSelectionSR
import org.eclipse.jface.text.TextSelection; //導入方法依賴的package包/類
public static SourceRange getSelectionSR(ITextEditor editor) {
TextSelection sel = getSelection(editor);
return new SourceRange(sel.getOffset(), sel.getLength());
}