Search in sources :

Example 6 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerHTML method doComputePartitioningTest.

/**
 * Compute the partitions for the given filename using the default partitioner
 * for that file type.
 *
 * @param filename
 * @return int
 * @throws IOException
 * @throws BadLocationException
 */
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = getClass().getResourceAsStream(filename);
    if (inStream == null)
        inStream = new StringBufferInputStream("");
    IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (DEBUG_PRINT_RESULT && useFormatter) {
        double baseTen = Math.log(10);
        formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
        formatter.setGroupingUsed(false);
    }
    partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
    if (DEBUG_PRINT_RESULT) {
        String contents = null;
        System.out.println("\nfilename: " + filename);
        for (int i = 0; i < partitions.length; i++) {
            try {
                contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
            } catch (BadLocationException e) {
                contents = "*error*";
            }
            if (useFormatter)
                System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
            else
                System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
        }
    }
    checkSeams();
    model.releaseFromEdit();
    inStream.close();
    if (partitions == null)
        return -1;
    return partitions.length;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 7 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class DTDColorPage method setupPicker.

protected void setupPicker(StyledTextColorPicker picker) {
    IModelManager mmanager = StructuredModelManager.getModelManager();
    picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForDTD.ContentTypeID_DTD).getParser());
    Dictionary descriptions = new Hashtable();
    initDescriptions(descriptions);
    Dictionary contextStyleMap = new Hashtable();
    initContextStyleMap(contextStyleMap);
    ArrayList styleList = new ArrayList();
    initStyleList(styleList);
    picker.setContextStyleMap(contextStyleMap);
    picker.setDescriptions(descriptions);
    picker.setStyleList(styleList);
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) ArrayList(java.util.ArrayList)

Example 8 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class ContentAssistUtils method getNodeAt.

/**
 * Returns the closest IndexedRegion for the offset and viewer allowing
 * for differences between viewer offsets and model positions. note: this
 * method returns an IndexedRegion for read only
 *
 * @param viewer
 *            the viewer whose document is used to compute the proposals
 * @param documentOffset
 *            an offset within the document for which completions should
 *            be computed
 * @return an IndexedRegion
 */
public static IndexedRegion getNodeAt(ITextViewer viewer, int documentOffset) {
    if (viewer == null)
        return null;
    IndexedRegion node = null;
    IModelManager mm = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    if (mm != null)
        model = mm.getExistingModelForRead(viewer.getDocument());
    try {
        if (model != null) {
            int lastOffset = documentOffset;
            node = model.getIndexedRegion(documentOffset);
            while (node == null && lastOffset >= 0) {
                lastOffset--;
                node = model.getIndexedRegion(lastOffset);
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
    return node;
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 9 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class ToggleBreakpointAction method getContentType.

protected String getContentType(IDocument document) {
    IModelManager mgr = StructuredModelManager.getModelManager();
    String contentType = null;
    IDocumentProvider provider = fTextEditor.getDocumentProvider();
    if (provider instanceof IDocumentProviderExtension4) {
        try {
            IContentType type = ((IDocumentProviderExtension4) provider).getContentType(fTextEditor.getEditorInput());
            if (type != null)
                contentType = type.getId();
        } catch (CoreException e) {
        /*
				 * A failure accessing the underlying store really isn't
				 * interesting, although it can be a problem for
				 * IStorageEditorInputs.
				 */
        }
    }
    if (contentType == null) {
        IStructuredModel model = null;
        try {
            model = mgr.getExistingModelForRead(document);
            if (model != null) {
                contentType = model.getContentTypeIdentifier();
            }
        } finally {
            if (model != null) {
                model.releaseFromRead();
            }
        }
    }
    return contentType;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDocumentProviderExtension4(org.eclipse.ui.texteditor.IDocumentProviderExtension4) IContentType(org.eclipse.core.runtime.content.IContentType) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 10 with IModelManager

use of org.eclipse.wst.sse.core.internal.provisional.IModelManager in project webtools.sourceediting by eclipse.

the class ContentSettingsPropertyPage method validateEdit.

/**
 * Method validateEdit.
 *
 * @param file
 *            org.eclipse.core.resources.IFile
 * @param context
 *            org.eclipse.swt.widgets.Shell
 * @return IStatus
 */
private static IStatus validateEdit(IFile file, Shell context) {
    if (file == null || !file.exists())
        return STATUS_ERROR;
    if (!(file.isReadOnly()))
        return STATUS_OK;
    IPath location = file.getLocation();
    final long beforeModifiedFromJavaIO = (location != null) ? location.toFile().lastModified() : IResource.NULL_STAMP;
    final long beforeModifiedFromIFile = file.getModificationStamp();
    IStatus status = ResourcesPlugin.getWorkspace().validateEdit(new IFile[] { file }, context);
    if (!status.isOK())
        return status;
    final long afterModifiedFromJavaIO = (location != null) ? location.toFile().lastModified() : IResource.NULL_STAMP;
    final long afterModifiedFromIFile = file.getModificationStamp();
    if (beforeModifiedFromJavaIO != afterModifiedFromJavaIO || beforeModifiedFromIFile != afterModifiedFromIFile) {
        IModelManager manager = StructuredModelManager.getModelManager();
        IStructuredModel model = manager.getExistingModelForRead(file);
        if (model != null) {
            if (!model.isDirty()) {
                try {
                    file.refreshLocal(IResource.DEPTH_ONE, null);
                } catch (CoreException e) {
                    return STATUS_ERROR;
                } finally {
                    model.releaseFromRead();
                }
            } else {
                model.releaseFromRead();
            }
        }
    }
    if ((beforeModifiedFromJavaIO != afterModifiedFromJavaIO) || (beforeModifiedFromIFile != afterModifiedFromIFile)) {
        // applied.
        return STATUS_ERROR;
    }
    return STATUS_OK;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)139 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)102 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)45 IOException (java.io.IOException)37 InputStream (java.io.InputStream)27 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)27 IFile (org.eclipse.core.resources.IFile)23 CoreException (org.eclipse.core.runtime.CoreException)21 BadLocationException (org.eclipse.jface.text.BadLocationException)13 FileNotFoundException (java.io.FileNotFoundException)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)11 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 IProject (org.eclipse.core.resources.IProject)9 StringBufferInputStream (java.io.StringBufferInputStream)8 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)7 IDocument (org.eclipse.jface.text.IDocument)6 PageDirectiveAdapter (org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter)6 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5