diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse')
4 files changed, 213 insertions, 68 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/XSDEditNamespacesAction.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/XSDEditNamespacesAction.java index cacaeb1712..0a2e3d9822 100644 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/XSDEditNamespacesAction.java +++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/actions/XSDEditNamespacesAction.java @@ -22,15 +22,18 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager; import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xml.ui.internal.actions.ReplacePrefixAction; import org.eclipse.wst.xml.ui.internal.util.XMLCommonResources; -import org.eclipse.wst.xsd.ui.internal.dialogs.XSDEditSchemaNS; +import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNamespaceInformationCommand; +import org.eclipse.wst.xsd.ui.internal.common.util.Messages; import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; import org.eclipse.wst.xsd.ui.internal.nsedit.SchemaPrefixChangeHandler; +import org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler; +import org.eclipse.wst.xsd.ui.internal.widgets.XSDEditSchemaInfoDialog; import org.eclipse.xsd.XSDSchema; import org.eclipse.xsd.util.XSDConstants; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; public class XSDEditNamespacesAction extends Action { @@ -57,8 +60,12 @@ public class XSDEditNamespacesAction extends Action { if (element != null) { Shell shell = XMLCommonResources.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(); - XSDEditSchemaNS dialog = new XSDEditSchemaNS(shell, new Path(resourceLocation)); - + String targetNamespace = null; + if (xsdSchema != null) { + targetNamespace = xsdSchema.getTargetNamespace(); + } + XSDEditSchemaInfoDialog dialog = new XSDEditSchemaInfoDialog(shell, new Path(resourceLocation), targetNamespace); + List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(element); List oldNamespaceInfoList = NamespaceInfo.cloneNamespaceInfoList(namespaceInfoList); @@ -71,15 +78,29 @@ public class XSDEditNamespacesAction extends Action { NamespaceInfo oldCopy = new NamespaceInfo(info); info.setProperty("oldCopy", oldCopy); //$NON-NLS-1$ } + +// String currentElementFormQualified = ""; +// String currentAttributeFormQualified = ""; + +// boolean hasElementForm = element.hasAttribute(XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE); +// if (hasElementForm) currentElementFormQualified = element.getAttribute(XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE); +// +// boolean hasAttributeForm = element.hasAttribute(XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE); +// if (hasAttributeForm) currentAttributeFormQualified = element.getAttribute(XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE); dialog.setNamespaceInfoList(namespaceInfoList); dialog.create(); dialog.getShell().setSize(500, 400); dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_MENU_EDIT_SCHEMA_INFORMATION_TITLE")); //$NON-NLS-1$ +// dialog.setIsElementQualified(currentElementFormQualified); +// dialog.setIsAttributeQualified(currentAttributeFormQualified); dialog.setBlockOnOpen(true); dialog.open(); - String xsdPrefix = ""; //$NON-NLS-1$ + String xsdPrefix = null; //$NON-NLS-1$ + String origXSDPrefix = xsdSchema.getSchemaForSchemaQNamePrefix(); + String newTNSPrefix = ""; + if (dialog.getReturnCode() == Window.OK) { Element xsdSchemaElement = xsdSchema.getElement(); @@ -90,6 +111,18 @@ public class XSDEditNamespacesAction extends Action { // see if we need to rename any prefixes Map prefixMapping = createPrefixMapping(oldNamespaceInfoList, namespaceInfoList); + String origTNSPrefix = null; + Map origPrefixMap = xsdSchema.getQNamePrefixToNamespaceMap(); + for (Iterator iter = origPrefixMap.keySet().iterator(); iter.hasNext();) + { + String key = (String) iter.next(); + String ns = (String) origPrefixMap.get(key); + if ((targetNamespace == null && ns == null) || targetNamespace != null && targetNamespace.equals(ns)) + { + origTNSPrefix = key; + break; + } + } Map map2 = new Hashtable(); for (Iterator iter = newInfoList.iterator(); iter.hasNext(); ) { @@ -102,6 +135,10 @@ public class XSDEditNamespacesAction extends Action { { xsdPrefix = pref; } + if (uri.equals(dialog.getTargetNamespace())) + { + newTNSPrefix = pref; + } map2.put(pref, uri); } @@ -110,34 +147,76 @@ public class XSDEditNamespacesAction extends Action { try { doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE")); + boolean targetNamespaceChanged = (targetNamespace != null && !targetNamespace.equals(dialog.getTargetNamespace()) || targetNamespace == null && dialog.getTargetNamespace() != null); + boolean tnsPrefixChanged = !newTNSPrefix.equals(origTNSPrefix); + boolean xsdPrefixChanged = (!(origXSDPrefix == null && xsdPrefix.equals("")) || (origXSDPrefix != null && !origXSDPrefix.equals(xsdPrefix))); + + xsdSchema.setIncrementalUpdate(false); - if (xsdPrefix != null && xsdPrefix.length() == 0) + // First handle the prefix change for the target namespace + if (tnsPrefixChanged) { - xsdSchema.setSchemaForSchemaQNamePrefix(null); + prefixMapping.remove(origTNSPrefix); + UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand(Messages._UI_ACTION_NAMESPACE_INFORMATION_CHANGE, xsdSchema, newTNSPrefix, targetNamespace); + command.execute(); + xsdSchema.update(); } - else + // Second, handle the target namespace change + if (targetNamespaceChanged) { - xsdSchema.setSchemaForSchemaQNamePrefix(xsdPrefix); + // set the targetNamespace attribute + xsdSchema.setTargetNamespace(dialog.getTargetNamespace()); + + TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, targetNamespace, dialog.getTargetNamespace()); + targetNamespaceChangeHandler.resolve(); } + // Third, handle the schema for schema prefix change + if (xsdPrefixChanged) + { + if (xsdPrefix != null && xsdPrefix.length() == 0) + { + xsdSchema.setSchemaForSchemaQNamePrefix(null); + } + else + { + xsdSchema.setSchemaForSchemaQNamePrefix(xsdPrefix); + } + + namespaceInfoManager.removeNamespaceInfo(element); + namespaceInfoManager.addNamespaceInfo(element, newInfoList, false); + xsdSchema.setIncrementalUpdate(true); - xsdSchema.update(); - - SchemaPrefixChangeHandler spch = new SchemaPrefixChangeHandler(xsdSchema, xsdPrefix); - spch.resolve(); - xsdSchema.update(); + // Now change the references to any schema types/components ie. string --> xs:string + SchemaPrefixChangeHandler spch = new SchemaPrefixChangeHandler(xsdSchema, xsdPrefix); + spch.resolve(); + + // Change the prefix for all schema components + updateAllNodes(element, xsdPrefix); + + prefixMapping.remove(origXSDPrefix); + } + // Now handle the other changes. PrefixMapping size should be greater than 0 for any remaining prefix changes - xsdSchema.setIncrementalUpdate(false); + if (prefixMapping.size() > 0) + { + for (Iterator iter = prefixMapping.keySet().iterator(); iter.hasNext(); ) + { + String oldPrefix = (String)iter.next(); + String newPrefix = (String)prefixMapping.get(oldPrefix); + + // Now update any references to this old prefix in the schema with the value of the new prefix + String ns = (String)origPrefixMap.get(oldPrefix); + SchemaPrefixChangeHandler spch = new SchemaPrefixChangeHandler(xsdSchema, newPrefix, ns); + spch.resolve(); + } + } namespaceInfoManager.removeNamespaceInfo(element); namespaceInfoManager.addNamespaceInfo(element, newInfoList, false); + xsdSchema.setIncrementalUpdate(true); - - // don't need these any more? - ReplacePrefixAction replacePrefixAction = new ReplacePrefixAction(null, element, prefixMapping); - replacePrefixAction.run(); } catch (Exception e) { -// e.printStackTrace(); } finally { @@ -146,6 +225,56 @@ public class XSDEditNamespacesAction extends Action { } } +// String attributeFormQualified = dialog.getAttributeFormQualified(); +// String elementFormQualified = dialog.getElementFormQualified(); +// +// boolean elementFormChanged = true; +// boolean attributeFormChanged = true; +// if (elementFormQualified.equals(currentElementFormQualified)) +// { +// elementFormChanged = false; +// } +// if (attributeFormQualified.equals(currentAttributeFormQualified)) +// { +// attributeFormChanged = false; +// } +// if (elementFormChanged) +// { +// doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_SCHEMA_ELEMENTFORMDEFAULT_CHANGE")); +// if (elementFormQualified.equals(XSDForm.QUALIFIED_LITERAL.getName())) +// { +// xsdSchema.setElementFormDefault(XSDForm.QUALIFIED_LITERAL); +// } +// else if (elementFormQualified.equals(XSDForm.UNQUALIFIED_LITERAL.getName())) +// { +// xsdSchema.setElementFormDefault(XSDForm.UNQUALIFIED_LITERAL); +// } +// else +// { +// // Model should allow us to remove the attribute +// xsdSchema.getElement().removeAttribute(XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE); +// } +// doc.getModel().endRecording(this); +// } +// if (attributeFormChanged) +// { +// doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_SCHEMA_ATTRIBUTEFORMDEFAULT_CHANGE")); +// if (attributeFormQualified.equals(XSDForm.QUALIFIED_LITERAL.getName())) +// { +// xsdSchema.setAttributeFormDefault(XSDForm.QUALIFIED_LITERAL); +// } +// else if (attributeFormQualified.equals(XSDForm.UNQUALIFIED_LITERAL.getName())) +// { +// xsdSchema.setAttributeFormDefault(XSDForm.UNQUALIFIED_LITERAL); +// } +// else +// { +// // Model should allow us to remove the attribute +// xsdSchema.getElement().removeAttribute(XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE); +// } +// +// doc.getModel().endRecording(this); +// } } } @@ -190,4 +319,26 @@ public class XSDEditNamespacesAction extends Action { } return map; } + + private void updateAllNodes(Element element, String prefix) + { + element.setPrefix(prefix); + NodeList list = element.getChildNodes(); + if (list != null) + { + for (int i=0; i < list.getLength(); i++) + { + Node child = list.item(i); + if (child != null && child instanceof Element) + { + child.setPrefix(prefix); + if (child.hasChildNodes()) + { + updateAllNodes((Element)child, prefix); + } + } + } + } + } + } diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/SchemaPrefixChangeHandler.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/SchemaPrefixChangeHandler.java index f0a5349cba..3ce74a83c2 100644 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/SchemaPrefixChangeHandler.java +++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/SchemaPrefixChangeHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. + * Copyright (c) 2001, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,11 +29,20 @@ public class SchemaPrefixChangeHandler { String newPrefix; XSDSchema xsdSchema; + String namespace; public SchemaPrefixChangeHandler(XSDSchema xsdSchema, String newPrefix) { this.xsdSchema = xsdSchema; this.newPrefix= newPrefix; + namespace = XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001; + } + + public SchemaPrefixChangeHandler(XSDSchema xsdSchema, String newPrefix, String namespace) + { + this.xsdSchema = xsdSchema; + this.newPrefix= newPrefix; + this.namespace = namespace; } public void resolve() @@ -81,8 +90,7 @@ public class SchemaPrefixChangeHandler { String ns = type.getTargetNamespace(); if (ns == null) ns = ""; -// if (ns.equals(xsdSchema.getSchemaForSchemaNamespace())) - if (ns.equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) + if (ns.equals(namespace)) { Element domElement = element.getElement(); if (domElement != null && domElement instanceof IDOMNode) @@ -106,8 +114,7 @@ public class SchemaPrefixChangeHandler { String ns = baseType.getTargetNamespace(); if (ns == null) ns = ""; -// if (ns.equals(xsdSchema.getSchemaForSchemaNamespace())) - if (ns.equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) + if (ns.equals(namespace)) { XSDDOMHelper domHelper = new XSDDOMHelper(); Element derivedBy = domHelper.getDerivedByElement(simpleType.getElement()); @@ -127,7 +134,7 @@ public class SchemaPrefixChangeHandler { String ns = itemType.getTargetNamespace(); if (ns == null) ns = ""; - if (ns.equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) + if (ns.equals(namespace)) { XSDDOMHelper domHelper = new XSDDOMHelper(); Node listNode = domHelper.getChildNode(simpleType.getElement(), XSDConstants.LIST_ELEMENT_TAG); @@ -162,7 +169,7 @@ public class SchemaPrefixChangeHandler XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)i.next(); String ns = st.getTargetNamespace(); if (ns == null) ns = ""; - if (ns.equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) + if (ns.equals(namespace)) { sb.append(getNewQName(st, st.getName(), newPrefix)); } @@ -189,8 +196,7 @@ public class SchemaPrefixChangeHandler { String ns = type.getTargetNamespace(); if (ns == null) ns = ""; -// if (ns.equals(xsdSchema.getSchemaForSchemaNamespace())) - if (ns.equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) + if (ns.equals(namespace)) { Element domElement = attr.getElement(); if (domElement != null && domElement instanceof IDOMNode) diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/XSDVisitor.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/XSDVisitor.java index cea2e24e68..115511a09e 100644 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/XSDVisitor.java +++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/nsedit/XSDVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. + * Copyright (c) 2001, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -142,9 +142,9 @@ public class XSDVisitor public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) { - if (type.getContentType() != null) + XSDComplexTypeContent complexContent = type.getContent(); + if (complexContent != null) { - XSDComplexTypeContent complexContent = type.getContentType(); if (complexContent instanceof XSDSimpleTypeDefinition) { visitSimpleTypeDefinition((XSDSimpleTypeDefinition)complexContent); diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/widgets/XSDEditSchemaInfoDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/widgets/XSDEditSchemaInfoDialog.java index 4062dcf850..abd0167c44 100644 --- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/widgets/XSDEditSchemaInfoDialog.java +++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/widgets/XSDEditSchemaInfoDialog.java @@ -21,25 +21,22 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.wst.xml.ui.internal.dialogs.EditSchemaInfoDialog; import org.eclipse.wst.xml.ui.internal.nsedit.CommonEditNamespacesTargetFieldDialog; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.xsd.XSDForm; -/** - * @deprecated. To be removed - * - */ public class XSDEditSchemaInfoDialog extends EditSchemaInfoDialog implements SelectionListener { String targetNamespace; CommonEditNamespacesTargetFieldDialog editNamespacesControl; + /** + * @deprecated - These have been moved to the Advanced Properties Tab + */ Combo elementFormCombo, attributeFormCombo; + /** + * @deprecated + */ String elementFormQualified = "", attributeFormQualified = ""; //$NON-NLS-1$ //$NON-NLS-2$ - private String [] formQualification = { "", XSDForm.QUALIFIED_LITERAL.getLiteral(), XSDForm.UNQUALIFIED_LITERAL.getLiteral() }; //$NON-NLS-1$ - public XSDEditSchemaInfoDialog(Shell parentShell, IPath resourceLocation, String targetNamespace) { super(parentShell, resourceLocation); this.targetNamespace = targetNamespace; @@ -68,34 +65,7 @@ public class XSDEditSchemaInfoDialog extends EditSchemaInfoDialog implements Sel } editNamespacesControl.setNamespaceInfoList(namespaceInfoList); editNamespacesControl.updateErrorMessage(namespaceInfoList); - - Label separator = new Label(dialogArea, SWT.SEPARATOR | SWT.HORIZONTAL); - GridData gd = new GridData(GridData.FILL_BOTH); - separator.setLayoutData(gd); - - Composite otherAttributesComposite = new Composite(dialogArea, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - otherAttributesComposite.setLayout(layout); - GridData data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = SWT.FILL; - otherAttributesComposite.setLayoutData(data); - - Label elementFormLabel = new Label(otherAttributesComposite, SWT.LEFT); - elementFormLabel.setText(Messages._UI_LABEL_ELEMENTFORMDEFAULT); - elementFormCombo = new Combo(otherAttributesComposite, SWT.NONE); - elementFormCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - elementFormCombo.setItems(formQualification); - elementFormCombo.addSelectionListener(this); - - Label attributeFormLabel = new Label(otherAttributesComposite, SWT.LEFT); - attributeFormLabel.setText(Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT); - - attributeFormCombo = new Combo(otherAttributesComposite, SWT.NONE); - attributeFormCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - attributeFormCombo.setItems(formQualification); - attributeFormCombo.addSelectionListener(this); applyDialogFont(parent); return dialogArea; } @@ -104,33 +74,51 @@ public class XSDEditSchemaInfoDialog extends EditSchemaInfoDialog implements Sel return editNamespacesControl.getTargetNamespace(); } + /** + * @deprecated + */ public void setIsElementQualified(String state) { elementFormCombo.setText(state); elementFormQualified = state; } + /** + * @deprecated + */ public void setIsAttributeQualified(String state) { attributeFormCombo.setText(state); attributeFormQualified = state; } + /** + * @deprecated + */ public String getElementFormQualified() { return elementFormQualified; } + /** + * @deprecated + */ public String getAttributeFormQualified() { return attributeFormQualified; } + /** + * @deprecated + */ public void widgetDefaultSelected(SelectionEvent e) { } + /** + * @deprecated + */ public void widgetSelected(SelectionEvent e) { if (e.widget == attributeFormCombo) |