[200062] cannot create xsd:any from context menu for datatype
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDComplexTypeDefinitionAdapter.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDComplexTypeDefinitionAdapter.java
index f7d544d..04fe5eb 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDComplexTypeDefinitionAdapter.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDComplexTypeDefinitionAdapter.java
@@ -35,6 +35,7 @@
import org.eclipse.wst.xsd.ui.internal.adt.facade.IType;
import org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAnyAttributeAction;
+import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAnyElementAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeGroupDefinitionAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction;
@@ -250,6 +251,7 @@
list.add(AddXSDElementAction.ID);
list.add(AddXSDElementAction.REF_ID);
+ list.add(AddXSDAnyElementAction.ID);
list.add(BaseSelectionAction.SEPARATOR_ID);
list.add(AddXSDAttributeDeclarationAction.ID);
list.add(AddXSDAttributeDeclarationAction.REF_ID);
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java
index 95fdae3..d50a53b 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java
@@ -10,12 +10,18 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.actions;
+import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDAdapterFactory;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAnyElementCommand;
import org.eclipse.wst.xsd.ui.internal.common.util.Messages;
+import org.eclipse.xsd.XSDComplexTypeContent;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDModelGroup;
+import org.eclipse.xsd.XSDParticle;
+import org.eclipse.xsd.XSDParticleContent;
public class AddXSDAnyElementAction extends XSDBaseAction
{
@@ -30,26 +36,45 @@
public void run()
{
- XSDModelGroup modelGroup = getModelGroup();
- if (modelGroup != null)
- {
- AddXSDAnyElementCommand command = new AddXSDAnyElementCommand(getText(), modelGroup);
- getCommandStack().execute(command);
- }
- }
-
- private XSDModelGroup getModelGroup()
- {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter)
{
selection = ((XSDBaseAdapter) selection).getTarget();
}
+
+ XSDModelGroup modelGroup = getModelGroup(selection);
+
+ AddXSDAnyElementCommand command = new AddXSDAnyElementCommand(getText(), modelGroup);
+ if (selection instanceof XSDComplexTypeDefinition)
+ {
+ command.setComplexType((XSDComplexTypeDefinition)selection);
+ }
+ command.setDoCreateModelGroupForComplexType(modelGroup == null);
+ getCommandStack().execute(command);
+ addedComponent = command.getAddedComponent();
+ Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
+ selectAddedComponent(adapter);
+ }
+
+ private XSDModelGroup getModelGroup(Object selection)
+ {
if (selection instanceof XSDModelGroup)
{
return (XSDModelGroup) selection;
}
+ else if (selection instanceof XSDComplexTypeDefinition)
+ {
+ XSDComplexTypeContent content = ((XSDComplexTypeDefinition)selection).getContent();
+ if (content instanceof XSDParticle)
+ {
+ XSDParticleContent particleContent = ((XSDParticle)content).getContent();
+ if (particleContent instanceof XSDModelGroup)
+ {
+ return (XSDModelGroup)particleContent;
+ }
+ }
+ }
return null;
}
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java
index d777ec3..1b88a58 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * Copyright (c) 2001, 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
@@ -10,26 +10,61 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.commands;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDCompositor;
import org.eclipse.xsd.XSDFactory;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDWildcard;
+import org.eclipse.xsd.util.XSDSchemaBuildingTools;
public class AddXSDAnyElementCommand extends BaseCommand
{
XSDModelGroup parent;
+ XSDComplexTypeDefinition complexType;
+ boolean doCreateModelGroupForComplexType = false;
public AddXSDAnyElementCommand(String label, XSDModelGroup parent)
{
super(label);
this.parent = parent;
}
+
+ public void setComplexType(XSDComplexTypeDefinition complexType)
+ {
+ this.complexType = complexType;
+ }
+
+ public void setDoCreateModelGroupForComplexType(boolean doCreate)
+ {
+ this.doCreateModelGroupForComplexType = doCreate;
+ }
+
+ private void createModelGroup()
+ {
+ XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
+ XSDParticle particle = factory.createXSDParticle();
+ parent = factory.createXSDModelGroup();
+ parent.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
+ particle.setContent(parent);
+ complexType.setContent(particle);
+ }
public void execute()
{
try
{
- beginRecording(parent.getElement());
+ if (doCreateModelGroupForComplexType)
+ {
+ Assert.isNotNull(complexType);
+ beginRecording(complexType.getElement());
+ createModelGroup();
+ }
+ else
+ {
+ beginRecording(parent.getElement());
+ }
XSDWildcard wildCard = XSDFactory.eINSTANCE.createXSDWildcard();
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(wildCard);