[170557] Extensions and Extension Properties View Fixes. Check for extensible add action commands
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
index 14e5263..ca4d8a8 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
@@ -73,25 +73,33 @@
}
private void addAnnotationSet(SpecificationForExtensionsSchema spec, XSDAnnotation xsdAnnotation)
- {
- // appInfo = xsdAnnotation.createApplicationInformation(spec.getNamespaceURI());
- // Don't pass in namespace to create the source attribute on the appInfo
- appInfo = xsdAnnotation.createApplicationInformation(null);
+ {
+ XSDSchema schema= xsdAnnotation.getSchema();
+ Element schemaElement = schema.getElement();
+
+ if (xsdAnnotation.getApplicationInformation().size() == 0)
+ {
+ appInfo = xsdAnnotation.createApplicationInformation(null);
+ xsdAnnotation.getElement().appendChild(appInfo);
+ List appInfos = xsdAnnotation.getApplicationInformation();
+ appInfos.add(appInfo);
+ }
+ else
+ {
+ // use the first appInfo
+ appInfo = (Element)xsdAnnotation.getApplicationInformation().get(0);
+ }
+
+ String prefix = addNamespaceDeclarationIfRequired(schemaElement, "p", spec.getNamespaceURI());
if (appInfo != null)
{
Document doc = appInfo.getOwnerDocument();
- XSDSchema schema= xsdAnnotation.getSchema();
- Element schemaElement = schema.getElement();
- String prefix = addNamespaceDeclarationIfRequired(schemaElement, "p", spec.getNamespaceURI());
-
+
newElement = doc.createElementNS(spec.getNamespaceURI(), element.getName());
newElement.setPrefix(prefix);
appInfo.appendChild(newElement);
- xsdAnnotation.getElement().appendChild(appInfo);
- List appInfos = xsdAnnotation.getApplicationInformation();
- appInfos.add(appInfo);
xsdAnnotation.updateElement();
}
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java
new file mode 100644
index 0000000..b407f1f
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.xsd.ui.internal.common.commands;
+
+import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.util.XSDConstants;
+import org.w3c.dom.Element;
+
+public class ExtensibleAddExtensionCommand extends AddExtensionCommand
+{
+ protected XSDElementDeclaration element;
+ protected Element appInfo;
+ protected Element newElement;
+
+ public ExtensibleAddExtensionCommand(String label)
+ {
+ super(label);
+ }
+
+ public XSDElementDeclaration getXSDElementDeclarationElement()
+ {
+ return element;
+ }
+
+ public Element getNewElement()
+ {
+ return newElement;
+ }
+
+ public Element getAppInfo()
+ {
+ return appInfo;
+ }
+
+ public XSDSchema getXSDSchema()
+ {
+ return component.getSchema();
+ }
+
+ public void setInputs(XSDConcreteComponent input, XSDElementDeclaration element)
+ {
+ this.component = input;
+ this.element = element;
+ }
+
+ public void execute()
+ {
+ try
+ {
+ beginRecording(component.getElement());
+ super.execute();
+
+ addCustomizedActions();
+
+ formatChild(component.getElement());
+ }
+ finally
+ {
+ endRecording();
+ }
+ }
+
+ public void addCustomizedActions()
+ {
+
+ }
+
+ public void undo()
+ {
+ super.undo();
+// XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
+// xsdAnnotation.getElement().removeChild(appInfo);
+// List appInfos = xsdAnnotation.getApplicationInformation();
+// appInfos.remove(appInfo);
+// xsdAnnotation.updateElement();
+ }
+
+ public Object getNewObject()
+ {
+ return newElement;
+ }
+
+ // TODO... common this up with wsdl.ui
+ protected String addNamespaceDeclarationIfRequired(Element schemaElement, String prefixHint, String namespace)
+ {
+ String prefix = null;
+ NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument());
+ namespaceTable.addElement(schemaElement);
+ prefix = namespaceTable.getPrefixForURI(namespace);
+ if (prefix == null)
+ {
+ String basePrefix = prefixHint;
+ prefix = basePrefix;
+ String xmlnsColon = "xmlns:"; //$NON-NLS-1$
+ String attributeName = xmlnsColon + prefix;
+ int count = 0;
+ while (schemaElement.getAttribute(attributeName) != null)
+ {
+ count++;
+ prefix = basePrefix + count;
+ attributeName = xmlnsColon + prefix;
+ }
+ schemaElement.setAttribute(attributeName, namespace);
+ }
+ return prefix;
+ }
+
+ protected void addSchemaAttribute(Element schemaElement, String namespace, String attributeName, String attributeValue)
+ {
+ String prefix = null;
+ NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument());
+ namespaceTable.addElement(schemaElement);
+ prefix = namespaceTable.getPrefixForURI(namespace);
+ try
+ {
+ if (prefix != null)
+ {
+ schemaElement.setAttribute(prefix + ":" + attributeName, attributeValue);
+ }
+ else
+ {
+ schemaElement.setAttribute(attributeName, attributeValue);
+ }
+ }
+ catch (Exception e)
+ {
+
+ }
+ }
+
+ protected void addSourceAttributeToAppInfo(String namespace)
+ {
+ if (appInfo.getAttributeNode(XSDConstants.SOURCE_ATTRIBUTE) == null)
+ appInfo.setAttribute(XSDConstants.SOURCE_ATTRIBUTE, namespace);
+ }
+
+ /**
+ *
+ * @param element
+ * @param attributeName
+ * @param attributeValue
+ */
+ protected void addAttribute(Element element, String attributeName, String attributeValue)
+ {
+ element.setAttribute(attributeName, attributeValue);
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java
index 9755d59..2626cb3 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.commands;
+import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
import org.eclipse.xsd.util.XSDConstants;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
@@ -40,13 +41,14 @@
Node parent = node.getParentNode();
if (parent != null)
{
- parent.removeChild(node);
- // if parent is an AppInfo node then we should remove the appinfo
- //
- if (XSDConstants.APPINFO_ELEMENT_TAG.equals(parent.getLocalName()))
+ XSDDOMHelper.removeNodeAndWhitespace(node);
+
+ if (XSDDOMHelper.hasOnlyWhitespace(parent))
{
- Node grandpa = parent.getParentNode();
- grandpa.removeChild(parent);
+ if (XSDConstants.APPINFO_ELEMENT_TAG.equals(parent.getLocalName()))
+ {
+ XSDDOMHelper.removeNodeAndWhitespace(parent);
+ }
}
}
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java
index f81b8a9..e96f576 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java
@@ -23,6 +23,7 @@
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog;
+import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand;
import org.w3c.dom.Element;
public class ExtensionsSchemasRegistry
@@ -34,11 +35,12 @@
public static final String NAMESPACEURI = "namespaceURI"; //$NON-NLS-1$
public static final String XSDFILEURL = "xsdFileURL"; //$NON-NLS-1$
public static final String LABELPROVIDER = "labelProviderClass"; //$NON-NLS-1$
+ public static final String ADD_COMMAND_CLASS = "addCommandClass"; //$NON-NLS-1$
protected IPreferenceStore prefStore;
protected String extensionId;
- HashMap propertyMap;
+ HashMap propertyMap, commandMap;
ArrayList nsURIProperties;
private ICatalog systemCatalog;
private String deprecatedExtensionId;
@@ -68,6 +70,7 @@
nsURIProperties = new ArrayList();
propertyMap = new HashMap();
+ commandMap = new HashMap();
getAllExtensionsSchemasContribution(extensionId);
if (deprecatedExtensionId != null)
@@ -106,6 +109,7 @@
String namespaceURI = asiPropertiesElement.getAttribute(NAMESPACEURI);
String xsdFileURL = asiPropertiesElement.getAttribute(XSDFILEURL);
String labelProviderClass = asiPropertiesElement.getAttribute(LABELPROVIDER);
+ String actionHandlerClass = asiPropertiesElement.getAttribute(ADD_COMMAND_CLASS);
if (displayName == null)
{
@@ -126,9 +130,10 @@
extensionsSchemaSpec.setNamespaceURI(namespaceURI);
extensionsSchemaSpec.setDefautSchema();
+ String pluginId = asiPropertiesElement.getDeclaringExtension().getContributor().getName();
+
if (labelProviderClass != null)
{
- String pluginId = asiPropertiesElement.getDeclaringExtension().getContributor().getName();
ILabelProvider labelProvider = null;
try
{
@@ -148,8 +153,25 @@
}
}
- String plugin = asiPropertiesElement.getDeclaringExtension().getContributor().getName();
- extensionsSchemaSpec.setLocation(LOCATION_PREFIX + plugin + "/" + xsdFileURL); //$NON-NLS-1$
+
+ if (actionHandlerClass != null)
+ {
+ try
+ {
+ ExtensibleAddExtensionCommand actionHandler = (ExtensibleAddExtensionCommand)asiPropertiesElement.createExecutableExtension(ADD_COMMAND_CLASS);
+ if (actionHandler != null)
+ {
+ commandMap.put(namespaceURI, actionHandler);
+ extensionsSchemaSpec.setExtensibleAddExtensionCommand(actionHandler);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ extensionsSchemaSpec.setLocation(LOCATION_PREFIX + pluginId + "/" + xsdFileURL); //$NON-NLS-1$
nsURIProperties.add(extensionsSchemaSpec);
}
@@ -158,6 +180,22 @@
return nsURIProperties;
}
+
+ public ExtensibleAddExtensionCommand getAddExtensionHandler(String namespace)
+ {
+ // Didn't retrieve the config elements yet.
+ if (commandMap == null)
+ {
+ getAllExtensionsSchemasContribution();
+ }
+
+ Object object = commandMap.get(namespace);
+ if (object instanceof ExtensibleAddExtensionCommand)
+ {
+ return (ExtensibleAddExtensionCommand) object;
+ }
+ return null;
+ }
/**
* @deprecated