Check in new Common Component Selection Dialog; New set type dialog; Modify editor to launch new dialog; remove old set type dialog.
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/commands/SetTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/commands/SetTypeCommand.java
index 227e5d8..1603ffa 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/commands/SetTypeCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/commands/SetTypeCommand.java
@@ -1,7 +1,17 @@
package org.eclipse.wst.xsd.ui.internal.commands;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.XSDSetTypeDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDSetTypeHelper;
import org.eclipse.xsd.XSDCompositor;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
@@ -47,15 +57,38 @@
}
else
{
- XSDSetTypeDialog setTypeDialog = new XSDSetTypeDialog(Display.getDefault().getActiveShell(), element.getElement(), "Set Type", schema);
- setTypeDialog.create();
- setTypeDialog.open();
- int rc = setTypeDialog.getReturnCode();
+ Shell shell = Display.getCurrent().getActiveShell();
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+ IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile();
+
+ XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, schema);
+ XSDComponentSelectionDialog dialog = new XSDComponentSelectionDialog(shell, "Set Type", provider); // TODO: Externalize This
+ provider.setDialog(dialog);
+
+ dialog.setBlockOnOpen(true);
+ dialog.create();
+
+ if (dialog.open() == Window.OK) {
+ XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, schema);
+ helper.setType(element.getElement(), "type", dialog.getSelection());
+ }
}
formatChild(element.getElement());
}
}
+
+ private IEditorPart getActiveEditor()
+ {
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+// IEditorPart editorPart = part.getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
+
+ return editorPart;
+ }
protected boolean adopt(XSDConcreteComponent model)
{
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/ImportTypesDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/ImportTypesDialog.java
deleted file mode 100644
index 60fa5c0..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/ImportTypesDialog.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Vector;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-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.Label;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.common.ui.dialogs.SelectSingleFileDialog;
-import org.eclipse.xsd.XSDNamedComponent;
-import org.eclipse.xsd.XSDSchema;
-import org.eclipse.xsd.util.XSDResourceImpl;
-
-public class ImportTypesDialog extends SelectSingleFileDialog {
- private List importList;
- private Button importStyleCheckBox;
- private boolean isWSIStyleImport;
- private String kind = "type";
- private Object input;
- private ResourceSet resourceSet;
- private java.util.List importComponents;
- private Object listSelection;
- private boolean allowWSI;
- private Vector loaders;
-
- /*
- * String kind should be either "type" or "element"
- */
- public ImportTypesDialog(Shell parentShell, IStructuredSelection selection, boolean allowWSI, String kind) {
- super(parentShell, selection, true);
- this.allowWSI = allowWSI;
- this.kind = kind;
-
- loaders = new Vector();
- loaders.add(new XSDLoadAvaliableItems());
- }
-
- protected Control createDialogArea(Composite parent) {
- Control area = super.createDialogArea(parent);
- Composite base = new Composite((Composite) area, SWT.NONE);
- base.setLayout(new GridLayout());
-
- GridData compositeData = new GridData();
- compositeData.horizontalAlignment = GridData.FILL;
- compositeData.verticalAlignment = GridData.FILL;
- compositeData.grabExcessHorizontalSpace = true;
- compositeData.grabExcessVerticalSpace = true;
- base.setLayoutData(compositeData);
-
- Label listLabel = new Label(base, SWT.NONE);
- if (kind.equalsIgnoreCase("type")) {
- listLabel.setText("Types");
- }
- else {
- listLabel.setText("Elements");
- }
- importList = new List(base, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
-
- GridData importListData = new GridData();
- importListData.horizontalAlignment = GridData.FILL;
- importListData.verticalAlignment = GridData.FILL;
- importListData.grabExcessHorizontalSpace = true;
- importListData.grabExcessVerticalSpace = true;
- importList.setLayoutData(importListData);
-
- if (allowWSI) {
- importStyleCheckBox = new Button(base, SWT.CHECK);
-// importStyleCheckBox.setText(WSDLEditorPlugin.getWSDLString("_UI_USE_WS-I_STYLE_SCHEMA_IMPORT"));
- importStyleCheckBox.setText("WS-I style import");
- importStyleCheckBox.setSelection(true);
- isWSIStyleImport = true;
- importStyleCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
-
- SelectionAdapter selectionAdapter = new SelectionAdapter()
- {
- public void widgetSelected(SelectionEvent event)
- {
- if (event.widget == importList && importList.getSelectionCount() > 0) {
- listSelection = importComponents.get(importList.getSelectionIndex());
- }
- else if (event.widget == importStyleCheckBox) {
- isWSIStyleImport = importStyleCheckBox.getSelection();
- }
- }
- };
- importStyleCheckBox.addSelectionListener(new SelectionAdapter()
- {
- public void widgetSelected(SelectionEvent event) {
- isWSIStyleImport = importStyleCheckBox.getSelection();
- }
- });
-
- Label titleBarSeparator = new Label(base, SWT.HORIZONTAL | SWT.SEPARATOR);
- titleBarSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- }
-
- selectSingleFileView.addSelectionChangedTreeListener(new TreeListener());
- importList.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent event) {
- if (importList.getSelectionCount() > 0) {
- listSelection = importComponents.get(importList.getSelectionIndex());
- }
- }
- });
-
- return area;
- }
-
- public Object getListSelection() {
- return listSelection;
- }
-
- public boolean isWSIStyleImport() {
- if (allowWSI) {
- return isWSIStyleImport;
- }
- else {
- return false;
- }
- }
-
- public void addLoadAvaliableItemsClass(LoadAvaliableItems newLoader) {
- loaders.add(newLoader);
- }
-
- private class TreeListener implements ISelectionChangedListener {
- public TreeListener() {
- }
-
- public void selectionChanged(SelectionChangedEvent event) {
- if (delayedEvent != null) {
- delayedEvent.CANCEL = true;
- }
-
- delayedEvent = new DelayedEvent(event);
- Display.getCurrent().timerExec(500, delayedEvent);
-
- // Do not allow WS-I style imports on WSDL files
- ISelection selection = event.getSelection();
- if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof IFile) {
- IFile iFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
-
- String ext = iFile.getFileExtension();
- if (ext.equalsIgnoreCase("wsdl")) {
- importStyleCheckBox.setEnabled(false);
- isWSIStyleImport = false;
- }
- else if (ext.equalsIgnoreCase("xsd")) {
- importStyleCheckBox.setEnabled(true);
- isWSIStyleImport = importStyleCheckBox.getSelection();
- }
- }
- }
-
- private DelayedEvent delayedEvent;
-
- private class DelayedEvent implements Runnable {
- public boolean CANCEL = false;
- private SelectionChangedEvent event;
-
- public DelayedEvent(SelectionChangedEvent event) {
- this.event = event;
- }
- public void run() {
- if (!CANCEL) {
- // We clear the selection made in the List... it may no longer apply to the newly selected file
- listSelection = null;
- importComponents = Collections.EMPTY_LIST;
- importList.removeAll();
-
- // We populate the avaliable types/element list
- ISelection selection = event.getSelection();
- if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() instanceof IFile) {
- IFile iFile = (IFile) ((IStructuredSelection) selection).getFirstElement();
-
- // Attempt to load the avaliable Types/Elements from the selected File
- int loaderIndex = 0;
- while (importComponents.size() < 1 && loaderIndex < loaders.size()) {
- importComponents = ((LoadAvaliableItems) loaders.elementAt(loaderIndex)).getAvaliableItems(iFile);
- loaderIndex++;
- }
-
- // Make the first item in the list the selection
- if (importComponents.size() > 0) {
- listSelection = importComponents.get(0);
- }
-
- for (Iterator it = ((java.util.List) importComponents).iterator(); it.hasNext();) {
- XSDNamedComponent comp = (XSDNamedComponent) it.next();
- importList.add(comp.getName());
- }
- }
- }
- }
- }
- }
-
- /*
- * Loads Avaliable Types/Elements from the given IFile. Handles XSD files
- */
- private class XSDLoadAvaliableItems extends LoadAvaliableItems {
- public XSDLoadAvaliableItems() {}
-
- protected java.util.List loadFile(IFile iFile) {
- java.util.List modelObjectList = Collections.EMPTY_LIST;
- try {
- if (iFile != null) {
- URI uri = URI.createPlatformResourceURI(iFile.getFullPath().toString());
-
- Object rootModelObject = null;
- if (uri.toString().endsWith("xsd")) {
- ResourceSet resourceSet = new ResourceSetImpl();
- Resource resource = resourceSet.getResource(uri, true);
- if (resource instanceof XSDResourceImpl) {
- rootModelObject = ((XSDResourceImpl) resource).getSchema();
- }
- }
-
- if (rootModelObject != null) {
- modelObjectList = new ArrayList(getModelObjects(rootModelObject));
- }
- }
- }
- catch (Exception e) {}
-
- return modelObjectList;
- }
-
- private Collection getModelObjects(Object rootModelObject) {
- ArrayList objects = new ArrayList();
-
- if (rootModelObject instanceof XSDSchema) {
- XSDSchema xsdSchema = (XSDSchema)rootModelObject;
- if (kind.equalsIgnoreCase("type")) {
- objects.addAll(((XSDSchema) xsdSchema).getTypeDefinitions());
- }
- else if (kind.equalsIgnoreCase("element")) {
- objects.addAll(((XSDSchema) xsdSchema).getElementDeclarations());
- }
- }
-
- return objects;
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/LoadAvaliableItems.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/LoadAvaliableItems.java
deleted file mode 100644
index 8decdda..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/LoadAvaliableItems.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import org.eclipse.core.resources.IFile;
-
-/*
- * Loads Avaliable Types/Elements from the given IFile. Implementors
- * needed to handle certain File types (xsd, wsdl, etc...)
- */
-public abstract class LoadAvaliableItems {
- public java.util.List getAvaliableItems(IFile file) {
- return loadFile(file);
- }
-
- protected abstract java.util.List loadFile(IFile iFile);
-}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewComponentDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewComponentDialog.java
deleted file mode 100644
index fb37a20..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewComponentDialog.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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.types;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-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.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-
-/*
- * This class is a copy of NewComponentDialog.java in org.eclipse.wst.wsdl.ui.
- * We have a copy because we want a similar look and feel to both editors.
- * We should remove NewComponentDialog.java in org.eclipse.wst.wsdl.ui and point
- * all references to this class.
- */
-public class NewComponentDialog extends Dialog implements ModifyListener
-{
- protected Text nameField;
- protected Button okButton;
- protected String defaultName;
- protected String title;
- protected Label errorMessageLabel;
- protected List usedNames;
-
- public NewComponentDialog(Shell parentShell, String title, String defaultName)
- {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.RESIZE);
- this.defaultName = defaultName;
- this.title = title;
- }
-
- public NewComponentDialog(Shell parentShell, String title, String defaultName, List usedNames)
- {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.RESIZE);
- this.defaultName = defaultName;
- this.title = title;
- this.usedNames = usedNames;
- }
-
- public int createAndOpen()
- {
- create();
- getShell().setText(title);
- setBlockOnOpen(true);
- return open();
- }
-
- protected Control createContents(Composite parent)
- {
- Control control = super.createContents(parent);
- nameField.forceFocus();
- nameField.selectAll();
- updateErrorMessage();
- return control;
- }
-
-
- protected void createButtonsForButtonBar(Composite parent)
- {
- okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
- createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
- }
-
- protected void createExtendedContent(Composite parent)
- {
- }
-
-
- protected Control createDialogArea(Composite parent)
- {
- Composite dialogArea = (Composite)super.createDialogArea(parent);
-
- Composite composite = new Composite(dialogArea, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginWidth = 0;
- composite.setLayout(layout);
-
- GridData gdFill= new GridData();
- gdFill.horizontalAlignment= GridData.FILL;
- gdFill.grabExcessHorizontalSpace= true;
- gdFill.verticalAlignment= GridData.FILL;
- gdFill.grabExcessVerticalSpace= true;
- composite.setLayoutData(gdFill);
-
- Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText(XSDEditorPlugin.getXSDString("_UI_NAME"));
-
- nameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
- GridData gd= new GridData();
- gd.horizontalAlignment= GridData.FILL;
- gd.grabExcessHorizontalSpace= true;
- gd.widthHint = 200;
- nameField.setLayoutData(gd);
- nameField.setText(defaultName);
- nameField.addModifyListener(this);
-
- createExtendedContent(dialogArea);
-
- // error message
- errorMessageLabel = new Label(dialogArea, SWT.NONE);
- errorMessageLabel.setText("error message goes here");
- GridData gd2 = new GridData();
- gd2.horizontalAlignment= GridData.FILL;
- gd2.grabExcessHorizontalSpace= true;
- gd2.widthHint = 200;
- errorMessageLabel.setLayoutData(gd2);
-// Color color = new Color(errorMessageLabel.getDisplay(), 200, 0, 0);
-// errorMessageLabel.setForeground(color);
-
- return dialogArea;
- }
-
- public void modifyText(ModifyEvent e)
- {
- updateErrorMessage();
- }
-
- protected String computeErrorMessage(String name)
- {
- if (usedNames == null)
- return null;
-
- Iterator iterator = usedNames.iterator();
- while (iterator.hasNext()) {
- if (name.equalsIgnoreCase((String) iterator.next())) {
- return "Warning: duplicate name already exists"; // Must be translated
- }
- }
-
- return null;
- }
-
- protected void updateErrorMessage()
- {
- String errorMessage = null;
- String name = nameField.getText().trim();
- if (name.length() > 0)
- {
- errorMessage = computeErrorMessage(name);
- }
- else
- {
- errorMessage = "";
- }
- errorMessageLabel.setText(errorMessage != null ? errorMessage : "");
-// okButton.setEnabled(errorMessage == null);
- }
-
- protected void buttonPressed(int buttonId)
- {
- if (buttonId == IDialogConstants.OK_ID)
- {
- defaultName = nameField.getText();
- }
- super.buttonPressed(buttonId);
- }
-
- public String getName()
- {
- return defaultName;
- }
-}
-
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewTypeDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewTypeDialog.java
deleted file mode 100644
index be6f116..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/NewTypeDialog.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import java.util.List;
-
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-
-/*
- * This class extends NewComponentDialog to allow additional widgets. More
- * specifically, the 'create complex type or simple type' checkbox
- */
-public class NewTypeDialog extends NewComponentDialog implements SelectionListener {
- protected Button complexRadio;
- protected Button simpleRadio;
- private boolean createComplexTypeBoolean;
-
- private List complexNames;
- private List simpleNames;
-
- public NewTypeDialog(Shell parentShell, String defaultName) {
- super(parentShell, "New Type", defaultName);
- }
-
- /*
- * The argument usedNames is the used names for the Complex Types.
- * See method setUsedComplexTypeNames(List) for more information.
- */
- public NewTypeDialog(Shell parentShell, String defaultName, List usedNames) {
- super(parentShell, "New Type", defaultName, usedNames);
- setUsedComplexTypeNames(usedNames);
- }
-
- protected void createExtendedContent(Composite parent) {
- Composite child = new Composite (parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 1;
- layout.marginWidth = 0;
- layout.marginHeight = 0;
- child.setLayout(layout);
-
- complexRadio = new Button(child, SWT.RADIO);
- complexRadio.addSelectionListener(this);
- complexRadio.setSelection(true);
- complexRadio.setText(XSDEditorPlugin.getXSDString("_UI_PAGE_HEADING_COMPLEXTYPE"));
-
- simpleRadio = new Button(child, SWT.RADIO);
- simpleRadio.addSelectionListener(this);
- simpleRadio.setText(XSDEditorPlugin.getXSDString("_UI_PAGE_HEADING_SIMPLETYPE"));
- }
-
- public boolean isComplexType() {
- return createComplexTypeBoolean;
- }
-
- protected void buttonPressed(int buttonId) {
- if (buttonId == IDialogConstants.OK_ID) {
- createComplexTypeBoolean = complexRadio.getSelection();
- }
- super.buttonPressed(buttonId);
- }
-
- /*
- * Used to set the used names for complex types. If the user enters a name (for a complex
- * type) which is in this list, a warning message will appear.
- *
- * Note:
- * The used names list supplied in the constructor is meant for the complex names list.
- * So, this method does not need to be called. If this method is called, the list
- * supplied by this method will be used instead of the list supplied from the constructor.
- */
- public void setUsedComplexTypeNames(List complexNames) {
- this.complexNames = complexNames;
- }
-
- /*
- * Used to set the used names for simple types. If the user enters a name (for a simple
- * type) which is in this list, a warning message will appear.
- */
- public void setUsedSimpleTypeNames(List simpleNames) {
- this.simpleNames = simpleNames;
- }
-
- /*
- * SelectionListener methods
- */
- public void widgetSelected(SelectionEvent event) {
- // We need to update the usedNames list
- if (complexRadio.getSelection()) {
- if (simpleRadio.getSelection()) {
- simpleRadio.setSelection(false);
- }
-
- usedNames = complexNames;
- updateErrorMessage();
- }
- else if (simpleRadio.getSelection()){
- if (complexRadio.getSelection()) {
- complexRadio.setSelection(false);
- }
-
- usedNames = simpleNames;
- updateErrorMessage();
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent event) {
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeDialog.java
deleted file mode 100644
index 820c3ad..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeDialog.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-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.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDNamedComponent;
-import org.eclipse.xsd.XSDSchema;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-
-/*
- * Abstract class used to set the Type or Element.
- */
-public abstract class SetTypeDialog extends Dialog {
- protected Object input;
- protected String kind;
- private String dialogTitle;
-
- // widgets
- protected Text textFilter;
- private Button createButton;
- private Button removeButton;
- private Button importButton;
- protected Button viewTypeCheckBox;
-
- protected SetTypeTreeView treeView; // A Tree Viewer helper class
- protected TypesDialogTreeObject treeRootViewerInput; // Root Input object for our Tree
-
- public SetTypeDialog(Shell shell, Object input, String dialogTitle, String kind) {
- super(shell);
- this.input = input;
- this.kind = kind;
- this.dialogTitle = dialogTitle;
- }
-
- public Control createDialogArea(Composite parent) {
- getShell().setText(dialogTitle);
-
- Composite base = (Composite) super.createDialogArea(parent);
- GridData gData = (GridData) base.getLayoutData();
- gData.heightHint = 500;
- gData.widthHint = 400;
-
- // Create Text textFilter
- Label filterLabel = new Label(base, SWT.NONE);
- filterLabel.setText("(? = any character, * = any string)");
- textFilter = new Text(base, SWT.SINGLE | SWT.BORDER);
- textFilter.addModifyListener(new SetTypeModifyAdapter());
- GridData textFilterData = new GridData();
- textFilterData.horizontalAlignment = GridData.FILL;
- textFilterData.grabExcessHorizontalSpace = true;
- textFilter.setLayoutData(textFilterData);
-
- // Create and expand entire Tree when we first open the dialog
- createTree(base);
- treeView.expandAll();
-
- SetTypeSelectionAdapter selectionAdapter = new SetTypeSelectionAdapter();
-
- // Create viewTypeCheckBox
- viewTypeCheckBox = createCheckBox(base, "Flat View");
- viewTypeCheckBox.setSelection(false);
- viewTypeCheckBox.addSelectionListener(selectionAdapter);
-
- // Create Composite 2
- Composite comp2 = new Composite(base, SWT.NONE);
- GridLayout layout2 = new GridLayout();
- layout2.numColumns = 2;
- comp2.setLayout(layout2);
-
- GridData gdk = new GridData();
- gdk.grabExcessHorizontalSpace = true;
- gdk.horizontalAlignment = SWT.CENTER;
- comp2.setLayoutData(gdk);
-
- // Create Add and Remove Buttons
- createButton = createPushButton(comp2, "Create New");
- // removeButton = createPushButton(comp2, "Remove");
- createButton.addSelectionListener(selectionAdapter);
-
- // Create Composite 3
- Composite comp3 = new Composite(base, SWT.NONE);
- GridLayout layout3 = new GridLayout();
- layout3.numColumns = 2;
- comp3.setLayout(layout3);
-
- // Create Browse Button
- importButton = createPushButton(comp2, "import...");
- importButton.addSelectionListener(selectionAdapter);
-
- // Build the separator line
- Label titleBarSeparator = new Label(base, SWT.HORIZONTAL
- | SWT.SEPARATOR);
- titleBarSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- return base;
- }
-
- /**
- * Helper method for creating buttons.
- */
- public static Button createPushButton(Composite parent, String label) {
- Button button = new Button(parent, SWT.PUSH);
- button.setText(label);
-
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- button.setLayoutData(data);
-
- return button;
- }
-
- /**
- * Helper method for creating check box
- */
- public static Button createCheckBox(Composite parent, String label) {
- Button button = new Button(parent, SWT.CHECK);
- button.setText(label);
-
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- button.setLayoutData(data);
- return button;
- }
-
- private void createTree(Composite base) {
- String title;
- if (kind.equalsIgnoreCase("type")) {
- title = "Avaliable Types";
- } else {
- title = "Avaliable Elements";
- }
-
- treeView = new SetTypeTreeView(base, title);
- treeView.addTreeSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- updateCanFinish(event.getSelection());
- }
- });
-
- populateTreeViewer(false, "", false, false);
- }
-
- protected void populateTreeViewer(boolean isFlatView, String filterString,
- boolean saveExpansionState, boolean restoreExpansionState) {
- if (saveExpansionState) {
- treeView.storeExpansionState();
- }
-
- treeRootViewerInput = new TypesDialogTreeObject("root");
- if (isFlatView) {
- // Flat View
- createFlatView(treeRootViewerInput, filterString);
- }
- else {
- // Tree View
- createTreeView(treeRootViewerInput, filterString);
- }
- treeView.setInput(treeRootViewerInput);
-
- if (restoreExpansionState) {
- treeView.restoreExpansionState();
- }
- }
-
- private String insertString(String target, String newString, String string) {
- ArrayList list = new ArrayList();
- StringBuffer stringBuffer = new StringBuffer(string);
-
- int index = stringBuffer.indexOf(target);
- while (index != -1) {
- stringBuffer = stringBuffer.insert(index, newString);
- index = stringBuffer.indexOf(target, index + newString.length()
- + target.length());
- }
-
- return stringBuffer.toString();
- }
-
- /*
- * If supported metacharacters are used in the filter string, we need to insert
- * a "." before each metacharacter.
- */
- private String processFilterString(String inputString) {
- if (!(inputString.equals(""))) {
- inputString = insertString("*", ".", inputString);
- inputString = insertString("?", ".", inputString);
- inputString = inputString + ".*";
- } else {
- inputString = ".*";
- }
-
- return inputString.toLowerCase();
- }
-
- private class SetTypeModifyAdapter implements ModifyListener {
- public void modifyText(ModifyEvent e) {
- if (e.widget == textFilter) {
- if (delayedEvent != null) {
- delayedEvent.CANCEL = true;
- }
-
- delayedEvent = new DelayedEvent();
- Display.getCurrent().timerExec(400, delayedEvent);
- }
- }
- }
-
- private DelayedEvent delayedEvent;
-
- private class DelayedEvent implements Runnable {
- public boolean CANCEL = false;
-
- public void run() {
- if (!CANCEL) {
- populateTreeViewer(viewTypeCheckBox.getSelection(),
- processFilterString(textFilter.getText()),
- false, false);
-
- // Expand all and select first item which matches
- treeView.expandAll();
- treeView.selectFirstItem();
- }
- }
- }
-
- private class SetTypeSelectionAdapter extends SelectionAdapter {
- public void widgetSelected(SelectionEvent e) {
- if (e.widget == viewTypeCheckBox) {
- // Toggle between Flat view and Tree view
- if (viewTypeCheckBox.getSelection()) {
- populateTreeViewer(viewTypeCheckBox.getSelection(),
- processFilterString(textFilter.getText()), true,
- false);
- }
- else {
- populateTreeViewer(viewTypeCheckBox.getSelection(),
- processFilterString(textFilter.getText()), false,
- true);
- }
- }
- else if (e.widget == createButton) {
- createButtonPressed();
- }
- else if (e.widget == importButton) {
- importButtonPressed();
- }
- }
- }
-
- protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- getButton(IDialogConstants.OK_ID).setEnabled(false);
- }
-
-
- protected List getUsedComplexTypeNames(XSDSchema schema) {
- List usedNames = new ArrayList();
- Iterator names = schema.getTypeDefinitions().iterator();
- while (names.hasNext()) {
- XSDNamedComponent comp = (XSDNamedComponent) names.next();
- if (comp instanceof XSDComplexTypeDefinition) {
- usedNames.add(comp.getName());
- }
- }
-
- return usedNames;
- }
-
- protected List getUsedSimpleTypeNames(XSDSchema schema) {
- List usedNames = new ArrayList();
- Iterator names = schema.getTypeDefinitions().iterator();
- while (names.hasNext()) {
- XSDNamedComponent comp = (XSDNamedComponent) names.next();
- if (comp instanceof XSDSimpleTypeDefinition) {
- usedNames.add(comp.getName());
- }
- }
-
- return usedNames;
- }
-
- protected List getUsedElementNames(XSDSchema schema) {
- List usedNames = new ArrayList();
- Iterator names = schema.getElementDeclarations().iterator();
- while (names.hasNext()) {
- XSDNamedComponent comp = (XSDNamedComponent) names.next();
- usedNames.add(comp.getName());
- }
-
- return usedNames;
- }
-
- /*
- * This method should be subclassed.
- */
- protected abstract void createButtonPressed();
-
- /*
- * This method should be subclassed
- */
- protected abstract void importButtonPressed();
-
- /*
- * This method should be subclassed
- */
- protected abstract void createTreeView(TypesDialogTreeObject root, String filterString);
-
- /*
- * This methods should be subclassed
- */
- protected abstract void createFlatView(TypesDialogTreeObject root, String filterString);
-
- /*
- * This method should be subclassed
- */
- protected abstract void updateCanFinish(Object object);
-
- /*
- * This method should be subclassed
- */
- protected void okPressed() {
- super.okPressed();
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeTreeView.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeTreeView.java
deleted file mode 100644
index 64f0598..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/SetTypeTreeView.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 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.types;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-
-public class SetTypeTreeView {
- private TreeViewer treeViewer;
- private TypesDialogTreeObject rootTreeObject;
- private HashMap expansionStateMap;
-
- public SetTypeTreeView(Composite base, String stringLabel) {
- Label label = new Label(base, SWT.NONE);
- label.setText(stringLabel);
-
- treeViewer = new TreeViewer(new Tree(base, SWT.SINGLE | SWT.BORDER));
- treeViewer.setContentProvider(new TreeObjectContentProvider());
- treeViewer.setLabelProvider(new TreeObjectLabelProvider());
-
- Control treeWidget = treeViewer.getTree();
- GridData gd = new GridData(GridData.FILL_BOTH);
- treeWidget.setLayoutData(gd);
-
- expansionStateMap = new HashMap();
- }
-
- public void setInput(TypesDialogTreeObject input) {
- rootTreeObject = input;
- treeViewer.setInput(input);
- treeViewer.refresh();
- }
-
- /*
- * Take a snapshot of the current expansion state. We will use this
- * snapshot to restore the expanded state of TreeViewer based on the new input.
- * Usage: setTypeTreeView.storeExpansionState()
- * setTypeTreeView.setInput(input);
- * setTypeTreeView.restoreExpansionState()
- */
- public void storeExpansionState() {
- // Easy to record expansion state since expansion should only
- // occur at the 'top' level
- if (rootTreeObject != null) {
- expansionStateMap = new HashMap(rootTreeObject.getChildren().size());
- Iterator childrenIt = rootTreeObject.getChildren().iterator();
- while (childrenIt.hasNext()) {
- TypesDialogTreeObject item = (TypesDialogTreeObject) childrenIt.next();
- expansionStateMap.put(item.getDataObject(), isExpanded(item));
- }
- }
- }
-
- public void restoreExpansionState() {
- Iterator childrenIt = rootTreeObject.getChildren().iterator();
- while (childrenIt.hasNext()) {
- TypesDialogTreeObject item = (TypesDialogTreeObject) childrenIt.next();
- Boolean expand = (Boolean) expansionStateMap.get(item.getDataObject());
- if (expand == Boolean.TRUE) {
- TreeItem treeItem = getTreeItem(item);
- if (treeItem != null && treeItem.getItemCount() > 0) {
- // Expand the TreeItem by calling showItem() on the first child of TreeItem
- treeViewer.getTree().showItem(treeItem.getItems()[0]);
- }
- }
- }
- }
-
- private Boolean isExpanded(TypesDialogTreeObject item) {
- TreeItem treeItem = getTreeItem(item);
- return Boolean.valueOf(treeItem.getExpanded());
- }
-
- private TreeItem getTreeItem(TreeItem root, TypesDialogTreeObject item) {
- TreeItem treeItem = null;
-
- if (root.getData().equals(item)) {
- treeItem = root;
- }
- else {
- // Check it's children
- TreeItem items[] = root.getItems();
- for (int index = 0; index < items.length; index++) {
- if (items[index].getData() != null) {
- treeItem = getTreeItem(items[index], item);
- if (treeItem != null) {
- break;
- }
- }
- }
- }
-
- return treeItem;
- }
-
- public TreeItem getTreeItem(TypesDialogTreeObject item) {
- boolean found = false;
- TreeItem treeItem = null;
- TreeItem treeItems[] = treeViewer.getTree().getItems();
- for (int index = 0; index < treeItems.length; index++) {
- if (treeItems[index].getData() != null) {
- treeItem = getTreeItem(treeItems[index], item);
- if (treeItem != null) {
- break;
- }
- }
- }
-
- return treeItem;
- }
-
- public TypesDialogTreeObject getSelection() {
- return (TypesDialogTreeObject) ((StructuredSelection) treeViewer.getSelection()).getFirstElement();
- }
-
- public void selectTreeObject(TypesDialogTreeObject selectionObject) {
- if (selectionObject != null) {
- StructuredSelection structuredSelection = new StructuredSelection(selectionObject);
- treeViewer.setSelection(structuredSelection, true);
- }
- }
-
- public void expandAll() {
- treeViewer.expandAll();
- }
-
- public void setRedraw(boolean redraw) {
- treeViewer.getTree().setRedraw(redraw);
- }
-
- /*
- * Select the first TypesDialogTreeObject avaliable (where the TypesDialogTreeObject is not a direct
- * child of the input (rootTreeObject). For example, select the first avaliable
- * Complex or Simple type. Not the Headings)
- */
- public void selectFirstItem() {
- Iterator rootChildren = rootTreeObject.getChildren().iterator();
- while (rootChildren.hasNext()) {
- TypesDialogTreeObject rootChild = (TypesDialogTreeObject) rootChildren.next();
- if (rootChild.getChildren().size() > 0) {
- selectTreeObject((TypesDialogTreeObject) rootChild.getChildren().get(0));
- break;
- }
- }
- }
-
- public void addTreeSelectionChangedListener(ISelectionChangedListener listener) {
- treeViewer.addSelectionChangedListener(listener);
- }
-
-/////////////////////////////////////////////////////////////////////////
- /*
- * TreeContentProvider for TypesDialogTreeObject.java
- */
- private class TreeObjectContentProvider implements ITreeContentProvider {
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- public Object[] getElements(Object inputElement) {
- if (inputElement instanceof TypesDialogTreeObject) {
- return ((TypesDialogTreeObject) inputElement).getChildren().toArray();
- }
- return (new ArrayList()).toArray();
- }
-
- public void dispose() {
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof TypesDialogTreeObject) {
- return ((TypesDialogTreeObject) parentElement).getChildren().toArray();
- }
- return (new ArrayList()).toArray();
- }
-
- public Object getParent(Object element) {
- if (element instanceof TypesDialogTreeObject) {
- return ((TypesDialogTreeObject) element).getParent();
- }
- return null;
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof TypesDialogTreeObject) {
- if (((TypesDialogTreeObject) element).getChildren().size() > 0) {
- return true;
- }
- }
- return false;
- }
- }
-
- /*
- * TreeLabelProvider for TypesDialogTreeObject.java
- */
- private class TreeObjectLabelProvider extends LabelProvider {
- public Image getImage(Object element) {
- if (element instanceof TypesDialogTreeObject) {
- return ((TypesDialogTreeObject) element).getImage();
- }
-
- return null;
- }
-
- public String getText(Object element) {
- if (element instanceof TypesDialogTreeObject) {
- return ((TypesDialogTreeObject) element).getEntireLabel();
- }
- return null;
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/TypesDialogTreeObject.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/TypesDialogTreeObject.java
deleted file mode 100644
index 2e70e64..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/TypesDialogTreeObject.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDSchema;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-
-public class TypesDialogTreeObject {
- private Object dataObject;
- private TypesDialogTreeObject parent;
- private ArrayList children;
- private String label;
- private String appendLabel = "";
- private int type;
-
- // Used to determine the type of object we're dealing with.
- // If dataObject is String, we need more info.... so we look at the type (below).
- public final static int UNKNOWN_TYPE = 0;
- public final static int BUILT_IN_TYPE = 1;
- public final static int INLINE_SCHEMA = 2;
- public final static int ANONYMOUS_COMPLEX_TYPE = 3;
- public final static int ANONYMOUS_SIMPLE_TYPE = 4;
-
- public TypesDialogTreeObject(Object dataObject) {
- this.dataObject = dataObject;
- children = new ArrayList();
- type = TypesDialogTreeObject.UNKNOWN_TYPE;
- }
-
- public TypesDialogTreeObject(Object dataObject, int type) {
- this(dataObject);
- this.type = type;
- }
-
- public void addChild(TypesDialogTreeObject child) {
- children.add(child);
- child.setParent(this);
- }
-
- public void addAll(List kids) {
- Iterator it = kids.iterator();
- while (it.hasNext()) {
- Object item = it.next();
- if (item instanceof TypesDialogTreeObject) {
- addChild((TypesDialogTreeObject) item);
- }
- }
- }
-
- public List getChildren() {
- return children;
- }
-
- public TypesDialogTreeObject getParent() {
- return parent;
- }
-
- public void setParent(TypesDialogTreeObject newParent) {
- parent = newParent;
- }
-
- /*
- * We should move getImage() and computeDefaultLabel() code out of TypesDialogTreeObject to make
- * it more generic...... but since this class was created specifically for the TypesDialog we'll
- * leave it here.
- */
- private void computeDefaultLabel() {
- if (dataObject instanceof XSDSchema) {
- XSDSchema schema = (XSDSchema) dataObject;
- URI schemaURI = URI.createURI(schema.getSchemaLocation());
- label = schemaURI.lastSegment();
- }
- else if (dataObject instanceof XSDComplexTypeDefinition) {
- label = ((XSDComplexTypeDefinition) dataObject).getName();
- }
- else if (dataObject instanceof XSDSimpleTypeDefinition) {
- label = ((XSDSimpleTypeDefinition) dataObject).getName();
- }
- else if (dataObject instanceof String) {
- label = (String) dataObject;
- }
- else {
- label = "";
- }
- }
-
- public void setLabel(String newLabel) {
- label = newLabel;
- }
-
- public String getLabel() {
- if (label == null) {
- computeDefaultLabel();
- }
- return label;
- }
-
- public void setAppendLabel(String newLabel) {
- appendLabel = newLabel;
- }
-
- public String getAppendLabel() {
- return appendLabel;
- }
-
- public String getEntireLabel() {
- return getLabel() + getAppendLabel();
- }
-
- /*
- * We should move getImage() and computeDefaultLabel() code out of TypesDialogTreeObject to make
- * it more generic...... but since this class was created specifically for the TypesDialog we'll
- * leave it here.
- */
- public Image getImage() {
- if (dataObject instanceof XSDSchema) {
- return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif");
- }
- else if (dataObject instanceof XSDComplexTypeDefinition) {
- return XSDEditorPlugin.getXSDImage("icons/XSDComplexType.gif");
- }
- else if (dataObject instanceof XSDSimpleTypeDefinition) {
- return XSDEditorPlugin.getPlugin().getIconImage("obj16/smpl_restrict_obj");
- }
- else if (dataObject instanceof XSDElementDeclaration) {
- return XSDEditorPlugin.getXSDImage("icons/XSDElement.gif");
- }
- else if (dataObject instanceof String && getType() == TypesDialogTreeObject.BUILT_IN_TYPE) {
- return XSDEditorPlugin.getPlugin().getIconImage("obj16/smpl_restrict_obj");
- }
- else if (dataObject instanceof String && getType() == TypesDialogTreeObject.ANONYMOUS_COMPLEX_TYPE) {
- return XSDEditorPlugin.getXSDImage("icons/XSDComplexType.gif");
- }
- else if (dataObject instanceof String && getType() == TypesDialogTreeObject.ANONYMOUS_SIMPLE_TYPE) {
- return XSDEditorPlugin.getPlugin().getIconImage("obj16/smpl_restrict_obj");
- }
-
- else {
- return XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif");
- }
- }
-
- public Object getDataObject() {
- return dataObject;
- }
-
- public void setType(int type) {
- this.type = type;
- }
-
- public int getType() {
- return type;
- }
-
- /*
- * Search for the first match of the given fileName with the return value of
- * TypesDialogTreeObject.getLabel(). This method will search the children of
- * the given TypesDialogTreeObject. It will not search recursively.
- */
- public static TypesDialogTreeObject getTreeObject(TypesDialogTreeObject rootObject, String fileName) {
- Iterator rootChildrenIt = rootObject.getChildren().iterator();
- TypesDialogTreeObject rootChild = null;
- boolean found = false;
-
- while (rootChildrenIt.hasNext()) {
- rootChild = (TypesDialogTreeObject) rootChildrenIt.next();
- if (rootChild.getLabel().equals(fileName)) {
- found = true;
- break;
- }
- }
-
- if (found) {
- return rootChild;
- }
- else {
- return null;
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/XSDSetTypeDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/XSDSetTypeDialog.java
deleted file mode 100644
index bbbb64e..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/XSDSetTypeDialog.java
+++ /dev/null
@@ -1,679 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.types;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.wst.xml.uriresolver.util.URIHelper;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-import org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction;
-import org.eclipse.wst.xsd.ui.internal.actions.CreateSimpleTypeAction;
-import org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute;
-import org.eclipse.wst.xsd.ui.internal.refactor.delete.XSDExternalFileCleanup;
-import org.eclipse.wst.xsd.ui.internal.util.TypesHelper;
-import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDImport;
-import org.eclipse.xsd.XSDInclude;
-import org.eclipse.xsd.XSDNamedComponent;
-import org.eclipse.xsd.XSDRedefine;
-import org.eclipse.xsd.XSDSchema;
-import org.eclipse.xsd.XSDSchemaContent;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-import org.eclipse.xsd.impl.XSDImportImpl;
-import org.eclipse.xsd.util.XSDConstants;
-import org.eclipse.xsd.util.XSDParser;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class XSDSetTypeDialog extends SetTypeDialog {
- private boolean showAnonymous = true;
- boolean showComplexTypes = true;
- private XSDSchema xsdSchema;
-
- /*
- * input should be of type Element..... For example, if our current selection is a GlobalElement, input should
- * be the Element of the GlobalElement
- */
- public XSDSetTypeDialog(Shell shell, Element input, String dialogTitle, XSDSchema xsdSchema) {
- super(shell, input, dialogTitle, "type");
- this.xsdSchema = xsdSchema;
- }
-
- protected void createTreeView(TypesDialogTreeObject root, String filterString) {
- TypesDialogTreeObject builtInRoot = new TypesDialogTreeObject("Built-in simple type");
- root.addChild(builtInRoot);
- createBuiltInTypes(builtInRoot, filterString);
-
- TypesDialogTreeObject typesRoot = new TypesDialogTreeObject("Types");
- root.addChild(typesRoot);
- createComplexTypes(typesRoot, filterString);
- createSimpleTypes(typesRoot, filterString);
- createFromImport(root, filterString, false);
- createFromInclude(root, filterString, false);
- createFromRedefine(root, filterString, false);
- }
-
- protected void createFlatView(TypesDialogTreeObject root, String filterString) {
- createComplexTypes(treeRootViewerInput, filterString);
- createSimpleTypes(treeRootViewerInput, filterString);
- createFromImport(root, filterString, true);
- createFromInclude(root, filterString, true);
- createFromRedefine(root, filterString, true);
- createBuiltInTypes(treeRootViewerInput, filterString);
- }
-
- public void createBuiltInTypes(TypesDialogTreeObject root, String filterString) {
- Iterator iterator = getBuiltInTypes().iterator();
- Pattern regex = Pattern.compile(filterString);
- if (iterator.hasNext()) {
- while (iterator.hasNext()) {
- Object item = iterator.next();
- String itemString = item.toString();
- Matcher m = regex.matcher(itemString.toLowerCase());
- if (itemString.toLowerCase().startsWith(filterString) || m.matches()) {
- TypesDialogTreeObject treeObject = new TypesDialogTreeObject(item, TypesDialogTreeObject.BUILT_IN_TYPE);
- root.addChild(treeObject);
- }
- }
- }
- }
-
- public void createComplexTypes(TypesDialogTreeObject root, String filterString) {
- TypesHelper typesHelper = new TypesHelper(xsdSchema);
- filterString = filterString.toLowerCase();
- Pattern regex = java.util.regex.Pattern.compile(filterString);
-
- // Add anonymous
- addAnonymousType(root, regex, filterString);
-
- List complexTypes = typesHelper.getUserComplexTypes();
- createComplexSimpleTreeObject(root, complexTypes, filterString, true);
- }
-
- public void createSimpleTypes(TypesDialogTreeObject root, String filterString) {
- TypesHelper typesHelper = new TypesHelper(xsdSchema);
- filterString = filterString.toLowerCase();
- Pattern regex = java.util.regex.Pattern.compile(filterString);
-
- // Add anonymous
- addAnonymousType(root, regex, filterString);
-
- // Add anyType
- Matcher m = regex.matcher("anyType");
- if ("anyType".startsWith(filterString) || m.matches()) {
- TypesDialogTreeObject simpleTreeObject = new TypesDialogTreeObject("anyType");
- root.addChild(simpleTreeObject);
- simpleTreeObject.setLabel(typesHelper.getPrefix(xsdSchema.getSchemaForSchemaNamespace(), true) + "anyType");
- }
-
- List simpleTypes = typesHelper.getUserSimpleTypes();
- createComplexSimpleTreeObject(root, simpleTypes, filterString, true);
- }
-
- private void addAnonymousType(TypesDialogTreeObject root, Pattern regex, String filterString) {
- if (showAnonymous)
- {
- Matcher m = regex.matcher("**anonymous**");
- if ("**anonymous**".startsWith(filterString) || m.matches()) {
- TypesDialogTreeObject simpleTreeObject = new TypesDialogTreeObject("**anonymous**");
- simpleTreeObject.setType(TypesDialogTreeObject.ANONYMOUS_SIMPLE_TYPE);
- root.addChild(simpleTreeObject);
- }
- }
- }
-
- private void createFromImport(TypesDialogTreeObject root, String filterString, boolean isFlatView) {
- Iterator imports = getXSDImports().iterator();
- while (imports.hasNext()) {
- XSDImport importItem = (XSDImport) imports.next();
- if (importItem.getSchemaLocation() != null) {
- ((XSDImportImpl) importItem).importSchema();
- TypesHelper helper = new TypesHelper(importItem.getResolvedSchema());
-
- TypesDialogTreeObject importRoot = root;
- if (!isFlatView) {
- // Create the TypesDialogTreeObject
- importRoot = new TypesDialogTreeObject(importItem.getResolvedSchema());
- root.addChild(importRoot);
- importRoot.setAppendLabel(" (Import)");
- }
-
- List types = helper.getUserComplexTypes();
- types.addAll(helper.getUserSimpleTypes());
- createComplexSimpleTreeObject(importRoot, types, filterString, false);
- }
- }
- }
-
- private void createFromInclude(TypesDialogTreeObject root, String filterString, boolean isFlatView) {
- Iterator imports = getXSDIncludes().iterator();
- while (imports.hasNext()) {
- XSDInclude includeItem = (XSDInclude) imports.next();
- if (includeItem.getSchemaLocation() != null) {
- TypesHelper helper = new TypesHelper(includeItem.getResolvedSchema());
-
- TypesDialogTreeObject includeRoot = root;
- if (!isFlatView) {
- // Create the TypesDialogTreeObject
- includeRoot = new TypesDialogTreeObject(includeItem.getResolvedSchema());
- root.addChild(includeRoot);
- includeRoot.setAppendLabel(" (Include)");
- }
-
- List types = helper.getUserComplexTypes();
- types.addAll(helper.getUserSimpleTypes());
- createComplexSimpleTreeObject(includeRoot, types, filterString, false);
- }
- }
- }
-
- private void createFromRedefine(TypesDialogTreeObject root, String filterString, boolean isFlatView) {
- Iterator redefines = getXSDRedefines().iterator();
- while (redefines.hasNext()) {
- XSDRedefine redefineItem = (XSDRedefine) redefines.next();
- if (redefineItem.getSchemaLocation() != null) {
- TypesHelper helper = new TypesHelper(redefineItem.getResolvedSchema());
-
- TypesDialogTreeObject includeRoot = root;
- if (!isFlatView) {
- // Create the TypesDialogTreeObject
- includeRoot = new TypesDialogTreeObject(redefineItem.getResolvedSchema());
- root.addChild(includeRoot);
- includeRoot.setAppendLabel(" (Redefine)");
- }
-
- List types = helper.getUserComplexTypes();
- types.addAll(helper.getUserSimpleTypes());
- createComplexSimpleTreeObject(includeRoot, types, filterString, false);
- }
- }
- }
-
- private void createComplexSimpleTreeObject(TypesDialogTreeObject root, List complexTypes, String filterString, boolean sameNS) {
- Pattern regex = java.util.regex.Pattern.compile(filterString);
- boolean proceed = true;
-
- for (int i = 0; i < complexTypes.size(); i++) {
- XSDNamedComponent item = (XSDNamedComponent) complexTypes.get(i);
-
- if (sameNS) {
- // We do this check because Types from Includes might show up. However, we don't want to show them
- String itemLocation = item.getSchema().getSchemaLocation();
- String currentSchemaLocation = xsdSchema.getSchemaLocation();
- if (itemLocation != null) {
- proceed = itemLocation.equals(currentSchemaLocation);
- }
- else {
- proceed = false;
- }
- }
-
- if (proceed) {
- String itemString = item.getName();
- Matcher m = regex.matcher(itemString.toLowerCase());
-
- if (itemString.toLowerCase().startsWith(filterString) || m.matches()) {
- TypesDialogTreeObject treeObject = new TypesDialogTreeObject(item);
- root.addChild(treeObject);
- treeObject.setLabel(itemString);
- }
- }
- }
- }
-
- private List getXSDImports() {
- List imports = new ArrayList();
-
- Iterator contents = xsdSchema.getContents().iterator();
- while (contents.hasNext()) {
- XSDSchemaContent content = (XSDSchemaContent) contents.next();
- if (content instanceof XSDImport) {
- imports.add(content);
- }
- }
-
- return imports;
- }
-
- private List getXSDIncludes() {
- List includes = new ArrayList();
-
- Iterator contents = xsdSchema.getContents().iterator();
- while (contents.hasNext()) {
- XSDSchemaContent content = (XSDSchemaContent) contents.next();
- if (content instanceof XSDInclude) {
- includes.add(content);
- }
- }
-
- return includes;
- }
-
- private List getXSDRedefines() {
- List includes = new ArrayList();
-
- Iterator contents = xsdSchema.getContents().iterator();
- while (contents.hasNext()) {
- XSDSchemaContent content = (XSDSchemaContent) contents.next();
- if (content instanceof XSDRedefine) {
- includes.add(content);
- }
- }
-
- return includes;
- }
-
- public java.util.List getBuiltInTypes() {
- TypesHelper helper = new TypesHelper(xsdSchema);
- return helper.getBuiltInTypeNamesList();
- }
-
- private String getUniqueName(String baseName, List usedNames) {
- String uniqueName = baseName;
- int number = 1;
- boolean foundMatch = true;
-
- while (foundMatch) {
- foundMatch = false;
- Iterator names = usedNames.iterator();
- while (names.hasNext()) {
- String name = (String) names.next();
-
- if (uniqueName.equalsIgnoreCase(name)) {
- foundMatch = true;
- uniqueName = baseName + String.valueOf(number++);
- break;
- }
- }
- }
-
- return uniqueName;
- }
-
- protected void createButtonPressed() {
- List usedComplexNames = getUsedComplexTypeNames(xsdSchema);
- List usedSimpleNames = getUsedSimpleTypeNames(xsdSchema);
- String newItemName = getUniqueName("NewComplexType", usedComplexNames);
-
- NewTypeDialog dialog = new NewTypeDialog(XSDEditorPlugin.getShell(), newItemName, usedComplexNames);
- dialog.setUsedSimpleTypeNames(usedSimpleNames);
-
- int rc = dialog.createAndOpen();
- if (rc == IDialogConstants.OK_ID) {
- newItemName = dialog.getName();
- ArrayList attributes = new ArrayList();
- attributes.add(new DOMAttribute(XSDConstants.NAME_ATTRIBUTE, newItemName));
-
- if (dialog.isComplexType()) {
- CreateElementAction action = new CreateElementAction(XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_COMPLEX_TYPE"));
- action.setElementTag(XSDConstants.COMPLEXTYPE_ELEMENT_TAG);
- action.setAttributes(attributes);
- action.setParentNode(xsdSchema.getElement());
- action.setXSDSchema(xsdSchema);
- action.run();
- }
- else {
- CreateSimpleTypeAction action = new CreateSimpleTypeAction(XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_COMPLEX_TYPE"));
- action.setElementTag(XSDConstants.SIMPLETYPE_ELEMENT_TAG);
- action.setAttributes(attributes);
- action.setParentNode(xsdSchema.getElement());
- action.setXSDSchema(xsdSchema);
- action.run();
- }
-
- // Update tree view
- if (viewTypeCheckBox.getSelection()) {
- populateTreeViewer(viewTypeCheckBox.getSelection(), textFilter.getText(), false, false);
- treeView.selectTreeObject(TypesDialogTreeObject.getTreeObject(treeRootViewerInput, newItemName));
- }
- else {
- populateTreeViewer(viewTypeCheckBox.getSelection(), textFilter.getText(), true, true);
-
- TypesDialogTreeObject parentTreeObject = TypesDialogTreeObject.getTreeObject(treeRootViewerInput, "Types");
- treeView.selectTreeObject(TypesDialogTreeObject.getTreeObject(parentTreeObject, newItemName));
- }
- }
- }
-
- protected void importButtonPressed() {
- ImportTypesDialog dialog = new ImportTypesDialog(XSDEditorPlugin.getShell(), null, false, kind);
- String [] filters = { "xsd" };
-// IFile currentWFile = ((IFileEditorInput)editorPart.getEditorInput()).getFile();
-// IFile [] excludedFiles = { currentFile };
- IFile[] excludedFiles = new IFile[0];
-
- dialog.addFilterExtensions(filters, excludedFiles);
- dialog.create();
-
- // Translate strings below
- dialog.getShell().setText("Select");
- dialog.setTitle("Select File");
- dialog.setMessage("Select a XSD file to import");
-
- int rc = dialog.open();
- if (rc == IDialogConstants.OK_ID) {
- XSDNamedComponent selection = (XSDNamedComponent) dialog.getListSelection();
- IFile importFile = dialog.getFile();
- XSDSchema externalSchema = doLoadExternalModel(importFile);
-
- // Compare namespaces to determine if we should treat this as an Import or Include
- boolean isInclude = false;
- String externalNamespace = externalSchema.getTargetNamespace();
- if (externalNamespace.equalsIgnoreCase(xsdSchema.getTargetNamespace())) {
- isInclude = true;
- }
-
- // Determine schemaLocation
- IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile();
- String locationAttribute = URIHelper.getRelativeURI(importFile.getLocation(), currentIFile.getLocation());
-
- if (externalSchema != null) { // In case we have problems loading the file.... we should display an error message.
- Element newElement;
- if (isInclude) {
- List attributes = new ArrayList();
- attributes.add(new DOMAttribute(XSDConstants.SCHEMALOCATION_ATTRIBUTE, locationAttribute));
- newElement = createElement(XSDConstants.INCLUDE_ELEMENT_TAG, attributes);
- }
- else if (!isInclude) {
- List attributes = new ArrayList();
- attributes.add(new DOMAttribute(XSDConstants.NAMESPACE_ATTRIBUTE, externalNamespace));
- attributes.add(new DOMAttribute(XSDConstants.SCHEMALOCATION_ATTRIBUTE, locationAttribute));
- newElement = createElement(XSDConstants.IMPORT_ELEMENT_TAG, attributes);
- handleImportNS(newElement, externalSchema);
- }
- }
-
- // We need to refresh our tree view
- if (viewTypeCheckBox.getSelection()) {
- populateTreeViewer(viewTypeCheckBox.getSelection(), textFilter.getText(), false, false);
- treeView.selectTreeObject(TypesDialogTreeObject.getTreeObject(treeRootViewerInput, selection.getName()));
- }
- else {
- populateTreeViewer(viewTypeCheckBox.getSelection(), textFilter.getText(), true, true);
-
- // We now want to expand the newly imported file and selected the proper type/element
- TypesDialogTreeObject parentTreeObject = TypesDialogTreeObject.getTreeObject(treeRootViewerInput, dialog.getFile().getName());
- treeView.selectTreeObject(TypesDialogTreeObject.getTreeObject(parentTreeObject, selection.getName()));
- }
-
- }
- }
-
- private Element createElement(String elementTag, List attributes) {
- Node relativeNode = XSDDOMHelper.getNextElementNode(xsdSchema.getElement().getFirstChild());
-
- CreateElementAction action = new CreateElementAction("");
- action.setElementTag(elementTag);
- action.setAttributes(attributes);
- action.setParentNode(xsdSchema.getElement());
- action.setRelativeNode(relativeNode);
- action.setXSDSchema(xsdSchema);
- return action.createAndAddNewChildElement();
- }
-
- private IEditorPart getActiveEditor()
- {
- IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
- IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
- IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
-
- return editorPart;
- }
-
- /**
- * Create a MOF model for the imported file
- */
- protected XSDSchema doLoadExternalModel(IFile iFile)
- {
- String xsdModelFile = iFile.getLocation().toOSString();
- String xsdFileName = iFile.getName();
- IProgressMonitor monitor = new NullProgressMonitor();
- String errorMessage = null;
- String currentNameSpace = xsdSchema.getTargetNamespace();
-
- monitor.beginTask("Loading XML Schema", 100);
- monitor.worked(50);
-
- XSDParser parser = new XSDParser();
- parser.parse(xsdModelFile);
-
- XSDSchema externalSchema = parser.getSchema();
- if (externalSchema != null)
- {
- if (externalSchema.getDiagnostics() != null &&
- externalSchema.getDiagnostics().size() > 0)
- {
- errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_INCORRECT_XML_SCHEMA", xsdFileName);
- }
- }
- else
- {
- errorMessage = XSDEditorPlugin.getPlugin().getString("_UI_INCORRECT_XML_SCHEMA", xsdFileName);
- }
- if (errorMessage != null) {
-// System.out.println("\nError loading XML Schema:\n" + errorMessage);
- }
-
- monitor.subTask("Finish Loading");
- monitor.worked(80);
-
- return externalSchema;
- }
-
- private void handleImportNS(Element importElement, XSDSchema externalSchema) {
- String namespace = externalSchema.getTargetNamespace();
- if (namespace == null) namespace = "";
-
- XSDImport xsdImport = (XSDImport) xsdSchema.getCorrespondingComponent(importElement);
- xsdImport.setResolvedSchema(externalSchema);
-
- java.util.Map map = xsdSchema.getQNamePrefixToNamespaceMap();
-
-// System.out.println("changed Import Map is " + map.values());
-// System.out.println("changed import Map keys are " + map.keySet());
-
- // Referential integrity on old import
- // How can we be sure that if the newlocation is the same as the oldlocation
- // the file hasn't changed
-
- XSDSchema referencedSchema = xsdImport.getResolvedSchema();
- if (referencedSchema != null)
- {
- XSDExternalFileCleanup cleanHelper = new XSDExternalFileCleanup(referencedSchema);
- cleanHelper.visitSchema(xsdSchema);
- }
-
- Element schemaElement = xsdSchema.getElement();
-
- // update the xmlns in the schema element first, and then update the import element next
- // so that the last change will be in the import element. This keeps the selection
- // on the import element
- TypesHelper helper = new TypesHelper(externalSchema);
- String prefix = helper.getPrefix(namespace, false);
-
- if (map.containsKey(prefix))
- {
- prefix = null;
- }
-
- if (prefix == null || (prefix !=null && prefix.length() == 0))
- {
- StringBuffer newPrefix = new StringBuffer("pref"); //$NON-NLS-1$
- int prefixExtension = 1;
- while (map.containsKey(newPrefix.toString()) && prefixExtension < 100)
- {
- newPrefix = new StringBuffer("pref" + String.valueOf(prefixExtension));
- prefixExtension++;
- }
- prefix = newPrefix.toString();
- }
-
- if (namespace.length() > 0)
- {
- // if ns already in map, use its corresponding prefix
- if (map.containsValue(namespace))
- {
- TypesHelper typesHelper = new TypesHelper(xsdSchema);
- prefix = typesHelper.getPrefix(namespace, false);
- }
- else // otherwise add to the map
- {
- schemaElement.setAttribute("xmlns:"+prefix, namespace);
- }
- }
-
-
-// System.out.println("changed Import Map is " + map.values());
-// System.out.println("changed import Map keys are " + map.keySet());
- }
-
- protected void updateCanFinish(Object object) {
- if (object instanceof StructuredSelection) {
- Object selectionObject = ((StructuredSelection) object).getFirstElement();
- if (selectionObject instanceof TypesDialogTreeObject) {
- TypesDialogTreeObject treeObject = (TypesDialogTreeObject) selectionObject;
- if (treeObject.getDataObject() instanceof XSDComplexTypeDefinition ||
- treeObject.getDataObject() instanceof XSDSimpleTypeDefinition ||
- (treeObject.getDataObject() instanceof String && treeObject.getDataObject().toString().equals("anyType")) ||
- (treeObject.getDataObject() instanceof String && treeObject.getDataObject().toString().equals("**anonymous**") ||
- (treeObject.getDataObject() instanceof String && treeObject.getType() == TypesDialogTreeObject.BUILT_IN_TYPE))) {
-
- getButton(IDialogConstants.OK_ID).setEnabled(true);
- }
- else {
- getButton(IDialogConstants.OK_ID).setEnabled(false);
- }
- }
- else {
- getButton(IDialogConstants.OK_ID).setEnabled(false);
- }
- }
- }
-
- protected void okPressed() {
- Element element = (Element) input;
- String typeObject = "";
- TypesDialogTreeObject treeObject = (TypesDialogTreeObject) treeView.getSelection();
-
- // Get the new type --> typeObject
- if (treeObject.getDataObject() instanceof String) {
- // Should be a built-in type or anonymous or anyType
- typeObject = (String) treeObject.getDataObject();
- }
- else {
- XSDNamedComponent item = (XSDNamedComponent) treeObject.getDataObject();
- typeObject = item.getName();
-
- TypesHelper typesHelper = new TypesHelper(item.getSchema());
- List prefixedNames = typesHelper.getPrefixedNames(item.getTargetNamespace(), item.getName());
- if (prefixedNames.size() > 0) {
- // Grab the first prefixed name
- typeObject = (String) prefixedNames.get(0);
- }
- }
-
- // Get the previous type --> previousStringType
- String previousStringType = "";
- Attr attr = element.getAttributeNode("type");
- if (attr != null) {
- String value = attr.getValue();
- }
-
- if (!XSDDOMHelper.inputEquals(element, XSDConstants.UNION_ELEMENT_TAG, false))
- {
- if (typeObject.equals("**anonymous**"))
- {
- if (treeObject.getType() == TypesDialogTreeObject.ANONYMOUS_SIMPLE_TYPE)
- {
- if (!previousStringType.equals("**anonymous**"))
- {
- updateElementToAnonymous(element, XSDConstants.SIMPLETYPE_ELEMENT_TAG);
- }
- }
- else
- {
- if (!previousStringType.equals("**anonymous**"))
- {
- updateElementToAnonymous(element, XSDConstants.COMPLEXTYPE_ELEMENT_TAG);
- }
- }
- // element.removeAttribute(XSDConstants.TYPE_ATTRIBUTE);
- element.removeAttribute("type");
- }
- else
- {
- XSDDOMHelper.updateElementToNotAnonymous(element);
- //element.setAttribute(XSDConstants.TYPE_ATTRIBUTE, typeObject.toString());
- element.setAttribute("type", typeObject.toString());
- }
- }
-
- super.okPressed();
- }
-
- private void updateElementToAnonymous(Element element, String xsdType) {
- String prefix = element.getPrefix();
- prefix = (prefix == null) ? "" : (prefix + ":");
- XSDDOMHelper.updateElementToNotAnonymous(element);
- boolean hasChildrenElements = hasElementChildren(element);
- Element childNode = null;
- if (xsdType.equals(XSDConstants.COMPLEXTYPE_ELEMENT_TAG)) {
- childNode = element.getOwnerDocument().createElementNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, prefix + XSDConstants.COMPLEXTYPE_ELEMENT_TAG);
- }
- else if (xsdType.equals(XSDConstants.SIMPLETYPE_ELEMENT_TAG)) {
- childNode = element.getOwnerDocument().createElementNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, prefix + XSDConstants.SIMPLETYPE_ELEMENT_TAG);
- }
-
- if (childNode != null) {
- XSDDOMHelper helper = new XSDDOMHelper();
- Node annotationNode = helper.getChildNode(element, XSDConstants.ANNOTATION_ELEMENT_TAG);
- if (annotationNode == null) {
- Node firstChild = element.getFirstChild();
- element.insertBefore(childNode, firstChild);
- } else {
- Node nextSibling = annotationNode.getNextSibling();
- element.insertBefore(childNode, nextSibling);
- }
- XSDDOMHelper.formatChild(childNode);
- }
- }
-
- private boolean hasElementChildren(Node parentNode) {
- boolean hasChildrenElements = false;
- if (parentNode != null && parentNode.hasChildNodes()) {
- NodeList nodes = parentNode.getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- if (nodes.item(i) instanceof Element) {
- hasChildrenElements = true;
- break;
- }
- }
- }
- return hasChildrenElements;
- }
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/ComponentSelectionDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/ComponentSelectionDialog.java
new file mode 100644
index 0000000..3ac3853
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/ComponentSelectionDialog.java
@@ -0,0 +1,354 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.common;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+public class ComponentSelectionDialog extends Dialog {
+ private String dialogTitle;
+
+ protected IComponentSelectionProvider provider;
+ private List componentTreeViewerInput;
+
+ // widgets
+ protected Composite topComposite;
+ private String filterTextLabel = "";
+ private String componentListLabel = "Components:"; // TODO: Externalize String
+ private Text textFilter;
+ protected TreeViewer componentTreeViewer;
+ private org.eclipse.swt.widgets.List qualifierList;
+
+ protected Object componentSelection;
+ protected Object qualifierTextSelection;
+
+ public ComponentSelectionDialog(Shell shell, String dialogTitle, IComponentSelectionProvider provider) {
+ super(shell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.dialogTitle = dialogTitle;
+ this.provider = provider;
+
+ componentTreeViewerInput = new ArrayList();
+ }
+
+ /*
+ * This method should be called before createDialogArea(Composite)
+ */
+ public void setComponentTreeLabel(String string) {
+ componentListLabel = string;
+ }
+
+ /*
+ * This method should be called before createDialogArea(Composite)
+ */
+ public void setFilterLabel(String string) {
+ filterTextLabel = string;
+ }
+
+ public Control createDialogArea(Composite parent) {
+ getShell().setText(dialogTitle);
+
+ Composite mainComposite = (Composite) super.createDialogArea(parent);
+ GridData gData = (GridData) mainComposite.getLayoutData();
+ gData.heightHint = 500;
+ gData.widthHint = 400;
+
+ // Subclasses may use this Composite to add desired widgets
+ topComposite = new Composite(mainComposite, SWT.NONE);
+ topComposite.setLayoutData(new GridData());
+ topComposite.setLayout(new GridLayout());
+
+ // do we need to introduce a method here to contain this
+ // so we can add different parent other than 'topComposite'
+ Composite filterLabelAndTree = new Composite(mainComposite, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ filterLabelAndTree.setLayoutData(new GridData(GridData.FILL_BOTH));
+ filterLabelAndTree.setLayout(layout);
+
+ // Create Text textFilter
+ Label filterLabel = new Label(filterLabelAndTree, SWT.NONE);
+ filterLabel.setText(filterTextLabel + "(? = any character, * = any string):"); // TODO: Externalize String
+
+ textFilter = new Text(filterLabelAndTree, SWT.SINGLE | SWT.BORDER);
+ textFilter.addModifyListener(new TextFilterModifyAdapter());
+ GridData textFilterData = new GridData();
+ textFilterData.horizontalAlignment = GridData.FILL;
+ textFilterData.grabExcessHorizontalSpace = true;
+ textFilter.setLayoutData(textFilterData);
+
+ // Create Component TreeViewer
+ createComponentTreeViewer(filterLabelAndTree);
+
+ // Create Qualifier List widget
+ Label qualifierLabel = new Label(mainComposite, SWT.NONE);
+ qualifierLabel.setText("Qualifier:"); // TODO: Externalize String
+
+ qualifierList = new org.eclipse.swt.widgets.List(mainComposite, SWT.BORDER | SWT.SINGLE);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.heightHint = 45;
+ qualifierList.setLayoutData(data);
+
+ // Populate the Component TreeViewer via the provider
+ // TODO: Is this the right way to set/get the ContentProvider?
+ componentTreeViewer.setContentProvider(new ComponentTreeContentProvider());
+ componentTreeViewer.setLabelProvider(provider.getLabelProvider());
+ componentTreeViewer.setSorter(new ViewerSorter());
+ populateComponentTreeViewer("");
+
+ return mainComposite;
+ }
+
+ protected TreeViewer createTreeViewer(Composite comp, String title) {
+ Label label = new Label(comp, SWT.NONE);
+ label.setText(title);
+
+ TreeViewer treeViewer = new TreeViewer(new Tree(comp, SWT.SINGLE | SWT.BORDER));
+ Control treeWidget = treeViewer.getTree();
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ treeWidget.setLayoutData(gd);
+
+ return treeViewer;
+ }
+
+ /*
+ * Creates the Component TreeViewer.
+ */
+ private void createComponentTreeViewer(Composite base) {
+ componentTreeViewer = createTreeViewer(base, componentListLabel);
+
+ componentTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) event.getSelection();
+ List qualifiers = provider.getQualifier(structuredSelection.getFirstElement());
+ updateQualifierList(qualifiers);
+ }
+ });
+ }
+
+ private void updateQualifierList(List qualifiers) {
+ qualifierList.removeAll();
+ Iterator it = qualifiers.iterator();
+ while (it.hasNext()) {
+ qualifierList.add(it.next().toString());
+ }
+ }
+
+
+ /*
+ * Returns the processed filter text for the Text field. Inserts a "."
+ * before each supported meta-character.
+ */
+ protected String getProcessedFilterString() {
+ return processFilterString(textFilter.getText());
+ }
+
+ /*
+ * If supported metacharacters are used in the filter string, we need to
+ * insert a "." before each metacharacter.
+ */
+ private String processFilterString(String inputString) {
+ if (!(inputString.equals(""))) {
+ inputString = insertString("*", ".", inputString);
+ inputString = insertString("?", ".", inputString);
+ inputString = inputString + ".*";
+ } else {
+ inputString = ".*";
+ }
+
+ return inputString.toLowerCase();
+ }
+
+ /*
+ * Helper method to insert a "." before each metacharacter in the
+ * search/filter string.
+ */
+ private String insertString(String target, String newString, String string) {
+ ArrayList list = new ArrayList();
+ StringBuffer stringBuffer = new StringBuffer(string);
+
+ int index = stringBuffer.indexOf(target);
+ while (index != -1) {
+ stringBuffer = stringBuffer.insert(index, newString);
+ index = stringBuffer.indexOf(target, index + newString.length() + target.length());
+ }
+
+ return stringBuffer.toString();
+ }
+
+ /*
+ * Listens to changes made in the text filter widget
+ */
+ private class TextFilterModifyAdapter implements ModifyListener {
+ public void modifyText(ModifyEvent e) {
+ if (e.widget == textFilter) {
+ if (delayedEvent != null) {
+ delayedEvent.CANCEL = true;
+ }
+
+ delayedEvent = new DelayedEvent();
+ Display.getCurrent().timerExec(400, delayedEvent);
+ }
+ }
+ }
+
+ //TODO... do we really need one instance?
+ private DelayedEvent delayedEvent;
+
+ /*
+ * Update the component TreeViewer when the text filter is modified.
+ * Use a DelayedEvent so we don't update on every keystroke.
+ */
+ private class DelayedEvent implements Runnable {
+ public boolean CANCEL = false;
+
+ public void run() {
+ if (!CANCEL) {
+ populateComponentTreeViewer(getProcessedFilterString());
+
+ // Select first match
+ if (componentTreeViewer.getTree().getItemCount() > 0) {
+ TreeItem item = componentTreeViewer.getTree().getItems()[0];
+ TreeItem items[] = new TreeItem[1];
+ items[0] = item;
+ componentTreeViewer.getTree().setSelection(items);
+ }
+
+ // Update qualifierList
+ IStructuredSelection structuredSelection = (IStructuredSelection) componentTreeViewer.getSelection();
+ List qualifiers = provider.getQualifier(structuredSelection.getFirstElement());
+ updateQualifierList(qualifiers);
+
+ updateCanFinish();
+ }
+ }
+ }
+
+ class ComponentList implements IComponentList
+ {
+
+
+ public void addComponent(Object o) {
+ // TODO Auto-generated method stub
+
+ }
+}
+
+ /*
+ * Populate the Component TreeViewer with items. If a filter text is
+ * available, filter out the items.
+ */
+ protected void populateComponentTreeViewer(String filter) {
+ componentTreeViewerInput.clear();
+ ILabelProvider labelProvider = provider.getLabelProvider();
+
+ // TODO: We need to use getComponents(IComponentList) instead...
+// IComponentList
+ Pattern regex = Pattern.compile(filter);
+ Iterator it = provider.getComponents().iterator();
+ while (it.hasNext()) {
+ Object item = it.next();
+ String itemString = labelProvider.getText(item);
+ Matcher m = regex.matcher(itemString.toLowerCase());
+ if (itemString.toLowerCase().startsWith(filter) || m.matches()) {
+ componentTreeViewerInput.add(item);
+ }
+ }
+
+
+ componentTreeViewer.setInput(componentTreeViewerInput);
+ }
+
+ /*
+ * If there is a selection in the ComponentTreeViewer, enable OK
+ */
+ protected void updateCanFinish() {
+ IStructuredSelection selection = (IStructuredSelection) componentTreeViewer.getSelection();
+ if (selection.getFirstElement() != null) {
+ getButton(IDialogConstants.OK_ID).setEnabled(true);
+ }
+ else {
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ }
+ }
+
+ protected void okPressed() {
+ IStructuredSelection selection = (IStructuredSelection) componentTreeViewer.getSelection();
+ componentSelection = selection.getFirstElement();
+ int qualifierIndex = qualifierList.getSelectionIndex();
+ if (qualifierIndex < 0) {
+ qualifierIndex = 0;
+ }
+ qualifierTextSelection = qualifierList.getItem(qualifierIndex);
+
+ super.okPressed();
+ }
+
+ private class ComponentTreeContentProvider implements ITreeContentProvider {
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof List) {
+ return ((List) parentElement).toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (getChildren(element).length > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentList.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentList.java
new file mode 100644
index 0000000..2ee9a3a
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentList.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.common;
+
+public interface IComponentList {
+ void addComponent(Object o);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentSelectionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentSelectionProvider.java
new file mode 100644
index 0000000..becb45c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentSelectionProvider.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.common;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+
+public interface IComponentSelectionProvider {
+
+ // don't use
+ List getComponents();
+
+ // instead use this one
+ // warning ... this will get called on a non UI thread
+ void getComponents(IComponentList list);
+
+ String getType(Object component);
+ ILabelProvider getLabelProvider();
+ List getQualifier(Object component);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/ResourceView.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/ResourceView.java
new file mode 100644
index 0000000..2a61449
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/ResourceView.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xml;
+
+public class ResourceView {
+/*
+ Label scopeComboLabel = new Label(topComposite, SWT.NONE);
+ scopeComboLabel.setText(searchScopeComboLabel);
+ scopeCombo = new Combo(topComposite, SWT.NONE);
+ initializeSearchScopeCombo();
+
+ sashForm = new SashForm(topComposite, SWT.VERTICAL);
+ GridData sashGD = new GridData(GridData.FILL_BOTH);
+ sashGD.grabExcessHorizontalSpace = true;
+ sashGD.grabExcessVerticalSpace = true;
+ sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
+ sashForm.setLayout(new GridLayout());
+
+ int[] sashFormWeights = new int[2];
+ sashFormWeights[0] = 0;
+ sashFormWeights[1] = 7;
+ sashForm.setWeights(sashFormWeights);
+
+ // Create PageBook for High Level TreeViewer
+ highLevelPageBook = new PageBook(sashForm, SWT.NONE);
+ GridData fileSystemPBData = new GridData();
+ fileSystemPBData.horizontalAlignment = SWT.FILL;
+ highLevelPageBook.setLayoutData(fileSystemPBData);
+
+ blankHighLevelComposite = new Composite(highLevelPageBook, SWT.NONE);
+ highLevelComposite = new Composite(highLevelPageBook, SWT.NONE);
+ GridLayout fileSystemLayout = new GridLayout();
+ fileSystemLayout.marginWidth = 0;
+ highLevelComposite.setLayout(fileSystemLayout);
+ highLevelComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ createHighLevelTreeViewer(highLevelComposite);
+ populateHighLevelTreeViewer();
+
+ highLevelPageBook.showPage(blankHighLevelComposite);
+////////////////////////////////////////////////////////////////////////////// //
+
+ /*
+ * Creates the High Level TreeViewer (Top TreeViewer).
+ *
+ private void createHighLevelTreeViewer(Composite base) {
+ highLevelTreeViewer = createTreeViewer(highLevelComposite, "Resources");
+ initializeHighLevelTreeViewer();
+ String ext[] = new String[1];
+ ext[0] = "xsd";
+ addFilterExtensions(highLevelTreeViewer, ext, new IFile[0]);
+
+ initializeHighLevelTreeViewer();
+ populateHighLevelTreeViewer();
+ }
+
+
+ protected void showHighLevelView(boolean show) {
+ if (show) {
+ int[] sashFormWeights = new int[2];
+ sashFormWeights[0] = 4;
+ sashFormWeights[1] = 5;
+ sashForm.setWeights(sashFormWeights);
+
+ highLevelPageBook.showPage(highLevelComposite);
+ topComposite.layout(true, true);
+
+ showHighLevelView();
+ } else {
+ int[] sashFormWeights = new int[2];
+ sashFormWeights[0] = 0;
+ sashFormWeights[1] = 7;
+ sashForm.setWeights(sashFormWeights);
+
+ highLevelPageBook.showPage(blankHighLevelComposite);
+ topComposite.layout(true, true);
+
+ hideHighLevelView();
+ }
+ }
+
+ protected void setFilter(TreeViewer treeViewer, ViewerFilter filter) {
+ treeViewer.getTree().setRedraw(false);
+ treeViewer.resetFilters();
+ treeViewer.addFilter(filter);
+ treeViewer.getTree().setRedraw(true);
+ treeViewer.getTree().redraw();
+ }
+
+ // ///////////////////////////////////////////////////
+ // This is a convenience method that allows filtering of the given file
+ // exensions. It internally creates a ResourceFilter so that users of this
+ // class don't have to construct one.
+ // If the extensions provided don't have '.', one will be added.
+ protected void addFilterExtensions(TreeViewer treeViewer, String[] filterExtensions, IFile[] excludedFiles) {
+ // First add the '.' to the filterExtensions if they don't already have
+ // one
+ String[] correctedFilterExtensions = new String[filterExtensions.length];
+ for (int i = 0; i < filterExtensions.length; i++) {
+ // If the extension doesn't start with a '.', then add one.
+ if (filterExtensions[i].startsWith(".")) {
+ correctedFilterExtensions[i] = filterExtensions[i];
+ } else {
+ correctedFilterExtensions[i] = "." + filterExtensions[i];
+ }
+ }
+ ViewerFilter filter;
+ if (excludedFiles != null) {
+ filter = new SetTypeResourceFilter(correctedFilterExtensions, excludedFiles, null);
+ } else {
+ filter = new SetTypeResourceFilter(correctedFilterExtensions, null);
+ }
+ setFilter(treeViewer, filter);
+ }
+
+
+
+ * Creates a Generic TreeViewer object with the specified label and sets
+ * it's GridData value.
+
+ protected TreeViewer createTreeViewer(Composite comp, String title) {
+ Label label = new Label(comp, SWT.NONE);
+ label.setText(title);
+
+ TreeViewer treeViewer = new TreeViewer(new Tree(comp, SWT.SINGLE | SWT.BORDER));
+ Control treeWidget = treeViewer.getTree();
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ treeWidget.setLayoutData(gd);
+
+ return treeViewer;
+ }
+*/
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentFinder.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentFinder.java
new file mode 100644
index 0000000..910b851
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentFinder.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xml;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * this thing parsers xml artifacts and picks out the components names
+ *
+ */
+public class XMLComponentFinder {
+ protected IFile currentIFile;
+// protected List validExtensions; // List of extensions as String objects
+// protected List excludeFiles; // List of files (full path) as String objects
+
+
+ /**
+ *
+ */
+ public XMLComponentFinder() {
+// validExtensions = new ArrayList();
+// excludeFiles = new ArrayList();
+ }
+
+ /*
+ * Takes in the IFile we are currently editing.
+ * The currentIFile must be set before the getEnclosingProjectFiles()
+ * method will return correctly.
+ */
+ public void setFile(IFile file) {
+ currentIFile = file;
+ }
+
+/*
+ private String getNormalizedLocation(String location) {
+ try {
+ URL url = new URL(location);
+ URL resolvedURL = Platform.resolve(url);
+ location = resolvedURL.getPath();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return location;
+ }
+ */
+
+
+// /////////////////////////////////////////////////////////////////////////////////
+ /**
+ * Returns a List of absolute file locations. For example
+ * "D:\files\....\file.xsd"
+ */
+ protected void traverseIContainer(IContainer container, List extensions, List excludeFiles, List list) throws Exception {
+ IResource[] children = container.members();
+
+ for (int index = 0; index < children.length; index++) {
+ if (children[index] instanceof IFolder) {
+ traverseIContainer((IFolder) children[index], extensions, excludeFiles, list);
+ } else if (children[index] instanceof IFile) {
+ IFile file = (IFile) children[index];
+ String fileName = file.getLocation().toOSString();
+ String ext = file.getFileExtension();
+ boolean b = true;
+ if (extensions.contains(ext) && !excludeFiles.contains(fileName)) {
+ list.add(file.getLocation());
+ }
+ }
+ }
+ }
+
+
+///////////////////////////////////////////////////////////////////////////////////
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java
new file mode 100644
index 0000000..a59f9b1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xml;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentList;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider;
+
+public class XMLComponentSelectionProvider implements IComponentSelectionProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider#getComponents()
+ */
+ public List getComponents() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider#getComponents(org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentList)
+ */
+ public void getComponents(IComponentList list) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider#getType(java.lang.Object)
+ */
+ public String getType(Object component) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider#getLabelProvider()
+ */
+ public ILabelProvider getLabelProvider() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider#getQualifier(java.lang.Object)
+ */
+ public List getQualifier(Object component) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSpecification.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSpecification.java
new file mode 100644
index 0000000..04c2546
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSpecification.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xml;
+
+import java.util.Hashtable;
+
+/*
+ * Simple class which keeps track of attribute information.
+ * This class is basically a Hashtable with convenience methods.
+ */
+public class XMLComponentSpecification {
+ String tagPath;
+ Hashtable hashtable;
+ String targetNamespace;
+ String fileLocation;
+
+ public XMLComponentSpecification(String path) {
+ this.tagPath = path;
+ hashtable = new Hashtable();
+ }
+
+ public void addAttributeInfo(Object attribute, Object value) {
+ hashtable.put(attribute, value);
+ }
+
+ public Object getAttributeInfo(Object attribute) {
+ return hashtable.get(attribute);
+ }
+
+ public String getTagPath() {
+ return tagPath;
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public void setTargetNamespace(String tns) {
+ targetNamespace = tns;
+ }
+
+ public String getFileLocation() {
+ return fileLocation;
+ }
+
+ public void setFileLocation(String location) {
+ fileLocation = location;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLQuickScan.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLQuickScan.java
new file mode 100644
index 0000000..47d56a1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLQuickScan.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 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.types.xml;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.transform.TransformerFactory;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ */
+public class XMLQuickScan {
+
+ /*
+ * Returns information about matches encountered
+ * based on the criteria provided.
+ */
+ public static List getTagInfo(String fullFilePath, List paths, List attributes) {
+ XSDGlobalElementTypeContentHandler handler = new XSDGlobalElementTypeContentHandler();
+ handler.stringTagPaths = paths;
+ handler.searchAttributes = attributes;
+ handler.fileLocation = fullFilePath;
+
+ ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
+
+ try {
+ IPath path = new Path(fullFilePath);
+ FileInputStream inputStream = new FileInputStream(new File(path.toOSString()));
+
+
+// SAXParser sparser = SAXParserFactory.newInstance().newSAXParser();
+// XMLReader reader = sparser.getXMLReader();
+
+ // Line below is a hack to get XMLReader working
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+
+ XMLReader reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(handler);
+ reader.parse(new InputSource(inputStream));
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(prevClassLoader);
+ }
+ return handler.getSearchAttributeValues();
+ }
+
+ public static class XSDGlobalElementTypeContentHandler extends DefaultHandler {
+ protected List stringTagPaths;
+ protected List searchAttributes;
+ private List matchingTags = new ArrayList();
+ private String targetNamespace = "";
+ private String fileLocation;
+
+ StringBuffer currentPath = new StringBuffer();
+
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ currentPath.append("/" + localName);
+
+ // Search for targetNamespace if we haven't encountered it yet.
+ if (targetNamespace.equals("")) {
+ int nAttributes = attributes.getLength();
+ for (int i = 0; i < nAttributes; i++)
+ {
+ if (attributes.getLocalName(i).equals("targetNamespace"))
+ {
+ targetNamespace = attributes.getValue(i);
+ break;
+ }
+ }
+ }
+
+ // Search for the path
+ for (int index = 0; index < stringTagPaths.size(); index++) {
+ String path = (String) stringTagPaths.get(index);
+ if (currentPath.length() == path.length() && currentPath.toString().equals(path)) {
+ // Found a path match
+ createTagInfo(attributes, (String[]) searchAttributes.get(index));
+ }
+ }
+ }
+
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ int slashIndex = currentPath.lastIndexOf("/");
+ currentPath.delete(slashIndex, currentPath.length());
+ }
+
+ /*
+ * Information about a tag is stored in a TagInfo class.
+ */
+ private void createTagInfo(Attributes attributes, String[] attributesToSearch) {
+ XMLComponentSpecification spec = new XMLComponentSpecification(currentPath.toString());
+
+// tagInfo.addAttributeInfo("name", attributes.getValue("name"));
+ for (int index = 0; index < attributesToSearch.length; index++) {
+ String attrString = (String) attributesToSearch[index];
+ String value = attributes.getValue(attrString);
+ if (value != null) {
+ spec.addAttributeInfo(attrString, value);
+ }
+ }
+ spec.setTargetNamespace(targetNamespace);
+ spec.setFileLocation(fileLocation);
+ matchingTags.add(spec);
+ }
+
+ private int getAttributeNameIndex(String attrName) {
+ for (int index = 0; index < searchAttributes.size(); index++) {
+ if (searchAttributes.get(index).equals(attrName)) {
+ return index;
+ }
+ }
+
+ // Not found. We are not looking for this Attribute Name
+ return -1;
+ }
+
+ public List getSearchAttributeValues() {
+ return matchingTags;
+ }
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentFinder.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentFinder.java
new file mode 100644
index 0000000..2b2ce2d
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentFinder.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xsd;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentFinder;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLQuickScan;
+
+public class XSDComponentFinder extends XMLComponentFinder {
+ public static final int ENCLOSING_PROJECT_SCOPE = 0;
+ public static final int ENTIRE_WORKSPACE_SCOPE = 1;
+
+ private List extensions;
+ private List excludeFiles;
+
+ public XSDComponentFinder() {
+ extensions = new ArrayList();
+ excludeFiles = new ArrayList();
+
+ extensions.add("xsd");
+ }
+
+ public void addValidExtensions(List newExtensions) {
+ extensions.addAll(newExtensions);
+ }
+
+ public void addExcludeFiles(List newExclude) {
+ excludeFiles.addAll(newExclude);
+ }
+
+ public List getWorkbenchResourceComponents(int scope) {
+ List components = new ArrayList();
+ List filePaths = new ArrayList();
+
+ // We don't want to search through the current file we're working on.
+ if (currentIFile != null) {
+ excludeFiles.add(currentIFile.getLocation().toOSString());
+ }
+
+ // Find files matching the search criteria specified in List extensions and
+ // List excludeFiles.
+ switch (scope) {
+ case ENCLOSING_PROJECT_SCOPE:
+ filePaths = getEnclosingProjectFiles();
+ break;
+
+ case ENTIRE_WORKSPACE_SCOPE:
+ filePaths = getWorkspaceFiles();
+ break;
+
+ default:
+
+ break;
+ }
+
+ // Search for the components in each of the files specified in the path.
+ List paths = new ArrayList();
+ paths.add("/schema/complexType");
+ paths.add("/schema/simpleType");
+
+ List attributes = new ArrayList();
+ String[] nameAttr = new String[1];
+ String[] nameAttr2 = new String[1];
+ nameAttr[0] = "name";
+ nameAttr2[0] = "name";
+ attributes.add(nameAttr);
+ attributes.add(nameAttr2);
+
+ Iterator pathsIterator = filePaths.iterator();
+ while (pathsIterator.hasNext()) {
+// String stringPath = ((Path) pathsIterator.next()).toOSString();
+ String stringPath = ((Path) pathsIterator.next()).toString();
+ components.addAll(XMLQuickScan.getTagInfo(stringPath, paths, attributes));
+ }
+
+ return components;
+ }
+
+ /*
+ * Returns a List of absolute file locations. For example
+ * "D:\files\....\file.xsd"
+ */
+ private List getEnclosingProjectFiles() {
+ List files = new ArrayList();
+
+ if (currentIFile != null) {
+ IWorkspaceRoot iwr = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = currentIFile.getProject();
+ try {
+ traverseIContainer(project, extensions, excludeFiles, files);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ return files;
+ }
+
+ private List getWorkspaceFiles() {
+ List files = new ArrayList();
+ IWorkspaceRoot iwr = ResourcesPlugin.getWorkspace().getRoot();
+ IProject[] projects = iwr.getProjects();
+
+ try {
+ for (int index = 0; index < projects.length; index++) {
+ traverseIContainer(projects[index], extensions, excludeFiles, files);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return files;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionDialog.java
new file mode 100644
index 0000000..dfaf18c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionDialog.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xsd;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.ComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSpecification;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider.XMLComponentTreeObject;
+
+public class XSDComponentSelectionDialog extends ComponentSelectionDialog {
+ private CCombo scopeCombo;
+
+ public static final String explicitlyReferencedString = "Explicitly Referenced Files";
+ public static final String enclosingProjectString = "Enclosing Project";
+ public static final String entireWorkspaceString = "Entire Workspace";
+
+ private String searchScopeString = enclosingProjectString;
+ public XSDComponentSelectionDialog(Shell shell, String dialogTitle, IComponentSelectionProvider provider) {
+ super(shell, dialogTitle, provider);
+ }
+
+ public Control createDialogArea(Composite parent) {
+ setFilterLabel("Filter by name "); // TODO: Externalize String
+ setComponentTreeLabel("Matching types:"); // TODO: Externalize String
+ super.createDialogArea(parent);
+
+ // We use the Composite topComposite to create additional widgets
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ topComposite.setLayout(layout);
+
+ Label scopeComboLabel = new Label(topComposite, SWT.NONE);
+ scopeComboLabel.setText("Search Scope:"); // TODO: Externalize String
+ scopeCombo = new CCombo(topComposite, SWT.BORDER);
+ scopeCombo.setBackground(ColorConstants.white);
+ scopeCombo.addSelectionListener(new ScopeComboSelectionListener());
+
+ scopeCombo.add(explicitlyReferencedString);
+ scopeCombo.add(enclosingProjectString);
+ scopeCombo.add(entireWorkspaceString);
+ scopeCombo.setText(enclosingProjectString);
+ scopeCombo.setEditable(false);
+ topComposite.setFocus();
+
+ return parent;
+ }
+
+ /*
+ * Returns the selected search scope.
+ */
+ public String getSearchScope() {
+ return searchScopeString;
+ }
+
+ public XMLComponentSpecification getSelection() {
+ XMLComponentTreeObject treeObject = (XMLComponentTreeObject) componentSelection;
+ List specs = treeObject.getXMLComponentSpecification();
+
+ int matchingIndex = 0;
+ for (int index = 0; index < specs.size(); index++) {
+ XMLComponentSpecification spec = (XMLComponentSpecification) specs.get(index);
+ IPath path = new Path(spec.getFileLocation());
+ String specText = spec.getTargetNamespace() + " - " + path.lastSegment();
+ if (specText.equals(qualifierTextSelection)) {
+ matchingIndex = index;
+ break;
+ }
+ }
+
+ return (XMLComponentSpecification) specs.get(matchingIndex);
+ }
+
+ private class ScopeComboSelectionListener extends SelectionAdapter {
+ public void widgetSelected(SelectionEvent e) {
+ if (e.widget == scopeCombo) {
+ searchScopeString = scopeCombo.getItem(scopeCombo.getSelectionIndex());
+ populateComponentTreeViewer(getProcessedFilterString());
+
+ // Select the first matching component. Though we should be smarter here
+ // and determine if there was a selection before the scope switch (and if
+ // the component is still available.
+ Tree tree = componentTreeViewer.getTree();
+ TreeItem items[] = tree.getItems();
+ if (items.length > 0) {
+ TreeItem select[] = new TreeItem[1];
+ select[0] = items[0];
+ tree.setSelection(select);
+ }
+
+ updateCanFinish();
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionProvider.java
new file mode 100644
index 0000000..895d598
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionProvider.java
@@ -0,0 +1,433 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xsd;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentList;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSpecification;
+import org.eclipse.wst.xsd.ui.internal.util.TypesHelper;
+import org.eclipse.xsd.XSDComplexTypeDefinition;
+import org.eclipse.xsd.XSDImport;
+import org.eclipse.xsd.XSDInclude;
+import org.eclipse.xsd.XSDNamedComponent;
+import org.eclipse.xsd.XSDRedefine;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSchemaContent;
+import org.eclipse.xsd.XSDSimpleTypeDefinition;
+import org.eclipse.xsd.impl.XSDImportImpl;
+
+/*
+ *
+ */
+public class XSDComponentSelectionProvider extends LabelProvider implements IComponentSelectionProvider {
+ private XSDComponentFinder xsdComponentFinder;
+ private XSDComponentSelectionDialog dialog;
+ private XSDSchema schema;
+
+ private boolean showComplexTypes = true;
+
+ /*
+ * Takes in the IFile we are currently editing.
+ */
+ public XSDComponentSelectionProvider(IFile file, XSDSchema schema) {
+ xsdComponentFinder = new XSDComponentFinder();
+ xsdComponentFinder.setFile(file);
+ this.schema = schema;
+ }
+
+ public void setDialog(XSDComponentSelectionDialog dialog) {
+ this.dialog = dialog;
+ }
+
+ public void showComplexTypes(boolean show) {
+ showComplexTypes = show;
+ }
+
+ /*
+ * The return value is a List of XMLComponentTreeObjects.
+ *
+ */
+ public void getComponents(IComponentList list) {
+
+ }
+
+ /*
+ * TODO: Need to revisit how we build up our treeObject list.... how we use
+ * the filterText. And it's somewhat messy, clean this up.
+ */
+ public List getComponents() {
+ List extensions = new ArrayList();
+ extensions.add("xsd");
+
+ String scope = "";
+ if (dialog != null) {
+ scope = dialog.getSearchScope();
+ }
+
+ List comps = new ArrayList();
+ if (scope.equals(XSDComponentSelectionDialog.enclosingProjectString)) {
+ comps = xsdComponentFinder.getWorkbenchResourceComponents(XSDComponentFinder.ENCLOSING_PROJECT_SCOPE);
+ }
+ else if (scope.equals(XSDComponentSelectionDialog.entireWorkspaceString)) {
+ comps = xsdComponentFinder.getWorkbenchResourceComponents(XSDComponentFinder.ENTIRE_WORKSPACE_SCOPE);
+ }
+
+// Group same item types together (simple/complex)
+ List complex = new ArrayList();
+ List simple = new ArrayList();
+ Iterator itemsIterator = comps.iterator();
+ while (itemsIterator.hasNext()) {
+ XMLComponentSpecification tagItem = (XMLComponentSpecification) itemsIterator.next();
+ if (tagItem.getTagPath().equals("/schema/complexType")) {
+ complex.add(tagItem);
+ }
+ else if (tagItem.getTagPath().equals("/schema/simpleType")) {
+ simple.add(tagItem);
+ }
+ }
+
+ Iterator complexIt = complex.iterator();
+ Iterator simpleIt = simple.iterator();
+ List treeObjects = new ArrayList();
+ if (showComplexTypes) {
+ while (complexIt.hasNext()) {
+ XMLComponentSpecification item = (XMLComponentSpecification) complexIt.next();
+ addDataItemToTreeNode(treeObjects, item);
+ }
+ }
+
+ while (simpleIt.hasNext()) {
+ XMLComponentSpecification item = (XMLComponentSpecification) simpleIt.next();
+ addDataItemToTreeNode(treeObjects, item);
+ }
+
+ // Grab Built-In types
+ Iterator builtInIt = getBuiltInTypes().iterator();
+ while (builtInIt.hasNext()) {
+ XMLComponentSpecification tagItem = (XMLComponentSpecification) builtInIt.next();
+ addDataItemToTreeNode(treeObjects, tagItem);
+ }
+
+ // Create current Schema's complex and simple types
+ createComplexTypes(treeObjects);
+ createSimpleTypes(treeObjects);
+
+ // Create from imports, includes, and redefines
+ createFromImport(treeObjects);
+ createFromInclude(treeObjects);
+ createFromRedefine(treeObjects);
+
+ return treeObjects;
+ }
+
+
+ protected void addDataItemToTreeNode(List comps, XMLComponentSpecification dataItem) {
+ boolean foundMatch = false;
+ Iterator it = comps.iterator();
+ XMLComponentTreeObject containingTreeObject = null;
+
+ while (it.hasNext()) {
+ XMLComponentTreeObject treeObject = (XMLComponentTreeObject) it.next();
+ if (treeObject.getName().equals(dataItem.getAttributeInfo("name"))) {
+ // If the existing data item and the new data item have the same names
+ if (treeObject.getXMLComponentSpecification().size() > 0) {
+ String existingPath = ((XMLComponentSpecification) treeObject.getXMLComponentSpecification().get(0)).getTagPath();
+ if (existingPath.equals(dataItem.getTagPath())) {
+ // If they are the same 'type' of items (according to the path value)
+ containingTreeObject = treeObject;
+ foundMatch = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (!foundMatch) {
+ containingTreeObject = new XMLComponentTreeObject(dataItem);
+ comps.add(containingTreeObject);
+ }
+ else {
+ containingTreeObject.addXMLComponentSpecification(dataItem);
+ }
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+ private List getBuiltInTypes() {
+ TypesHelper helper = new TypesHelper(schema);
+ Iterator it = helper.getBuiltInTypeNamesList().iterator();
+
+ List builtInComponentSpecs = new ArrayList();
+ while (it.hasNext()) {
+ Object item = it.next();
+ String itemString = item.toString();
+
+ XMLComponentSpecification builtInTypeItem = new XMLComponentSpecification("BUILT_IN_SIMPLE_TYPE");
+ builtInTypeItem.addAttributeInfo("name", itemString);
+ builtInTypeItem.setTargetNamespace(schema.getTargetNamespace());
+ String normalizedFile = getNormalizedLocation(schema.getSchemaLocation());
+ builtInTypeItem.setFileLocation(normalizedFile);
+
+ builtInComponentSpecs.add(builtInTypeItem);
+ }
+
+ return builtInComponentSpecs;
+ }
+
+ private void createComplexTypes(List treeObjectList) {
+ TypesHelper typesHelper = new TypesHelper(schema);
+ List complexTypes = typesHelper.getUserComplexTypes();
+ createComplexSimpleTreeObject(treeObjectList, complexTypes, true);
+ }
+
+ private void createSimpleTypes(List treeObjectList) {
+ TypesHelper typesHelper = new TypesHelper(schema);
+ List complexTypes = typesHelper.getUserSimpleTypes();
+ createComplexSimpleTreeObject(treeObjectList, complexTypes, true);
+ }
+
+
+ private void createFromImport(List treeObjectList) {
+ Iterator imports = getXSDImports().iterator();
+ while (imports.hasNext()) {
+ XSDImport importItem = (XSDImport) imports.next();
+ if (importItem.getSchemaLocation() != null) {
+ ((XSDImportImpl) importItem).importSchema();
+ TypesHelper helper = new TypesHelper(importItem.getResolvedSchema());
+
+ List types = helper.getUserComplexTypes();
+ types.addAll(helper.getUserSimpleTypes());
+ createComplexSimpleTreeObject(treeObjectList, types, false);
+ }
+ }
+ }
+
+ private void createFromInclude(List treeObjectList) {
+ Iterator imports = getXSDIncludes().iterator();
+ while (imports.hasNext()) {
+ XSDInclude includeItem = (XSDInclude) imports.next();
+ if (includeItem.getSchemaLocation() != null) {
+ TypesHelper helper = new TypesHelper(includeItem.getResolvedSchema());
+
+ List types = helper.getUserComplexTypes();
+ types.addAll(helper.getUserSimpleTypes());
+ createComplexSimpleTreeObject(treeObjectList, types, false);
+ }
+ }
+ }
+
+ private void createFromRedefine(List treeObjectList) {
+ Iterator redefines = getXSDRedefines().iterator();
+ while (redefines.hasNext()) {
+ XSDRedefine redefineItem = (XSDRedefine) redefines.next();
+ if (redefineItem.getSchemaLocation() != null) {
+ TypesHelper helper = new TypesHelper(redefineItem.getResolvedSchema());
+
+ List types = helper.getUserComplexTypes();
+ types.addAll(helper.getUserSimpleTypes());
+ createComplexSimpleTreeObject(treeObjectList, types, false);
+ }
+ }
+ }
+
+ protected List getXSDImports() {
+ List imports = new ArrayList();
+
+ Iterator contents = schema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDImport) {
+ imports.add(content);
+ }
+ }
+
+ return imports;
+ }
+
+ protected List getXSDIncludes() {
+ List includes = new ArrayList();
+
+ Iterator contents = schema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDInclude) {
+ includes.add(content);
+ }
+ }
+
+ return includes;
+ }
+
+ protected List getXSDRedefines() {
+ List includes = new ArrayList();
+
+ Iterator contents = schema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDRedefine) {
+ includes.add(content);
+ }
+ }
+
+ return includes;
+ }
+
+ private void createComplexSimpleTreeObject(List treeObjectList, List complexTypes, boolean sameNS) {
+ boolean proceed = true;
+
+ for (int i = 0; i < complexTypes.size(); i++) {
+ XSDNamedComponent item = (XSDNamedComponent) complexTypes.get(i);
+
+ if (sameNS) {
+ // We do this check because Types from Includes might show up. However, we don't want to show them
+ String itemLocation = item.getSchema().getSchemaLocation();
+ String currentSchemaLocation = schema.getSchemaLocation();
+ if (itemLocation != null) {
+ proceed = itemLocation.equals(currentSchemaLocation);
+ }
+ else {
+ proceed = false;
+ }
+ }
+
+ if (proceed) {
+ XMLComponentSpecification typeItem = null;
+ if (showComplexTypes && item instanceof XSDComplexTypeDefinition) {
+ typeItem = new XMLComponentSpecification("/schema/complexType");
+ typeItem.addAttributeInfo("name", ((XSDComplexTypeDefinition) item).getName());
+ }
+ else if (item instanceof XSDSimpleTypeDefinition) {
+ typeItem = new XMLComponentSpecification("/schema/simpleType");
+ typeItem.addAttributeInfo("name", ((XSDSimpleTypeDefinition) item).getName());
+ }
+
+ if (typeItem != null) {
+ typeItem.setTargetNamespace(item.getTargetNamespace());
+ String normalizedFile = getNormalizedLocation(schema.getSchemaLocation());
+ typeItem.setFileLocation(normalizedFile);
+
+ addDataItemToTreeNode(treeObjectList, typeItem);
+ }
+ }
+ }
+ }
+
+ private String getNormalizedLocation(String location) {
+ try {
+ URL url = new URL(location);
+ URL resolvedURL = Platform.resolve(url);
+ location = resolvedURL.getPath();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return location;
+ }
+
+
+////////////////////////////////////////////////////////////////////////////////
+
+ public ILabelProvider getLabelProvider() {
+ // TODO Auto-generated method stub
+ return this;
+ }
+
+ public Image getImage(Object element) {
+ XMLComponentTreeObject specification = (XMLComponentTreeObject) element;
+ XMLComponentSpecification spec = (XMLComponentSpecification) specification.getXMLComponentSpecification().get(0);
+ if (spec.getTagPath().equals("/schema/complexType")) {
+ return XSDEditorPlugin.getXSDImage("icons/XSDComplexType.gif");
+ }
+ else if (spec.getTagPath().equals("/schema/simpleType")) {
+ return XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif");
+ }
+ else if (spec.getTagPath().equals("BUILT_IN_SIMPLE_TYPE")) {
+ return XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif");
+ }
+
+ return null;
+ }
+
+ public String getText(Object element) {
+ XMLComponentTreeObject specification = (XMLComponentTreeObject) element;
+ return specification.getName();
+ }
+
+ public List getQualifier(Object component) {
+ List qualifiers = new ArrayList();
+ if (component != null) {
+ XMLComponentTreeObject specification = (XMLComponentTreeObject) component;
+ Iterator it = specification.getXMLComponentSpecification().iterator();
+ while (it.hasNext()) {
+ XMLComponentSpecification spec = (XMLComponentSpecification) it.next();
+ IPath path = new Path(spec.getFileLocation());
+ qualifiers.add(spec.getTargetNamespace() + " - " + path.lastSegment());
+ }
+ }
+
+ return qualifiers;
+ }
+
+ public String getType(Object component) {
+ XMLComponentTreeObject specification = (XMLComponentTreeObject) component;
+// return specification.kind;
+ return "";
+ }
+
+ private String processSeparators(String location) {
+ String processedString = location;
+
+
+
+ return processedString;
+ }
+
+ /*
+ * Object used to hold components with the same name but different qualifiers.
+ * This object will contain a list of XMLComponentSpecifications (with the same
+ * names but different qualifiers).
+ */
+ public class XMLComponentTreeObject {
+ private String name;
+ private List xmlComponentSpecifications;
+
+ public XMLComponentTreeObject(XMLComponentSpecification spec) {
+ xmlComponentSpecifications = new ArrayList();
+ xmlComponentSpecifications.add(spec);
+ name = (String) spec.getAttributeInfo("name");
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void addXMLComponentSpecification(XMLComponentSpecification spec) {
+ xmlComponentSpecifications.add(spec);
+ }
+
+ public List getXMLComponentSpecification() {
+ return xmlComponentSpecifications;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDSetTypeHelper.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDSetTypeHelper.java
new file mode 100644
index 0000000..2d5594c
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDSetTypeHelper.java
@@ -0,0 +1,378 @@
+/*******************************************************************************
+ * Copyright (c) 2004 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.types.xsd;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.xml.uriresolver.util.URIHelper;
+import org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction;
+import org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSpecification;
+import org.eclipse.wst.xsd.ui.internal.refactor.delete.XSDExternalFileCleanup;
+import org.eclipse.wst.xsd.ui.internal.util.TypesHelper;
+import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
+import org.eclipse.xsd.XSDImport;
+import org.eclipse.xsd.XSDInclude;
+import org.eclipse.xsd.XSDRedefine;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSchemaContent;
+import org.eclipse.xsd.XSDSchemaDirective;
+import org.eclipse.xsd.util.XSDConstants;
+import org.eclipse.xsd.util.XSDParser;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class XSDSetTypeHelper {
+ private XSDSchema xsdSchema;
+ private IFile currentIFile;
+
+ public XSDSetTypeHelper(IFile iFile, XSDSchema schema) {
+ currentIFile = iFile;
+ xsdSchema = schema;
+ }
+
+ public void setType(Element element, String property, XMLComponentSpecification spec) {
+ addImportIfNecessary(element, spec);
+ String typeObject = getPrefixedTypeName(spec);
+
+ // Get the previous type --> previousStringType
+ String previousStringType = "";
+ Attr attr = element.getAttributeNode(property);
+ if (attr != null) {
+ String value = attr.getValue();
+ }
+
+ if (!XSDDOMHelper.inputEquals(element, XSDConstants.UNION_ELEMENT_TAG, false))
+ {
+ if (spec != null && spec.getTagPath().equals("**anonymous**"))
+ {
+ if (spec.getTagPath().equals("ANONYMOUS_SIMPLE_TYPE"))
+ {
+ if (!previousStringType.equals("**anonymous**"))
+ {
+ updateElementToAnonymous(element, XSDConstants.SIMPLETYPE_ELEMENT_TAG);
+ }
+ }
+ else
+ {
+ if (!previousStringType.equals("**anonymous**"))
+ {
+ updateElementToAnonymous(element, XSDConstants.COMPLEXTYPE_ELEMENT_TAG);
+ }
+ }
+ // element.removeAttribute(XSDConstants.TYPE_ATTRIBUTE);
+ element.removeAttribute(property);
+ }
+ else
+ {
+ XSDDOMHelper.updateElementToNotAnonymous(element);
+ //element.setAttribute(XSDConstants.TYPE_ATTRIBUTE, typeObject.toString());
+ element.setAttribute(property, typeObject.toString());
+ }
+ }
+ }
+
+ public void addImportIfNecessary(Element element, XMLComponentSpecification spec) {
+ String typeObject = "";
+
+ // Get the new type --> typeObject
+ if (spec != null) {
+ String itemType = spec.getTagPath();
+ typeObject = (String) spec.getAttributeInfo("name");
+
+ if (!itemType.equals("BUILT_IN_SIMPLE_TYPE")) {
+ // Do an actual import if needed
+ XSDParser parser = new XSDParser();
+ parser.parse(spec.getFileLocation());
+ XSDSchema schema = parser.getSchema();
+ String tns = schema.getTargetNamespace();
+
+ boolean exists = false;
+ // Check if the type is defined in the 'current' file itself.
+ String currentFile = getNormalizedLocation(xsdSchema.getSchemaLocation());
+ IPath currentFilePath = new Path(currentFile);
+ if (currentFilePath.equals(spec.getFileLocation())) {
+ exists = true;
+ }
+
+ if (!exists) {
+ if (tns.equals(xsdSchema.getTargetNamespace())) {
+ // Check if the schema is in a redefine/include
+ List existingList = getXSDIncludes();
+ existingList.addAll(getXSDRedefines());
+ Iterator it = existingList.iterator();
+ while (it.hasNext()) {
+ XSDSchemaDirective existingSchema = (XSDSchemaDirective) it.next();
+ String normalizedFile = getNormalizedLocation(existingSchema.getResolvedSchema().getSchemaLocation());
+ String normalizedSpec = spec.getFileLocation();
+
+ if (normalizedFile.equals(normalizedSpec)) {
+ // Found and existing one
+ exists = true;
+ }
+ }
+ }
+ else {
+ // Check if the schema is in a import
+ List existingList = getXSDImports();
+ Iterator it = existingList.iterator();
+ while (it.hasNext()) {
+ XSDSchemaDirective existingSchema = (XSDSchemaDirective) it.next();
+ String normalizedFile = getNormalizedLocation(existingSchema.getResolvedSchema().getSchemaLocation());
+ String normalizedSpec = spec.getFileLocation();
+
+ if (normalizedFile.equals(normalizedSpec)) {
+ // Found and existing one
+ exists = true;
+ }
+ }
+ }
+ }
+
+ if (!exists) {
+ doImport(spec.getFileLocation(), schema);
+ }
+ }
+ }
+ }
+
+ /*
+ * Return the prefixed type name for the type described by the given
+ * XMLComponentSpecification object.
+ * If the type described is a Built-in type, do not add the prefix
+ */
+ public String getPrefixedTypeName(XMLComponentSpecification spec) {
+ String typeObject = (String) spec.getAttributeInfo("name");
+
+ if (!spec.getTagPath().equals("BUILT_IN_SIMPLE_TYPE")) {
+ TypesHelper typesHelper = new TypesHelper(xsdSchema); // ???? Is this correct?
+ List prefixedNames = typesHelper.getPrefixedNames(spec.getTargetNamespace(), typeObject);
+ if (prefixedNames.size() > 0) {
+ // Grab the first prefixed name
+ typeObject = (String) prefixedNames.get(0);
+ }
+ }
+
+ return typeObject;
+ }
+
+ private void updateElementToAnonymous(Element element, String xsdType) {
+ String prefix = element.getPrefix();
+ prefix = (prefix == null) ? "" : (prefix + ":");
+ XSDDOMHelper.updateElementToNotAnonymous(element);
+ boolean hasChildrenElements = hasElementChildren(element);
+ Element childNode = null;
+ if (xsdType.equals(XSDConstants.COMPLEXTYPE_ELEMENT_TAG)) {
+ childNode = element.getOwnerDocument().createElementNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, prefix + XSDConstants.COMPLEXTYPE_ELEMENT_TAG);
+ }
+ else if (xsdType.equals(XSDConstants.SIMPLETYPE_ELEMENT_TAG)) {
+ childNode = element.getOwnerDocument().createElementNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, prefix + XSDConstants.SIMPLETYPE_ELEMENT_TAG);
+ }
+
+ if (childNode != null) {
+ XSDDOMHelper helper = new XSDDOMHelper();
+ Node annotationNode = helper.getChildNode(element, XSDConstants.ANNOTATION_ELEMENT_TAG);
+ if (annotationNode == null) {
+ Node firstChild = element.getFirstChild();
+ element.insertBefore(childNode, firstChild);
+ } else {
+ Node nextSibling = annotationNode.getNextSibling();
+ element.insertBefore(childNode, nextSibling);
+ }
+ XSDDOMHelper.formatChild(childNode);
+ }
+ }
+
+ private boolean hasElementChildren(Node parentNode) {
+ boolean hasChildrenElements = false;
+ if (parentNode != null && parentNode.hasChildNodes()) {
+ NodeList nodes = parentNode.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ if (nodes.item(i) instanceof Element) {
+ hasChildrenElements = true;
+ break;
+ }
+ }
+ }
+ return hasChildrenElements;
+ }
+
+ // TODO: We shouldn't need to pass in IPath externalSchemaPath.
+ private void doImport(String externalSchemaPath, XSDSchema externalSchema) {
+ // Determine schemaLocation
+ String locationAttribute = URIHelper.getRelativeURI(externalSchemaPath, currentIFile.getLocation().toOSString());
+
+ boolean isInclude = false;
+ if (externalSchema.getTargetNamespace().equals(xsdSchema.getTargetNamespace())) {
+ isInclude = true;
+ }
+
+ if (externalSchema != null) { // In case we have problems loading the file.... we should display an error message.
+ Element newElement;
+ if (isInclude) {
+ List attributes = new ArrayList();
+ attributes.add(new DOMAttribute(XSDConstants.SCHEMALOCATION_ATTRIBUTE, locationAttribute));
+ newElement = createElement(XSDConstants.INCLUDE_ELEMENT_TAG, attributes);
+ }
+ else if (!isInclude) {
+ List attributes = new ArrayList();
+ attributes.add(new DOMAttribute(XSDConstants.NAMESPACE_ATTRIBUTE, externalSchema.getTargetNamespace()));
+ attributes.add(new DOMAttribute(XSDConstants.SCHEMALOCATION_ATTRIBUTE, locationAttribute));
+ newElement = createElement(XSDConstants.IMPORT_ELEMENT_TAG, attributes);
+ handleImportNS(newElement, externalSchema);
+ }
+ }
+ }
+
+ private void handleImportNS(Element importElement, XSDSchema externalSchema) {
+ String namespace = externalSchema.getTargetNamespace();
+ if (namespace == null) namespace = "";
+
+ XSDImport xsdImport = (XSDImport) xsdSchema.getCorrespondingComponent(importElement);
+ xsdImport.setResolvedSchema(externalSchema);
+
+ java.util.Map map = xsdSchema.getQNamePrefixToNamespaceMap();
+
+// System.out.println("changed Import Map is " + map.values());
+// System.out.println("changed import Map keys are " + map.keySet());
+
+ // Referential integrity on old import
+ // How can we be sure that if the newlocation is the same as the oldlocation
+ // the file hasn't changed
+
+ XSDSchema referencedSchema = xsdImport.getResolvedSchema();
+ if (referencedSchema != null)
+ {
+ XSDExternalFileCleanup cleanHelper = new XSDExternalFileCleanup(referencedSchema);
+ cleanHelper.visitSchema(xsdSchema);
+ }
+
+ Element schemaElement = xsdSchema.getElement();
+
+ // update the xmlns in the schema element first, and then update the import element next
+ // so that the last change will be in the import element. This keeps the selection
+ // on the import element
+ TypesHelper helper = new TypesHelper(externalSchema);
+ String prefix = helper.getPrefix(namespace, false);
+
+ if (map.containsKey(prefix))
+ {
+ prefix = null;
+ }
+
+ if (prefix == null || (prefix !=null && prefix.length() == 0))
+ {
+ StringBuffer newPrefix = new StringBuffer("pref"); //$NON-NLS-1$
+ int prefixExtension = 1;
+ while (map.containsKey(newPrefix.toString()) && prefixExtension < 100)
+ {
+ newPrefix = new StringBuffer("pref" + String.valueOf(prefixExtension));
+ prefixExtension++;
+ }
+ prefix = newPrefix.toString();
+ }
+
+ if (namespace.length() > 0)
+ {
+ // if ns already in map, use its corresponding prefix
+ if (map.containsValue(namespace))
+ {
+ TypesHelper typesHelper = new TypesHelper(xsdSchema);
+ prefix = typesHelper.getPrefix(namespace, false);
+ }
+ else // otherwise add to the map
+ {
+ schemaElement.setAttribute("xmlns:"+prefix, namespace);
+ }
+ }
+
+
+// System.out.println("changed Import Map is " + map.values());
+// System.out.println("changed import Map keys are " + map.keySet());
+ }
+
+ private Element createElement(String elementTag, List attributes) {
+ Node relativeNode = XSDDOMHelper.getNextElementNode(xsdSchema.getElement().getFirstChild());
+
+ CreateElementAction action = new CreateElementAction("");
+ action.setElementTag(elementTag);
+ action.setAttributes(attributes);
+ action.setParentNode(xsdSchema.getElement());
+ action.setRelativeNode(relativeNode);
+ action.setXSDSchema(xsdSchema);
+ return action.createAndAddNewChildElement();
+ }
+
+ private String getNormalizedLocation(String location) {
+ try {
+ URL url = new URL(location);
+ URL resolvedURL = Platform.resolve(url);
+ location = resolvedURL.getPath();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return location;
+ }
+
+ private List getXSDImports() {
+ List imports = new ArrayList();
+
+ Iterator contents = xsdSchema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDImport) {
+ imports.add(content);
+ }
+ }
+
+ return imports;
+ }
+
+ private List getXSDIncludes() {
+ List includes = new ArrayList();
+
+ Iterator contents = xsdSchema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDInclude) {
+ includes.add(content);
+ }
+ }
+
+ return includes;
+ }
+
+ private List getXSDRedefines() {
+ List includes = new ArrayList();
+
+ Iterator contents = xsdSchema.getContents().iterator();
+ while (contents.hasNext()) {
+ XSDSchemaContent content = (XSDSchemaContent) contents.next();
+ if (content instanceof XSDRedefine) {
+ includes.add(content);
+ }
+ }
+
+ return includes;
+ }
+
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/graph/editparts/ElementDeclarationEditPart.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/graph/editparts/ElementDeclarationEditPart.java
index 1ccb786..8646771 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/graph/editparts/ElementDeclarationEditPart.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/graph/editparts/ElementDeclarationEditPart.java
@@ -14,6 +14,7 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
@@ -27,8 +28,18 @@
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.requests.LocationRequest;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDSetTypeHelper;
import org.eclipse.wst.xsd.ui.internal.gef.util.figures.SpacingFigure;
import org.eclipse.wst.xsd.ui.internal.graph.XSDChildUtility;
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphUtil;
@@ -37,7 +48,6 @@
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.ComboBoxCellEditorManager;
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.ComponentNameDirectEditManager;
import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.SimpleDirectEditPolicy;
-import org.eclipse.wst.xsd.ui.internal.graph.editpolicies.TypeReferenceDirectEditManager;
import org.eclipse.wst.xsd.ui.internal.graph.figures.ContainerFigure;
import org.eclipse.wst.xsd.ui.internal.graph.figures.ExpandableGraphNodeFigure;
import org.eclipse.wst.xsd.ui.internal.graph.figures.FillLayout;
@@ -50,6 +60,7 @@
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
import org.eclipse.xsd.XSDTypeDefinition;
+import org.w3c.dom.Element;
@@ -308,9 +319,33 @@
{
if (!getXSDElementDeclaration().isElementDeclarationReference())
{
- TypeReferenceDirectEditManager manager = new TypeReferenceDirectEditManager(this, getXSDElementDeclaration(), typeValueLabel);
- simpleDirectEditPolicy.setDelegate(manager);
- manager.show();
+// TypeReferenceDirectEditManager manager = new TypeReferenceDirectEditManager(this, getXSDElementDeclaration(), typeValueLabel);
+// simpleDirectEditPolicy.setDelegate(manager);
+// manager.show();
+//TODO remove TypeReferenceDirectEditManager since it is not used any longer
+
+ Shell shell = Display.getCurrent().getActiveShell();
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+ IFile currentIFile = ((IFileEditorInput)editorPart.getEditorInput()).getFile();
+
+ XSDSchema schema = getXSDElementDeclaration().getSchema();
+
+ XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, schema);
+ XSDComponentSelectionDialog dialog = new XSDComponentSelectionDialog(shell, "Set Type", provider); // TODO: Externalize This
+ provider.setDialog(dialog);
+
+ dialog.setBlockOnOpen(true);
+ dialog.create();
+
+ if (dialog.open() == Window.OK) {
+ Element element = getXSDElementDeclaration().getElement();
+ XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, schema);
+ helper.setType(element, "type", dialog.getSelection());
+ }
+
+
}
// just ignore type edit for element ref's
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/ComplexTypeSection.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/ComplexTypeSection.java
index 4de57c5..62bbb24 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/ComplexTypeSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/ComplexTypeSection.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.properties.section;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
@@ -23,12 +24,21 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.wst.common.ui.properties.ITabbedPropertyConstants;
import org.eclipse.wst.common.ui.properties.TabbedPropertySheetWidgetFactory;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
import org.eclipse.wst.xsd.ui.internal.actions.SetBaseTypeAction;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSpecification;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDSetTypeHelper;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDConstants;
import org.w3c.dom.Element;
@@ -173,25 +183,44 @@
element = ((XSDComplexTypeDefinition)getInput()).getContent().getElement();
}
- SimpleContentBaseTypeOptionsDialog dialog = new SimpleContentBaseTypeOptionsDialog(shell, element, BASE_TYPE_ID, ((XSDConcreteComponent)getInput()).getSchema());
-
- dialog.setBlockOnOpen(true);
- dialog.create();
-
- int result = dialog.open();
+// SimpleContentBaseTypeOptionsDialog dialog = new SimpleContentBaseTypeOptionsDialog(shell, element, BASE_TYPE_ID, ((XSDConcreteComponent)getInput()).getSchema());
+// dialog.setBlockOnOpen(true);
+// dialog.create();
+// int result = dialog.open();
+
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+ IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile();
+
+ Object input = getInput();
+ XSDSchema schema = null;
+ if (input instanceof XSDConcreteComponent) {
+ schema = ((XSDConcreteComponent) input).getSchema();
+ }
+
+ XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, schema);
+ XSDComponentSelectionDialog dialog = new XSDComponentSelectionDialog(shell, "Set Type", provider); // TODO: Externalize This
+ provider.setDialog(dialog);
+ dialog.setBlockOnOpen(true);
+ dialog.create();
+ int result = dialog.open();
if (result == Window.OK)
{
- String typeString = dialog.getType();
-
- String derivedBy = getDomHelper().getDerivedByName(element);
- SetBaseTypeAction setBaseTypeAction = new SetBaseTypeAction(XSDEditorPlugin.getXSDString("_UI_LABEL_SET_BASE_TYPE")); //$NON-NLS-1$
- setBaseTypeAction.setXSDSchema(xsdSchema);
- setBaseTypeAction.setComplexTypeElement(ctElement);
- setBaseTypeAction.setType(typeString);
- setBaseTypeAction.setDerivedBy(derivedBy);
- setBaseTypeAction.performAction();
-
+ XMLComponentSpecification spec = dialog.getSelection();
+ XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, schema);
+ helper.addImportIfNecessary(element, spec);
+
+ String typeString = helper.getPrefixedTypeName(spec);
+ String derivedBy = getDomHelper().getDerivedByName(element);
+ SetBaseTypeAction setBaseTypeAction = new SetBaseTypeAction(XSDEditorPlugin.getXSDString("_UI_LABEL_SET_BASE_TYPE")); //$NON-NLS-1$
+ setBaseTypeAction.setXSDSchema(xsdSchema);
+ setBaseTypeAction.setComplexTypeElement(ctElement);
+ setBaseTypeAction.setType(typeString);
+ setBaseTypeAction.setDerivedBy(derivedBy);
+ setBaseTypeAction.performAction();
+
}
refresh();
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/SimpleTypeSection.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/SimpleTypeSection.java
index 833292e..ddcaf08 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/SimpleTypeSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/SimpleTypeSection.java
@@ -15,7 +15,9 @@
import java.util.List;
import java.util.StringTokenizer;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
@@ -28,11 +30,18 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.wst.common.ui.properties.ITabbedPropertyConstants;
import org.eclipse.wst.common.ui.properties.TabbedPropertySheetWidgetFactory;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
import org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction;
import org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDSetTypeHelper;
import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDSimpleTypeDefinition;
@@ -255,8 +264,19 @@
{
Shell shell = Display.getCurrent().getActiveShell();
Element element = ((XSDConcreteComponent)input).getElement();
- TypesDialog dialog = null;
+ Dialog dialog = null;
+ String property = "";
+ Element secondaryElement = null;
+
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+ IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile();
+ XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, xsdSchema);
+ dialog = new XSDComponentSelectionDialog(shell, "Set Type", provider); // TODO: Externalize This
+ provider.setDialog((XSDComponentSelectionDialog) dialog);
+
if (input instanceof XSDSimpleTypeDefinition)
{
XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)input;
@@ -264,8 +284,12 @@
if (st.getVariety() == XSDVariety.LIST_LITERAL)
{
Element listElement = (Element)domHelper.getChildNode(simpleTypeElement, XSDConstants.LIST_ELEMENT_TAG);
- dialog = new TypesDialog(shell, listElement, XSDConstants.ITEMTYPE_ATTRIBUTE, xsdSchema);
- dialog.showComplexTypes = false;
+// dialog = new TypesDialog(shell, listElement, XSDConstants.ITEMTYPE_ATTRIBUTE, xsdSchema);
+// dialog.showComplexTypes = false;
+ provider.showComplexTypes(false);
+
+ secondaryElement = listElement;
+ property = XSDConstants.ITEMTYPE_ATTRIBUTE;
}
else if (st.getVariety() == XSDVariety.ATOMIC_LITERAL)
{
@@ -277,8 +301,12 @@
}
if (derivedByElement != null)
{
- dialog = new TypesDialog(shell, derivedByElement, XSDConstants.BASE_ATTRIBUTE, xsdSchema);
- dialog.showComplexTypes = false;
+// dialog = new TypesDialog(shell, derivedByElement, XSDConstants.BASE_ATTRIBUTE, xsdSchema);
+// dialog.showComplexTypes = false;
+ provider.showComplexTypes(false);
+
+ secondaryElement = derivedByElement;
+ property = XSDConstants.BASE_ATTRIBUTE;
}
else
{
@@ -317,12 +345,14 @@
}
else
{
- dialog = new TypesDialog(shell, element, "type", xsdSchema); //$NON-NLS-1$
+// dialog = new TypesDialog(shell, element, "type", xsdSchema); //$NON-NLS-1$
+ property = "type";
}
}
else
{
- dialog = new TypesDialog(shell, element, "type", xsdSchema); //$NON-NLS-1$
+// dialog = new TypesDialog(shell, element, "type", xsdSchema); //$NON-NLS-1$
+ property = "type";
}
beginRecording(XSDEditorPlugin.getXSDString("_UI_TYPE_CHANGE"), element); //$NON-NLS-1$
dialog.setBlockOnOpen(true);
@@ -331,6 +361,12 @@
if (result == Window.OK)
{
+ if (secondaryElement == null) {
+ secondaryElement = element;
+ }
+ XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, xsdSchema);
+ helper.setType(secondaryElement, property, ((XSDComponentSelectionDialog) dialog).getSelection());
+
XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)getInput();
st.setElement(element);
updateSimpleTypeFacets();
diff --git a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/TypesSection.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/TypesSection.java
index c0d8ab0..db1a417 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/TypesSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/TypesSection.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.properties.section;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
@@ -22,13 +23,21 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.wst.common.ui.properties.TabbedPropertySheetWidgetFactory;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionDialog;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDComponentSelectionProvider;
+import org.eclipse.wst.xsd.ui.internal.dialogs.types.xsd.XSDSetTypeHelper;
import org.eclipse.wst.xsd.ui.internal.widgets.TypeSection;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDConcreteComponent;
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;
@@ -221,6 +230,7 @@
{
if (e.widget == button)
{
+/*
Shell shell = Display.getCurrent().getActiveShell();
Object input = getInput();
Element element = ((XSDConcreteComponent)getInput()).getElement();
@@ -262,7 +272,7 @@
// {
dialog = new TypesDialog(shell, element, "type", xsdSchema); //$NON-NLS-1$
// }
-
+
dialog.setBlockOnOpen(true);
dialog.create();
int result = dialog.open();
@@ -281,6 +291,31 @@
// endRecording(element);
// }
}
+*/
+ Shell shell = Display.getCurrent().getActiveShell();
+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
+ IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile();
+
+ Object input = getInput();
+ XSDSchema schema = null;
+ if (input instanceof XSDConcreteComponent) {
+ schema = ((XSDConcreteComponent) input).getSchema();
+ }
+
+ XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, schema);
+ XSDComponentSelectionDialog dialog = new XSDComponentSelectionDialog(shell, "Set Type", provider); // TODO: Externalize This
+ provider.setDialog(dialog);
+
+ dialog.setBlockOnOpen(true);
+ dialog.create();
+
+ if (dialog.open() == Window.OK) {
+ Element element = ((XSDConcreteComponent)getInput()).getElement();
+ XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, schema);
+ helper.setType(element, "type", dialog.getSelection());
+ }
refresh();
}