Search in sources :

Example 1 with DocumentRegionProcessor

use of org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor in project webtools.sourceediting by eclipse.

the class SemanticHighlightingManager method enable.

/**
 * Enable semantic highlighting.
 */
private void enable() {
    loadSemanticHighlightings();
    fPresenter = new SemanticHighlightingPresenter();
    fPresenter.install(fSourceViewer, fPresentationReconciler);
    // if (fEditor != null) {
    fReconciler = new SemanticHighlightingReconciler();
    fReconciler.install(fSourceViewer, fPresenter, fHighlightings, fHighlightingStyles);
    IReconciler reconciler = fConfiguration.getReconciler(fSourceViewer);
    if (reconciler instanceof DocumentRegionProcessor)
        ((DocumentRegionProcessor) reconciler).setSemanticHighlightingStrategy(fReconciler);
// } else {
// fPresenter.updatePresentation(null, createHardcodedPositions(), new HighlightedPosition[0]);
// }
}
Also used : IReconciler(org.eclipse.jface.text.reconciler.IReconciler) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Example 2 with DocumentRegionProcessor

use of org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor in project webtools.sourceediting by eclipse.

the class TestSourceValidationFramework method getSourceValidatorIDs.

private List getSourceValidatorIDs(String fileName) throws Exception {
    List validatorIds = new ArrayList(1);
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    IFile file = ensureFileIsAccessible(PROJECT_NAME + SEPARATOR + fileName, null);
    IEditorPart editor = IDE.openEditor(page, file, TestStructuredTextEditor.class.getName(), true);
    ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
    TestStructuredTextEditor testTextEditor = (TestStructuredTextEditor) textEditor;
    IReconciler reconciler = testTextEditor.textViewerConfiguration.getReconciler(testTextEditor.getTextViewer());
    assertNotNull(reconciler);
    assertTrue("unexpected IReconciler implementation: " + reconciler.getClass(), reconciler instanceof DocumentRegionProcessor);
    Class reconcilerClass = reconciler.getClass();
    Method method = null;
    while (reconcilerClass != Object.class && method == null) {
        Method[] methods = reconcilerClass.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals("getValidatorStrategy")) {
                method = methods[i];
            }
        }
        reconcilerClass = reconcilerClass.getSuperclass();
    }
    assertNotNull("no getValidatorStrategy method found on " + reconciler.getClass(), method);
    method.setAccessible(true);
    ValidatorStrategy strategy = (ValidatorStrategy) method.invoke(reconciler, new Object[0]);
    assertNotNull(strategy);
    Field fMetaData = strategy.getClass().getDeclaredField("fMetaData");
    assertNotNull("validator metadata field \"fMetaData\" not found on strategy " + strategy.getClass(), fMetaData);
    fMetaData.setAccessible(true);
    List metadata = (List) fMetaData.get(strategy);
    assertNotNull(metadata);
    for (int i = 0; i < metadata.size(); i++) {
        validatorIds.add(((ValidatorMetaData) metadata.get(i)).getValidatorId());
    }
    page.closeEditor(editor, false);
    return validatorIds;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) List(java.util.List) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Example 3 with DocumentRegionProcessor

use of org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor in project webtools.sourceediting by eclipse.

the class TestStructuredTextEditor method addReconcilingListener.

private void addReconcilingListener(StructuredTextEditor editor, ISourceReconcilingListener listener) throws Exception {
    Method mConfig = AbstractTextEditor.class.getDeclaredMethod("getSourceViewerConfiguration", null);
    mConfig.setAccessible(true);
    Object config = mConfig.invoke(editor, null);
    assertTrue("Did not get a source viewer configuration", config instanceof SourceViewerConfiguration);
    IReconciler reconciler = ((SourceViewerConfiguration) config).getReconciler(fEditor.getTextViewer());
    assertTrue("Reconciler is not a DirtyRegionProcessor", reconciler instanceof DocumentRegionProcessor);
    ((DocumentRegionProcessor) reconciler).addReconcilingListener(listener);
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) Method(java.lang.reflect.Method) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Example 4 with DocumentRegionProcessor

use of org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method addReconcilingListeners.

private void addReconcilingListeners(SourceViewerConfiguration config, StructuredTextViewer stv) {
    try {
        List reconcilingListeners = new ArrayList(fReconcilingListeners.length);
        String[] ids = getConfigurationPoints();
        for (int i = 0; i < ids.length; i++) {
            // $NON-NLS-1$
            reconcilingListeners.addAll(ExtendedConfigurationBuilder.getInstance().getConfigurations("sourceReconcilingListener", ids[i]));
        }
        fReconcilingListeners = (ISourceReconcilingListener[]) reconcilingListeners.toArray(new ISourceReconcilingListener[reconcilingListeners.size()]);
    } catch (ClassCastException e) {
        // $NON-NLS-1$
        Logger.log(Logger.ERROR, "Configuration has a reconciling listener that does not implement ISourceReconcilingListener.");
    }
    IReconciler reconciler = config.getReconciler(stv);
    if (reconciler instanceof DocumentRegionProcessor) {
        for (int i = 0; i < fReconcilingListeners.length; i++) ((DocumentRegionProcessor) reconciler).addReconcilingListener(fReconcilingListeners[i]);
    }
}
Also used : IReconciler(org.eclipse.jface.text.reconciler.IReconciler) ArrayList(java.util.ArrayList) IShowInTargetList(org.eclipse.ui.part.IShowInTargetList) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) List(java.util.List) ISourceReconcilingListener(org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener) Point(org.eclipse.swt.graphics.Point) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Example 5 with DocumentRegionProcessor

