[205515] unable to add/edit attribute references for complex types in schema
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeDeclarationAdapter.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeDeclarationAdapter.java
index 15adc90..59fc8e1 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeDeclarationAdapter.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeDeclarationAdapter.java
@@ -34,6 +34,11 @@
   {
     return getXSDAttributeDeclaration().eContainer() instanceof XSDSchema;
   }
+  
+  public boolean isReference()
+  {
+    return getXSDAttributeDeclaration().isAttributeDeclarationReference();
+  }
 
   public IModel getModel()
   {
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeUseAdapter.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeUseAdapter.java
index c736f7b..668365c 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeUseAdapter.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/adapters/XSDAttributeUseAdapter.java
@@ -94,4 +94,8 @@
     return getGlobalXSDContainer(getXSDAttributeUse());
   }
 
+  public boolean isReference()
+  {
+    return getXSDAttributeUse().getAttributeDeclaration().isAttributeDeclarationReference();
+  }
 }
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editparts/XSDBaseFieldEditPart.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editparts/XSDBaseFieldEditPart.java
index 32edfba..6a41f7c 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editparts/XSDBaseFieldEditPart.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/design/editparts/XSDBaseFieldEditPart.java
@@ -14,8 +14,15 @@
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter;
 import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
+import org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter;
 import org.eclipse.wst.xsd.ui.internal.adt.design.IAnnotationProvider;
+import org.eclipse.wst.xsd.ui.internal.adt.design.directedit.AttributeReferenceDirectEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ElementReferenceDirectEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelCellEditorLocator;
+import org.eclipse.wst.xsd.ui.internal.adt.design.directedit.LabelEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.design.directedit.ReferenceDirectEditManager;
 import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart;
 import org.eclipse.wst.xsd.ui.internal.adt.design.figures.IFieldFigure;
 import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
@@ -96,4 +103,40 @@
     installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, selectionHandlesEditPolicy);
     installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new DragAndDropEditPolicy(getViewer(), selectionHandlesEditPolicy));
   }
+  
+  protected void directEditNameField()
+  {
+    Object model = getModel();
+    IFieldFigure fieldFigure = getFieldFigure();
+    if ( model instanceof IField) 
+    {
+      IField field = (IField) model;
+      if (field.isReference())
+      {
+        ReferenceDirectEditManager manager = null;
+        if (field instanceof XSDElementDeclarationAdapter)
+        {
+          manager = new ElementReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
+        }
+        else if (field instanceof XSDAttributeDeclarationAdapter)
+        {
+          manager = new AttributeReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
+        }
+        if (manager != null)
+        {
+          ReferenceUpdateCommand elementUpdateCommand = new ReferenceUpdateCommand();
+          elementUpdateCommand.setDelegate(manager);
+          adtDirectEditPolicy.setUpdateCommand(elementUpdateCommand);
+          manager.show();
+        }
+      }
+      else
+      {
+        LabelEditManager manager = new LabelEditManager(this, new LabelCellEditorLocator(this, null));
+        NameUpdateCommandWrapper wrapper = new NameUpdateCommandWrapper();
+        adtDirectEditPolicy.setUpdateCommand(wrapper);
+        manager.show();
+      }
+    }
+  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewAttributeDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewAttributeDialog.java
new file mode 100644
index 0000000..5602942
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/dialogs/NewAttributeDialog.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.dialogs;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification;
+import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog;
+import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils;
+import org.eclipse.wst.xsd.ui.internal.editor.Messages;
+import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDSchema;
+
+public class NewAttributeDialog extends NewComponentDialog implements IComponentDialog
+{
+  protected XSDSchema schema;
+  protected Object setObject;
+  protected int typeKind;
+  protected Object selection;
+
+  public NewAttributeDialog()
+  {
+    super(Display.getCurrent().getActiveShell(), Messages._UI_LABEL_NEW_ATTRIBUTE, "NewAttribute");     //$NON-NLS-1$
+  }
+
+  public NewAttributeDialog(XSDSchema schema)
+  {
+    super(Display.getCurrent().getActiveShell(), Messages._UI_LABEL_NEW_ATTRIBUTE, "NewAttribute");     //$NON-NLS-1$
+    this.schema = schema;
+  }
+  
+  private void setup() {
+    if (schema != null) {
+      List usedNames = getUsedElementNames();
+      setUsedNames(usedNames);
+      setDefaultName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", schema.getAttributeDeclarations()));
+    }
+  }
+  
+  public int createAndOpen()
+  {
+  setup();
+    int returnCode = super.createAndOpen();
+    if (returnCode == 0)
+    {
+      if (setObject instanceof Adapter)
+      {  
+        //Command command = new AddComplexTypeDefinitionCommand(getName(), schema);
+      }        
+    }  
+    return returnCode;
+  }
+
+  public ComponentSpecification getSelectedComponent()
+  {
+    ComponentSpecification componentSpecification =  new ComponentSpecification(null, getName(), null);    
+    componentSpecification.setMetaName(IXSDSearchConstants.ATTRIBUTE_META_NAME);
+    componentSpecification.setNew(true);
+    return componentSpecification;
+  }
+
+  public void setInitialSelection(ComponentSpecification componentSpecification)
+  {
+    // TODO Auto-generated method stub
+  }
+  
+  private List getUsedElementNames() {
+    List usedNames = new ArrayList();     
+    if (schema != null ) {
+      List elementsList = schema.getAttributeDeclarations();
+      Iterator elements = elementsList.iterator(); 
+      while (elements.hasNext()) {
+        usedNames.add(((XSDAttributeDeclaration) elements.next()).getName());
+      }
+    }
+    
+    return usedNames;
+  }
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/InternalXSDMultiPageEditor.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/InternalXSDMultiPageEditor.java
index 2bf9c07..481e423 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/InternalXSDMultiPageEditor.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/InternalXSDMultiPageEditor.java
@@ -329,7 +329,7 @@
         return page;
       }
     }
-    else if (type == XSDElementReferenceEditManager.class)
+    else if (type == XSDAttributeReferenceEditManager.class)
     {
     	IEditorInput editorInput = getEditorInput();
     	if (editorInput instanceof IFileEditorInput)
@@ -342,9 +342,25 @@
     		// an array of schemas
     		// hmm.. perhaps just pass in a ResourceSet
     		XSDSchema[] schemas = {xsdSchema};
-    		return new XSDElementReferenceEditManager(fileEditorInput.getFile(), schemas);
+    		return new XSDAttributeReferenceEditManager(fileEditorInput.getFile(), schemas);
     	}
     }
