[189233] [Editor] New Type dialog for an attribute should be constrained to 'simple types' only
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDBaseAttributeAdapter.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDBaseAttributeAdapter.java
index f795cff..4eec05f 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDBaseAttributeAdapter.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDBaseAttributeAdapter.java
@@ -30,6 +30,7 @@
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
 import org.eclipse.xsd.XSDAttributeDeclaration;
 import org.eclipse.xsd.XSDTypeDefinition;
+import org.eclipse.xsd.util.XSDConstants;
 
 // a base adapter for reuse by an AttributeUse and AttributeDeclaration
 //
@@ -63,7 +64,7 @@
 
   public String getKind()
   {
-    return "attribute"; //$NON-NLS-1$
+    return XSDConstants.ATTRIBUTE_ELEMENT_TAG;
   }
 
   public int getMaxOccurs()
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewTypeDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewTypeDialog.java
index e4aaf04..202e215 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewTypeDialog.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewTypeDialog.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
@@ -65,7 +65,7 @@
 	  if (schema != null) {
 		  List usedNames = getUsedTypeNames();
 		  setUsedNames(usedNames);
-		  setDefaultName(XSDCommonUIUtils.createUniqueElementName("NewType", schema.getTypeDefinitions()));
+		  setDefaultName(XSDCommonUIUtils.createUniqueElementName(name, schema.getTypeDefinitions()));
 	  }
   }
   
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/Messages.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/Messages.java
index 5ae183f..df6b0a2 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/Messages.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/Messages.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
@@ -71,6 +71,7 @@
   public static String _UI_LABEL_SET_COMMON_BUILT_IN_TYPES;
   public static String _UI_LABEL_SELECT_TYPES_FILTER_OUT;
   public static String _UI_LABEL_NEW_TYPE;
+  public static String _UI_VALUE_NEW_TYPE;  
   public static String _UI_LABEL_COMPLEX_TYPE;
   public static String _UI_LABEL_SIMPLE_TYPE;
   public static String _UI_LABEL_NEW_ELEMENT;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDTypeReferenceEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDTypeReferenceEditManager.java
index 1a78dde..8748901 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDTypeReferenceEditManager.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDTypeReferenceEditManager.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
@@ -16,10 +16,14 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.gef.commands.Command;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
 import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentDescriptionProvider;
 import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager2;
 import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog;
+import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject;
+import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
 import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand;
 import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand;
 import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand;
@@ -37,12 +41,12 @@
 import org.eclipse.xsd.util.XSDConstants;
 import org.eclipse.xsd.util.XSDSchemaBuildingTools;
 
-public class XSDTypeReferenceEditManager implements ComponentReferenceEditManager
+public class XSDTypeReferenceEditManager implements ComponentReferenceEditManager, ComponentReferenceEditManager2
 {  
   protected IFile currentFile;
   protected XSDSchema[] schemas;
-  
   private static ComponentSpecification result[];
+  private IADTObject referencer;
   
   public XSDTypeReferenceEditManager(IFile currentFile, XSDSchema[] schemas)
   {
@@ -54,6 +58,16 @@
   {
     // TODO (cs) implement me!    
   }
+  
+  public IADTObject getReferencer()
+  {
+    return referencer;
+  }
+  
+  public void setReferencer(IADTObject referencer)
+  {
+    this.referencer = referencer;
+  }
 
   public IComponentDialog getBrowseDialog()
   {
@@ -82,12 +96,33 @@
 
   public IComponentDialog getNewDialog()
   {
-	  if (schemas.length > 0) {
-		  return new NewTypeDialog(schemas[0]);
-	  }
-	  else {
-		  return new NewTypeDialog();
-	  }
+    NewTypeDialog result = null;
+    if (schemas.length > 0) 
+    {
+      result = new NewTypeDialog(schemas[0]);
+    }
+    else 
+    {
+      result = new NewTypeDialog();
+    }
+    if (referencer instanceof IField)
+    {
+      IField field = (IField)referencer;
+      if (XSDConstants.ATTRIBUTE_ELEMENT_TAG.equals(field.getKind()))
+      {
+        result.allowComplexType(false);
+      }
+      String fieldName = field.getName();
+      if (fieldName != null)
+      {  
+        fieldName = fieldName.trim();
+        if (fieldName.length() > 0)
+        {  
+          result.setDefaultName(NLS.bind(Messages._UI_VALUE_NEW_TYPE, fieldName));
+        }  
+      }  
+    }
+    return result;
   }
 
   public ComponentSpecification[] getQuickPicks()
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/messages.properties
index dcdc5a5..83a3900 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/messages.properties
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/messages.properties
@@ -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
@@ -98,6 +98,7 @@
 _UI_LABEL_SET_ELEMENT_REFERENCE=Set element reference
 
 _UI_LABEL_NEW_TYPE=New Type
+_UI_VALUE_NEW_TYPE={0}Type
 _UI_LABEL_NEW_ELEMENT=New Element
 _UI_LABEL_COMPLEX_TYPE=Complex Type
 _UI_LABEL_TARGET_NAMESPACE=Target Namespace: 
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/TypeReferenceDirectEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/TypeReferenceDirectEditManager.java
index c781c67..6f9b7e4 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/TypeReferenceDirectEditManager.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/TypeReferenceDirectEditManager.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
@@ -23,6 +23,7 @@
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
 import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager2;
 import org.eclipse.wst.xsd.ui.internal.adt.editor.Messages;
 import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager;
@@ -154,6 +155,11 @@
     if (editor != null)
     {
         result = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class);
+        if (result instanceof ComponentReferenceEditManager2)
+        {
+          ComponentReferenceEditManager2 manager = (ComponentReferenceEditManager2)result;
+          manager.setReferencer(setObject);
+        }
     }  
     return result;
   }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/edit/ComponentReferenceEditManager2.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/edit/ComponentReferenceEditManager2.java
new file mode 100644
index 0000000..c01312d
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/edit/ComponentReferenceEditManager2.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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.adt.edit;
+
+import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject;
+
+public interface ComponentReferenceEditManager2 extends ComponentReferenceEditManager
+{
+  void setReferencer(IADTObject field);
+  IADTObject getReferencer();
+}