use of org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor in project webtools.sourceediting by eclipse.

the class StructuredTextEditor method handlePreferenceStoreChanged.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.texteditor.AbstractTextEditor#handlePreferenceStoreChanged(org.eclipse.jface.util.PropertyChangeEvent)
	 */
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
    String property = event.getProperty();
    if (EditorPreferenceNames.EDITOR_TEXT_HOVER_MODIFIERS.equals(property)) {
        updateHoverBehavior();
    } else // enable or disable as you type validation
    if (CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS.equals(property)) {
        IReconciler reconciler = this.getSourceViewerConfiguration().getReconciler(this.getSourceViewer());
        if (reconciler instanceof DocumentRegionProcessor) {
            ((DocumentRegionProcessor) reconciler).setValidatorStrategyEnabled(isValidationEnabled());
        }
    } else if (AbstractStructuredFoldingStrategy.FOLDING_ENABLED.equals(property)) {
        if (getSourceViewer() instanceof ProjectionViewer) {
            // installed yet
            if (isFoldingEnabled() && (fProjectionSupport == null)) {
                installProjectionSupport();
            }
            ProjectionViewer pv = (ProjectionViewer) getSourceViewer();
            if (pv.isProjectionMode() != isFoldingEnabled()) {
                if (pv.canDoOperation(ProjectionViewer.TOGGLE)) {
                    pv.doOperation(ProjectionViewer.TOGGLE);
                }
            }
        }
    } else // update content assist preferences
    if (EditorPreferenceNames.CODEASSIST_PROPOSALS_BACKGROUND.equals(property)) {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer != null) {
            SourceViewerConfiguration configuration = getSourceViewerConfiguration();
            if (configuration != null) {
                IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
                if (contentAssistant instanceof ContentAssistant) {
                    ContentAssistant assistant = (ContentAssistant) contentAssistant;
                    RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), EditorPreferenceNames.CODEASSIST_PROPOSALS_BACKGROUND);
                    Color color = EditorUtility.getColor(rgb);
                    assistant.setProposalSelectorBackground(color);
                }
            }
        }
    } else // update content assist preferences
    if (EditorPreferenceNames.CODEASSIST_PROPOSALS_FOREGROUND.equals(property)) {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer != null) {
            SourceViewerConfiguration configuration = getSourceViewerConfiguration();
            if (configuration != null) {
                IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
                if (contentAssistant instanceof ContentAssistant) {
                    ContentAssistant assistant = (ContentAssistant) contentAssistant;
                    RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), EditorPreferenceNames.CODEASSIST_PROPOSALS_FOREGROUND);
                    Color color = EditorUtility.getColor(rgb);
                    assistant.setProposalSelectorForeground(color);
                }
            }
        }
    } else // update content assist preferences
    if (EditorPreferenceNames.CODEASSIST_PARAMETERS_BACKGROUND.equals(property)) {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer != null) {
            SourceViewerConfiguration configuration = getSourceViewerConfiguration();
            if (configuration != null) {
                IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
                if (contentAssistant instanceof ContentAssistant) {
                    ContentAssistant assistant = (ContentAssistant) contentAssistant;
                    RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), EditorPreferenceNames.CODEASSIST_PARAMETERS_BACKGROUND);
                    Color color = EditorUtility.getColor(rgb);
                    assistant.setContextInformationPopupBackground(color);
                    assistant.setContextSelectorBackground(color);
                }
            }
        }
    } else // update content assist preferences
    if (EditorPreferenceNames.CODEASSIST_PARAMETERS_FOREGROUND.equals(property)) {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer != null) {
            SourceViewerConfiguration configuration = getSourceViewerConfiguration();
            if (configuration != null) {
                IContentAssistant contentAssistant = configuration.getContentAssistant(sourceViewer);
                if (contentAssistant instanceof ContentAssistant) {
                    ContentAssistant assistant = (ContentAssistant) contentAssistant;
                    RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), EditorPreferenceNames.CODEASSIST_PARAMETERS_FOREGROUND);
                    Color color = EditorUtility.getColor(rgb);
                    assistant.setContextInformationPopupForeground(color);
                    assistant.setContextSelectorForeground(color);
                }
            }
        }
    }
    super.handlePreferenceStoreChanged(event);
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) Color(org.eclipse.swt.graphics.Color) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) RGB(org.eclipse.swt.graphics.RGB) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Aggregations

IReconciler (org.eclipse.jface.text.reconciler.IReconciler)5 DocumentRegionProcessor (org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)5 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)2 Field (java.lang.reflect.Field)1 IFile (org.eclipse.core.resources.IFile)1 ListenerList (org.eclipse.core.runtime.ListenerList)1 ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)1 Color (org.eclipse.swt.graphics.Color)1 Point (org.eclipse.swt.graphics.Point)1 RGB (org.eclipse.swt.graphics.RGB)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IShowInTargetList (org.eclipse.ui.part.IShowInTargetList)1