+    else if (type == XSDElementReferenceEditManager.class)
+    {
+      IEditorInput editorInput = getEditorInput();
+      if (editorInput instanceof IFileEditorInput)
+      {
+        IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
+        // TODO (cs) currently we assume the schema editor will only ever edit a
+        // single schema
+        /// but if we want to enable the schema editor to edit wsdl files we
+        // should pass in
+        // an array of schemas
+        // hmm.. perhaps just pass in a ResourceSet
+        XSDSchema[] schemas = {xsdSchema};
+        return new XSDElementReferenceEditManager(fileEditorInput.getFile(), schemas);
+      }
+    }
     else if (type == XSDTypeReferenceEditManager.class)
     {
       IEditorInput editorInput = getEditorInput();
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 df6b0a2..334623b 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
@@ -75,6 +75,7 @@
   public static String _UI_LABEL_COMPLEX_TYPE;
   public static String _UI_LABEL_SIMPLE_TYPE;
   public static String _UI_LABEL_NEW_ELEMENT;
+  public static String _UI_LABEL_NEW_ATTRIBUTE;
   public static String _UI_MENU_XSD_EDITOR;
   public static String _UI_LABEL_SOURCE;
   public static String _UI_ACTION_ADD_ELEMENT;
@@ -82,13 +83,16 @@
   public static String _UI_ACTION_NEW;
   public static String _UI_ACTION_BROWSE;
   public static String _UI_ACTION_UPDATE_ELEMENT_REFERENCE;
+  public static String _UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE;
   public static String _UI_LABEL_TARGET_NAMESPACE;
   public static String _UI_LABEL_NO_NAMESPACE;
   public static String _UI_ACTION_ADD_COMPLEX_TYPE;
   public static String _UI_ACTION_ADD_SIMPLE_TYPE;
   public static String _UI_LABEL_NAME_SEARCH_FILTER_TEXT;
   public static String _UI_LABEL_ELEMENTS_COLON;
+  public static String _UI_LABEL_ATTRIBUTES_COLON;
   public static String _UI_LABEL_SET_ELEMENT_REFERENCE;
+  public static String _UI_LABEL_SET_ATTRIBUTE_REFERENCE;
   public static String _UI_LABEL_TYPES_COLON;
   public static String _UI_LABEL_SET_TYPE;
 
@@ -105,6 +109,7 @@
   public static String _UI_ACTION_ADD_INCLUDE;
   public static String _UI_ACTION_ADD_IMPORT;
   public static String _UI_ACTION_ADD_REDEFINE;
+  public static String _UI_ACTION_ADD_ATTRIBUTE;
   public static String _UI_ACTION_ADD_ATTRIBUTE_REF;
 
   public static String _UI_LABEL_ELEMENTFORMDEFAULT;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDAttributeReferenceEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDAttributeReferenceEditManager.java
new file mode 100644
index 0000000..0940414
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/XSDAttributeReferenceEditManager.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.editor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.gef.commands.Command;
+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.IComponentDialog;
+import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceAndManagerDirectivesCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeReferenceCommand;
+import org.eclipse.wst.xsd.ui.internal.dialogs.NewAttributeDialog;
+import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate;
+import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDSchema;
+
+public class XSDAttributeReferenceEditManager extends XSDElementReferenceEditManager implements ComponentReferenceEditManager
+{
+  public XSDAttributeReferenceEditManager(IFile currentFile, XSDSchema[] schemas)
+  {
+    super(currentFile, schemas);
+  }
+
+  public IComponentDialog getBrowseDialog()
+  {
+    XSDSearchListDialogDelegate dialogDelegate = 
+      new XSDSearchListDialogDelegate(XSDSearchListDialogDelegate.ATTRIBUTE_META_NAME, currentFile, schemas);
+    return dialogDelegate;
+  }
+
+  public IComponentDialog getNewDialog()
+  {
+    if (schemas.length > 0) {
+      return new NewAttributeDialog(schemas[0]);
+    }
+    else {
+      return new NewAttributeDialog();
+    }
+  }
+
+  public void modifyComponentReference(Object referencingObject, ComponentSpecification referencedComponent)
+  {
+    XSDAttributeDeclaration concreteComponent = null;
+    if (referencingObject instanceof Adapter)
+    {
+      Adapter adapter = (Adapter)referencingObject;
+      if (adapter.getTarget() instanceof XSDAttributeDeclaration)
+      {
+        concreteComponent = (XSDAttributeDeclaration)adapter.getTarget();
+      }
+    }
+    else if (referencingObject instanceof XSDConcreteComponent)
+    {
+      concreteComponent = (XSDAttributeDeclaration) referencingObject;
+    }
+    if (concreteComponent != null)
+    {
+        if (referencedComponent.isNew())
+        {  
+          XSDAttributeDeclaration attributeDec = null;
+          if (referencedComponent.getMetaName() == IXSDSearchConstants.ATTRIBUTE_META_NAME)
+          {  
+            AddXSDAttributeDeclarationCommand command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, concreteComponent.getSchema());
+            command.setNameToAdd(referencedComponent.getName());
+            command.execute();
+            attributeDec = (XSDAttributeDeclaration) command.getAddedComponent();
+          }
+          if (attributeDec != null)
+          {
+            Command command = new UpdateAttributeReferenceCommand(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, concreteComponent, attributeDec);
+            command.execute();
+          }  
+        }  
+        else
+        {
+          Command command = new UpdateAttributeReferenceAndManagerDirectivesCommand(concreteComponent, referencedComponent.getName(), referencedComponent.getQualifier(), referencedComponent.getFile());
+          command.setLabel(Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE);
+          command.execute();
+        }  
+      }
+  }
+}
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 83a3900..9475b01 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
@@ -72,6 +72,7 @@
 _UI_NO_TYPE_DEFINED=(no type defined)
 _UI_ACTION_UPDATE_NAME=Update Name
 _UI_ACTION_UPDATE_ELEMENT_REFERENCE=Update Element reference
+_UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE=Update Attribute reference
 _UI_ACTION_ADD_FIELD=Add Field
 _UI_ACTION_ADD_ELEMENT=Add Element
 _UI_ACTION_ADD_INCLUDE=Add Include
@@ -81,6 +82,7 @@
 _UI_ACTION_ADD_COMPLEX_TYPE=Add Complex Type
 _UI_ACTION_ADD_SIMPLE_TYPE=Add Simple Type
 _UI_ACTION_SET_TYPE=Set Type
