[134335] Misc enhancements to SelectComponentDialog, AddAppinfoDialog
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDComponentDescriptionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDComponentDescriptionProvider.java
index d62bce1..25bb6b3 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDComponentDescriptionProvider.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDComponentDescriptionProvider.java
@@ -182,4 +182,8 @@
       result = ELEMENT_IMAGE;
     return result;
   }
+
+  public Image getFileIcon(Object component) {
+	return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif");
+  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDSearchListDialogDelegate.java b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDSearchListDialogDelegate.java
index 31b50b0..3e1b237 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDSearchListDialogDelegate.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-adt-xsd/org/eclipse/wst/xsd/editor/internal/search/XSDSearchListDialogDelegate.java
@@ -69,7 +69,8 @@
     	
         configuration.setDescriptionProvider(descriptionProvider);
         configuration.setSearchListProvider(searchListProvider);
-        configuration.setFilterLabelText("Name:");
+        configuration.setFilterLabelText("Name (? = any character, * = any string):");
+        configuration.setListLabelText("Elements:");
         //TODO externalize string
         dialog = new ScopedComponentSearchListDialog(shell, "Set element reference", configuration);
     }
@@ -82,6 +83,8 @@
       configuration.setDescriptionProvider(descriptionProvider);
       configuration.setSearchListProvider(searchListProvider);
       configuration.setNewComponentHandler(new NewTypeButtonHandler());
+      configuration.setFilterLabelText("Name (? = any character, * = any string):");
+      configuration.setListLabelText("Types:");
       dialog = new ScopedComponentSearchListDialog(shell, XSDEditorPlugin.getXSDString("_UI_LABEL_SET_TYPE"), configuration);
     }
     
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddApplicationInfoDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddApplicationInfoDialog.java
index 4bc103f..e0e7023 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddApplicationInfoDialog.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddApplicationInfoDialog.java
@@ -41,6 +41,7 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableItem;
@@ -66,7 +67,7 @@
    * Element view. (required by LabelProvider)  */ 
   protected static Document tempDoc = new DocumentImpl();
   
