Search in sources :

Example 1 with ISourceReconcilingListener

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

the class DocumentRegionProcessor method removeReconcilingListener.

public void removeReconcilingListener(ISourceReconcilingListener listener) {
    Set listeners = new HashSet(Arrays.asList(fReconcileListeners));
    listeners.remove(listener);
    fReconcileListeners = (ISourceReconcilingListener[]) listeners.toArray(new ISourceReconcilingListener[listeners.size()]);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ISourceReconcilingListener(org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener) HashSet(java.util.HashSet)

Example 2 with ISourceReconcilingListener

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

the class TestStructuredTextEditor method testInitialReconciling.

/**
 * Test receiving the initial reconcile notification when the editor opens
 */
public void testInitialReconciling() throws Exception {
    IFile file = getOrCreateFile(PROJECT_NAME + "/" + "reconcilingtest.xml");
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final int[] state = new int[2];
    Arrays.fill(state, -1);
    ISourceReconcilingListener listener = new ISourceReconcilingListener() {

        int mod = 0;

        public void reconciled(IDocument document, IAnnotationModel model, boolean forced, IProgressMonitor progressMonitor) {
            state[1] = mod++;
        }

        public void aboutToBeReconciled() {
            state[0] = mod++;
        }
    };
    IEditorPart editor = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
    try {
        assertTrue("Not a StructuredTextEditor", editor instanceof StructuredTextEditor);
        addReconcilingListener((StructuredTextEditor) editor, listener);
        waitForReconcile(state);
        assertTrue("Initial: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
        assertTrue("Initial: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 0);
        assertTrue("Initial: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 1);
    } finally {
        if (editor != null && activePage != null) {
            activePage.closeEditor(editor, false);
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISourceReconcilingListener(org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with ISourceReconcilingListener

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

the class TestStructuredTextEditor method testFocusedReconciling.

/**
 * Test that an editor notifies reconciling listeners when the editor gets focus.
 */
public void testFocusedReconciling() throws Exception {
    IFile file = getOrCreateFile(PROJECT_NAME + "/" + "focustest.xml");
    IFile fileAlt = getOrCreateFile(PROJECT_NAME + "/" + "focustestAlt.xml");
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final int[] state = new int[2];
    Arrays.fill(state, -1);
    ISourceReconcilingListener listener = new ISourceReconcilingListener() {

        int mod = 0;

        public void reconciled(IDocument document, IAnnotationModel model, boolean forced, IProgressMonitor progressMonitor) {
            state[1] = mod++;
        }

        public void aboutToBeReconciled() {
            state[0] = mod++;
        }
    };
    IEditorPart editor = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
    try {
        assertTrue("Not a StructuredTextEditor", editor instanceof StructuredTextEditor);
        addReconcilingListener((StructuredTextEditor) editor, listener);
        waitForReconcile(state);
        assertTrue("Initial: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
        assertTrue("Initial: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 0);
        assertTrue("Initial: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 1);
        IDE.openEditor(activePage, fileAlt, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
        Arrays.fill(state, -1);
        IEditorPart editorPart = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
        assertEquals("Didn't get the original editor back.", editor, editorPart);
        waitForReconcile(state);
        assertTrue("Modified: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
        assertTrue("Modified: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 2);
        assertTrue("Modified: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 3);
    } finally {
        if (editor != null && activePage != null) {
            activePage.closeEditor(editor, false);
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISourceReconcilingListener(org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with ISourceReconcilingListener

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

the class TestStructuredTextEditor method testModificationReconciling.

/**
 * Test that modifications to the editor's content will notify reconciling listeners
 */
public void testModificationReconciling() throws Exception {
    IFile file = getOrCreateFile(PROJECT_NAME + "/" + "reconcilingmodificationtest.xml");
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final int[] state = new int[2];
    Arrays.fill(state, -1);
    ISourceReconcilingListener listener = new ISourceReconcilingListener() {

        int mod = 0;

        public void reconciled(IDocument document, IAnnotationModel model, boolean forced, IProgressMonitor progressMonitor) {
            state[1] = mod++;
        }

        public void aboutToBeReconciled() {
            state[0] = mod++;
        }
    };
    IEditorPart editor = IDE.openEditor(activePage, file, "org.eclipse.wst.sse.ui.StructuredTextEditor.test");
    try {
        assertTrue("Not a StructuredTextEditor", editor instanceof StructuredTextEditor);
        addReconcilingListener((StructuredTextEditor) editor, listener);
        waitForReconcile(state);
        assertTrue("Initial: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
        assertTrue("Initial: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 0);
        assertTrue("Initial: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 1);
        IDocument document = ((StructuredTextEditor) editor).getDocumentProvider().getDocument(editor.getEditorInput());
        assertTrue("Editor doesn't have a document", document != null);
        document.set("<?xml version=\"1.0\" ?>");
        Arrays.fill(state, -1);
        waitForReconcile(state);
        assertTrue("Modified: Reconciling did not complete in a timely fashion", state[0] != -1 && state[1] != -1);
        assertTrue("Modified: aboutToBeReconciled not invoked first (" + state[0] + ")", state[0] == 2);
        assertTrue("Modified: reconciled not invoked after aboutToBeReconciled (" + state[1] + ")", state[1] == 3);
    } finally {
        if (editor != null && activePage != null) {
            activePage.closeEditor(editor, false);
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISourceReconcilingListener(org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with ISourceReconcilingListener

use of org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener 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)

Aggregations

ISourceReconcilingListener (org.eclipse.wst.sse.ui.reconcile.ISourceReconcilingListener)6 IFile (org.eclipse.core.resources.IFile)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IDocument (org.eclipse.jface.text.IDocument)3 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)3 IEditorPart (org.eclipse.ui.IEditorPart)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListenerList (org.eclipse.core.runtime.ListenerList)1 IReconciler (org.eclipse.jface.text.reconciler.IReconciler)1 Point (org.eclipse.swt.graphics.Point)1 IShowInTargetList (org.eclipse.ui.part.IShowInTargetList)1 DocumentRegionProcessor (org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)1