+_UI_ACTION_ADD_ATTRIBUTE=Add Attribute
 _UI_ACTION_ADD_ATTRIBUTE_REF=Add Attribute Ref
 _UI_ACTION_NEW=New...
 _UI_ACTION_BROWSE=Browse...
@@ -96,14 +98,17 @@
 _UI_LABEL_SELECT_TYPES_FILTER_OUT=Select the types that you do not want to filter out: 
 _UI_LABEL_NAME_SEARCH_FILTER_TEXT=Name (? = any character, * = any string):
 _UI_LABEL_SET_ELEMENT_REFERENCE=Set element reference
+_UI_LABEL_SET_ATTRIBUTE_REFERENCE=Set attribute reference
 
 _UI_LABEL_NEW_TYPE=New Type
 _UI_VALUE_NEW_TYPE={0}Type
 _UI_LABEL_NEW_ELEMENT=New Element
+_UI_LABEL_NEW_ATTRIBUTE=New Attribute
 _UI_LABEL_COMPLEX_TYPE=Complex Type
 _UI_LABEL_TARGET_NAMESPACE=Target Namespace: 
 _UI_LABEL_NO_NAMESPACE=No Namespace
 _UI_LABEL_ELEMENTS_COLON=Elements:
+_UI_LABEL_ATTRIBUTES_COLON=Attributes:
 _UI_LABEL_SIMPLE_TYPE=Simple Type
 _UI_LABEL_TYPES_COLON=Types:
 
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDAttributeSearchListProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDAttributeSearchListProvider.java
new file mode 100644
index 0000000..e74fa12
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDAttributeSearchListProvider.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.editor.search;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.core.search.SearchEngine;
+import org.eclipse.wst.common.core.search.scope.SearchScope;
+import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList;
+import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants;
+import org.eclipse.xsd.XSDSchema;
+
+public class XSDAttributeSearchListProvider extends XSDSearchListProvider
+{
+
+  public XSDAttributeSearchListProvider(IFile currentFile, XSDSchema[] schemas)
+  {
+    super(currentFile, schemas);
+  }
+
+  public void populateComponentList(IComponentList list, SearchScope scope, IProgressMonitor pm)
+  {
+    // now we traverse the types already defined within the visible schemas
+    // we do this in addition to the component search since this should execute
+    // very quickly and there's a good chance the user wants to select a time that's 
+    // already imported/included
+    // TODO (cs) ensure we don't add duplicates when we proceed to use the search list
+    //
+    List visitedSchemas = new ArrayList();
+    for (int i = 0; i < schemas.length; i++)
+    {
+      XSDSchema schema = schemas[i];
+      ComponentCollectingXSDVisitor visitor = new ComponentCollectingXSDVisitor(list, IXSDSearchConstants.ATTRIBUTE_META_NAME);
+      visitor.visitSchema(schema, true);
+      visitedSchemas.addAll(visitor.getVisitedSchemas());
+    }
+    // finally we call the search API's to do a potentially slow search
+    if (scope != null)
+    {
+      populateComponentListUsingSearch(list, scope, pm, createFileMap(visitedSchemas));
+    }
+  }
+
+  private void populateComponentListUsingSearch(IComponentList list, SearchScope scope, IProgressMonitor pm, HashMap files)
+  {
+    SearchEngine searchEngine = new SearchEngine();
+    InternalSearchRequestor requestor = new InternalSearchRequestor(list, files);
+    findMatches(searchEngine, requestor, scope, IXSDSearchConstants.ATTRIBUTE_META_NAME);
+  }
+
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDComponentDescriptionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDComponentDescriptionProvider.java
index aa9a034..1ecd327 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDComponentDescriptionProvider.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDComponentDescriptionProvider.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
@@ -22,6 +22,7 @@
 import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentDescriptionProvider;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
 import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants;
+import org.eclipse.xsd.XSDAttributeDeclaration;
 import org.eclipse.xsd.XSDComplexTypeDefinition;
 import org.eclipse.xsd.XSDConcreteComponent;
 import org.eclipse.xsd.XSDElementDeclaration;
@@ -41,6 +42,7 @@
   private static final Image SIMPLE_TYPE_IMAGE =  XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif");
   private static final Image COMPLEX_TYPE_IMAGE = XSDEditorPlugin.getXSDImage("icons/XSDComplexType.gif");
   private static final Image ELEMENT_IMAGE = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif");
+  private static final Image ATTRIBUTE_IMAGE = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif");
   //private final static Image BUILT_IN_TYPE)IMAGE = 
     
   public String getQualifier(Object component)
@@ -172,6 +174,8 @@
     		  result = COMPLEX_TYPE_IMAGE;
     	  else if ( qualifiedName.equals(IXSDSearchConstants.ELEMENT_META_NAME))
     		  result = ELEMENT_IMAGE;
+    	  else if ( qualifiedName.equals(IXSDSearchConstants.ATTRIBUTE_META_NAME))
+    	    result = ATTRIBUTE_IMAGE;
       }
     }      
     else if (component instanceof XSDComplexTypeDefinition)
@@ -180,6 +184,8 @@
       result = SIMPLE_TYPE_IMAGE;
     else if (component instanceof XSDElementDeclaration)
       result = ELEMENT_IMAGE;
+    else if (component instanceof XSDAttributeDeclaration)
+      result = ATTRIBUTE_IMAGE;
     return result;
   }
 
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListDialogDelegate.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListDialogDelegate.java
index 8bbc6ab..7f62dab 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListDialogDelegate.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListDialogDelegate.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
@@ -27,6 +27,7 @@
 {
   public final static QualifiedName TYPE_META_NAME = new QualifiedName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "type"); //$NON-NLS-1$
   public final static QualifiedName ELEMENT_META_NAME = new QualifiedName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "element"); //$NON-NLS-1$
+  public final static QualifiedName ATTRIBUTE_META_NAME = new QualifiedName(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "attribute"); //$NON-NLS-1$
   // protected Object setObject;
   protected ComponentSpecification selection;
   protected IFile currentFile;
@@ -84,6 +85,18 @@
         //TODO externalize string
         dialog = new ScopedComponentSearchListDialog(shell, Messages._UI_LABEL_SET_ELEMENT_REFERENCE, configuration);     
     }