-  Button addButton, removeButton;
+  Button addButton, removeButton, editButton;
 
   public AddApplicationInfoDialog(Shell parent, ApplicationInformationPropertiesRegistry registry)
   {
@@ -136,7 +137,12 @@
     removeButton.setText("Remove");
     removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
     removeButton.addSelectionListener(this);
-
+    
+    editButton = new Button(buttonComposite, SWT.PUSH);
+    editButton.setText("Edit");
+    editButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+    editButton.addSelectionListener(this);
+    
     List initialSelection = getInitialElementSelections();
     if (initialSelection != null)
       categoryTableViewer.setSelection(new StructuredSelection(initialSelection));
@@ -250,12 +256,8 @@
     	
     	addNewCategoryDialog.setUnavailableCategoryNames(existingNames);
     	
-    	if ( addNewCategoryDialog.open() == Window.OK ){
-    		String location = addNewCategoryDialog.getAppInfoSchemaLocation();
-    		
-    		SpecificationForAppinfoSchema schemaSpec = new SpecificationForAppinfoSchema();
-    		schemaSpec.setDisplayName(addNewCategoryDialog.getNewCategoryName());
-    		schemaSpec.setLocation(location);
+    	if ( addNewCategoryDialog.open() == Window.OK ){    		
+    		SpecificationForAppinfoSchema schemaSpec = addNewCategoryDialog.getAppinfoSpec();
     		
     		fInput.add(schemaSpec);
     		existingNames.add(schemaSpec.getDisplayName());
@@ -281,6 +283,20 @@
         // TODO auto select either the prev category, the next category or the first category in the Table
     	getButton(IDialogConstants.OK_ID).setEnabled(false);
     }
+    else if (e.widget == editButton)
+    {
+        // use this dialog not for adding but for editing purpose.
+        AddNewCategoryDialog dialog = new AddNewCategoryDialog(getShell(), "Edit Category");
+        if ( dialog.open() == Window.OK){
+        	TableItem[] selections = categoryTableViewer.getTable().getSelection();        	
+        	SpecificationForAppinfoSchema spec = (SpecificationForAppinfoSchema) selections[0].getData();
+        	
+			spec.setDisplayName(dialog.getNewCategoryName());
+        	spec.setLocation(dialog.getCategoryLocation());
+        	categoryTableViewer.update(spec, null);
+        	refreshElementsViewer(spec);
+        }
+    }
   }
 
   /*
@@ -303,24 +319,42 @@
         Object obj = ((StructuredSelection) selection).getFirstElement();
         if (obj instanceof SpecificationForAppinfoSchema)
         {
-          SpecificationForAppinfoSchema properties = (SpecificationForAppinfoSchema) obj;
+          SpecificationForAppinfoSchema spec = (SpecificationForAppinfoSchema) obj;
 
-          XSDSchema xsdSchema = getASISchemaModel(properties);
+          refreshElementsViewer(spec);
 
-          if (xsdSchema == null){
-        	  // TODO display an error Dialog telling the user that
-        	  // her selected schema file is invalid. 
-        	  return;
+          if ( spec.isDefautSchema() ){
+        	editButton.setEnabled(false);
+        	removeButton.setEnabled(false);
           }
-          
-          List allItems = buildInput(xsdSchema);
-          elementTableViewer.setInput(allItems);
+          else{
+        	editButton.setEnabled(true);
+        	removeButton.setEnabled(true);
+          }
+
           getButton(IDialogConstants.OK_ID).setEnabled(false);
         }
       }
     }
   }
-  private List buildInput(XSDSchema xsdSchema)
+  
+  private void refreshElementsViewer(SpecificationForAppinfoSchema spec) {
+	  XSDSchema xsdSchema = getASISchemaModel(spec);
+	  
+	  if (xsdSchema == null){
+		  MessageBox errDialog = new MessageBox(getShell(), SWT.ICON_ERROR);
+		  errDialog.setText("Invalid Category");
+		  errDialog.setMessage("The xsd file of the selected category cannot be parsed. \n"
+				  +"Please validate the file.");
+		  errDialog.open();
+		  return;
+	  }
+	  
+	  List allItems = buildInput(xsdSchema);
+	  elementTableViewer.setInput(allItems);
+  }
+  
+  private static List buildInput(XSDSchema xsdSchema)
   {
     List elements = xsdSchema.getElementDeclarations();
     List attributes = xsdSchema.getAttributeDeclarations();
@@ -353,7 +387,7 @@
   }
 
   
-  private XSDSchema getASISchemaModel(SpecificationForAppinfoSchema appInfoSchemaSpec)
+  private static XSDSchema getASISchemaModel(SpecificationForAppinfoSchema appInfoSchemaSpec)
   {
     XSDSchema xsdSchema = XSDImpl.buildXSDModel(appInfoSchemaSpec.getLocation());
     
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddNewCategoryDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddNewCategoryDialog.java
index 4b7787e..e91237d 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddNewCategoryDialog.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/AddNewCategoryDialog.java
@@ -45,8 +45,8 @@
 {
 
   private static final String SCHEMA_LABEL = "Schema:";
-  private static final String DIALOG_TITLE = "Add Category";
   private static final String NAME_LABEL = "Name:";
+  private String dialogTitle = "Add Category";
   private MenuManager browseMenu;
   private Label name;
   private Text nameText;
@@ -67,6 +67,12 @@
     super(parentShell);
   }
 
+  public AddNewCategoryDialog(Shell parentShell, String dialogTitle)
+  {
+    super(parentShell);
+    this.dialogTitle = dialogTitle;
+  }
+  
   /**
    * receive a List of names which have already been added to the category list
    * 
@@ -78,6 +84,24 @@
     invalidNames = unavailNames;
   }
 
+  public String getNewCategoryName()
+  {
+    return categoryName.trim();
+  }
+
+  public String getCategoryLocation()
+  {
+    return appInfoSchemaLocation;
+  }
+  
+  public SpecificationForAppinfoSchema getAppinfoSpec(){
+	SpecificationForAppinfoSchema schemaSpec = new SpecificationForAppinfoSchema();
+	schemaSpec.setDisplayName(getNewCategoryName());
+	schemaSpec.setLocation(getCategoryLocation());
+	
+	return schemaSpec;
+  }
+  
   // we initially disable the Ok button
   protected Control createButtonBar(Composite parent)
   {
@@ -88,7 +112,7 @@
 
   protected Control createDialogArea(Composite parent)
   {
-    getShell().setText(DIALOG_TITLE);
+    getShell().setText(dialogTitle);
 
     Composite mainComposite = (Composite) super.createDialogArea(parent);
     GridLayout layout = new GridLayout(3, false);
@@ -292,13 +316,4 @@
     }
   }
 
-  public String getNewCategoryName()
-  {
-    return categoryName.trim();
-  }
-
-  public String getAppInfoSchemaLocation()
-  {
-    return appInfoSchemaLocation;
-  }
 }
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/ApplicationInformationPropertiesRegistry.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/ApplicationInformationPropertiesRegistry.java
index 49682f2..f0b4463 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/ApplicationInformationPropertiesRegistry.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/ApplicationInformationPropertiesRegistry.java
@@ -73,8 +73,6 @@
           // If there is no display name, force the user
           // to manually create a name. Therefore, we ignore entry without
           // a display name.
-          // TODO (trung) still in testing phase,
-          // remove the comment for "continue;" when needed
           continue;
         }
 
@@ -84,11 +82,10 @@
         }
 
         SpecificationForAppinfoSchema asiAppinfoSpec = createEntry();
-        if (displayName == null)
-          displayName = namespaceURI;
         asiAppinfoSpec.setDescription(description);
         asiAppinfoSpec.setDisplayName(displayName);
         asiAppinfoSpec.setNamespaceURI(namespaceURI);
+        asiAppinfoSpec.setDefautSchema();
 
         if (labelProviderClass != null)
         {
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/SpecificationForAppinfoSchema.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/SpecificationForAppinfoSchema.java
index 65d560d..f074b83 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/SpecificationForAppinfoSchema.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/common/properties/sections/appinfo/SpecificationForAppinfoSchema.java
@@ -19,6 +19,7 @@
   private String namespaceURI;
   private String location;
   private ILabelProvider labelProvider;
+  private boolean isDefaultSchema = false;
 
   public SpecificationForAppinfoSchema()
   {
@@ -102,4 +103,12 @@
   {
     this.labelProvider = labelProvider;
   }
+  
+  public boolean isDefautSchema(){
+	  return isDefaultSchema ;
+  }
+
+  public void setDefautSchema(){
+	  isDefaultSchema = true;
+  }
 }