Search in sources :

Example 36 with StructuredTextViewer

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

the class JSPCompletionProcessor method computeCompletionProposals.

/**
 * The same as the normal <code>computeCompeltaionProposals</code> except the calculated
 * java position is offset by the given extra offset.
 *
 * @param viewer
 *            the viewer whose document is used to compute the proposals
 * @param documentPosition
 *            an offset within the document for which completions should
 *            be computed
 * @param javaPositionExtraOffset
 * 				the extra offset for the java position
 * @return an array of completion proposals or <code>null</code> if no
 *         proposals are possible
 */
protected ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
    initialize(pos);
    JSPProposalCollector collector = null;
    IDOMModel xmlModel = null;
    try {
        if (viewer instanceof StructuredTextViewer)
            fViewer = (StructuredTextViewer) viewer;
        xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument());
        IDOMDocument xmlDoc = xmlModel.getDocument();
        if (fTranslationAdapter == null || xmlModel.getId() != fModelId) {
            fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
            fModelId = xmlModel.getId();
        }
        if (fTranslationAdapter != null) {
            JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
            fJavaPosition = translation.getJavaOffset(getDocumentPosition()) + javaPositionExtraOffset;
            if (DEBUG)
                System.out.println(debug(translation));
            try {
                ICompilationUnit cu = translation.getCompilationUnit();
                // or without a valid position
                if (cu == null || -1 == fJavaPosition)
                    return new ICompletionProposal[0];
                collector = getProposalCollector(cu, translation);
                synchronized (cu) {
                    cu.codeComplete(fJavaPosition, collector, (WorkingCopyOwner) null);
                }
            } catch (CoreException coreEx) {
                // a possible Java Model Exception due to not being a Web
                // (Java) Project
                coreEx.printStackTrace();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    // throw out exceptions on code assist.
    } finally {
        if (xmlModel != null) {
            xmlModel.releaseFromRead();
        }
    }
    ICompletionProposal[] results = new ICompletionProposal[0];
    if (collector != null) {
        results = collector.getJSPCompletionProposals();
        if (results == null || results.length < 1)
            fErrorMessage = JSPUIMessages.Java_Content_Assist_is_not_UI_;
    }
    return results;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) CoreException(org.eclipse.core.runtime.CoreException)

Example 37 with StructuredTextViewer

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

the class CSSTemplatePreferencePage method doCreateViewer.

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;
    String contentTypeID = ContentTypeIdForCSS.ContentTypeID_CSS;
    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(contentTypeID);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(viewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 38 with StructuredTextViewer

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

the class FormattingTests method getConfiguredViewer.

/**
 * @param document {@link IDocument} to display in the dummy viewer
 * @param configuration {@link SourceViewerConfiguration} to configure the dummy viewer with
 * @return a configured {@link ISourceViewer} using the given parameters
 */
private static ISourceViewer getConfiguredViewer(IDocument document, SourceViewerConfiguration configuration) {
    ISourceViewer viewer = null;
    assertNotNull("Could not get current display to run test with.", Display.getCurrent());
    Shell shell = null;
    if (PlatformUI.isWorkbenchRunning()) {
        shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    } else {
        shell = new Shell(Display.getCurrent());
    }
    Composite parent = new Composite(shell, SWT.NONE);
    viewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
    viewer.setDocument(document);
    viewer.configure(configuration);
    return viewer;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 39 with StructuredTextViewer

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

the class TestViewerConfigurationJSP method setUpViewerConfiguration.

private void setUpViewerConfiguration() {
    if (Display.getCurrent() != null) {
        Shell shell = null;
        Composite parent = null;
        if (PlatformUI.isWorkbenchRunning()) {
            shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        } else {
            shell = new Shell(Display.getCurrent());
        }
        parent = new Composite(shell, SWT.NONE);
        // dummy viewer
        fViewer = new StructuredTextViewer(parent, null, null, false, SWT.NONE);
        fConfig = new StructuredTextViewerConfigurationJSP();
    } else {
        fDisplayExists = false;
        Logger.log(Logger.INFO, "Remember, viewer configuration tests are not run because workbench is not open (normal on build machine)");
    }
}
Also used : StructuredTextViewerConfigurationJSP(org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 40 with StructuredTextViewer

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

the class DTDTemplatePreferencePage method doCreateViewer.

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;
    String contentTypeID = ContentTypeIdForDTD.ContentTypeID_DTD;
    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(contentTypeID);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(viewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) 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