Search in sources :

Example 56 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class JSPJavaContentAssistProcessor method computeContextInformation.

/**
 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer,
 *      int)
 */
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
    List results = new ArrayList();
    // need to compute context info here, if it's JSP, call java computer
    IDocument doc = viewer.getDocument();
    IDocumentPartitioner dp = null;
    if (doc instanceof IDocumentExtension3) {
        dp = ((IDocumentExtension3) doc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    }
    if (dp != null) {
        // IDocumentPartitioner dp = viewer.getDocument().getDocumentPartitioner();
        String type = dp.getPartition(documentOffset).getType();
        if (type == IJSPPartitions.JSP_DEFAULT || type == IJSPPartitions.JSP_CONTENT_JAVA) {
            // get context info from completion results...
            ICompletionProposal[] proposals = computeCompletionProposals(viewer, documentOffset);
            for (int i = 0; i < proposals.length; i++) {
                IContextInformation ci = proposals[i].getContextInformation();
                if (ci != null)
                    results.add(ci);
            }
        }
    }
    return (IContextInformation[]) results.toArray(new IContextInformation[results.size()]);
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) List(java.util.List) IDocument(org.eclipse.jface.text.IDocument)

Example 57 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class BasicStructuredDocument method stopRewriteSessionOnPartitioners.

/**
 * Stops the given rewrite session.
 *
 * @param session the rewrite session
 * @since 2.0
 */
final void stopRewriteSessionOnPartitioners(DocumentRewriteSession session) {
    if (fDocumentPartitioners != null) {
        DocumentPartitioningChangedEvent event = new DocumentPartitioningChangedEvent(this);
        Iterator e = fDocumentPartitioners.keySet().iterator();
        while (e.hasNext()) {
            String partitioning = (String) e.next();
            IDocumentPartitioner partitioner = (IDocumentPartitioner) fDocumentPartitioners.get(partitioning);
            if (partitioner instanceof IDocumentPartitionerExtension3) {
                IDocumentPartitionerExtension3 extension = (IDocumentPartitionerExtension3) partitioner;
                extension.stopRewriteSession(session);
                event.setPartitionChange(partitioning, 0, getLength());
            }
        }
        if (!event.isEmpty())
            fireDocumentPartitioningChanged(event);
    }
}
Also used : DocumentPartitioningChangedEvent(org.eclipse.jface.text.DocumentPartitioningChangedEvent) IDocumentPartitionerExtension3(org.eclipse.jface.text.IDocumentPartitionerExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) Iterator(java.util.Iterator)

Example 58 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class JSPModelLoader method reInitializeEmbeddedType.

/**
 * This is "reinitialize" since there should always be at least the
 * default one assigned, before we start checking the stream
 */
