Java Code Examples for org.eclipse.jface.viewers.ISelectionProvider#getSelection()
The following examples show how to use
org.eclipse.jface.viewers.ISelectionProvider#getSelection() .
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: OpenViewActionGroup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void initialize(ISelectionProvider provider) { fSelectionProvider= provider; ISelection selection= provider.getSelection(); fOpenImplementation.update(selection); fOpenSuperImplementation.update(selection); fOpenAttachedJavadoc.update(selection); fOpenTypeHierarchy.update(selection); fOpenCallHierarchy.update(selection); if (!fEditorIsOwner) { if (fShowOpenPropertiesAction) { if (selection instanceof IStructuredSelection) { fOpenPropertiesDialog.selectionChanged((IStructuredSelection) selection); } else { fOpenPropertiesDialog.selectionChanged(selection); } } provider.addSelectionChangedListener(fOpenImplementation); provider.addSelectionChangedListener(fOpenSuperImplementation); provider.addSelectionChangedListener(fOpenAttachedJavadoc); provider.addSelectionChangedListener(fOpenTypeHierarchy); provider.addSelectionChangedListener(fOpenCallHierarchy); // no need to register the open properties dialog action since it registers itself } }
Example 2
Source File: OpenAnalysisHelpHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is a trace fAnalysis = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfAnalysisElement) { fAnalysis = (TmfAnalysisElement) element; } } return (fAnalysis != null); }
Example 3
Source File: OpenExperimentHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { // Check if we are closing down final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfExperimentElement) { fExperiment = (TmfExperimentElement) element; } } // We only enable opening from the Traces folder for now return ((fExperiment != null) && (!fExperiment.getTraces().isEmpty())); }
Example 4
Source File: SurroundWithActionGroup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * The Menu to show when right click on the editor * {@inheritDoc} */ @Override public void fillContextMenu(IMenuManager menu) { ISelectionProvider selectionProvider= fEditor.getSelectionProvider(); if (selectionProvider == null) return; ISelection selection= selectionProvider.getSelection(); if (!(selection instanceof ITextSelection)) return; ITextSelection textSelection= (ITextSelection)selection; if (textSelection.getLength() == 0) return; String menuText= ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTemplateSubMenuName; MenuManager subMenu = new MenuManager(menuText, SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID); subMenu.setActionDefinitionId(SurroundWithTemplateMenuAction.SURROUND_WITH_QUICK_MENU_ACTION_ID); menu.appendToGroup(fGroup, subMenu); subMenu.add(new Action() {}); subMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { manager.removeAll(); SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction, fSurroundWithTryMultiCatchAction); } }); }
Example 5
Source File: OccurrencesSearchGroup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new <code>OccurrencesSearchGroup</code>. The group requires * that the selection provided by the given selection provider is of type * {@link IStructuredSelection}. * * @param site the site that will own the action group. * @param specialSelectionProvider the selection provider used instead of the * sites selection provider. * * @since 3.4 */ public OccurrencesSearchGroup(IWorkbenchSite site, ISelectionProvider specialSelectionProvider) { fSite= site; fGroupId= IContextMenuConstants.GROUP_SEARCH; fOccurrencesInFileAction= new FindOccurrencesInFileAction(site); fOccurrencesInFileAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE); // Need to reset the label fOccurrencesInFileAction.setText(SearchMessages.Search_FindOccurrencesInFile_shortLabel); fExceptionOccurrencesAction= new FindExceptionOccurrencesAction(site); fExceptionOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE); fFindImplementorOccurrencesAction= new FindImplementOccurrencesAction(site); fFindImplementorOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE); fBreakContinueTargetOccurrencesAction= new FindBreakContinueTargetOccurrencesAction(site); fBreakContinueTargetOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_BREAK_CONTINUE_TARGET_OCCURRENCES); fMethodExitOccurrencesAction= new FindMethodExitOccurrencesAction(site); fMethodExitOccurrencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_METHOD_EXIT_OCCURRENCES); // register the actions as selection listeners ISelectionProvider provider= specialSelectionProvider == null ? fSite.getSelectionProvider() : specialSelectionProvider; ISelection selection= provider.getSelection(); registerAction(fOccurrencesInFileAction, provider, selection, specialSelectionProvider); registerAction(fExceptionOccurrencesAction, provider, selection, specialSelectionProvider); registerAction(fFindImplementorOccurrencesAction, provider, selection, specialSelectionProvider); registerAction(fBreakContinueTargetOccurrencesAction, provider, selection, specialSelectionProvider); registerAction(fMethodExitOccurrencesAction, provider, selection, specialSelectionProvider); }
Example 6
Source File: SelectionDispatchAction.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public ISelection getSelection() { ISelectionProvider selectionProvider= getSelectionProvider(); if (selectionProvider != null) return selectionProvider.getSelection(); else return null; }
Example 7
Source File: RenumberProofHandler.java From tlaplus with MIT License | 5 votes |
private boolean setFields(boolean reallySet) { // The following code copied with minor modifications from BoxedCommentHandler TLAEditor editor; editor = EditorUtil.getTLAEditorWithFocus(); // gets the editor to which command applies if (editor == null) { return false; } IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); String text = doc.get(); ISelectionProvider selectionProvider = editor.getSelectionProvider(); TextSelection selection = (TextSelection) selectionProvider.getSelection(); TheoremNode node = EditorUtil.getCurrentTheoremNode(); if (node == null) { return false; } ProofNode pf = node.getProof(); if (pf instanceof NonLeafProofNode) { pfNode = (NonLeafProofNode) pf; } else { return false; } if (reallySet) { this.doc = doc; this.text = text; this.selectionProvider = selectionProvider; this.selection = selection; this.node = node; } return true; }
Example 8
Source File: ProjectActionGroup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new <code>ProjectActionGroup</code>. The group requires * that the selection provided by the given selection provider is of type * {@link IStructuredSelection}. * * @param site the site that will own the action group. * @param selectionProvider the selection provider used instead of the * page selection provider. * * @since 3.4 */ public ProjectActionGroup(IWorkbenchSite site, ISelectionProvider selectionProvider) { fSelectionProvider= selectionProvider; ISelection selection= selectionProvider.getSelection(); fCloseAction= new CloseResourceAction(site); fCloseAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_CLOSE_PROJECT); fCloseUnrelatedAction= new CloseUnrelatedProjectsAction(site); fCloseUnrelatedAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_CLOSE_UNRELATED_PROJECTS); fOpenAction= new OpenProjectAction(site); fOpenAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_OPEN_PROJECT); if (selection instanceof IStructuredSelection) { IStructuredSelection s= (IStructuredSelection)selection; fOpenAction.selectionChanged(s); fCloseAction.selectionChanged(s); fCloseUnrelatedAction.selectionChanged(s); } fSelectionChangedListener= new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection s= event.getSelection(); if (s instanceof IStructuredSelection) { performSelectionChanged((IStructuredSelection) s); } } }; selectionProvider.addSelectionChangedListener(fSelectionChangedListener); IWorkspace workspace= ResourcesPlugin.getWorkspace(); workspace.addResourceChangeListener(fOpenAction); workspace.addResourceChangeListener(fCloseAction); workspace.addResourceChangeListener(fCloseUnrelatedAction); }
Example 9
Source File: EditorUtil.java From tlaplus with MIT License | 5 votes |
/** * If there is currently a TLAEditor with focus, * and that editor is unmodified and is currently parsed, * and its cursor is "at" a TheoremNode, then it returns * that TheoremNode. Otherwise, it returns null. */ public static TheoremNode getCurrentTheoremNode() { // get editor and return null if it doesn't exist or // is dirty. TLAEditor editor = getTLAEditorWithFocus(); if ((editor == null) || (editor.isDirty())) { return null; } ISelectionProvider selectionProvider = editor.getSelectionProvider(); Assert.isNotNull(selectionProvider, "Active editor does not have a selection provider. This is a bug."); ISelection selection = selectionProvider.getSelection(); if (!(selection instanceof ITextSelection)) { return null; } ITextSelection textSelection = (ITextSelection) selection; IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); // check if editor's file is currently parsed. if (editor.getEditorInput() instanceof FileEditorInput) { IFile file = ((FileEditorInput) editor.getEditorInput()).getFile(); String moduleName = ResourceHelper.getModuleName(file); ParseResult parseResult = ResourceHelper.getValidParseResult(file); return ResourceHelper.getTheoremNodeWithCaret(parseResult, moduleName, textSelection, document); } return null; }
Example 10
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 5 votes |
/** * Returns the line base selection values for the given editor part. * * <p>The given editor part must not be <code>null</code>. * * @param editorPart the editorPart for which to get the text selection * @return the line base selection values for the given editor part or {@link * TextSelection#EMPTY_SELECTION} if the given editor part is is <code>null</code> or not a * text editor, the editor does not have a valid selection provider or document provider, a * valid IDocument could not be obtained form the document provider, or the correct line * numbers or in-lin offsets could not be calculated */ public static TextSelection getSelection(IEditorPart editorPart) { if (!(editorPart instanceof ITextEditor)) { return TextSelection.EMPTY_SELECTION; } ITextEditor textEditor = (ITextEditor) editorPart; ISelectionProvider selectionProvider = textEditor.getSelectionProvider(); if (selectionProvider == null) { return TextSelection.EMPTY_SELECTION; } IDocumentProvider documentProvider = textEditor.getDocumentProvider(); if (documentProvider == null) { return TextSelection.EMPTY_SELECTION; } IDocument document = documentProvider.getDocument(editorPart.getEditorInput()); if (document == null) { return TextSelection.EMPTY_SELECTION; } ITextSelection textSelection = (ITextSelection) selectionProvider.getSelection(); int offset = textSelection.getOffset(); int length = textSelection.getLength(); return calculateSelection(document, offset, length); }
Example 11
Source File: AbstractSearchIndexResultPage.java From Pydev with Eclipse Public License 1.0 | 5 votes |
public Object getAdapter(Class<?> adapter) { if (IShowInTargetList.class.equals(adapter)) { return SHOW_IN_TARGET_LIST; } if (adapter == IShowInSource.class) { ISelectionProvider selectionProvider = getSite().getSelectionProvider(); if (selectionProvider == null) { return null; } ISelection selection = selectionProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = ((StructuredSelection) selection); final Set<Object> newSelection = new HashSet<>(structuredSelection.size()); Iterator<?> iter = structuredSelection.iterator(); while (iter.hasNext()) { Object element = iter.next(); if (element instanceof ICustomLineElement) { element = ((ICustomLineElement) element).getParent(); } newSelection.add(element); } return new IShowInSource() { @Override public ShowInContext getShowInContext() { return new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection))); } }; } return null; } return null; }
Example 12
Source File: ShowActionGroup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void initialize(IWorkbenchSite site, boolean isJavaEditor) { fSite= site; ISelectionProvider provider= fSite.getSelectionProvider(); ISelection selection= provider.getSelection(); fShowInPackagesViewAction.update(selection); if (!isJavaEditor) { provider.addSelectionChangedListener(fShowInPackagesViewAction); } }
Example 13
Source File: ReferencesSearchGroup.java From typescript.java with MIT License | 5 votes |
/** * Creates a new <code>ReferencesSearchGroup</code>. The group requires that * the selection provided by the site's selection provider is of type <code> * org.eclipse.jface.viewers.IStructuredSelection</code>. * * @param site * the view part that owns this action group */ public ReferencesSearchGroup(IWorkbenchSite site) { fSite = site; fGroupId = IContextMenuConstants.GROUP_SEARCH; // fFindReferencesAction= new FindReferencesAction(site); // fFindReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKSPACE); fFindReferencesInProjectAction = new FindReferencesInProjectAction(site); fFindReferencesInProjectAction .setActionDefinitionId(ITypeScriptEditorActionDefinitionIds.SEARCH_REFERENCES_IN_PROJECT); // fFindReferencesInHierarchyAction= new // FindReferencesInHierarchyAction(site); // fFindReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_HIERARCHY); // fFindReferencesInWorkingSetAction= new // FindReferencesInWorkingSetAction(site); // fFindReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_REFERENCES_IN_WORKING_SET); // register the actions as selection listeners ISelectionProvider provider = fSite.getSelectionProvider(); ISelection selection = provider.getSelection(); // registerAction(fFindReferencesAction, provider, selection); registerAction(fFindReferencesInProjectAction, provider, selection); // registerAction(fFindReferencesInHierarchyAction, provider, // selection); // registerAction(fFindReferencesInWorkingSetAction, provider, // selection); }
Example 14
Source File: RefactorActionGroup.java From typescript.java with MIT License | 5 votes |
public RefactorActionGroup(TypeScriptEditor editor, String groupName) { fEditor = editor; fGroupName = groupName; fSite = editor.getEditorSite(); fSelectionProvider = fSite.getSelectionProvider(); ISelectionProvider provider = editor.getSelectionProvider(); ISelection selection = provider.getSelection(); fRenameAction = new RenameAction(editor); initAction(fRenameAction, selection, ITypeScriptEditorActionDefinitionIds.RENAME_ELEMENT); editor.setAction("RenameElement", fRenameAction); //$NON-NLS-1$ }
Example 15
Source File: OpenAnalysisOutputHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isEnabled() { /* Check if we are closing down */ final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } /* Get the selection */ final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } final ISelection selection = selectionProvider.getSelection(); /* Make sure there is only one selection and that it is an analysis output */ fOutputElement = null; if (selection instanceof TreeSelection) { final TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml final Object element = sel.getFirstElement(); if (element instanceof TmfAnalysisOutputElement) { fOutputElement = (TmfAnalysisOutputElement) element; } } return (fOutputElement != null); }
Example 16
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); } }
Example 17
Source File: RectangleSupport.java From e4macs with Eclipse Public License 1.0 | 4 votes |
ITextSelection getCurrentSelection(ITextEditor editor){ ISelectionProvider selectionProvider = editor.getSelectionProvider(); return (ITextSelection) selectionProvider.getSelection(); }
Example 18
Source File: EmacsPlusCmdHandler.java From e4macs with Eclipse Public License 1.0 | 4 votes |
/** * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ @SuppressWarnings("unchecked") public Object execute(ExecutionEvent event) throws ExecutionException { ITextEditor editor = getTextEditor(event); if (editor == null) { if (isWindowCommand()) { Object result = checkExecute(event); if (result == Check.Fail) { beep(); result = null; } return result; } else if (isConsoleCommand()) { // intercept and dispatch execution if console supported and used in a console view IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart != null && (activePart instanceof IConsoleView) && (activePart instanceof PageBookView)) { IPage textPage = ((PageBookView)activePart).getCurrentPage(); if (textPage instanceof TextConsolePage) { return ((IConsoleDispatch)this).consoleDispatch(((TextConsolePage)textPage).getViewer(),(IConsoleView)activePart,event); } } } } try { setThisEditor(editor); isEditable = getEditable(); if (editor == null || isBlocked()) { beep(); asyncShowMessage(editor, INEDITABLE_BUFFER, true); return null; } // Retrieve the universal-argument parameter value if passed if (extractUniversalCount(event) != 1) { // check if we should dispatch a related command based on the universal argument String dispatchId = checkDispatchId(event.getCommand().getId()); if (dispatchId != null) { // recurse on new id (inverse or arg value driven) return dispatchId(editor, dispatchId, getParams(event.getCommand(), event.getParameters())); } } setThisDocument(editor.getDocumentProvider().getDocument(editor.getEditorInput())); // Get the current selection ISelectionProvider selectionProvider = editor.getSelectionProvider(); ITextSelection selection = (ITextSelection) selectionProvider.getSelection(); preTransform(editor, selection); return transformWithCount(editor, getThisDocument(), selection, event); } finally { // normal commands clean up here if (isTransform()) { postExecute(); } } }
Example 19
Source File: CommandPrefixDigitHandler.java From tlaplus with MIT License | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { ParserDependencyStorage pds = Activator.getModuleDependencyStorage(); String moduleName = EditorUtil.getTLAEditorWithFocus().getModuleName(); List vec = pds.getListOfExtendedModules(moduleName + TLAConstants.Files.TLA_EXTENSION); System.out.println("ExtendedModules"); for (int i = 0; i < vec.size(); i++) { System.out.println((String) vec.get(i)); } vec = pds.getListOfModulesToReparse(moduleName + TLAConstants.Files.TLA_EXTENSION); System.out.println("ModulesToReparse"); for (int i = 0; i < vec.size(); i++) { System.out.println((String) vec.get(i)); } ModuleNode module = ResourceHelper.getModuleNode(moduleName); TLAEditor editor = EditorUtil.getTLAEditorWithFocus(); // gets the editor to which command applies if (editor == null) { return null; } IFile file = ((FileEditorInput) editor.getEditorInput()).getFile(); SpecObj spec = ResourceHelper.getValidParseResult(file).getSpecObj(); if (true) { return null; } System.out.println("ConstantDecls"); SemanticNode[] nodes = module.getConstantDecls(); for (int i = 0; i < nodes.length; i++) { System.out.println(" " // + nodes[i].getName()+ ": " + nodes[i].getLocation().toString()); } System.out.println("VariableDecls"); nodes = module.getVariableDecls(); for (int i = 0; i < nodes.length; i++) { System.out.println(" " // + nodes[i].getName()+ ": " + nodes[i].getLocation().toString()); } System.out.println("OpDefs"); nodes = module.getOpDefs(); for (int i = 0; i < nodes.length; i++) { System.out.println(" " // + nodes[i].getName()+ ": " + nodes[i].getLocation().toString()); } System.out.println("TopLevel"); nodes = module.getTopLevel(); for (int i = 0; i < nodes.length; i++) { System.out.println(" " // + nodes[i].getName()+ ": " + nodes[i].getLocation().toString()); } // IEditorReference[] references = UIHelper.getActivePage().getEditorReferences(); // // StringAndLocation token = EditorUtil.getCurrentToken(); // if (token == null) { // System.out.println("Null returned"); // } else { // System.out.println(token.toString()); // } editor = EditorUtil.getTLAEditorWithFocus(); // gets the editor to which command applies if (editor == null) { return null; } file = ((FileEditorInput) editor.getEditorInput()).getFile(); spec = ResourceHelper.getValidParseResult(file).getSpecObj(); // doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); // gets document being edited. ISelectionProvider selectionProvider = editor.getSelectionProvider(); TextSelection selection = (TextSelection) selectionProvider.getSelection(); // reset the prefix if the selection has changed if (existsPrefix && !selection.equals(lastSelection)) { existsPrefix = false; prefixValue = 0; } lastSelection = selection; String cmdId = event.getCommand().getId(); int digit = Integer.parseInt(cmdId.substring(cmdId.length() - 1)); prefixValue = 10 * prefixValue + digit; existsPrefix = true; // offset = selection.getOffset(); // TODO Auto-generated method stub return null; }
Example 20
Source File: SelectionConverter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Converts the selection provided by the given part into a structured selection. The following * conversion rules are used: * <ul> * <li><code>part instanceof JavaEditor</code>: returns a structured selection using code * resolve to convert the editor's text selection.</li> * <li><code>part instanceof IWorkbenchPart</code>: returns the part's selection if it is a * structured selection.</li> * <li><code>default</code>: returns an empty structured selection.</li> * </ul> * * @param part the part * @return the selection * @throws JavaModelException thrown when the type root can not be accessed */ public static IStructuredSelection getStructuredSelection(IWorkbenchPart part) throws JavaModelException { if (part instanceof JavaEditor) return new StructuredSelection(codeResolve((JavaEditor)part)); ISelectionProvider provider= part.getSite().getSelectionProvider(); if (provider != null) { ISelection selection= provider.getSelection(); if (selection instanceof IStructuredSelection) return (IStructuredSelection)selection; } return StructuredSelection.EMPTY; }