Search in sources :

Example 11 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor 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 12 with StructuredTextEditor

use of org.eclipse.wst.sse.ui.StructuredTextEditor 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 13 with StructuredTextEditor

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

the class TestStructuredTextEditor method setUp.

protected void setUp() throws Exception {
    if (!fIsSetup) {
        // create project
        createProject(PROJECT_NAME);
        fFile = getOrCreateFile(PROJECT_NAME + "/" + FILE_NAME);
        fIsSetup = true;
    }
    if (fIsSetup && fEditor == null) {
        IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        IEditorInput input = new FileEditorInput(fFile);
        /*
			 * This should take care of testing init, createPartControl,
			 * beginBackgroundOperation, endBackgroundOperation methods
			 */
        IEditorPart part = page.openEditor(input, "org.eclipse.wst.sse.ui.StructuredTextEditor.test", true);
        if (part instanceof StructuredTextEditor)
            fEditor = (StructuredTextEditor) part;
        else
            assertTrue("Unable to open structured text editor", false);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IEditorInput(org.eclipse.ui.IEditorInput)

Example 14 with StructuredTextEditor

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

the class TestJSPContentAssistComputers method getEditor.

/**
 * <p>Given a <code>file</code> get an editor for it. If an editor has already
 * been retrieved for the given <code>file</code> then return the same already
 * open editor.</p>
 *
 * <p>When opening the editor it will also standardized the line
 * endings to <code>\n</code></p>
 *
 * @param file open and return an editor for this
 * @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
 */
private static StructuredTextEditor getEditor(IFile file) {
    StructuredTextEditor editor = (StructuredTextEditor) fFileToEditorMap.get(file);
    if (editor == null) {
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            IWorkbenchPage page = workbenchWindow.getActivePage();
            IEditorPart editorPart = IDE.openEditor(page, file, true, true);
            if (editorPart instanceof MultiPageEditorPart) {
                MultiPageEditorPart xmlEditorPart = (MultiPageEditorPart) editorPart;
                editor = xmlEditorPart.getAdapter(StructuredTextEditor.class);
            } else if (editorPart instanceof StructuredTextEditor) {
                editor = ((StructuredTextEditor) editorPart);
            } else {
                fail("Unable to open structured text editor: " + editorPart.getClass().getName());
            }
            if (editor != null) {
                standardizeLineEndings(editor);
                fFileToEditorMap.put(file, editor);
            } else {
                fail("Could not open editor for " + file);
            }
        } catch (Exception e) {
            fail("Could not open editor for " + file + " exception: " + e.getMessage());
        }
    }
    return editor;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 15 with StructuredTextEditor

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

the class TestJSPContentAssistComputers method runProposalTest.

/**
 * <p>Run a proposal test by opening the given file and invoking content assist for
 * each expected proposal count at the given line number and line character
 * offset and then compare the number of proposals for each invocation (pages) to the
 * expected number of proposals.</p>
 *
 * @param fileName
 * @param lineNum
 * @param lineRelativeCharOffset
 * @param expectedProposalCounts
 * @throws Exception
 */
private static void runProposalTest(String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts) throws Exception {
    IFile file = getFile(fileName);
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;
    ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);
    verifyProposalCounts(pages, expectedProposalCounts);
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Aggregations

StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)67 IFile (org.eclipse.core.resources.IFile)29 IEditorPart (org.eclipse.ui.IEditorPart)28 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)18 IDocument (org.eclipse.jface.text.IDocument)15 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)12 Position (org.eclipse.jface.text.Position)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 BadLocationException (org.eclipse.jface.text.BadLocationException)9 ITextSelection (org.eclipse.jface.text.ITextSelection)6 PartInitException (org.eclipse.ui.PartInitException)6 XMLMultiPageEditorPart (org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Action (org.eclipse.jface.action.Action)4 Separator (org.eclipse.jface.action.Separator)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3