[139090] Use component reference edit manager for element and attribute types in the property sheet.
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 ba4c544..d8129e6 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
@@ -11,7 +11,8 @@ package org.eclipse.wst.xsd.ui.internal.dialogs; import java.net.URL; -import org.eclipse.core.runtime.Platform; + +import org.eclipse.core.runtime.FileLocator; import org.eclipse.emf.common.notify.Adapter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -33,6 +34,7 @@ protected Object setObject; protected int typeKind; protected Object selection; + private boolean allowComplexType; public NewTypeDialog() { @@ -69,6 +71,7 @@ { final Button complexTypeButton = new Button(parent, SWT.RADIO); complexTypeButton.setText(Messages._UI_LABEL_COMPLEX_TYPE); + complexTypeButton.setEnabled(allowComplexType); final Button simpleTypeButton = new Button(parent, SWT.RADIO); simpleTypeButton.setText(Messages._UI_LABEL_SIMPLE_TYPE); @@ -87,8 +90,17 @@ } } }; - complexTypeButton.setSelection(true); - typeKind = COMPLEX_TYPE; + if (allowComplexType) + { + complexTypeButton.setSelection(true); + typeKind = COMPLEX_TYPE; + } + else + { + simpleTypeButton.setSelection(true); + typeKind = SIMPLE_TYPE; + } + simpleTypeButton.addSelectionListener(listener); complexTypeButton.addSelectionListener(listener); Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); @@ -96,12 +108,13 @@ separator.setLayoutData(gd); } + // TODO: Can we remove this? protected String getNormalizedLocation(String location) { try { URL url = new URL(location); - URL resolvedURL = Platform.resolve(url); + URL resolvedURL = FileLocator.resolve(url); location = resolvedURL.getPath(); } catch (Exception e) @@ -110,4 +123,9 @@ } return location; } + + public void allowComplexType(boolean value) + { + this.allowComplexType= value; + } }
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 4ee37fd..d0cc8e2 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
@@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; + import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.notify.Adapter; import org.eclipse.gef.commands.Command; @@ -36,6 +37,8 @@ protected IFile currentFile; protected XSDSchema[] schemas; + private static ComponentSpecification result[]; + public XSDTypeReferenceEditManager(IFile currentFile, XSDSchema[] schemas) { this.currentFile = currentFile; @@ -79,6 +82,9 @@ public ComponentSpecification[] getQuickPicks() { + if (result != null) + return result; + // TODO (cs) implement this properly - we should be providing a list of the // most 'common' built in schema types here // I believe Trung will be working on a perference page to give us this list @@ -94,7 +100,7 @@ list.add(new ComponentSpecification(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "int", null)); //$NON-NLS-1$ list.add(new ComponentSpecification(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string", null)); //$NON-NLS-1$ list.add(new ComponentSpecification(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "time", null)); //$NON-NLS-1$ - ComponentSpecification result[] = new ComponentSpecification[list.size()]; + result = new ComponentSpecification[list.size()]; list.toArray(result); 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 74f9396..bc79957 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
@@ -34,6 +34,7 @@ protected IFile currentFile; protected XSDSchema[] schemas; protected QualifiedName metaName; + protected boolean showComplexTypes = true; public XSDSearchListDialogDelegate(QualifiedName metaName, IFile currentFile, XSDSchema[] schemas) { @@ -53,6 +54,16 @@ // TODO Auto-generated method stub } + /** + * Whether to show complex types in the Dialog's List, has no effect if the + * dialog populates list of elements instead of type + * @param value + */ + public void showComplexTypes(boolean value) + { + showComplexTypes = value; + } + public int createAndOpen() { Shell shell = XSDEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); @@ -79,6 +90,8 @@ { XSDComponentDescriptionProvider descriptionProvider = new XSDComponentDescriptionProvider(); final XSDTypesSearchListProvider searchListProvider = new XSDTypesSearchListProvider(currentFile, schemas); + if (!showComplexTypes) + searchListProvider.showComplexTypes(false); ComponentSearchListDialogConfiguration configuration = new ComponentSearchListDialogConfiguration(); configuration.setDescriptionProvider(descriptionProvider);
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 107daae..9149470 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
@@ -12,17 +12,24 @@ import org.apache.xerces.util.XMLChar; import org.eclipse.gef.commands.Command; -import org.eclipse.swt.SWT; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorPart; +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.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.XSDEditorPlugin; +import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; +import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; import org.eclipse.xsd.XSDAttributeDeclaration; import org.eclipse.xsd.XSDTypeDefinition; import org.eclipse.xsd.util.XSDConstants; @@ -30,8 +37,7 @@ public class XSDAttributeDeclarationSection extends AbstractSection { protected Text nameText; - protected Text typeCombo; - protected Button button; + protected CCombo typeCombo; boolean isAttributeReference; public XSDAttributeDeclarationSection() @@ -55,7 +61,7 @@ GridData data = new GridData(); data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, "Name:"); //$NON-NLS-1$ + CLabel nameLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NAME); nameLabel.setLayoutData(data); // ------------------------------------------------------------------ @@ -87,23 +93,52 @@ data = new GridData(); data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; - - typeCombo = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - typeCombo.setEditable(false); - // baseTypeCombo.addListener(SWT.Modify, this); + typeCombo = getWidgetFactory().createCCombo(composite); typeCombo.setLayoutData(data); + typeCombo.addSelectionListener(this); - // ------------------------------------------------------------------ - // BaseTypeButton - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; + } - button = getWidgetFactory().createButton(composite, "", SWT.PUSH); //$NON-NLS-1$ - button.setImage(XSDEditorPlugin.getXSDImage("icons/browsebutton.gif")); //$NON-NLS-1$ - button.addSelectionListener(this); - button.setLayoutData(data); + private void fillTypesCombo() + { + IEditorPart editor = getActiveEditor(); + XSDTypeReferenceEditManager manager = (XSDTypeReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); + ComponentSpecification[] items = manager.getQuickPicks(); + + typeCombo.removeAll(); + typeCombo.add(Messages._UI_ACTION_BROWSE); + typeCombo.add(Messages._UI_ACTION_NEW); + for (int i = 0; i < items.length; i++) + { + typeCombo.add(items[i].getName()); + } + + XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration(); + XSDTypeDefinition namedComponentType = namedComponent.getType(); + String currentTypeName = namedComponentType.getQName(xsdSchema); // no prefix + ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager); + if (ret == null) //not in quickPick + typeCombo.add(currentTypeName); + } + + private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) + { + 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; + } + } + } + } + return null; } /* @@ -147,6 +182,7 @@ } else { + fillTypesCombo(); String typeName = ""; //$NON-NLS-1$ if (typeDef != null) { @@ -172,6 +208,47 @@ { return false; } + + public void doWidgetSelected(SelectionEvent e) + { + super.doWidgetSelected(e); + if (e.widget == typeCombo) + { + IEditorPart editor = getActiveEditor(); + if (editor == null) return; + ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); + + String selection = typeCombo.getText(); + ComponentSpecification newValue; + IComponentDialog dialog= null; + if ( selection.equals(Messages._UI_ACTION_BROWSE)) + { + dialog = manager.getBrowseDialog(); + ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); + } + else if ( selection.equals(Messages._UI_ACTION_NEW)) + { + dialog = manager.getNewDialog(); + ((NewTypeDialog) dialog).allowComplexType(false); + } + + if (dialog != null) + { + if (dialog.createAndOpen() == Window.OK) + { + newValue = dialog.getSelectedComponent(); + manager.modifyComponentReference(input, newValue); + } + } + else //use the value from selected quickPick item + { + newValue = getComponentSpecFromQuickPickForValue(selection, manager); + if (newValue != null) + manager.modifyComponentReference(input, newValue); + } +// refresh(); + } + } protected void doHandleEvent(Event event) {
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 09ca3a7..c9fba73 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
@@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; + import org.apache.xerces.util.XMLChar; -import org.eclipse.core.resources.IFile; import org.eclipse.gef.commands.Command; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.window.Window; @@ -23,31 +23,23 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSearchListDialog; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSearchListDialogConfiguration; import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.common.ui.internal.search.dialogs.ScopedComponentSearchListDialog; +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.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand; -import org.eclipse.wst.xsd.ui.internal.dialogs.NewTypeButtonHandler; +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.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDComponentDescriptionProvider; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDTypesSearchListProvider; +import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; +import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.xsd.XSDAttributeDeclaration; import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; import org.eclipse.xsd.XSDTypeDefinition; import org.eclipse.xsd.util.XSDConstants; import org.w3c.dom.Element; @@ -55,8 +47,7 @@ public class XSDElementDeclarationSection extends MultiplicitySection { protected Text nameText; - protected Text typeCombo; - protected Button typesBrowseButton; + protected CCombo typeCombo; protected CCombo componentNameCombo; boolean isElementReference; @@ -153,21 +144,18 @@ data.grabExcessHorizontalSpace = true; data.horizontalAlignment = GridData.FILL; - typeCombo = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ + typeCombo = getWidgetFactory().createCCombo(composite); //$NON-NLS-1$ typeCombo.setEditable(false); typeCombo.setLayoutData(data); - + typeCombo.addSelectionListener(this); + // ------------------------------------------------------------------ - // BaseTypeButton + // DummyLabel // ------------------------------------------------------------------ data = new GridData(); data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; data.grabExcessHorizontalSpace = false; - - typesBrowseButton = getWidgetFactory().createButton(composite, "", SWT.PUSH); //$NON-NLS-1$ - typesBrowseButton.setImage(XSDEditorPlugin.getXSDImage("icons/browsebutton.gif")); //$NON-NLS-1$ - typesBrowseButton.addSelectionListener(this); - typesBrowseButton.setLayoutData(data); + getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ // ------------------------------------------------------------------ // min property @@ -227,6 +215,7 @@ items.add(0, ""); //$NON-NLS-1$ componentNameCombo.setItems((String [])items.toArray(new String[0])); } +// fillTypesCombo(); setListenerEnabled(true); } @@ -241,6 +230,47 @@ } } + private void fillTypesCombo() + { + IEditorPart editor = getActiveEditor(); + ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); + ComponentSpecification[] items = manager.getQuickPicks(); + + typeCombo.removeAll(); + typeCombo.add(Messages._UI_ACTION_BROWSE); + typeCombo.add(Messages._UI_ACTION_NEW); + for (int i = 0; i < items.length; i++) + { + typeCombo.add(items[i].getName()); + } + // Add the current Type of this attribute if needed + XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration(); + String currentTypeName = namedComponent.getType().getQName(xsdSchema); //no prefix + ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName,manager); + if (ret == null) //not in quickPick + typeCombo.add(currentTypeName); + } + + private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) + { + 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; + } + } + } + } + return null; + } + /* * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() */ @@ -255,7 +285,6 @@ // refresh name nameText.setText(""); //$NON-NLS-1$ typeCombo.setText(""); //$NON-NLS-1$ - typesBrowseButton.setEnabled(true); String name = xsdElementDeclaration.getName(); if (name != null) { @@ -291,6 +320,7 @@ } else { + fillTypesCombo(); if (typeDefinition != null) { typeCombo.setText(typeName); @@ -317,44 +347,41 @@ public void doWidgetSelected(SelectionEvent e) { - if (e.widget == typesBrowseButton) + if (e.widget == typeCombo) { - Shell shell = Display.getCurrent().getActiveShell(); - IFile currentIFile = ((IFileEditorInput) getActiveEditor().getEditorInput()).getFile(); + IEditorPart editor = getActiveEditor(); + if (editor == null) return; + ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - /** Initialize the Set types Dialog */ - final XSDTypesSearchListProvider searchListProvider = - new XSDTypesSearchListProvider(currentIFile, new XSDSchema[] {xsdSchema} ); - ComponentSearchListDialogConfiguration configuration = new ComponentSearchListDialogConfiguration(); - configuration.setDescriptionProvider(new XSDComponentDescriptionProvider() ); - configuration.setSearchListProvider(searchListProvider); - configuration.setNewComponentHandler(new NewTypeButtonHandler()); - ComponentSearchListDialog dialog = new ScopedComponentSearchListDialog(shell, XSDEditorPlugin.getXSDString("_UI_LABEL_SET_TYPE"), configuration); //$NON-NLS-1$ - //dialog.setFilterLabel("Text:"); - - if (input instanceof XSDAttributeDeclaration) + String selection = typeCombo.getText(); + ComponentSpecification newValue; + IComponentDialog dialog= null; + if ( selection.equals(Messages._UI_ACTION_BROWSE)) { - searchListProvider.showComplexTypes(false); + dialog = manager.getBrowseDialog(); + ((XSDSearchListDialogDelegate) dialog).showComplexTypes(true); + } + else if ( selection.equals(Messages._UI_ACTION_NEW)) + { + dialog = manager.getNewDialog(); + ((NewTypeDialog) dialog).allowComplexType(true); } - dialog.setBlockOnOpen(true); - dialog.create(); - - if (dialog.open() == Window.OK) + if (dialog != null) { - //String newType = (String) dialog.getSelection().getAttributeInfo("name"); - //String nsType = (String) dialog.getSelection().getTargetNamespace(); - - ComponentSpecification selection = dialog.getSelectedComponent(); - String newType = selection.getName(); - String namespace = selection.getQualifier(); - - UpdateTypeReferenceCommand command = new UpdateTypeReferenceCommand((XSDElementDeclaration) input, xsdSchema.resolveTypeDefinition(namespace, newType)); - getCommandStack().execute(command); - - init(); - relayout(); + if (dialog.createAndOpen() == Window.OK) + { + newValue = dialog.getSelectedComponent(); + manager.modifyComponentReference(input, newValue); + } } + else //use the value from selected quickPick item + { + newValue = getComponentSpecFromQuickPickForValue(selection, manager); + if (newValue != null) + manager.modifyComponentReference(input, newValue); + } +// refresh(); } else if (e.widget == componentNameCombo) { @@ -455,8 +482,6 @@ public void dispose() { - if (typesBrowseButton != null && !typesBrowseButton.isDisposed()) - typesBrowseButton.removeSelectionListener(this); if (componentNameCombo != null && !componentNameCombo.isDisposed()) componentNameCombo.removeSelectionListener(this); if (minCombo != null && !minCombo.isDisposed()) @@ -469,7 +494,6 @@ protected void refreshRefCombo() { componentNameCombo.setText(""); //$NON-NLS-1$ - typesBrowseButton.setEnabled(false); XSDElementDeclaration namedComponent = (XSDElementDeclaration) input; Element element = namedComponent.getElement();