Search in sources :

Example 6 with DocumentImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.

the class AbstractSection method beginRecording.

public void beginRecording(String description, Element element) {
    DocumentImpl doc = getDocument(element);
    doc.getModel().beginRecording(this, description);
}
Also used : DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Example 7 with DocumentImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.

the class AbstractSection method endRecording.

public void endRecording(Element element) {
    DocumentImpl doc = getDocument(element);
    doc.getModel().endRecording(this);
}
Also used : DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Example 8 with DocumentImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.

the class XSDSchemaSection method doHandleEvent.

public void doHandleEvent(Event event) {
    // $NON-NLS-1$
    errorText.setText("");
    String prefixValue = prefixText.getText();
    String tnsValue = targetNamespaceText.getText();
    Element element = xsdSchema.getElement();
    TypesHelper helper = new TypesHelper(xsdSchema);
    String currentPrefix = helper.getPrefix(element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE), false);
    String currentNamespace = xsdSchema.getTargetNamespace();
    if (tnsValue.trim().length() == 0) {
        if (prefixValue.trim().length() > 0) {
            // $NON-NLS-1$
            errorText.setText(XSDEditorPlugin.getXSDString("_ERROR_TARGET_NAMESPACE_AND_PREFIX"));
            int length = errorText.getText().length();
            red = new Color(null, 255, 0, 0);
            StyleRange style = new StyleRange(0, length, red, targetNamespaceText.getBackground());
            errorText.setStyleRange(style);
            return;
        }
    }
    if (event.widget == prefixText) {
        // widget loses focus.
        if (prefixValue.equals(currentPrefix))
            return;
        updateNamespaceInfo(prefixValue, tnsValue);
    } else if (event.widget == targetNamespaceText) {
        // widget loses focus.
        if (tnsValue.equals(currentNamespace))
            return;
        DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager();
        List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(xsdSchema.getElement());
        Element xsdSchemaElement = xsdSchema.getElement();
        DocumentImpl doc = (DocumentImpl) xsdSchemaElement.getOwnerDocument();
        try {
            doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE"));
            if (// remove the targetNamespace attribute
            tnsValue.trim().length() == 0) {
                xsdSchemaElement.removeAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE);
                return;
            }
            // Now replace the namespace for the xmlns entry
            for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); ) {
                NamespaceInfo info = (NamespaceInfo) i.next();
                if (info.uri.equals(currentNamespace)) {
                    info.uri = tnsValue;
                }
            }
            xsdSchema.setIncrementalUpdate(false);
            // set the new xmlns entries
            namespaceInfoManager.removeNamespaceInfo(element);
            namespaceInfoManager.addNamespaceInfo(element, namespaceInfoList, false);
            xsdSchema.setIncrementalUpdate(true);
            // set the targetNamespace attribute
            xsdSchema.setTargetNamespace(tnsValue);
            TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, currentNamespace, tnsValue);
            targetNamespaceChangeHandler.resolve();
        } catch (Exception e) {
        } finally {
            try {
                xsdSchema.update();
            } finally {
                doc.getModel().endRecording(this);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) TargetNamespaceChangeHandler(org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl) TypesHelper(org.eclipse.wst.xsd.ui.internal.util.TypesHelper) DOMNamespaceInfoManager(org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager) Iterator(java.util.Iterator) List(java.util.List) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)

Example 9 with DocumentImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.

the class TestRangeCompare method testRangeCompare.

public void testRangeCompare() throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
    model.getStructuredDocument().set(decl);
    Document document = model.getDocument();
    // $NON-NLS-1$
    Element root = document.createElement("parent");
    document.appendChild(root);
    // $NON-NLS-1$
    Element child = document.createElement("child");
    root.appendChild(child);
    // $NON-NLS-1$
    child.appendChild(document.createElement("child1-1"));
    // $NON-NLS-1$
    Text textnode = document.createTextNode("Text Node");
    root.appendChild(textnode);
    // $NON-NLS-1$
    NodeList children = root.getElementsByTagName("child");
    Range range = ((DocumentImpl) document).createRange();
    range.setEnd(children.item(0), 1);
    Range sourceRange = ((DocumentImpl) document).createRange();
    sourceRange.setEnd(textnode, 0);
    int result = range.compareBoundaryPoints(Range.END_TO_END, sourceRange);
    assertEquals(-1, result);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) Range(org.w3c.dom.ranges.Range) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Example 10 with DocumentImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentImpl in project webtools.sourceediting by eclipse.

the class MakeLocalElementGlobalHandler method run.

public void run(ISelection selection, XSDElementDeclaration selectedComponent) {
    DocumentImpl doc = (DocumentImpl) selectedComponent.getElement().getOwnerDocument();
    doc.getModel().beginRecording(this, "MakeLocalElementGlobalHandler.text");
    MakeLocalElementGlobalCommand command = new MakeLocalElementGlobalCommand(selectedComponent);
    command.run();
    doc.getModel().endRecording(this);
}
Also used : MakeLocalElementGlobalCommand(org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Aggregations

DocumentImpl (org.eclipse.wst.xml.core.internal.document.DocumentImpl)11 Element (org.w3c.dom.Element)3 Iterator (java.util.Iterator)2 List (java.util.List)2 NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)2 TargetNamespaceChangeHandler (org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler)2 MakeAnonymousTypeGlobalCommand (org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeAnonymousTypeGlobalCommand)2 MakeLocalElementGlobalCommand (org.eclipse.wst.xsd.ui.internal.refactor.structure.MakeLocalElementGlobalCommand)2 NodeList (org.w3c.dom.NodeList)2 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Path (org.eclipse.core.runtime.Path)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 Color (org.eclipse.swt.graphics.Color)1 Shell (org.eclipse.swt.widgets.Shell)1 DOMNamespaceInfoManager (org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 IDOMDocumentType (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType)1 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)1 UpdateNamespaceInformationCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNamespaceInformationCommand)1