/** * Install this reconciler on the given editor and presenter. * * @param editor * the editor * @param sourceViewer * the source viewer * @param presenter * the highlighting presenter */ @Override public void install(final XtextEditor editor, final XtextSourceViewer sourceViewer, final HighlightingPresenter presenter) { synchronized (fReconcileLock) { cleanUpAfterReconciliation = false; // prevents a potentially already running reconciliation process to clean up after itself } this.presenter = presenter; this.editor = editor; this.sourceViewer = sourceViewer; if (calculator != null) { if (editor == null) { ((IXtextDocument) sourceViewer.getDocument()).addModelListener(this); } else if (editor.getDocument() != null) { editor.getDocument().addModelListener(this); } sourceViewer.addTextInputListener(this); } refresh(); }
public void install(StyledTextXtextAdapter styledTextXtextAdapter, XtextSourceViewer sourceViewer) { this.styledTextXtextAdapter = styledTextXtextAdapter; fSourceViewer = sourceViewer; if (styledTextXtextAdapter != null) { fConfiguration = styledTextXtextAdapter .getXtextSourceViewerConfiguration(); fPresentationReconciler = (XtextPresentationReconciler) fConfiguration .getPresentationReconciler(sourceViewer); } else { fConfiguration = null; fPresentationReconciler = null; } preferenceStore = getPreferenceStoreAccessor().getPreferenceStore(); preferenceStore.addPropertyChangeListener(this); enable(); }
@Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { if (viewer instanceof XtextSourceViewer) { IXtextDocument document = (IXtextDocument) viewer.getDocument(); return document.priorityReadOnly(createCompletionProposalComputer(viewer, offset)); } return new ICompletionProposal[0]; }
@Override public void propertyChange(PropertyChangeEvent event) { super.propertyChange(event); XtextEditor editor = myEditor; XtextSourceViewer sourceViewer = mySourceViewer; if (editor instanceof N4JSEditor && sourceViewer != null && event.getProperty().contains(".syntaxColorer.tokenStyles")) { ((N4JSEditor) editor).initializeViewerColors(sourceViewer); sourceViewer.invalidateTextPresentation(); } }
public EmbeddedEditor(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, IEditedResourceProvider resourceProvider, Runnable afterSetDocumet) { this.document = document; this.viewer = viewer; this.configuration = configuration; this.resourceProvider = resourceProvider; this.afterSetDocument = afterSetDocumet; }
/** * @since 2.3 */ public void install(XtextSourceViewerConfiguration configuration, XtextSourceViewer sourceViewer) { fSourceViewer= sourceViewer; fConfiguration= configuration; if(sourceViewer != null && configuration != null){ fPresentationReconciler= (XtextPresentationReconciler) fConfiguration.getPresentationReconciler(sourceViewer); } else { fPresentationReconciler = null; fConfiguration = null; } preferenceStore = getPreferenceStoreAccessor().getPreferenceStore(); preferenceStore.addPropertyChangeListener(this); enable(); }
/** * Install this presenter on the given source viewer and background presentation reconciler. * * @param sourceViewer * the source viewer * @param backgroundPresentationReconciler * the background presentation reconciler, can be <code>null</code>, in that case * {@link HighlightingPresenter#createPresentation(List, List)} should not be called */ public void install(XtextSourceViewer sourceViewer, XtextPresentationReconciler backgroundPresentationReconciler) { fSourceViewer = sourceViewer; fPresentationReconciler = backgroundPresentationReconciler; fSourceViewer.prependTextPresentationListener(this); fSourceViewer.addTextPresentationListener(this); fSourceViewer.addTextInputListener(this); manageDocument(fSourceViewer.getDocument()); }
/** * Install this reconciler on the given editor and presenter. * * @param editor * the editor * @param sourceViewer * the source viewer * @param presenter * the highlighting presenter */ public void install(XtextEditor editor, XtextSourceViewer sourceViewer, HighlightingPresenter presenter) { this.presenter = presenter; this.editor = editor; this.sourceViewer = sourceViewer; if (calculator != null) { if(editor == null){ ((IXtextDocument) sourceViewer.getDocument()).addModelListener(this); } else if (editor.getDocument() != null) editor.getDocument().addModelListener(this); sourceViewer.addTextInputListener(this); } refresh(); }
private void revealAnnotation(List<BTSModelAnnotation> relatingObjectsAnnotations, final boolean force) { try { // TODO annotations should be sorted based on startpos? Annotation anno = relatingObjectsAnnotations.get(0); final Position pos = annotationModel.getPosition(anno); if (pos != null) sync.asyncExec(new Runnable() { @SuppressWarnings("restriction") public void run() { XtextSourceViewer viewer = embeddedEditor.getViewer(); if (!force) { int topLine = viewer.getTopIndex(); int botLine = viewer.getBottomIndex(); int caretPos = viewer.getTextWidget().getCaretOffset(); int curLine = viewer.getTextWidget().getLineAtOffset(caretPos); int annoLineTop = viewer.getTextWidget().getLineAtOffset(pos.offset); int annoLineBot = viewer.getTextWidget().getLineAtOffset(pos.offset+pos.length); // consider changing displayed range if annotation exceeds current range // only jump if cursor would likely remain in visible range if ((topLine > annoLineTop) || (botLine < annoLineBot)) if (botLine - curLine >= topLine - annoLineTop) viewer.revealRange(pos.getOffset(), pos.length); } else // jump regardless of cursor position viewer.revealRange(pos.getOffset(), pos.length); } }); } catch (Exception e) { e.printStackTrace(); } }
/** * Install this reconciler on the given editor and presenter. * * @param editor * the editor * @param sourceViewer * the source viewer * @param presenter * the highlighting presenter */ public void install(StyledTextXtextAdapter xtextStyledText, XtextSourceViewer sourceViewer, HighlightingPresenter presenter) { this.presenter = presenter; this.styledTextXtextAdapter = xtextStyledText; this.sourceViewer = sourceViewer; if (calculator != null) { if (styledTextXtextAdapter.getXtextDocument() != null) styledTextXtextAdapter.getXtextDocument().addModelListener(this); sourceViewer.addTextInputListener(this); } refresh(); }
@Override public void complete_JRFieldObj(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ExpressionContext exprContext=(ExpressionContext) ((XtextSourceViewer) context.getViewer()).getData(ExpressionContext.ATTRIBUTE_EXPRESSION_CONTEXT); if(exprContext!=null){ List<JRField> allFields = ExpressionContextUtils.getAllDatasetsFields(exprContext); for(JRField field : allFields){ acceptor.accept(createCompletionProposal( "$F{" + field.getName() + "}", "$F{" + field.getName() + "}", getFieldIconImg(), context)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } }
@Override public void complete_JRVariableObj(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ExpressionContext exprContext=(ExpressionContext) ((XtextSourceViewer) context.getViewer()).getData(ExpressionContext.ATTRIBUTE_EXPRESSION_CONTEXT); if(exprContext!=null){ List<JRVariable> allVariables = ExpressionContextUtils.getAllDatasetsVariables(exprContext); for(JRVariable var : allVariables){ acceptor.accept(createCompletionProposal( "$V{" + var.getName() + "}", "$V{" + var.getName() + "}", getVariableIconImg(), context)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } }
@Override public void complete_JRParameterObj(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ExpressionContext exprContext=(ExpressionContext) ((XtextSourceViewer) context.getViewer()).getData(ExpressionContext.ATTRIBUTE_EXPRESSION_CONTEXT); if(exprContext!=null){ List<JRParameter> allParameters = ExpressionContextUtils.getAllDatasetsParameters(exprContext); for(JRParameter param : allParameters){ acceptor.accept(createCompletionProposal( "$P{" + param.getName() + "}", "$P{" + param.getName() + "}", getParameterIconImg(), context)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } }
@Override public void complete_JRResourceBundleKeyObj(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ExpressionContext exprContext=(ExpressionContext) ((XtextSourceViewer) context.getViewer()).getData(ExpressionContext.ATTRIBUTE_EXPRESSION_CONTEXT); if(exprContext!=null) { List<String> rbKeys = ExpressionContextUtils.getResourceBundleKeys(exprContext); for(String k : rbKeys) { acceptor.accept(createCompletionProposal( "$R{" + k + "}", "$R{" + k + "}", getResourceBundleKeyIconImg(), context)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } }
/** * Embeds an xText editor for the given resource into the given <code>parent</code>. * * @param parent the parent UI component * @param injector the injector configured for the editor and the grammar of <code>file</code> * @param resourceProvider the resource to be displayed * @param content the actual editable content in terms of prefix not to be shown [0], content to be displayed [1] * and postfix not to be shown[2] * @param requireWorkspaceResource whether the editor requires a workspace resource and shall complain at least in * the logs or whether it shall be silent * @return the embedded editor (or <b>null</b> if embedding failed) */ private static IEmbeddedEditor embedEditor(Composite parent, Injector injector, IEditedResourceProvider resourceProvider, String[] content, boolean requireWorkspaceResource) { // processIssuesBy EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class); EmbeddedEditor embeddedEditor = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations() .withParent(parent); // solution by: http://stackoverflow.com/questions/15324481/xtext-dsl-embedded-editor-in-a-dialog EmbeddedEditorModelAccess partialEditorModelAccess = embeddedEditor.createPartialEditor(content[0], content[1], content[2], false); XtextSourceViewer viewer = embeddedEditor.getViewer(); StyledText text = viewer.getTextWidget(); try { Font font = text.getFont(); if (null != font) { // TODO preliminary, use editor configuration instead FontData[] fontData = font.getFontData(); if (null != fontData && fontData.length > 0) { text.setFont(new Font(font.getDevice(), "Consolas", fontData[0].getHeight(), fontData[0].getStyle())); } } } catch (SWTError e) { // no font, ignore EASyLoggerFactory.INSTANCE.getLogger(EmbeddingHelper.class, Activator.PLUGIN_ID).error(e.getMessage()); } return new EmbeddedXtextSourceEditor(embeddedEditor, viewer, partialEditorModelAccess, requireWorkspaceResource); }
/** * Creates an editor representation instance. * * @param embeddedEditor the embedded editor * @param viewer the underlying source viewer * @param partialEditorModelAccess the model access * @param requireWorkspaceResource whether the editor requires a workspace resource and shall complain at least in * the logs or whether it shall be silent */ public EmbeddedXtextSourceEditor(EmbeddedEditor embeddedEditor, XtextSourceViewer viewer, EmbeddedEditorModelAccess partialEditorModelAccess, boolean requireWorkspaceResource) { this.embeddedEditor = embeddedEditor; this.viewer = viewer; this.partialEditorModelAccess = partialEditorModelAccess; try { URI uri = embeddedEditor.getDocument().getResourceURI(); java.net.URI netURI = new java.net.URI(uri.toString()); IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(netURI); if (null != files && files.length > 0) { resource = files[0]; } else { if (requireWorkspaceResource) { getLogger().error("No resource for " + uri); } } } catch (URISyntaxException e) { getLogger().exception(e); } viewer.getAnnotationModel().addAnnotationModelListener(new IAnnotationModelListener() { @Override public void modelChanged(IAnnotationModel model) { if (!skipNextUpdateEvent) { // loading / updating the model dirty = true; } skipNextUpdateEvent = false; } }); }
@Override public void install(XtextEditor editor, XtextSourceViewer sourceViewer) { this.myEditor = editor; this.mySourceViewer = sourceViewer; super.install(editor, sourceViewer); }
/** {@inheritDoc} */ @Override public XtextSourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final IOverviewRuler overviewRuler, final boolean showsAnnotationOverview, final int styles) { return new FixedXtextSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles); }
@Override public XtextSourceViewer get() { if (context == null) return null; XtextSourceViewer viewer = context.get(XtextSourceViewer.class); return viewer; }
@Override public void configure(Binder binder) { // TODO Auto-generated method stub super.configure(binder); binder.bind(XtextSourceViewer.class).toProvider((Class<? extends Provider<? extends XtextSourceViewer>>) BTSE4ToGuiceXtextSourceViewerProvider.class); }
public XtextSourceViewer getViewer() { return this.viewer; }
public void install(XtextEditor editor, XtextSourceViewer sourceViewer) { fEditor= editor; if (fEditor != null) { install(editor.getXtextSourceViewerConfiguration(), sourceViewer) ; } }
protected XtextSourceViewer createXtextSourceViewer() { final XtextSourceViewer result = new XtextSourceViewerEx(getStyledText(), getPreferenceStoreAccess().getPreferenceStore()); result.configure(getXtextSourceViewerConfiguration()); result.setDocument(getXtextDocument(), new AnnotationModel()); return result; }
protected XtextSourceViewer getXtextSourceviewer() { return this.sourceviewer; }
protected XtextSourceViewer getXtextSourceviewer() { return sourceviewer; }
public Class<? extends XtextSourceViewer.Factory> bindSourceViewerFactory() { return GamaSourceViewerFactory.class; }
/** * @see org.eclipse.xtext.ui.editor.XtextSourceViewer.Factory#createSourceViewer(org.eclipse.swt.widgets.Composite, * org.eclipse.jface.text.source.IVerticalRuler, * org.eclipse.jface.text.source.IOverviewRuler, boolean, int) */ @Override public XtextSourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final IOverviewRuler overviewRuler, final boolean showsAnnotationOverview, final int styles) { return new GamaSourceViewer(parent, ruler, overviewRuler, showsAnnotationOverview, styles); }
/** * Returns the viewer. * * @return the viewer */ protected XtextSourceViewer getViewer() { return (XtextSourceViewer) getEditor().getInternalSourceViewer(); }
void install(XtextEditor xtextEditor, XtextSourceViewer sourceViewer);