private void reInitializeEmbeddedType(IStructuredModel model, EmbeddedTypeHandler oldEmbeddedContentType, EmbeddedTypeHandler newEmbeddedContentType) {
    // check program logic
    // $NON-NLS-1$
    Assert.isNotNull(oldEmbeddedContentType, "Program error: invalid call during model initialization");
    // once we know the embedded content type, we need to set it in the
    // PageDirectiveAdapter ... the order of initialization is
    // critical here, the doc must have been created, but its contents not
    // set yet,
    // and all factories must have been set up also.
    IDOMModel domModel = (IDOMModel) model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getExistingAdapter(PageDirectiveAdapter.class);
    // ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
    // ((INodeNotifier)
    // document).getExistingAdapter(PropagatingAdapter.class);
    // ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
    // ((INodeNotifier)
    // document).getExistingAdapter(ModelQueryAdapter.class);
    oldEmbeddedContentType.uninitializeFactoryRegistry(model.getFactoryRegistry());
    oldEmbeddedContentType.uninitializeParser(structuredDocument.getParser());
    // since 'document' is not recreated in this
    // reinit path, we need to remove all adapters,
    // except for the propagated adapters (including page
    // directive adapter, and model query adapter).
    // to accomplish this, we'll just remove all, then
    // add back with a call to pre-load adapt.
    // let clients decide to unload adapters from document
    // Collection oldAdapters = document.getAdapters();
    // Iterator oldAdaptersIterator = oldAdapters.iterator();
    // while (oldAdaptersIterator.hasNext()) {
    // INodeAdapter oldAdapter = (INodeAdapter)
    // oldAdaptersIterator.next();
    // if (oldAdapter != pageDirectiveAdapter && oldAdapter !=
    // propagatingAdapter && oldAdapter != modelQueryAdapter) {
    // // DO NOT remove directly!
    // // can change contents while in notifity loop!
    // //oldAdaptersIterator.remove();
    // document.removeAdapter(oldAdapter);
    // }
    // }
    // DMW: I believe something like the following is needed,
    // since releases cached adapters
    // if (document instanceof DocumentImpl) {
    // ((DocumentImpl) document).releaseDocumentType();
    // ((DocumentImpl) document).releaseStyleSheets();
    // }
    // remember, embedded type factories are automatically cleared when
    // embededType changed
    pageDirectiveAdapter.setEmbeddedType(newEmbeddedContentType);
    // pageDirectiveAdapter.clearPageWatchers();
    if (newEmbeddedContentType != null) {
        // need to null out or else ModelParserAdapter
        // won't get reinitialized
        ((DOMModelImpl) model).setModelParser(null);
        newEmbeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
        newEmbeddedContentType.initializeParser(structuredDocument.getParser());
        // partitioner setup is the responsibility of this loader
        IDocumentPartitioner documentPartitioner = structuredDocument.getDocumentPartitioner();
        // added null/type checks for safety.
        if (documentPartitioner != null && documentPartitioner instanceof StructuredTextPartitionerForJSP) {
            if (newEmbeddedContentType.getFamilyId().equals(ContentTypeIdForXML.ContentTypeID_XML)) {
                ((StructuredTextPartitionerForJSP) documentPartitioner).setEmbeddedPartitioner(new StructuredTextPartitionerForXML());
            } else if (newEmbeddedContentType.getFamilyId().equals(ContentTypeIdForHTML.ContentTypeID_HTML)) {
                ((StructuredTextPartitionerForJSP) documentPartitioner).setEmbeddedPartitioner(new StructuredTextPartitionerForHTML());
            }
        }
    }
    // adding language here, in this convienent central
    // location, but some obvious renaming or refactoring
    // wouldn't hurt, in future.
    // I needed to add this language setting for JSP Fragment support
    // Note: this is the one that counts, since at this point,
    // the model has an ID, so we can look up IFile, etc.
    String language = getLanguage(model);
    if (language != null && language.length() > 0) {
        pageDirectiveAdapter.setLanguage(language);
    }
}
Also used : StructuredTextPartitionerForJSP(org.eclipse.jst.jsp.core.internal.text.StructuredTextPartitionerForJSP) StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DOMModelImpl(org.eclipse.wst.xml.core.internal.document.DOMModelImpl) StructuredTextPartitionerForHTML(org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) PageDirectiveAdapter(org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)

Example 59 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerXML method testDisconnectConnect.

public void testDisconnectConnect() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/xml/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            assertNotNull("partitioner was null for sDoc:" + sDoc, partitioner);
            try {
                stp.disconnect();
            } catch (Exception e) {
                assertTrue("problem disconnecting w/:" + sDoc + "/n" + e, false);
            }
            try {
                stp.connect(sDoc);
            } catch (Exception e) {
                assertTrue("problem connecting w/:" + sDoc + "/n" + e, false);
            }
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner) IOException(java.io.IOException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 60 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerXML method testGetDefaultPartitionType.

public void testGetDefaultPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/xml/example01.xml");
        if (model != null) {
            IStructuredDocument sDoc = model.getStructuredDocument();
            assertTrue("sDoc implementation not instance of IDocumentExtension3", sDoc instanceof IDocumentExtension3);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) sDoc).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
            assertTrue("partitioner doesn't implement IStructuredTextPartitioner", partitioner instanceof IStructuredTextPartitioner);
            IStructuredTextPartitioner stp = (IStructuredTextPartitioner) partitioner;
            String defaultPartitionType = stp.getDefaultPartitionType();
            assertTrue("wrong default partition type was: [" + defaultPartitionType + "] should be: [" + IXMLPartitions.XML_DEFAULT + "]", defaultPartitionType.equals(IXMLPartitions.XML_DEFAULT));
        } else {
            assertTrue("could not retrieve structured model", false);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Aggregations

IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)72 IDocument (org.eclipse.jface.text.IDocument)27 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)27 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)25 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)12 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 IFile (org.eclipse.core.resources.IFile)7 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)7 IStructuredTextPartitioner (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)6 BadLocationException (org.eclipse.jface.text.BadLocationException)5 ITypedRegion (org.eclipse.jface.text.ITypedRegion)5 DocumentEvent (org.eclipse.jface.text.DocumentEvent)4 IDocumentListener (org.eclipse.jface.text.IDocumentListener)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)3 IPath (org.eclipse.core.runtime.IPath)3 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)3 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)2 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)2