+    else if ( metaName == ATTRIBUTE_META_NAME)
+    {
+      XSDComponentDescriptionProvider descriptionProvider = new XSDComponentDescriptionProvider();
+      final XSDAttributeSearchListProvider searchListProvider = new XSDAttributeSearchListProvider(currentFile, schemas);
+      ComponentSearchListDialogConfiguration configuration = new ComponentSearchListDialogConfiguration();
+      
+        configuration.setDescriptionProvider(descriptionProvider);
+        configuration.setSearchListProvider(searchListProvider);
+        configuration.setFilterLabelText(Messages._UI_LABEL_NAME_SEARCH_FILTER_TEXT);
+        configuration.setListLabelText(Messages._UI_LABEL_ATTRIBUTES_COLON);
+        dialog = new ScopedComponentSearchListDialog(shell, Messages._UI_LABEL_SET_ATTRIBUTE_REFERENCE, configuration);     
+    }
     else if (metaName == TYPE_META_NAME)
     {
       XSDComponentDescriptionProvider descriptionProvider = new XSDComponentDescriptionProvider();
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListProvider.java
index 91af122..7afe5a8 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListProvider.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/ui/internal/editor/search/XSDSearchListProvider.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
@@ -33,6 +33,7 @@
 import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentSearchListProvider;
 import org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern;
 import org.eclipse.wst.xsd.ui.internal.search.IXSDSearchConstants;
+import org.eclipse.xsd.XSDAttributeDeclaration;
 import org.eclipse.xsd.XSDElementDeclaration;
 import org.eclipse.xsd.XSDImport;
 import org.eclipse.xsd.XSDInclude;
@@ -61,8 +62,7 @@
     try
     {
       IProject[] refs = currentFile.getProject().getReferencedProjects();
-      
-      System.out.println("dependencies:----");       
+            
       for (int i=0; i < refs.length; i++)
       {
         System.out.println("dep " + refs[i].getName());
@@ -114,6 +114,10 @@
         {
           list.add(content);
         }
+        else if (content instanceof XSDAttributeDeclaration && searchKind == IXSDSearchConstants.ATTRIBUTE_META_NAME)
+        {
+          list.add(content);
+        }
         else if (content instanceof XSDSimpleTypeDefinition && searchKind == IXSDSearchConstants.SIMPLE_TYPE_META_NAME)
         {
           // in this case we only want to show simple types
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/AttributeReferenceDirectEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/AttributeReferenceDirectEditManager.java
new file mode 100644
index 0000000..2b5e272
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/AttributeReferenceDirectEditManager.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.design.directedit;
+
+import org.eclipse.draw2d.Label;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager;
+import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
+import org.eclipse.wst.xsd.ui.internal.editor.XSDAttributeReferenceEditManager;
+
+public class AttributeReferenceDirectEditManager extends ReferenceDirectEditManager
+{
+  public AttributeReferenceDirectEditManager(IField parameter, AbstractGraphicalEditPart source, Label label)
+  {
+    super(parameter, source, label);
+  }
+
+  protected ComponentReferenceEditManager getComponentReferenceEditManager()
+  {
+    ComponentReferenceEditManager result = null;
+    IEditorPart editor = getActiveEditor();
+    if (editor != null)
+    {
+      result = (ComponentReferenceEditManager)editor.getAdapter(XSDAttributeReferenceEditManager.class);
+    }  
+    return result;
+  }
+  
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ElementReferenceDirectEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ElementReferenceDirectEditManager.java
index 8639828..54117a2 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ElementReferenceDirectEditManager.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ElementReferenceDirectEditManager.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,144 +10,20 @@
  *******************************************************************************/
 package org.eclipse.wst.xsd.ui.internal.adt.design.directedit;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.eclipse.draw2d.Label;
 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-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.editor.Messages;
 import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDElementReferenceEditManager;
 
-public class ElementReferenceDirectEditManager extends ComboBoxCellEditorManager
+public class ElementReferenceDirectEditManager extends ReferenceDirectEditManager
 {
-  protected AbstractGraphicalEditPart editPart;
-  protected IField setObject;
-
   public ElementReferenceDirectEditManager(IField parameter, AbstractGraphicalEditPart source, Label label)
   {
-    super(source, label);
-    editPart = source;
-    setObject = parameter;
-  }
-
-  protected CellEditor createCellEditorOn(Composite composite)
-  {
-    return super.createCellEditorOn(composite);
-  }
-
-  protected List computeComboContent()
-  {
-    List list = new ArrayList();
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager != null)
-    {
-       list.add(Messages._UI_ACTION_BROWSE);
-       list.add(Messages._UI_ACTION_NEW);
-       ComponentSpecification[] quickPicks = editManager.getQuickPicks();
-       if (quickPicks != null)
-       {
-         for (int i=0; i < quickPicks.length; i++)
-         {
-           ComponentSpecification componentSpecification = quickPicks[i];
-           list.add(componentSpecification.getName());
-         }  
-       }
-       ComponentSpecification[] history = editManager.getHistory();
-       if (history != null)
-       {
-         for (int i=0; i < history.length; i++)
-         {
-           ComponentSpecification componentSpecification = history[i];
-           list.add(componentSpecification.getName());
-         }  
-       }
-    } 
-    return list; 
-  }
-
-  protected ComponentSpecification getComponentSpecificationForValue(String value)
-  {
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager != null)
-    {  
-      ComponentSpecification[] quickPicks = editManager.getQuickPicks();
-      if (quickPicks != null)
-      {
-        for (int i=0; i < quickPicks.length; i++)
-        {
-          ComponentSpecification componentSpecification = quickPicks[i];
-          if (value.equals(componentSpecification.getName()))
-          {
-            return componentSpecification;
-          }                
-        }  
-      }
-      ComponentSpecification[] history = editManager.getHistory();
-      if (history != null)
-      {
-        for (int i=0; i < history.length; i++)
-        {
-          ComponentSpecification componentSpecification = history[i];
-          if (value.equals(componentSpecification.getName()))
-          {  
-            return componentSpecification;
-          }
-        }  
-      }
-    }
-    return null;
+    super(parameter, source, label);
   }
   
-  public void performModify(Object value)
-  {
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager == null)
-    {
-      return;
-    }
-    
-    // our crude combo box can only work with 'String' objects
-    // if we get a String back we need to do some clever mapping to get the ComponentSpecification 
-    //    
-    if (value instanceof String)
-    {
-      value = getComponentSpecificationForValue((String)value);     
-    }  
-    // we assume the selected value is always of the form of a ComponentSpecification
-    // 
-    if (value instanceof ComponentSpecification)      
-    {
-      // we need to perform an asyncExec here since the 'host' editpart may be
-      // removed as a side effect of performing the action           
-      DelayedSetElementReferenceRunnable runnable = new DelayedSetElementReferenceRunnable(editManager, setObject, (ComponentSpecification)value);
-      //runnable.run();
-      Display.getCurrent().asyncExec(runnable);
-    }
-  }
-
-  protected List computeSortedList(List list)
-  {
-    // return TypesHelper.sortList(list);
-    return list;
-  }
-  
-  protected CellEditor createCellEditor(Composite composite, String[] stringArray)
-  {
-    ADTComboBoxCellEditor cellEditor = new ADTComboBoxCellEditor(composite, stringArray, getComponentReferenceEditManager());
-    //((ADTComboBoxCellEditor) cellEditor).setObjectToModify(setObject);
-    return cellEditor;
-  }
-
   protected ComponentReferenceEditManager getComponentReferenceEditManager()
   {
     ComponentReferenceEditManager result = null;
@@ -158,32 +34,4 @@
     }  
     return result;
   }
-  
-  private IEditorPart getActiveEditor()
-  {
-    IWorkbench workbench = PlatformUI.getWorkbench();
-    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
-    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
-    return editorPart;
-  }    
-  
-  protected static class DelayedSetElementReferenceRunnable implements Runnable
-  {
-    protected ComponentReferenceEditManager componentReferenceEditManager;
-    protected ComponentSpecification newValue;
-    protected IField field;
-
-    public DelayedSetElementReferenceRunnable(ComponentReferenceEditManager componentReferenceEditManager,
-    		IField setObject, ComponentSpecification selectedValue)
-    {
-      this.componentReferenceEditManager = componentReferenceEditManager;
-      newValue = selectedValue;
-      field = setObject;
-    }
-
-    public void run()
-    {
-      componentReferenceEditManager.modifyComponentReference(field, newValue);
-    }
-  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ReferenceDirectEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ReferenceDirectEditManager.java
new file mode 100644
index 0000000..c98cbc2
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/directedit/ReferenceDirectEditManager.java
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * 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.design.directedit;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.Label;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+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.editor.Messages;
+import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
+
+public abstract class ReferenceDirectEditManager extends ComboBoxCellEditorManager
+{
+  protected AbstractGraphicalEditPart editPart;
+  protected IField setObject;
+
+  public ReferenceDirectEditManager(IField parameter, AbstractGraphicalEditPart source, Label label)
+  {
+    super(source, label);
+    editPart = source;
+    setObject = parameter;
+  }
+
+  protected CellEditor createCellEditorOn(Composite composite)
+  {
+    return super.createCellEditorOn(composite);
+  }
+
+  protected List computeComboContent()
+  {
+    List list = new ArrayList();
+    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
+    if (editManager != null)
+    {
+       list.add(Messages._UI_ACTION_BROWSE);
+       list.add(Messages._UI_ACTION_NEW);
+       ComponentSpecification[] quickPicks = editManager.getQuickPicks();
+       if (quickPicks != null)
+       {
+         for (int i=0; i < quickPicks.length; i++)
+         {
+           ComponentSpecification componentSpecification = quickPicks[i];
+           list.add(componentSpecification.getName());
+         }  
+       }
+       ComponentSpecification[] history = editManager.getHistory();
+       if (history != null)
+       {
+         for (int i=0; i < history.length; i++)
+         {
+           ComponentSpecification componentSpecification = history[i];
+           list.add(componentSpecification.getName());
+         }  
+       }
+    } 
+    return list; 
+  }
+
+  protected ComponentSpecification getComponentSpecificationForValue(String value)
+  {
+    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
+    if (editManager != null)
+    {  
+      ComponentSpecification[] quickPicks = editManager.getQuickPicks();
+      if (quickPicks != null)
+      {
+        for (int i=0; i < quickPicks.length; i++)
+        {
+          ComponentSpecification componentSpecification = quickPicks[i];
+          if (value.equals(componentSpecification.getName()))
+          {
+            return componentSpecification;
+          }                
+        }  
+      }
+      ComponentSpecification[] history = editManager.getHistory();
+      if (history != null)
+      {
+        for (int i=0; i < history.length; i++)
+        {
+          ComponentSpecification componentSpecification = history[i];
+          if (value.equals(componentSpecification.getName()))
+          {  
+            return componentSpecification;
+          }
+        }  
+      }
+    }
+    return null;
+  }
+  
+  public void performModify(Object value)
+  {
+    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
+    if (editManager == null)
+    {
+      return;
+    }
+    
+    // our crude combo box can only work with 'String' objects
+    // if we get a String back we need to do some clever mapping to get the ComponentSpecification 
+    //    
+    if (value instanceof String)
+    {
+      value = getComponentSpecificationForValue((String)value);     
+    }  
+    // we assume the selected value is always of the form of a ComponentSpecification
+    // 
+    if (value instanceof ComponentSpecification)      
+    {
+      // we need to perform an asyncExec here since the 'host' editpart may be
+      // removed as a side effect of performing the action           
+      DelayedSetReferenceRunnable runnable = new DelayedSetReferenceRunnable(editManager, setObject, (ComponentSpecification)value);
+      //runnable.run();
+      Display.getCurrent().asyncExec(runnable);
+    }
+  }
+
+  protected List computeSortedList(List list)
+  {
+    // return TypesHelper.sortList(list);
+    return list;
+  }
+  
+  protected CellEditor createCellEditor(Composite composite, String[] stringArray)
+  {
+    ADTComboBoxCellEditor cellEditor = new ADTComboBoxCellEditor(composite, stringArray, getComponentReferenceEditManager());
+    //((ADTComboBoxCellEditor) cellEditor).setObjectToModify(setObject);
+    return cellEditor;
+  }
+
+  protected abstract ComponentReferenceEditManager getComponentReferenceEditManager();
+  
+  protected IEditorPart getActiveEditor()
+  {
+    IWorkbench workbench = PlatformUI.getWorkbench();
+    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+    return editorPart;
+  }    
+  
+  protected class DelayedSetReferenceRunnable implements Runnable
+  {
+    protected ComponentReferenceEditManager componentReferenceEditManager;
+    protected ComponentSpecification newValue;
+    protected IField field;
+
+    public DelayedSetReferenceRunnable(ComponentReferenceEditManager componentReferenceEditManager,
+        IField setObject, ComponentSpecification selectedValue)
+    {
+      this.componentReferenceEditManager = componentReferenceEditManager;
+      newValue = selectedValue;
+      field = setObject;
+    }
+
+    public void run()
+    {
+      componentReferenceEditManager.modifyComponentReference(field, newValue);
+    }
+  }
+
+}
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 6f9b7e4..dbebae1 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
@@ -10,142 +10,19 @@
  *******************************************************************************/
 package org.eclipse.wst.xsd.ui.internal.adt.design.directedit;
 
-import java.util.ArrayList;
-import java.util.List;
 import org.eclipse.draw2d.Label;
 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-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;
 
-public class TypeReferenceDirectEditManager extends ComboBoxCellEditorManager
+public class TypeReferenceDirectEditManager extends ReferenceDirectEditManager //ComboBoxCellEditorManager
 {
-  protected AbstractGraphicalEditPart editPart;
-  protected IField setObject;
-
   public TypeReferenceDirectEditManager(IField parameter, AbstractGraphicalEditPart source, Label label)
   {
-    super(source, label);
-    editPart = source;
-    setObject = parameter;
-  }
-
-  protected CellEditor createCellEditorOn(Composite composite)
-  {
-    return super.createCellEditorOn(composite);
-  }
-
-  protected List computeComboContent()
-  {
-    List list = new ArrayList();
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager != null)
-    {
-       list.add(Messages._UI_ACTION_BROWSE);
-       list.add(Messages._UI_ACTION_NEW);
-       ComponentSpecification[] quickPicks = editManager.getQuickPicks();
-       if (quickPicks != null)
-       {
-         for (int i=0; i < quickPicks.length; i++)
-         {
-           ComponentSpecification componentSpecification = quickPicks[i];
-           list.add(componentSpecification.getName());
-         }  
-       }
-       ComponentSpecification[] history = editManager.getHistory();
-       if (history != null)
-       {
-         for (int i=0; i < history.length; i++)
-         {
-           ComponentSpecification componentSpecification = history[i];
-           list.add(componentSpecification.getName());
-         }  
-       }
-    } 
-    return list; 
-  }
-
-  protected ComponentSpecification getComponentSpecificationForValue(String value)
-  {
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager != null)
-    {  
-      ComponentSpecification[] quickPicks = editManager.getQuickPicks();
-      if (quickPicks != null)
-      {
-        for (int i=0; i < quickPicks.length; i++)
-        {
-          ComponentSpecification componentSpecification = quickPicks[i];
-          if (value.equals(componentSpecification.getName()))
-          {
-            return componentSpecification;
-          }                
-        }  
-      }
-      ComponentSpecification[] history = editManager.getHistory();
-      if (history != null)
-      {
-        for (int i=0; i < history.length; i++)
-        {
-          ComponentSpecification componentSpecification = history[i];
-          if (value.equals(componentSpecification.getName()))
-          {  
-            return componentSpecification;
-          }
-        }  
-      }
-    }
-    return null;
-  }
-  
-  public void performModify(Object value)
-  {
-    ComponentReferenceEditManager editManager = getComponentReferenceEditManager();
-    if (editManager == null)
-    {
-      return;
-    }
-    
-    // our crude combo box can only work with 'String' objects
-    // if we get a String back we need to do some clever mapping to get the ComponentSpecification 
-    //    
-    if (value instanceof String)
-    {
-      value = getComponentSpecificationForValue((String)value);     
-    }  
-    // we assume the selected value is always of the form of a ComponentSpecification
-    // 
-    if (value instanceof ComponentSpecification)      
-    {
-      // we need to perform an asyncExec here since the 'host' editpart may be
-      // removed as a side effect of performing the action           
-      DelayedSetTypeRunnable runnable = new DelayedSetTypeRunnable(editManager, setObject, (ComponentSpecification)value);
-      //runnable.run();
-      Display.getCurrent().asyncExec(runnable);
-    }
-  }
-
-  protected List computeSortedList(List list)
-  {
-    // return TypesHelper.sortList(list);
-    return list;
-  }
-  
-  protected CellEditor createCellEditor(Composite composite, String[] stringArray)
-  {
-    ADTComboBoxCellEditor cellEditor = new ADTComboBoxCellEditor(composite, stringArray, getComponentReferenceEditManager());
-    //((ADTComboBoxCellEditor) cellEditor).setObjectToModify(setObject);
-    return cellEditor;
+    super(parameter, source, label);
   }
 
   protected ComponentReferenceEditManager getComponentReferenceEditManager()
@@ -163,31 +40,4 @@
     }  
     return result;
   }
