Search in sources :

Example 41 with IStructuredModel

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

the class NewHTMLTemplatesWizardPage method createViewer.

/**
 * Creates, configures and returns a source viewer to present the template
 * pattern on the preference page. Clients may override to provide a
 * custom source viewer featuring e.g. syntax coloring.
 *
 * @param parent
 *            the parent control
 * @return a configured source viewer
 */
private SourceViewer createViewer(Composite parent) {
    SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() {

        StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationHTML();

        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return baseConfiguration.getConfiguredContentTypes(sourceViewer);
        }

        public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) {
            return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType);
        }
    };
    SourceViewer 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(ContentTypeIdForHTML.ContentTypeID_HTML);
    IDocument document = scratchModel.getStructuredDocument();
    viewer.configure(sourceViewerConfiguration);
    viewer.setDocument(document);
    return viewer;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) LineStyleProvider(org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) StructuredTextViewerConfiguration(org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) IDocument(org.eclipse.jface.text.IDocument)

Example 42 with IStructuredModel

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

the class CleanupActionHTMLDelegate method isXHTML.

private boolean isXHTML() {
    boolean isxhtml = false;
    if (fEditor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) fEditor;
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        IStructuredModel model = null;
        try {
            model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
            if (model instanceof IDOMModel) {
                IDOMDocument domDocument = ((IDOMModel) model).getDocument();
                if (domDocument != null)
                    isxhtml = domDocument.isXMLType();
            }
        } finally {
            if (model != null) {
                model.releaseFromRead();
            }
        }
    }
    return isxhtml;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument)

Example 43 with IStructuredModel

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

the class CleanupActionHTMLDelegate method run.

public void run(IAction action) {
    if (fEditor instanceof ITextEditor) {
        final ITextEditor editor = (ITextEditor) fEditor;
        CleanupDialogHTML cleanupDialog = new CleanupDialogHTML(editor.getSite().getShell());
        cleanupDialog.setisXHTMLType(isXHTML());
        if (cleanupDialog.open() == Window.OK) {
            // setup runnable
            Runnable runnable = new Runnable() {

                public void run() {
                    IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
                    if (cleanupProcessor != null) {
                        IStructuredModel model = null;
                        try {
                            model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                            if (model != null)
                                cleanupProcessor.cleanupModel(model);
                        } finally {
                            if (model != null)
                                model.releaseFromEdit();
                        }
                    }
                }
            };
            // TODO: make independent of 'model'.
            IStructuredModel model = null;
            try {
                model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
                if (model != null) {
                    // 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(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
                }
            } finally {
                if (model != null) {
                    // 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());
                    model.releaseFromEdit();
                }
            }
        }
    }
}
Also used : IStructuredCleanupProcessor(org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 44 with IStructuredModel

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

the class HTMLTemplatePreferencePage method doCreateViewer.

SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) {
    SourceViewer viewer = null;
    String contentTypeID = ContentTypeIdForHTML.ContentTypeID_HTML;
    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 45 with IStructuredModel

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

the class HTMLSourceValidator method getCorrespondingNode.

protected IndexedRegion getCorrespondingNode(IStructuredDocumentRegion sdRegion) {
    IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
    IndexedRegion indexedRegion = null;
    try {
        if (sModel != null)
            indexedRegion = sModel.getIndexedRegion(sdRegion.getStart());
    } finally {
        if (sModel != null)
            sModel.releaseFromRead();
    }
    return indexedRegion;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

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