@Override public IResource getLaunchableResource(IEditorPart editorpart) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editorpart); if (xtextEditor != null) { return xtextEditor.getResource(); } return null; }
protected IStorage getEditorResource(IWorkbenchPartSelection workbenchPartSelection) { IWorkbenchPart workbenchPart = workbenchPartSelection.getWorkbenchPart(); return (IStorage) (workbenchPart instanceof XtextEditor ? ((XtextEditor) workbenchPart).getResource() : null); }
private ValidationJob newValidationJob(XtextEditor editor) { MarkerIssueProcessor markerIssueProcessor = new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider); ValidationJob validationJob = new ValidationJob(resourceValidator, editor.getDocument(), markerIssueProcessor, CheckMode.NORMAL_AND_FAST); return validationJob; } }
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; } }
@Override public void afterCreatePartControl(XtextEditor editor) { super.afterCreatePartControl(editor); IResource resource = editor.getResource(); if (resource!=null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible() && !resource.getProject().isHidden()) { String title = Messages.NatureAddingEditorCallback_MessageDialog_Title; String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0 + resource.getProject().getName() + Messages.NatureAddingEditorCallback_MessageDialog_Msg1; Image image = null; MessageDialog dialog = new MessageDialog(editor.getEditorSite().getShell(), title, image, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); int open = dialog.open(); if (open==0) { toggleNature.toggleNature(resource.getProject()); } } }
@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()); }