-  
-  private IEditorPart getActiveEditor()
-  {
-    IWorkbench workbench = PlatformUI.getWorkbench();
-    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
-    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
-    return editorPart;
-  }    
-  
-  protected static class DelayedSetTypeRunnable implements Runnable
-  {
-    protected ComponentReferenceEditManager componentReferenceEditManager;
-    protected ComponentSpecification newValue;
-    protected IField field;
-
-    public DelayedSetTypeRunnable(ComponentReferenceEditManager componentReferenceEditManager, IField setObject, ComponentSpecification selectedValue)
-    {
-      this.componentReferenceEditManager = componentReferenceEditManager;
-      newValue = selectedValue;
-      field = setObject;
-    }
-
-    public void run()
-    {
-      componentReferenceEditManager.modifyComponentReference(field, newValue);
-    }
-  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/editparts/BaseFieldEditPart.java b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/editparts/BaseFieldEditPart.java
index f9fe653..bdbf8c3 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/editparts/BaseFieldEditPart.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt/org/eclipse/wst/xsd/ui/internal/adt/design/editparts/BaseFieldEditPart.java
@@ -52,8 +52,6 @@
 {
   protected TypeReferenceConnection connectionFigure;
   protected ADTDirectEditPolicy adtDirectEditPolicy = new ADTDirectEditPolicy();
-  protected TypeUpdateCommand typeUpdateCommand = new TypeUpdateCommand();
-  protected ElementReferenceUpdateCommand elementUpdateCommand = new ElementReferenceUpdateCommand();
   protected TypeReferenceConnection connectionFeedbackFigure;
   
   protected IFigure createFigure()
@@ -253,6 +251,7 @@
         if (hitTest(fieldFigure.getTypeLabel(), p))
         {
           TypeReferenceDirectEditManager manager = new TypeReferenceDirectEditManager((IField)model, this, fieldFigure.getTypeLabel());
+          TypeUpdateCommand typeUpdateCommand = new TypeUpdateCommand();
           typeUpdateCommand.setDelegate(manager);
           adtDirectEditPolicy.setUpdateCommand(typeUpdateCommand);
           manager.show();
@@ -268,15 +267,17 @@
     }
   }
   
-  private void directEditNameField() {
-	Object model = getModel();
-	IFieldFigure fieldFigure = getFieldFigure();
+  protected void directEditNameField()
+  {
+	  Object model = getModel();
+	  IFieldFigure fieldFigure = getFieldFigure();
   	if ( model instanceof IField) 
     {
       IField field = (IField) model;
       if (field.isReference())
       {
         ElementReferenceDirectEditManager manager = new ElementReferenceDirectEditManager((IField) model, this, fieldFigure.getNameLabel());
+        ReferenceUpdateCommand elementUpdateCommand = new ReferenceUpdateCommand();
         elementUpdateCommand.setDelegate(manager);
         adtDirectEditPolicy.setUpdateCommand(elementUpdateCommand);
         manager.show();
@@ -316,7 +317,7 @@
 
   }
   
-  class NameUpdateCommandWrapper extends Command implements IADTUpdateCommand
+  protected class NameUpdateCommandWrapper extends Command implements IADTUpdateCommand
   {
     Command command;
     protected DirectEditRequest request;
@@ -384,12 +385,12 @@
     }
   }
   
-  class ElementReferenceUpdateCommand extends Command implements IADTUpdateCommand
+  protected class ReferenceUpdateCommand extends Command implements IADTUpdateCommand
   {
 	    protected ComboBoxCellEditorManager delegate;
 	    protected DirectEditRequest request;
 	    
-	    public ElementReferenceUpdateCommand()
+	    public ReferenceUpdateCommand()
 	    {
 	      super(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE);
 	    }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java
index 1535564..8bd311a 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.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
@@ -32,6 +32,7 @@
   XSDModelGroup xsdModelGroup;
   XSDConcreteComponent parent;
   boolean isReference;
+  private String nameToAdd;
 
   public AddXSDAttributeDeclarationCommand(String label, XSDComplexTypeDefinition xsdComplexTypeDefinition)
   {
@@ -55,7 +56,7 @@
         beginRecording(xsdComplexTypeDefinition.getElement());
         if (!isReference)
         {
-          attribute.setName(getNewName("NewAttribute")); //$NON-NLS-1$
+          attribute.setName(getNewName(nameToAdd == null ? "NewAttribute" : nameToAdd)); //$NON-NLS-1$
           attribute.setTypeDefinition(xsdComplexTypeDefinition.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string")); //$NON-NLS-1$
         }
         else
@@ -118,6 +119,11 @@
 
   ArrayList names;
 
+  public void setNameToAdd(String name)
+  {
+    nameToAdd = name;
+  }
+
   protected String getNewName(String description)
   {
     ArrayList usedAttributeNames = new ArrayList();
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java
new file mode 100644
index 0000000..f042a6b
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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.core.resources.IFile;
+import org.eclipse.xsd.XSDAttributeDeclaration;
+import org.eclipse.xsd.XSDComponent;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDSchema;
+
+public class UpdateAttributeReferenceAndManagerDirectivesCommand extends UpdateComponentReferenceAndManageDirectivesCommand
+{
+
+  public UpdateAttributeReferenceAndManagerDirectivesCommand(XSDConcreteComponent concreteComponent, String componentName, String componentNamespace, IFile file)
+  {
+    super(concreteComponent, componentName, componentNamespace, file);
+  }
+
+  protected XSDComponent getDefinedComponent(XSDSchema schema, String componentName, String componentNamespace)
+  {
+    XSDAttributeDeclaration result = schema.resolveAttributeDeclaration(componentNamespace, componentName);
+    if (result.eContainer() == null)
+    {
+      result = null;
+    }
+    return result;
+  }
+
+  public void execute()
+  {
+    try
+    {
+      beginRecording(concreteComponent.getElement());
+      XSDComponent componentDef = computeComponent();
+      if (componentDef != null)
+      {
+        UpdateAttributeReferenceCommand command = new UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, (XSDAttributeDeclaration) concreteComponent,
+            (XSDAttributeDeclaration) componentDef);
+        command.execute();
+      }
+    }
+    catch (Exception e)
+    {
+    }
+    finally
+    {
+      endRecording();
+    }
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java
new file mode 100644
index 0000000..6af6375
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.xsd.XSDAttributeDeclaration;
+
+public class UpdateAttributeReferenceCommand extends BaseCommand
+{
+  XSDAttributeDeclaration attribute, ref;
+
+  public UpdateAttributeReferenceCommand(String label, XSDAttributeDeclaration attribute, XSDAttributeDeclaration ref)
+  {
+    super(label);
+    this.attribute = attribute;
+    this.ref = ref;
+  }
+
+  public void execute()
+  {
+    try
+    {
+      beginRecording(attribute.getElement());
+      attribute.setResolvedAttributeDeclaration(ref);
+    }
+    finally
+    {
+      endRecording();
+    }
+  }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java
index 873aa01..2507e7e 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.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
@@ -12,6 +12,7 @@
 
 import org.apache.xerces.util.XMLChar;
 import org.eclipse.gef.commands.Command;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
@@ -22,9 +23,11 @@
 import org.eclipse.swt.layout.RowLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
 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;
@@ -32,6 +35,7 @@
 import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand;
 import org.eclipse.wst.xsd.ui.internal.dialogs.NewTypeDialog;
 import org.eclipse.wst.xsd.ui.internal.editor.Messages;
+import org.eclipse.wst.xsd.ui.internal.editor.XSDAttributeReferenceEditManager;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
 import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager;
@@ -44,9 +48,9 @@
 public class XSDAttributeDeclarationSection extends RefactoringSection
 {
   protected Text nameText, defaultOrFixedText;
-  protected CCombo typeCombo, usageCombo, formCombo;
+  protected CCombo componentNameCombo, typeCombo, usageCombo, formCombo;
   protected Button defaultButton, fixedButton;
-  protected String typeName = ""; //$NON-NLS-1$
+  protected String typeName = "", refName = ""; //$NON-NLS-1$
   boolean isAttributeReference;
   
   public XSDAttributeDeclarationSection()
@@ -81,6 +85,7 @@
     data.horizontalAlignment = GridData.FILL;
     nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$
     nameText.setLayoutData(data);
+    nameText.setEnabled(!isAttributeReference);
     applyAllListeners(nameText);
     
     PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText,
@@ -90,8 +95,38 @@
     // Refactor/rename hyperlink
     // ------------------------------------------------------------------
     createRenameHyperlink(composite);
+    setRenameHyperlinkEnabled(!isAttributeReference);
 
     // ------------------------------------------------------------------
+    // Ref Label
+    // ------------------------------------------------------------------
+    if (isAttributeReference)
+    {
+      data = new GridData();
+      data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
+      data.grabExcessHorizontalSpace = false;
+      CLabel refLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_REFERENCE);
+      refLabel.setLayoutData(data);
+
+      // ------------------------------------------------------------------
+      // Ref Combo
+      // ------------------------------------------------------------------
+
+      data = new GridData();
+      data.grabExcessHorizontalSpace = true;
+      data.horizontalAlignment = GridData.FILL;
+
+      componentNameCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT);
+      componentNameCombo.addSelectionListener(this);
+      componentNameCombo.setLayoutData(data);
+      
+      PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo,
+          XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__NAME);
+
+      getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$
+    }
+    
+    // ------------------------------------------------------------------
     // typeLabel
     // ------------------------------------------------------------------
     getWidgetFactory().createCLabel(composite, typeLabel); //$NON-NLS-1$
@@ -104,6 +139,7 @@
     data.horizontalAlignment = GridData.FILL;
     typeCombo = getWidgetFactory().createCCombo(composite);
     typeCombo.setLayoutData(data);
+    typeCombo.setEnabled(!isAttributeReference);
     typeCombo.addSelectionListener(this);
     
     PlatformUI.getWorkbench().getHelpSystem().setHelp(typeCombo,
@@ -277,6 +313,11 @@
         nameText.setText(name);
       }
     }
+    
+    if (isAttributeReference)
+    {
+      refreshRefCombo();
+    }
 
     // refresh type
 
@@ -421,10 +462,48 @@
         if (newValue != null)
           manager.modifyComponentReference(input, newValue);
       }
-    } 
+    }
+    else if (e.widget == componentNameCombo)
+    {
+      IEditorPart editor = getActiveEditor();
+      if (editor == null) return;
+      ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDAttributeReferenceEditManager.class);    
+
+      String selection = componentNameCombo.getText();
+      ComponentSpecification newValue;
+      IComponentDialog dialog= null;
+      if ( selection.equals(Messages._UI_ACTION_BROWSE))
+      {
+        dialog = manager.getBrowseDialog();
+      }
+      else if ( selection.equals(Messages._UI_ACTION_NEW))
+      {
+        dialog = manager.getNewDialog();
+      }
+
+      if (dialog != null)
+      {
+        if (dialog.createAndOpen() == Window.OK)
+        {
+          newValue = dialog.getSelectedComponent();
+          manager.modifyComponentReference(input, newValue);
+        }
+        else
+        {
+          componentNameCombo.setText(refName);
+        }
+      }
+      else //use the value from selected quickPick item
+      {
+        newValue = getComponentSpecFromQuickPickForValue(selection, manager);
+        if (newValue != null)
+          manager.modifyComponentReference(input, newValue);
+      }
+
+    }
     else 
     {
-    	XSDAttributeDeclaration xsdAttribute = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
+    	XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
     	Element element = xsdAttribute.getElement();
       if (e.widget == usageCombo)
 	    {	      
@@ -534,7 +613,7 @@
     }
     else if (event.widget == defaultOrFixedText)
     {
-      XSDAttributeDeclaration xsdAttribute = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
+      XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
       String newValue = defaultOrFixedText.getText();
       Element element = xsdAttribute.getElement();
       if (element != null)
@@ -576,6 +655,8 @@
   
   public void dispose()
   {
+    if (componentNameCombo != null && !componentNameCombo.isDisposed())
+      componentNameCombo.removeSelectionListener(this);
     if (nameText != null && !nameText.isDisposed())
       removeListeners(nameText);
     if (typeCombo != null && !typeCombo.isDisposed())
@@ -583,4 +664,98 @@
     super.dispose();
   }
 
+  public void setInput(IWorkbenchPart part, ISelection selection)
+  {
+    super.setInput(part, selection);
+    setListenerEnabled(false);
+    init();
+    relayout();
+    
+    setListenerEnabled(true);
+  }
+  
+  protected void init()
+  {
+    if (input instanceof XSDAttributeDeclaration)
+    {
+      XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
+      isAttributeReference = xsdAttribute.isAttributeDeclarationReference();
+    }
+  }
+
+  protected void relayout()
+  {
+    Composite parentComposite = composite.getParent();
+    parentComposite.getParent().setRedraw(false);
+
+    if (parentComposite != null && !parentComposite.isDisposed())
+    {
+      Control[] children = parentComposite.getChildren();
+      for (int i = 0; i < children.length; i++)
+      {
+        children[i].dispose();
+      }
+    }
+
+    // Now initialize the new handler
+    createContents(parentComposite);
+    parentComposite.getParent().layout(true, true);
+
+    // Now turn painting back on
+    parentComposite.getParent().setRedraw(true);
+    refresh();
+  }
+  
+  protected void refreshRefCombo()
+  {
+    componentNameCombo.setText(""); //$NON-NLS-1$
+    fillComponentNameCombo();
+  }
+  
+  private void fillComponentNameCombo()
+  {
+    IEditorPart editor = getActiveEditor();
+    ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDAttributeReferenceEditManager.class);    
+    
+    componentNameCombo.removeAll();
+    componentNameCombo.add(Messages._UI_ACTION_BROWSE);
+    componentNameCombo.add(Messages._UI_ACTION_NEW);
+    ComponentSpecification[] quickPicks = manager.getQuickPicks();
+    if (quickPicks != null)
+    {
+      for (int i=0; i < quickPicks.length; i++)
+      {
+        ComponentSpecification componentSpecification = quickPicks[i];
+        componentNameCombo.add(componentSpecification.getName());
+      }  
+    }
+    ComponentSpecification[] history = manager.getHistory();
+    if (history != null)
+    {
+      for (int i=0; i < history.length; i++)
+      {
+        ComponentSpecification componentSpecification = history[i];
+        componentNameCombo.add(componentSpecification.getName());
+      }  
+    }
+    
+    XSDAttributeDeclaration namedComponent = (XSDAttributeDeclaration) input;
+    Element element = namedComponent.getElement();
+    if (element != null)
+    {
+      String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE);
+      if (attrValue == null)
+      {
+        attrValue = ""; //$NON-NLS-1$
+      }
+      ComponentSpecification ret = getComponentSpecFromQuickPickForValue(attrValue, manager);
+      if (ret == null)
+      {
+        componentNameCombo.add(attrValue);
+      }
+      componentNameCombo.setText(attrValue);
+      refName = attrValue;
+    } 
+  }
+
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java
index d73e477..35da31f 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java
@@ -148,6 +148,7 @@
     typeCombo = getWidgetFactory().createCCombo(composite); //$NON-NLS-1$
     typeCombo.setEditable(false);
     typeCombo.setLayoutData(data);
+    typeCombo.setEnabled(!isElementReference);
     typeCombo.addSelectionListener(this);
     PlatformUI.getWorkbench().getHelpSystem().setHelp(typeCombo,
     		XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__TYPE);