Search in sources :

Example 51 with StructuredTextViewer

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

the class StructuredTextEditor method beginBusyStateInternal.

private void beginBusyStateInternal() {
    fBusyState = true;
    startBusyTimer();
    ISourceViewer viewer = getSourceViewer();
    if (viewer instanceof StructuredTextViewer) {
        ((StructuredTextViewer) viewer).beginBackgroundUpdate();
    }
    showBusy(true);
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 52 with StructuredTextViewer

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

the class ToggleLineCommentHandler method processAction.

/**
 * @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
 * 	org.eclipse.ui.texteditor.ITextEditor, org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument,
 * 	org.eclipse.jface.text.ITextSelection)
 */
protected void processAction(ITextEditor textEditor, final IStructuredDocument document, ITextSelection textSelection) {
    IStructuredModel model = null;
    DocumentRewriteSession session = null;
    boolean changed = false;
    try {
        // get text selection lines info
        int selectionStartLine = textSelection.getStartLine();
        int selectionEndLine = textSelection.getEndLine();
        int selectionEndLineOffset = document.getLineOffset(selectionEndLine);
        int selectionEndOffset = textSelection.getOffset() + textSelection.getLength();
        // adjust selection end line
        if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) {
            selectionEndLine--;
        }
        // save the selection position since it will be changing
        Position selectionPosition = null;
        selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength());
        document.addPosition(selectionPosition);
        model = StructuredModelManager.getModelManager().getModelForEdit(document);
        if (model != null) {
            // makes it so one undo will undo all the edits to the document
            model.beginRecording(this, SSEUIMessages.ToggleComment_label, SSEUIMessages.ToggleComment_description);
            // keeps listeners from doing anything until updates are all done
            model.aboutToChangeModel();
            if (document instanceof IDocumentExtension4) {
                session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
            }
            changed = true;
            // get the display for the editor if we can
            Display display = null;
            if (textEditor instanceof StructuredTextEditor) {
                StructuredTextViewer viewer = ((StructuredTextEditor) textEditor).getTextViewer();
                if (viewer != null) {
                    display = viewer.getControl().getDisplay();
                }
            }
            // create the toggling operation
            IRunnableWithProgress toggleCommentsRunnable = new ToggleLinesRunnable(model.getContentTypeIdentifier(), document, selectionStartLine, selectionEndLine, display);
            // if toggling lots of lines then use progress monitor else just run the operation
            if ((selectionEndLine - selectionStartLine) > TOGGLE_LINES_MAX_NO_BUSY_INDICATOR && display != null) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell());
                dialog.run(false, true, toggleCommentsRunnable);
            } else {
                toggleCommentsRunnable.run(new NullProgressMonitor());
            }
        }
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        Logger.logException("Problem running toggle comment progess dialog.", e);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        Logger.logException("Problem running toggle comment progess dialog.", e);
    } catch (BadLocationException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Logger.logException("The given selection " + textSelection + " must be invalid", e);
    } finally {
        // clean everything up
        if (session != null && document instanceof IDocumentExtension4) {
            ((IDocumentExtension4) document).stopRewriteSession(session);
        }
        if (model != null) {
            model.endRecording(this);
            if (changed) {
                model.changedModel();
            }
            model.releaseFromEdit();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Position(org.eclipse.jface.text.Position) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) BadLocationException(org.eclipse.jface.text.BadLocationException) Display(org.eclipse.swt.widgets.Display)

Example 53 with StructuredTextViewer

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

the class JSPELContentAssistTest method testELChosenProposalCompletion.

public void testELChosenProposalCompletion() throws Exception {
    IFile file = getFile(FILE_1_PATH);
    ICompletionProposal[] props = getCompletionProposals(file, TEST_1_DOC_LOC);
    verifyProposals(props, TEST_1_EXPECTED_PROPS);
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    IDocument document = viewer.getDocument();
    props[0].apply(document);
    String inserted = document.get(TEST_1_DOC_LOC - 1, TEST_1_EXPECTED_PROPS[0].length());
    assertEquals("The completed proposal " + inserted + " does not match the expected completion " + TEST_1_EXPECTED_PROPS[0], TEST_1_EXPECTED_PROPS[0], inserted);
    editor.getSite().getPage().saveEditor(editor, false);
    editor.close(false);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 54 with StructuredTextViewer

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

the class TestCSSContentAssistComputers method testAdditionalProposalInfo.

public void testAdditionalProposalInfo() throws Exception {
    IFile file = getFile("test4.css");
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineLength(7) + 23;
    ICompletionProposal[][] pages = getProposals(viewer, offset, 4);
    assertTrue("Not enough pages", pages.length > 0);
    ICompletionProposal[] proposals = pages[0];
    for (int i = 0; i < proposals.length; i++) {
        if (proposals[i] instanceof ICompletionProposalExtension5) {
            Object obj = ((ICompletionProposalExtension5) proposals[i]).getAdditionalProposalInfo(null);
            assertTrue("Additional info must be of type ProposalInfo", obj instanceof ProposalInfo);
            ProposalInfo info = (ProposalInfo) obj;
            assertNotNull("CSSMMNode for Proposal Info should not be null", info);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposalExtension5(org.eclipse.jface.text.contentassist.ICompletionProposalExtension5) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 55 with StructuredTextViewer

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

the class NewJSPTemplatesWizardPage method createViewer.

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 *
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationJSP();

        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    // $NON-NLS-1$
    viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont"));
    IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)62 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)21 IDocument (org.eclipse.jface.text.IDocument)19 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)18 IFile (org.eclipse.core.resources.IFile)14 SourceViewer (org.eclipse.jface.text.source.SourceViewer)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)14 Composite (org.eclipse.swt.widgets.Composite)13 Shell (org.eclipse.swt.widgets.Shell)13 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)12 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)9 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)8 ArrayList (java.util.ArrayList)7 BadLocationException (org.eclipse.jface.text.BadLocationException)6 Position (org.eclipse.jface.text.Position)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6 List (java.util.List)5 Action (org.eclipse.jface.action.Action)4 IContributionManager (org.eclipse.jface.action.IContributionManager)4 Separator (org.eclipse.jface.action.Separator)4