Search in sources :

Example 31 with IStructuredModel

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

the class TestStructuredPartitionerHTML method testGetPartitionType.

public void testGetPartitionType() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/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("paritioner 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)

Example 32 with IStructuredModel

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

the class TestStructuredPartitionerHTML method testDisconnectConnect.

public void testDisconnectConnect() {
    IStructuredModel model = null;
    try {
        model = getModelForEdit("testfiles/html/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 33 with IStructuredModel

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

the class TestJSPContentFormatter method formatAndAssertEquals.

private void formatAndAssertEquals(String beforePath, String afterPath, boolean resetPreferences) throws UnsupportedEncodingException, IOException, CoreException {
    IStructuredModel beforeModel = null, afterModel = null;
    try {
        beforeModel = getModelForEdit(beforePath);
        assertNotNull("could not retrieve structured model for : " + beforePath, beforeModel);
        afterModel = getModelForEdit(afterPath);
        assertNotNull("could not retrieve structured model for : " + afterPath, afterModel);
        if (resetPreferences) {
            resetPreferencesToDefault();
        }
        SourceViewerConfiguration configuration = (SourceViewerConfiguration) ExtendedConfigurationBuilder.getInstance().getConfiguration(ExtendedConfigurationBuilder.SOURCEVIEWERCONFIGURATION, "org.eclipse.jst.jsp.core.jspsource");
        IContentFormatterExtension formatter = (IContentFormatterExtension) configuration.getContentFormatter(null);
        IDocument document = beforeModel.getStructuredDocument();
        Region region = new Region(0, document.getLength());
        fContext.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
        formatter.format(document, fContext);
        ByteArrayOutputStream formattedBytes = new ByteArrayOutputStream();
        // "beforeModel" should now be
        beforeModel.save(formattedBytes);
        // after the formatter
        ByteArrayOutputStream afterBytes = new ByteArrayOutputStream();
        afterModel.save(afterBytes);
        String expectedContents = new String(afterBytes.toByteArray(), UTF_8);
        expectedContents = StringUtils.replace(expectedContents, "\r\n", "\r");
        expectedContents = StringUtils.replace(expectedContents, "\r", "\n");
        String actualContents = new String(formattedBytes.toByteArray(), UTF_8);
        actualContents = StringUtils.replace(actualContents, "\r\n", "\r");
        actualContents = StringUtils.replace(actualContents, "\r", "\n");
        assertTrue(onlyWhiteSpaceDiffers(expectedContents, actualContents));
        assertEquals("Formatted document differs from the expected.", expectedContents, actualContents);
    } finally {
        if (beforeModel != null)
            beforeModel.releaseFromEdit();
        if (afterModel != null)
            afterModel.releaseFromEdit();
    }
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Region(org.eclipse.jface.text.Region) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentFormatterExtension(org.eclipse.jface.text.formatter.IContentFormatterExtension) IDocument(org.eclipse.jface.text.IDocument)

Example 34 with IStructuredModel

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

the class StructuredTextViewer method doModelOperation.

/**
 * Perform the operation under a model change event
 * @param operation the operation to perform
 */
private void doModelOperation(int operation) {
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) getDocument());
    model.aboutToChangeModel();
    try {
        super.doOperation(operation);
    } finally {
        model.changedModel();
    }
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 35 with IStructuredModel

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

the class CleanupAction method run.

public void run() {
    if (getTextEditor() instanceof StructuredTextEditor) {
        final StructuredTextEditor editor = (StructuredTextEditor) getTextEditor();
        Dialog cleanupDialog = getCleanupDialog(editor.getSite().getShell());
        if (cleanupDialog != null) {
            if (cleanupDialog.open() == Window.OK) {
                // setup runnable
                Runnable runnable = new Runnable() {

                    public void run() {
                        IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                        if (cleanupProcessor != null)
                            cleanupProcessor.cleanupModel(editor.getModel());
                    }
                };
                // TODO: make independent of 'model'.
                IStructuredModel model = editor.getModel();
                if (model != null) {
                    try {
                        // begin recording
                        ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                        // $NON-NLS-1$ //$NON-NLS-2$
                        model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
                        // tell the model that we are about to make a big
                        // model change
                        model.aboutToChangeModel();
                        // run
                        BusyIndicator.showWhile(editor.getTextViewer().getControl().getDisplay(), runnable);
                    } finally {
                        // tell the model that we are done with the big
                        // model
                        // change
                        model.changedModel();
                        // end recording
                        ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
                        model.endRecording(this, selection.getOffset(), selection.getLength());
                    }
                }
            }
        }
    }
}
Also used : IStructuredCleanupProcessor(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor) Dialog(org.eclipse.jface.dialogs.Dialog) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)482 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)110 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)102 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)81 IFile (org.eclipse.core.resources.IFile)75 IOException (java.io.IOException)69 CoreException (org.eclipse.core.runtime.CoreException)49 IDocument (org.eclipse.jface.text.IDocument)46 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)42 InputStream (java.io.InputStream)40 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)36 Path (org.eclipse.core.runtime.Path)35 BadLocationException (org.eclipse.jface.text.BadLocationException)34 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)32 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)32 IProject (org.eclipse.core.resources.IProject)31 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)31 IPath (org.eclipse.core.runtime.IPath)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Document (org.w3c.dom.Document)19