Search in sources :

Example 66 with IModelManager

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

the class ViewerTestXML method setupViewerForNew.

/**
 * Set up source viewer with a new document & configure it
 */
private void setupViewerForNew() {
    // if was following selection, stop
    stopFollowSelection();
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDocument doc = modelManager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML);
    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 67 with IModelManager

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

the class TestOpenEditorXML method testBug151069.

/**
 * Test structured document is reloaded on resource change
 */
public void testBug151069() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    // set h1 to readonly
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getExistingModelForEdit(doc);
        if (model != null) {
            NodeList nl = model.getDocument().getElementsByTagName("h1");
            IDOMElement h1 = (IDOMElement) nl.item(0);
            h1.setEditable(false, true);
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
    String newContent = "new content";
    ((IDocumentExtension4) doc).set(newContent, fFile.getModificationStamp());
    assertEquals("Set contents in document with read only regions failed", newContent, doc.get());
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDocument(org.eclipse.jface.text.IDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 68 with IModelManager

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

the class XMLColorPage method setupPicker.

protected void setupPicker(StyledTextColorPicker picker) {
    IModelManager mmanager = StructuredModelManager.getModelManager();
    picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML).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 69 with IModelManager

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

the class NamespaceSelectionAdapter method widgetSelected.

@Override
public void widgetSelected(SelectionEvent e) {
    IEditorPart activeEditor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = createNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 70 with IModelManager

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

the class PrefixHandler method execute.

/**
 * This will use the active editor, and try and retrieve a structured
 * model from it.  If successful, it setups the namespace edit dialog
 * to capture the namespace information.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    XPathUIPlugin plugin = XPathUIPlugin.getDefault();
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    // suppress an NPE in the log (shouldn't happen with the enabledWhen rule)
    if (activeEditor == null)
        return null;
    IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IDOMModel model = null;
    try {
        model = (IDOMModel) modelManager.getModelForRead(file);
        IDOMDocument document = model.getDocument();
        if (document != null) {
            List<NamespaceInfo> info = plugin.getNamespaceInfo(document);
            IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
            EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
            dlg.setNamespaceInfoList(info);
            if (SWT.OK == dlg.open()) {
            // Apply changes
            }
        }
    } catch (Exception ex) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    return null;
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IFile(org.eclipse.core.resources.IFile) XPathUIPlugin(org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IEditorPart(org.eclipse.ui.IEditorPart) EditNamespacePrefixDialog(org.eclipse.wst.xml.xpath.ui.internal.views.EditNamespacePrefixDialog) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) ExecutionException(org.eclipse.core.commands.ExecutionException)

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