Search in sources :

Example 6 with TypesHelper

use of org.eclipse.wst.xsd.ui.internal.util.TypesHelper in project webtools.sourceediting by eclipse.

the class TypeSection method getPrefix.

public String getPrefix(String ns, XSDSchema xsdSchema) {
    TypesHelper helper = new TypesHelper(xsdSchema);
    String key = helper.getPrefix(ns, true);
    return key;
}
Also used : TypesHelper(org.eclipse.wst.xsd.ui.internal.util.TypesHelper)

Example 7 with TypesHelper

use of org.eclipse.wst.xsd.ui.internal.util.TypesHelper 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 8 with TypesHelper

use of org.eclipse.wst.xsd.ui.internal.util.TypesHelper in project webtools.sourceediting by eclipse.

the class XSDModelGroupDefinitionSection method setInput.

public void setInput(IWorkbenchPart part, ISelection selection) {
    super.setInput(part, selection);
    init();
    relayout();
    if (isReference) {
        TypesHelper helper = new TypesHelper(xsdSchema);
        List items = new ArrayList();
        items = helper.getModelGroups();
        if (input instanceof XSDModelGroupDefinition) {
            XSDModelGroupDefinition group = (XSDModelGroupDefinition) input;
            XSDConcreteComponent parent = group.getContainer();
            while (parent != null) {
                if (parent instanceof XSDModelGroupDefinition) {
                    items.remove(((XSDModelGroupDefinition) parent).getQName());
                    break;
                }
                parent = parent.getContainer();
            }
        }
        // $NON-NLS-1$
        items.add(0, "");
        componentNameCombo.setItems((String[]) items.toArray(new String[0]));
    }
}
Also used : TypesHelper(org.eclipse.wst.xsd.ui.internal.util.TypesHelper) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition)

Aggregations

TypesHelper (org.eclipse.wst.xsd.ui.internal.util.TypesHelper)8 Element (org.w3c.dom.Element)5 List (java.util.List)3 ArrayList (java.util.ArrayList)2 TargetNamespaceChangeHandler (org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler)2 XSDImport (org.eclipse.xsd.XSDImport)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 IFile (org.eclipse.core.resources.IFile)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 Color (org.eclipse.swt.graphics.Color)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IFileEditorInput (org.eclipse.ui.IFileEditorInput)1 DOMNamespaceInfoManager (org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager)1 NamespaceInfo (org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo)1 DocumentImpl (org.eclipse.wst.xml.core.internal.document.DocumentImpl)1