Search in sources :

Example 16 with StructuredTextEditor

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

the class CSSCodeFoldingTest method testAddNode.

/**
 * <p><b>TEST:</b> that folding annotations are updated after node is added</p>
 */
public void testAddNode() throws Exception {
    IFile file = getFile("CSSFoldingTest2.css");
    StructuredTextEditor editor = getEditor(file);
    try {
        StructuredTextViewer viewer = editor.getTextViewer();
        IDocument doc = viewer.getDocument();
        doc.replace(255, 0, "\ntd {\nborder: 1px solid black;\n}\n");
        editor.doSave(null);
        List expectedPositions = new ArrayList();
        expectedPositions.add(new Position(291, 69));
        expectedPositions.add(new Position(256, 31));
        expectedPositions.add(new Position(21, 113));
        expectedPositions.add(new Position(434, 120));
        expectedPositions.add(new Position(181, 72));
        expectedPositions.add(new Position(366, 62));
        waitForReconcileThenVerify(viewer, expectedPositions);
    } catch (BadLocationException e) {
        fail("Test is broken, add location has become invalid.\n" + e.getMessage());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 17 with StructuredTextEditor

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

the class CSSCodeFoldingTest method testRemoveNode.

/**
 * <p><b>TEST:</b> that folding annotations are updated after node is removed</p>
 */
public void testRemoveNode() throws Exception {
    IFile file = getFile("CSSFoldingTest1.css");
    StructuredTextEditor editor = getEditor(file);
    try {
        StructuredTextViewer viewer = editor.getTextViewer();
        IDocument doc = viewer.getDocument();
        doc.replace(253, 76, "");
        editor.doSave(null);
        final List expectedPositions = new ArrayList();
        expectedPositions.add(new Position(325, 120));
        expectedPositions.add(new Position(21, 113));
        expectedPositions.add(new Position(181, 72));
        expectedPositions.add(new Position(257, 62));
        waitForReconcileThenVerify(viewer, expectedPositions);
    } catch (BadLocationException e) {
        fail("Test is broken, replace location has become invalid.\n" + e.getMessage());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 18 with StructuredTextEditor

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

the class CSSCodeFoldingTest method testInitFolding.

/**
 * <p><b>TEST:</b> the initially placed folding annotations</p>
 */
public void testInitFolding() throws Exception {
    IFile file = getFile("CSSFoldingTest1.css");
    StructuredTextEditor editor = getEditor(file);
    List expectedPositions = new ArrayList();
    expectedPositions.add(new Position(401, 120));
    expectedPositions.add(new Position(333, 62));
    expectedPositions.add(new Position(181, 72));
    expectedPositions.add(new Position(258, 69));
    expectedPositions.add(new Position(21, 113));
    waitForReconcileThenVerify(editor.getTextViewer(), expectedPositions);
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 19 with StructuredTextEditor

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

the class PlatformStatusLineUtil method _displayTemporaryMessage.

static boolean _displayTemporaryMessage(ITextViewer viewer, String msg, boolean isError) {
    boolean messageShown = false;
    IEditorPart editor = getActiveEditor();
    if (editor != null) {
        ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
        if (textEditor != null && textEditor instanceof StructuredTextEditor) {
            if (((StructuredTextEditor) textEditor).getTextViewer() == viewer) {
                IStatusLineManager statusLineManager = editor.getEditorSite().getActionBars().getStatusLineManager();
                if (isError)
                    statusLineManager.setErrorMessage(msg);
                else
                    statusLineManager.setMessage(msg);
                new OneTimeListener(viewer.getTextWidget(), new ClearStatusLine(statusLineManager, isError));
                messageShown = true;
            }
        }
    }
    if (!messageShown) {
        displayErrorMessage(msg);
        addOneTimeClearListener();
    }
    return messageShown;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)

Example 20 with StructuredTextEditor

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

the class FindOccurrencesActionDelegate method run.

public void run(IAction action) {
    boolean okay = false;
    if (fEditor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) fEditor;
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null) {
            ITextSelection textSelection = getTextSelection(textEditor);
            FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
            if (findOccurrenceProcessor != null) {
                if (textEditor.getEditorInput() instanceof IFileEditorInput) {
                    IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
                    okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
                }
            }
        }
    }
    if (okay) {
        // clear status message
        PlatformStatusLineUtil.clearStatusLine();
    } else {
        // $NON-NLS-1$
        String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
        if (fEditor instanceof StructuredTextEditor) {
            PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) fEditor).getTextViewer(), errorMessage);
        } else {
            PlatformStatusLineUtil.displayErrorMessage(errorMessage);
            PlatformStatusLineUtil.addOneTimeClearListener();
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

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