Java Code Examples for org.eclipse.jface.viewers.ISelectionProvider#setSelection()
The following examples show how to use
org.eclipse.jface.viewers.ISelectionProvider#setSelection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarkOccurrencesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testMarkOccurrencesCrossFile() throws Exception { String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }"; String model2 = "Foo {}"; IFile modelFile1 = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test1.outlinetestlanguage", model1); IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test2.outlinetestlanguage", model2); IResourcesSetupUtil.waitForBuild(); XtextEditor editor = openEditor(modelFile1); ISelectionProvider selectionProvider = editor.getSelectionProvider(); selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1)); IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel) .added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3); listener.start(); annotationModel.addAnnotationModelListener(listener); setMarkOccurrences(true); listener.verify(TIMEOUT); }
Example 2
Source File: EditorSearchControls.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void modifyText(final ModifyEvent e) { boolean wrap = true; final String text = find.getText(); if (lastText.startsWith(text)) { wrap = false; } lastText = text; if (EMPTY.equals(text) || "".equals(text)) { adjustEnablement(false, null); final ISelectionProvider selectionProvider = editor.getSelectionProvider(); if (selectionProvider != null) { final ISelection selection = selectionProvider.getSelection(); if (selection instanceof TextSelection) { final ITextSelection textSelection = (ITextSelection) selection; selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0)); } } } else { find(true, true, wrap); } }
Example 3
Source File: MultiPageReportEditor.java From birt with Eclipse Public License 1.0 | 6 votes |
public void setSelection( ISelection selection ) { IEditorPart activeEditor = ( (FormEditor) getMultiPageEditor( ) ).getActivePageInstance( ); if ( activeEditor != null ) { ISelectionProvider selectionProvider = activeEditor.getSite( ) .getSelectionProvider( ); if ( selectionProvider != null ) selectionProvider.setSelection( selection ); } else { this.globalSelection = selection; fireSelectionChanged( new SelectionChangedEvent( this, globalSelection ) ); } }
Example 4
Source File: SelectionKeeper.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Restores the selection previously gotten. */ public void restoreSelection(ISelectionProvider selectionProvider, IDocument doc) { //OK, now, the start line and the end line should not change -- because the document changed, //the columns may end up being wrong, so, we must update things so that the selection stays OK. int numberOfLines = doc.getNumberOfLines(); int startLine = fixBasedOnNumberOfLines(this.startLine, numberOfLines); int endLine = fixBasedOnNumberOfLines(this.endLine, numberOfLines); final int startLineOffset = getOffset(doc, startLine); final int startLineLen = getLineLength(doc, startLine); final int startLineDelimiterLen = getLineDelimiterLen(doc, startLine); int startOffset = fixOffset(startLineOffset + startCol, startLineOffset, startLineOffset + startLineLen - startLineDelimiterLen); final int endLineOffset = getOffset(doc, endLine); final int endLineLen = getLineLength(doc, endLine); final int endLineDelimiterLen = getLineDelimiterLen(doc, endLine); int endOffset = fixOffset(endLineOffset + endCol, endLineOffset, endLineOffset + endLineLen - endLineDelimiterLen); selectionProvider.setSelection(new TextSelection(startOffset, endOffset - startOffset)); }
Example 5
Source File: MarkOccurrencesTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testMarkOccurrences() throws Exception { String model = "Foo { Bar(Foo) {} Baz(Foo Bar) {} }"; IFile modelFile = IResourcesSetupUtil.createFile("MarkOccurrencesTest/src/Test.outlinetestlanguage", model); XtextEditor editor = openEditor(modelFile); ISelectionProvider selectionProvider = editor.getSelectionProvider(); selectionProvider.setSelection(new TextSelection(0, 1)); IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); ExpectationBuilder listener = new ExpectationBuilder(editor, annotationModel).added(DECLARATION_ANNOTATION_TYPE, 0, 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3); listener.start(); annotationModel.addAnnotationModelListener(listener); setMarkOccurrences(true); listener.verify(TIMEOUT); listener.start(); listener.removed(DECLARATION_ANNOTATION_TYPE, 0, 3) .removed(OCCURRENCE_ANNOTATION_TYPE, model.indexOf("Foo", 3), 3) .removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Foo"), 3) .added(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3) .added(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3); selectionProvider.setSelection(new TextSelection(model.lastIndexOf("Bar"), 1)); listener.verify(TIMEOUT); listener.start(); listener.removed(DECLARATION_ANNOTATION_TYPE, model.indexOf("Bar"), 3).removed(OCCURRENCE_ANNOTATION_TYPE, model.lastIndexOf("Bar"), 3); setMarkOccurrences(false); listener.verify(TIMEOUT); }
Example 6
Source File: CoreEditorUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Sets the current selection for the given range. * * @param editor the editor to be operated on * @param offset the offset of the range, must not be negative * @param length the length of the range, must not be negative */ public static void setSelection(IEditorPart editor, int offset, int length) { ISelectionProvider provider = editor.getEditorSite().getSelectionProvider(); if (provider != null) { IWorkbenchPart activePart = WorkbenchUtils.getActivePart(); if (activePart instanceof IEditorPart) { IWorkbenchPage page = WorkbenchUtils.getActivePage(); page.getNavigationHistory().markLocation((IEditorPart) activePart); } provider.setSelection(new TextSelection(offset, length)); } }
Example 7
Source File: FindBarDecorator.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void modifyText(ModifyEvent e) { adjustEnablement(); if (ignore > 0 || !searchOnModifyText) { return; } IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore(); if (!preferenceStore.getBoolean(IPreferencesConstants.INCREMENTAL_SEARCH_ON_FIND_BAR)) { return; } textFind.setBackground(null); boolean wrap = true; String text = textFind.getText(); if (lastText.startsWith(text)) { wrap = false; } lastText = text; if (StringUtil.EMPTY.equals(text)) { ISelectionProvider selectionProvider = textEditor.getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); if (selection instanceof TextSelection) { ITextSelection textSelection = (ITextSelection) selection; selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0)); } } else { findBarFinder.find(true, true, wrap); } showCountTotal(); }
Example 8
Source File: FindBarDecorator.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void replace(boolean newFind) { ISelectionProvider selectionProvider = this.textEditor.getSelectionProvider(); ISelection selection = selectionProvider.getSelection(); if (!(selection instanceof ITextSelection)) { FindBarPlugin.log(new AssertionError("Expected text editor selection to be an ITextSelection. Was: " //$NON-NLS-1$ + selection)); return; } ITextSelection textSelection = (ITextSelection) selection; String comboText = textFind.getText(); if (comboText.length() == 0) { return; } setFindText(comboText); setFindTextOnReplace(getReplaceText()); selectionProvider.setSelection(new TextSelection(this.textEditor.getDocumentProvider().getDocument( this.textEditor.getEditorInput()), textSelection.getOffset(), 0)); // Do initial search before replace (always forward search as we just selected the initial offset). if (!findBarFinder.find(true, false, false)) { return; // The messages (why the find didn't work) should be set already. } try { getFindReplaceDialog().replaceSelection(getReplaceText(), getConfiguration().getRegularExpression()); showCountTotal(); } catch (Exception e1) { statusLineManager.setMessage(true, MessageFormat.format(Messages.FindBarDecorator_ReplaceError, e1.getMessage()), null); FindBarPlugin.log(e1); return; } if (newFind) { if (getConfiguration().getSearchBackward()) { findBarFinder.find(false); } else { findBarFinder.find(true); } } else { statusLineManager.setMessage(false, StringUtil.EMPTY, null); } }