@Override public IResource getLaunchableResource(IEditorPart editorpart) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editorpart); if (xtextEditor != null) { return xtextEditor.getResource(); } return null; }
protected TextAttribute createTextAttribute(String id, TextStyle defaultTextStyle) { TextStyle textStyle = new TextStyle(); preferencesAccessor.populateTextStyle(id, textStyle, defaultTextStyle); int style = textStyle.getStyle(); Font fontFromFontData = EditorUtils.fontFromFontData(textStyle.getFontData()); return new TextAttribute( EditorUtils.colorFromRGB(textStyle.getColor()), EditorUtils.colorFromRGB(textStyle.getBackgroundColor()), style, fontFromFontData); }
public static Color colorFromRGB(RGB rgb) { if (rgb == null) return null; return colorFromString(StringConverter.asString(rgb)); }
public Object execute(final ExecutionEvent event) throws ExecutionException { final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { final IXtextDocument document = xtextEditor.getDocument(); document.readOnly(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); quickOutlinePopup.setEvent((Event) event.getTrigger()); quickOutlinePopup.open(); } }); } return null; }
@Override protected String getQualifiedName(ExecutionEvent event) { XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event); if (activeXtextEditor == null) { return null; } final ITextSelection selection = getTextSelection(activeXtextEditor); return activeXtextEditor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() { public String exec(XtextResource xTextResource) throws Exception { EObject selectedElement = getSelectedName(selection, xTextResource); return getQualifiedName(selectedElement); } }); }
protected XtextEditor openEditor(IFile file) throws Exception { IEditorPart openEditor = openEditor(file, getEditorId()); XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { return xtextEditor; } else if (openEditor instanceof ErrorEditorPart) { Field field = openEditor.getClass().getDeclaredField("error"); field.setAccessible(true); throw new IllegalStateException("Couldn't open the editor.",((Status)field.get(openEditor)).getException()); } else { fail("Opened Editor with id:" + getEditorId() + ", is not an XtextEditor"); } return null; }
@Override public void applyStyles(TextStyle textStyle) { textStyle.strikeout = (xtextTextStyle.getStyle() & TextAttribute.STRIKETHROUGH) != 0; textStyle.underline = (xtextTextStyle.getStyle() & TextAttribute.UNDERLINE) != 0; if (xtextTextStyle.getFontData() == null && xtextTextStyle.getStyle() != org.eclipse.xtext.ui.editor.utils.TextStyle.DEFAULT_FONT_STYLE) { FontData fontData = new FontData(); fontData.setStyle(xtextTextStyle.getStyle()); xtextTextStyle.setFontData(fontData); } textStyle.font = fontFromFontData(xtextTextStyle.getFontData()); if (xtextTextStyle.getBackgroundColor() != null) textStyle.background = colorFromRGB(xtextTextStyle.getBackgroundColor()); textStyle.foreground = colorFromRGB(xtextTextStyle.getColor()); } }
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().readOnly(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; }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = findEObjectByURI(uri, resource); if (object != null) { ITextRegion location = (crossReference != null) ? locationProvider .getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } } }); } }
public Object execute(ExecutionEvent event) throws ExecutionException { try { final XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { syncUtil.totalSync(preferences.isSaveAllBeforeRefactoring(), renameRefactoringController.getActiveLinkedMode() == null);
protected XtextEditor openEditor(IFile file) throws Exception { IEditorPart openEditor = openEditor(file, getEditorId()); XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { ISourceViewer sourceViewer = xtextEditor.getInternalSourceViewer(); ((ProjectionViewer)sourceViewer).doOperation(ProjectionViewer.EXPAND_ALL); return xtextEditor; } else if (openEditor instanceof ErrorEditorPart) { Field field = openEditor.getClass().getDeclaredField("error"); field.setAccessible(true); throw new IllegalStateException("Couldn't open the editor.",((Status)field.get(openEditor)).getException()); } else { fail("Opened Editor with id:" + getEditorId() + ", is not an XtextEditor"); } return null; }
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; }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { if (uri.fragment() != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = resource.getEObject(uri.fragment()); ITextRegion location = (crossReference != null) ? locationProvider.getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } }); } } }
public Object execute(ExecutionEvent event) throws ExecutionException { XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { IValidationIssueProcessor issueProcessor; IXtextDocument xtextDocument = xtextEditor.getDocument(); IResource resource = xtextEditor.getResource(); if(resource != null) issueProcessor = new MarkerIssueProcessor(resource, markerCreator, markerTypeProvider); else issueProcessor = new AnnotationIssueProcessor(xtextDocument, xtextEditor.getInternalSourceViewer().getAnnotationModel(), issueResolutionProvider); ValidationJob validationJob = new ValidationJob(resourceValidator, xtextDocument, issueProcessor, CheckMode.ALL); validationJob.schedule(); } return this; } }
public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) { Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator(); if (storages != null && storages.hasNext()) { try { IStorage storage = storages.next().getFirst(); // TODO we should create a JarEntryEditorInput if storage is a NonJavaResource from jdt to match the editor input used when double clicking on the same resource in a jar. IEditorInput editorInput = (storage instanceof IFile) ? new FileEditorInput((IFile) storage) : new XtextReadonlyEditorInput(storage); IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID); selectAndReveal(editor, uri, crossReference, indexInList, select); return EditorUtils.getXtextEditor(editor); } catch (WrappedException e) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); } catch (PartInitException partInitException) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); } } return null; }
@Override public void launch(IEditorPart editor, String mode) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editor); final ISelection selection = xtextEditor.getSelectionProvider().getSelection(); if (selection instanceof ITextSelection) { final ITextSelection sel = (ITextSelection) selection; final EObject obj = xtextEditor.getDocument().readOnly(resource -> { final IParseResult parseRes = resource.getParseResult(); if (parseRes == null) { return null; } final ICompositeNode rootNode = parseRes.getRootNode(); final ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, sel.getOffset()); return NodeModelUtils.findActualSemanticObjectFor(node); }); if (obj != null) { final EObject elt = EcoreUtil2.getContainerOfType(obj, getValidEObjectType()); if (elt != null) { searchAndLaunch(mode, elt); return; } } } else if (selection != null) { launch(selection, mode); return; } // Default launching searchAndLaunch(mode, xtextEditor.getResource()); }