Search in sources :

Example 96 with IModelManager

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

the class FileUtil method createModel.

public static ICSSModel createModel() {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        // $NON-NLS-1$
        model = modelManager.getModelForEdit("test" + uniqueNum++ + ".css", new NullInputStream(), null);
        // always use the same line delimiter for these tests, regardless
        // of plaform or preference settings
        model.getStructuredDocument().setLineDelimiter(commonEOL);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (ICSSModel) model;
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 97 with IModelManager

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

the class ViewerTestHTML method setupViewerForNew.

/**
 * Set up source viewer with a new document & configure it
 */
void setupViewerForNew() {
    // if was following selection, stop
    stopFollowSelection();
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDocument doc = modelManager.createStructuredDocumentFor(ContentTypeIdForHTML.ContentTypeID_HTML);
    doc.set(DEFAULT_VIEWER_CONTENTS);
    fSourceViewer.setDocument(doc);
    // need to reconfigure after set document just so highlighter works
    fSourceViewer.configure(fConfig);
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDocument(org.eclipse.jface.text.IDocument)

Example 98 with IModelManager

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

the class TestStructuredPartitionerHTML method getPartitionTest.

/**
 * Retrieves the single partition at the given offset for the given file, using the
 * default partitioner for that file type.  This test allows for verifying the zero-length
 * partitioning behavior.
 *
 * @param filename
 * @param offset
 * @return ITypedRegion
 * @throws IOException
 * @throws BadLocationException
 */
protected ITypedRegion getPartitionTest(String filename, int offset) throws IOException, BadLocationException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = getClass().getResourceAsStream(filename);
    IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    partitions = null;
    ITypedRegion partition = structuredDocument.getPartition(offset);
    if (DEBUG_PRINT_RESULT) {
        String contents = null;
        System.out.println("\nfilename: " + filename);
        try {
            contents = structuredDocument.get(partition.getOffset(), partition.getLength());
        } catch (BadLocationException e) {
            contents = "*error*";
        }
        System.out.println(partition + " [" + StringUtils.escape(contents) + "]");
    }
    model.releaseFromEdit();
    inStream.close();
    return partition;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) ITypedRegion(org.eclipse.jface.text.ITypedRegion) 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 99 with IModelManager

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

the class ModelTest method createXMLModel.

public static IDOMModel createXMLModel() {
    // return new XMLModelImpl();
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        // assertTrue("modelManager must not be null", modelManager !=
        // null);
        model = modelManager.getModelForEdit("test.xml", new NullInputStream(), null);
        // always use the same line delimiter for these tests, regardless
        // of
        // plaform or preference settings
        model.getStructuredDocument().setLineDelimiter(TestWriter.commonEOL);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // null);
    return (IDOMModel) model;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 100 with IModelManager

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

the class TestJSPContentFormatter method getModelForEdit.

/**
 * must release model (from edit) after
 *
 * @param filename
 *            relative to this class (TestFormatProcessorCSS)
 */
private IStructuredModel getModelForEdit(final String filename) {
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
    assertTrue("unable to find file: " + filename, file.exists());
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForEdit(file);
    } catch (CoreException ce) {
        ce.printStackTrace();
    } catch (IOException io) {
        io.printStackTrace();
    }
    return model;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

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