本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.equals方法的具體用法?Java ITextSelection.equals怎麽用?Java ITextSelection.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.equals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLine
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private static String getLine() {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IDocument doc;
int offset;
String line = "";
// If we are dealing with a text editor.
if(editor instanceof ITextEditor) {
// Get the current selection of the document (for determining what line a query is on).
ISelectionProvider selectionProvider = ((ITextEditor)editor).getSelectionProvider();
if (selectionProvider.equals(null)) return "";
ISelection selection = selectionProvider.getSelection();
if (selection.equals(null)) return "";
ITextEditor ite = (ITextEditor)editor;
if (ite.equals(null)) return "";
// Get the current document (for isolating substring of text in document using line number from selection).
doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
if (doc.equals(null)) return "";
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)selection;
try {
// Get the line number we are currently on.
if (textSelection.equals(null)) return "";
offset = textSelection.getOffset();
// Get the string on the current line and use that as the query line to be auto-completed.
if (offset > doc.getLength() || offset < 0) return "";
line = doc.get(doc.getLineOffset(doc.getLineOfOffset(offset)), doc.getLineLength(doc.getLineOfOffset(offset)));
} catch (BadLocationException e) {
System.out.println("Error with getting input query.");
e.printStackTrace();
return "";
}
}
} else {
// If we are not dealing with a text editor.
return "";
}
return line;
}
示例2: execute
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ITextEditor current_editor = (ITextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IDocument current_doc = current_editor.getDocumentProvider().getDocument(current_editor.getEditorInput());
if (!InputHandler.documents.contains(current_doc)) {
current_doc.addDocumentListener(InputHandler.qdl);
}
// Get the current active editor.
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
// If the current active editor is a text editor (i.e. not any other workbench component)
if ( part instanceof ITextEditor ) {
// Use text editor context to locate the document of the editor and get the input stream to that editor.
ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorInput() );
// Get the current selection to query on.
ISelection sel = editor.getSelectionProvider().getSelection();
if (sel instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)sel;
try {
// Get the line number we are currently on.
if (textSelection.equals(null)) return null;
int offset = textSelection.getOffset();
// Get the string on the current line and use that as the query line to be auto-completed.
if (offset > doc.getLength() || offset < 0) return null;
String text = doc.get(doc.getLineOffset(doc.getLineOfOffset(offset)), doc.getLineLength(doc.getLineOfOffset(offset)));
if (text.equals("") || text.equals(null)) return null;
boolean eol = false;
if (text.endsWith("\n")) eol = true;
String whitespace_before = text.substring(0, text.indexOf(text.trim()));
text = text.trim();
// Get the vector of URLS from the getPosts query.
Vector<String> results = Searcher.getThreads(text);
if (results.size() == 0) return null;
Vector<String> url = new Vector<String>();
for (int i=0; i<results.size(); i++) {
url.add(results.get(i));
}
// Get the accepted answer code snippet.
Vector<String> code = Searcher.getCodeSnippets(url);
if (code.size() == 0) return null;
Vector<String> fixed_code = fixSpacing(code,whitespace_before);
previous_search.clear();
previous_search = fixed_code;
previous_query = text;
// Find line length and offset to replace.
int line_num = doc.getLineOfOffset(offset);
int line_length = 0;
int line_offset = 0;
try {
line_length = doc.getLineLength(line_num);
line_offset = doc.getLineOffset(line_num);
if (eol) line_length -= 1;
} catch (BadLocationException e1) {
e1.printStackTrace();
}
// Replace the code snippet back into the document.
doc.replace(line_offset, line_length, fixed_code.get(0));
previous_offset = line_offset;
previous_length = fixed_code.get(0).length();
//Move cursor to the end of the inserted snippet.
editor.selectAndReveal(previous_offset + previous_length, 0);
doc.addDocumentListener(InputHandler.doclistener);
} catch (BadLocationException e) {
System.out.println("Error with getting input query.");
e.printStackTrace();
return null;
}
}
}
return null;
}