Java Code Examples for org.eclipse.xtext.ui.editor.utils.EditorUtils#getActiveXtextEditor()
The following examples show how to use
org.eclipse.xtext.ui.editor.utils.EditorUtils#getActiveXtextEditor() .
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: ShowQuickOutlineActionHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { final IXtextDocument document = xtextEditor.getDocument(); document.priorityReadOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { final QuickOutlinePopup quickOutlinePopup = createPopup(xtextEditor.getEditorSite().getShell()); quickOutlinePopup.setEditor(xtextEditor); quickOutlinePopup.setInput(document); if (event.getTrigger() != null) { quickOutlinePopup.setEvent((Event) event.getTrigger()); } quickOutlinePopup.open(); } }); } return null; }
Example 2
Source File: AbstractOpenHierarchyHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { IWorkbenchWindow workbenchWindow = editor.getEditorSite().getWorkbenchWindow(); editor.getDocument().priorityReadOnly(resource -> { openHierarchy(eObjectAtOffsetHelper.resolveElementAt(resource, ((ITextSelection) selection).getOffset()), workbenchWindow); return null; }); } } return null; }
Example 3
Source File: FindReferencesHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getDocument().priorityReadOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { EObject target = eObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset()); findReferences(target); } }); } } catch (Exception e) { LOG.error(Messages.FindReferencesHandler_3, e); } return null; }
Example 4
Source File: OpenDeclarationHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); IRegion region = new Region(selection.getOffset(), selection.getLength()); ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer(); IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false); if (hyperlinks != null && hyperlinks.length > 0) { IHyperlink hyperlink = hyperlinks[0]; hyperlink.open(); } } return null; }
Example 5
Source File: EditorCopyQualifiedNameHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override protected String getQualifiedName(ExecutionEvent event) { XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event); if (activeXtextEditor == null) { return null; } final ITextSelection selection = getTextSelection(activeXtextEditor); return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<String, XtextResource>() { @Override public String exec(XtextResource xTextResource) throws Exception { EObject context = getContext(selection, xTextResource); EObject selectedElement = getSelectedName(selection, xTextResource); return getQualifiedName(selectedElement, context); } }); }
Example 6
Source File: AbstractJvmElementHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getDocument().priorityReadOnly(new IUnitOfWork<Void, XtextResource>() { @Override public java.lang.Void exec(XtextResource resource) throws Exception { JvmIdentifiableElement jvmIdentifiable = jvmElementAtOffsetHelper.getJvmIdentifiableElement(resource, selection.getOffset()); if (jvmIdentifiable != null) { IJavaElement javaType = javaElementFinder.findElementFor(jvmIdentifiable); if (javaType != null) openPresentation(editor, javaType, jvmIdentifiable); } return null; } }); } return null; }
Example 7
Source File: ImportStaticMethodHandler.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { try { Object _xblockexpression = null; { this.syncUtil.totalSync(false); final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if ((editor != null)) { ISelection _selection = editor.getSelectionProvider().getSelection(); final ITextSelection selection = ((ITextSelection) _selection); final IXtextDocument document = editor.getDocument(); this.importer.importStaticMethod(document, selection); } _xblockexpression = null; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 8
Source File: TypeChooser.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public JvmDeclaredType choose(final List<JvmDeclaredType> candidateTypes, Iterable<TypeUsage> usages, final XtextResource resource) { XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(); if (activeXtextEditor==null) return null; revealInEditor(activeXtextEditor, usages, resource); Shell shell = Display.getDefault().getActiveShell(); IStructuredContentProvider contentProvider = new ContentProvider(); Dialog dialog = new Dialog(shell, new LabelProvider(labelProvider), contentProvider); dialog.setInput(candidateTypes); dialog.setInitialSelections((Object[])new JvmDeclaredType[] { candidateTypes.get(0) }); int result = dialog.open(); if(originalSelection != null) activeXtextEditor.getSelectionProvider().setSelection(originalSelection); if(result == Window.OK && dialog.getResult().length > 0) return (JvmDeclaredType) dialog.getResult()[0]; else return null; }
Example 9
Source File: ImportStaticExtensionMethodHandler.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { try { Object _xblockexpression = null; { this.syncUtil.totalSync(false); final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if ((editor != null)) { ISelection _selection = editor.getSelectionProvider().getSelection(); final ITextSelection selection = ((ITextSelection) _selection); final IXtextDocument document = editor.getDocument(); this.importer.importStaticMethod(document, selection); } _xblockexpression = null; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 10
Source File: OrganizeImportsHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final IXtextDocument document = editor.getDocument(); doOrganizeImports(document); } return null; }
Example 11
Source File: CorrectIndentationHandler.java From sarl with Apache License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event); if (activeXtextEditor == null) { return null; } final IXtextDocument doc = activeXtextEditor.getDocument(); final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection(); final IRegion region = new Region(selection.getOffset(), selection.getLength()); this.formatterProvider.get().format(doc, region); return null; }
Example 12
Source File: CheckValidateActionHandler.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null && xtextEditor.getEditorInput() instanceof XtextReadonlyEditorInput) { return null; } return super.execute(event); }
Example 13
Source File: ExtractMethodHandler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try { syncUtil.totalSync(false); final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); final IXtextDocument document = editor.getDocument(); XtextResource copiedResource = document.priorityReadOnly(new IUnitOfWork<XtextResource, XtextResource>() { @Override public XtextResource exec(XtextResource state) throws Exception { return resourceCopier.loadIntoNewResourceSet(state); } }); List<XExpression> expressions = expressionUtil.findSelectedSiblingExpressions(copiedResource, selection); if (!expressions.isEmpty()) { ExtractMethodRefactoring extractMethodRefactoring = refactoringProvider.get(); if (extractMethodRefactoring.initialize(editor, expressions, true)) { updateSelection(editor, expressions); ExtractMethodWizard wizard = wizardFactory.create(extractMethodRefactoring); RefactoringWizardOpenOperation_NonForking openOperation = new RefactoringWizardOpenOperation_NonForking( wizard); openOperation.run(editor.getSite().getShell(), "Extract Method"); } } } } catch (InterruptedException e) { return null; } catch (Exception exc) { LOG.error("Error during refactoring", exc); MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error during refactoring", exc.getMessage() + "\nSee log for details"); } return null; }
Example 14
Source File: PasteJavaCodeHandler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event); if (activeXtextEditor == null || !activeXtextEditor.isEditable()) { return null; } String clipboardText = ClipboardUtil.getTextFromClipboard(); if (!Strings.isEmpty(clipboardText)) { JavaImportData javaImports = ClipboardUtil.getJavaImportsContent(); doPasteJavaCode(activeXtextEditor, clipboardText, javaImports); } return null; }
Example 15
Source File: InsertStringHandler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { // Hack, would be nicer with document edits, but this way we don't loose auto edit StyledText textWidget = editor.getInternalSourceViewer().getTextWidget(); Event e = new Event(); e.character = replaceChar; e.type = SWT.KeyDown; e.doit = true; textWidget.notifyListeners(SWT.KeyDown, e); } return null; }
Example 16
Source File: EditorOverlay.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void draw() { XtextEditor editor = EditorUtils.getActiveXtextEditor(); if (editor != null && (hoveredElement != null || !selectedElements.isEmpty())) { ISourceViewer isv = editor.getInternalSourceViewer(); styledText = isv.getTextWidget(); drawSelection(); } else { clear(); } }
Example 17
Source File: ExtractVariableHandler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try { syncUtil.totalSync(false); final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); final IXtextDocument document = editor.getDocument(); XtextResource resource = document.priorityReadOnly(new IUnitOfWork<XtextResource, XtextResource>() { @Override public XtextResource exec(XtextResource state) throws Exception { return resourceCopier.loadIntoNewResourceSet(state); } }); XExpression expression = expressionUtil.findSelectedExpression(resource, selection); if(expression != null) { ExtractVariableRefactoring introduceVariableRefactoring = refactoringProvider.get(); if(introduceVariableRefactoring.initialize(editor, expression)) { ITextRegion region = locationInFileProvider.getFullTextRegion(expression); editor.selectAndReveal(region.getOffset(), region.getLength()); ExtractVariableWizard wizard = new ExtractVariableWizard(introduceVariableRefactoring); RefactoringWizardOpenOperation_NonForking openOperation = new RefactoringWizardOpenOperation_NonForking( wizard); openOperation.run(editor.getSite().getShell(), "Extract Local Variable"); } } } } catch (InterruptedException e) { return null; } catch (Exception exc) { LOG.error("Error during refactoring", exc); MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error during refactoring", exc.getMessage() + "\nSee log for details"); } return null; }
Example 18
Source File: CFGraph.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Constructor */ public CFGraph() { locFileProvider = new DefaultLocationInFileProvider(); editor = EditorUtils.getActiveXtextEditor(); styledText = editor.getInternalSourceViewer().getTextWidget(); layoutDone = false; }
Example 19
Source File: IEditorUtils.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
/** {@inheritDoc} */ @Override public XtextEditor getActiveXtextEditor() { return EditorUtils.getActiveXtextEditor(); }