Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types')
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/ComponentSelectionDialog.java445
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentList.java18
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentSelectionProvider.java27
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/ResourceView.java141
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentFinder.java114
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionDialog.java180
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java141
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSpecification.java57
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLQuickScan.java130
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentFinder.java70
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionDialog.java28
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionProvider.java346
-rw-r--r--bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDSetTypeHelper.java358
13 files changed, 0 insertions, 2055 deletions
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
deleted file mode 100644
index 77ce6ad4d0..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/ComponentSelectionDialog.java
+++ /dev/null
@@ -1,445 +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.common;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-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;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-
-public class ComponentSelectionDialog extends Dialog {
- private Display display = Display.getCurrent();
- private String dialogTitle;
-
- protected IComponentSelectionProvider provider;
- private List componentTreeViewerInput;
- private List masterComponentList;
-
- // widgets
- protected Composite topComposite;
- protected Composite bottomComposite;
- private String filterTextLabel = "";
- private String componentListLabel = XSDEditorPlugin.getXSDString("_UI_LABEL_COMPONENTS");
- 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();
- masterComponentList = 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 void create() {
- super.create();
- setTextFilterFocus();
- }
-
- protected void setTextFilterFocus() {
- textFilter.setFocus();
- }
-
- 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);
- 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.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- textFilter.addModifyListener(new TextFilterModifyAdapter());
- GridData textFilterData = new GridData();
- textFilterData.horizontalAlignment = GridData.FILL;
- textFilterData.grabExcessHorizontalSpace = true;
- textFilter.setLayoutData(textFilterData);
-
- //textFilter.setSelection(0);
- //textFilter.setf
-
-
- // Create Component TreeViewer
- createComponentTreeViewer(filterLabelAndTree);
-
- // Create Qualifier List widget
- Label qualifierLabel = new Label(mainComposite, SWT.NONE);
- qualifierLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_QUALIFIER"));
-
- 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);
-
- bottomComposite = new Composite(mainComposite, SWT.NONE);
- bottomComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- bottomComposite.setLayout(new GridLayout());
-
- // 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());
- componentTreeViewer.setInput(componentTreeViewerInput);
-
- populateMasterComponentList();
- refreshTreeViewer("");
-
- 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.getQualifiers(structuredSelection.getFirstElement());
- updateQualifierList(qualifiers);
- updateCanFinish();
- }
- });
- }
-
- 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) {
- 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) {
- refreshTreeViewer(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.getQualifiers(structuredSelection.getFirstElement());
- updateQualifierList(qualifiers);
-
- updateCanFinish();
- }
- }
- }
-
- class ComponentList implements IComponentList {
- private Vector objectVector = new Vector();
- private long currentChangeCounter = 0;
-
- public void addComponent(Object o) {
- objectVector.add(o);
- currentChangeCounter++;
- doViewerUpdate();
- }
-
- private void doViewerUpdate() {
- // TODO: Investigate if we should also add a timer condition??
- if (currentChangeCounter == 10) {
- currentChangeCounter = 0;
- fireUpdateList(this);
- }
- }
-
- public int size() {
- return objectVector.size();
- }
-
- public List subList(int startIndex, int endIndex) {
- return objectVector.subList(startIndex, endIndex);
- }
-
- public Iterator iterator() {
- return objectVector.iterator();
- }
- }
-
-
- // this method gets called from a non-ui thread so needs to call
- // asyncExec to ensure the UI updates happen on the UI thread
- //
- protected void fireUpdateList(final ComponentList list) {
- Runnable runnable = new Runnable() {
- public void run(){
- // add new objects
- int growingListSize = list.size();
- int currentSize = masterComponentList.size();
- if (growingListSize > currentSize) {
- masterComponentList.addAll(list.subList(currentSize, growingListSize));
- }
-
- refreshTreeViewer(getProcessedFilterString());
- }
- };
- display.asyncExec(runnable);
- }
-
-
- /*
- * Populate the Component TreeViewer with items.
- */
- protected void populateMasterComponentList() {
- masterComponentList.clear();
-
- final ComponentList componentList = new ComponentList();
- provider.getComponents(componentList, true);
-
- Job job = new Job("read components") {
- protected IStatus run(IProgressMonitor monitor) {
- try {
- // this stuff gets executed on a non-UI thread
- //
- provider.getComponents(componentList, false);
-
- // Do a final update of our Input for the component tree viewer.
- fireUpdateList(componentList);
- }
- catch (Exception e) {
- }
- return Status.OK_STATUS;
- }
- };
- job.schedule();
- }
-
- protected void refreshTreeViewer(String filterText) {
- componentTreeViewerInput.clear();
- ILabelProvider labelProvider = provider.getLabelProvider();
- Pattern regex = Pattern.compile(filterText);
- Iterator it = masterComponentList.iterator();
- while (it.hasNext()) {
- Object item = it.next();
- String itemString = labelProvider.getText(item);
- Matcher m = regex.matcher(itemString.toLowerCase());
- if (itemString.toLowerCase().startsWith(filterText) || m.matches()) {
- componentTreeViewerInput.add(item);
- }
- }
-
- componentTreeViewer.refresh();
- }
-
- /*
- * 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
deleted file mode 100644
index 5c5d46ad84..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentList.java
+++ /dev/null
@@ -1,18 +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.common;
-
-import java.util.Iterator;
-
-public interface IComponentList {
- public void addComponent(Object o);
- public Iterator iterator();
-}
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
deleted file mode 100644
index de68271167..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/common/IComponentSelectionProvider.java
+++ /dev/null
@@ -1,27 +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.common;
-
-import java.util.List;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-
-public interface IComponentSelectionProvider {
-
- // warning ... this will get called on a non UI thread
- void getComponents(IComponentList list, boolean quick);
-
- String getType(Object component);
- ILabelProvider getLabelProvider();
- List getQualifiers(Object component);
- String getNameFieldTitle();
- String getListTitle();
-}
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
deleted file mode 100644
index 2a61449b58..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/ResourceView.java
+++ /dev/null
@@ -1,141 +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.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
deleted file mode 100644
index d73adcb0b8..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentFinder.java
+++ /dev/null
@@ -1,114 +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.xml;
-
-import java.util.ArrayList;
-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.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-
-/**
- * this thing parsers xml artifacts and picks out the specified components attributes
- *
- */
-public class XMLComponentFinder {
- public static final int ENCLOSING_PROJECT_SCOPE = 0;
- public static final int ENTIRE_WORKSPACE_SCOPE = 1;
-
- 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;
- }
-
- public void setValidExtensions(List newExtensions) {
- validExtensions.clear();
- validExtensions.addAll(newExtensions);
- }
-
- public void addExcludeFiles(List newExclude) {
- excludeFiles.addAll(newExclude);
- }
-
- /*
- * Returns a List of absolute file locations. For example
- * "D:\files\....\file.xsd"
- */
- protected List getEnclosingProjectFiles() {
- List files = new ArrayList();
-
- if (currentIFile != null) {
- IProject project = currentIFile.getProject();
- try {
- traverseIContainer(project, validExtensions, excludeFiles, files);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- return files;
- }
-
- protected 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], validExtensions, excludeFiles, files);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return files;
- }
-
- /**
- * 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();
- 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/XMLComponentSelectionDialog.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionDialog.java
deleted file mode 100644
index d9a74d5813..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionDialog.java
+++ /dev/null
@@ -1,180 +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.xml;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-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.Group;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
-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.XMLComponentSelectionProvider.XMLComponentTreeObject;
-
-public class XMLComponentSelectionDialog extends ComponentSelectionDialog {
-
- protected final static String DEFAULT_NAME_FIELD_TITLE = XSDEditorPlugin.getXSDString("_UI_LABEL_COMPONENT_NAME");
- protected final static String DEFAULT_LIST_TITLE = XSDEditorPlugin.getXSDString("_UI_LABEL_MATCHING_COMPONENTS");
-
- public static final String SCOPE_SPECIFIED_FILE = XSDEditorPlugin.getXSDString("_UI_LABEL_SPECIFIED_FILE");
-
- public static final String SCOPE_ENCLOSING_PROJECT = XSDEditorPlugin.getXSDString("_UI_LABEL_ENCLOSING_PROJECT");
-
- public static final String SCOPE_WORKSPACE = XSDEditorPlugin.getXSDString("_UI_LABEL_WORKSPACE");
-
- public static final String SCOPE_CURRENT_RESOURCE = XSDEditorPlugin.getXSDString("_UI_LABEL_CURRENT_RESOURCE");
-
- private String currentSearchScope = SCOPE_CURRENT_RESOURCE;
-
- protected Button chooseButton;
- protected Button[] radioButton = new Button[3];
-
- public XMLComponentSelectionDialog(Shell shell, String dialogTitle,
- IComponentSelectionProvider provider) {
- super(shell, dialogTitle, provider);
- }
-
-public Control createDialogArea(Composite parent) {
-
- setFilterLabel(provider.getNameFieldTitle() != null ? provider.getNameFieldTitle() : DEFAULT_NAME_FIELD_TITLE);
- setComponentTreeLabel(provider.getListTitle() != null ? provider.getListTitle() : DEFAULT_LIST_TITLE);
- super.createDialogArea(parent);
-
- // We use the Composite topComposite to create additional widgets
- GridLayout layout = new GridLayout();
- layout.marginWidth = 0;
- bottomComposite.setLayout(layout);
-
-
- Group group = new Group(bottomComposite, SWT.NONE);
- GridLayout gridLayout = new GridLayout(3, false);
- //gridLayout.marginWidth = 0;
- //gridLayout.marginLeft = 2;
- group.setLayout(gridLayout);
- group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- group.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_SEARCH_SCOPE"));
-
- ScopeChangeListener scopeChangeListener = new ScopeChangeListener();
- radioButton[0] = new Button(group, SWT.RADIO);
- radioButton[0].setText(SCOPE_WORKSPACE);
-
- radioButton[1] = new Button(group, SWT.RADIO);
- radioButton[1].setText(SCOPE_ENCLOSING_PROJECT);
-
- radioButton[2] = new Button(group, SWT.RADIO);
- radioButton[2].setText(SCOPE_CURRENT_RESOURCE);
-
- //radioButton[3] = new Button(group, SWT.RADIO);
- //radioButton[3].setText("Resource Set");
-
-
- for (int i = 0; i < radioButton.length; i++)
- {
- if (radioButton[i].getText().equals(currentSearchScope))
- {
- radioButton[i].setSelection(true);
- }
- radioButton[i].addSelectionListener(scopeChangeListener);
- }
- if (false){
- Composite selectFileGroup = new Composite(group, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan = 2;
- selectFileGroup.setLayoutData(gd);
- GridLayout gridLayout3 = new GridLayout(2, false);
- gridLayout3.marginWidth = 0;
- gridLayout3.marginHeight = 0;
- selectFileGroup.setLayout(gridLayout3);
- Text t = new Text(selectFileGroup, SWT.BORDER | SWT.READ_ONLY);
- t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- Button choose = new Button(selectFileGroup, SWT.NONE);
- choose.setText("Choose...");
- choose.addSelectionListener(scopeChangeListener);
- }
-
-
- Button check = new Button(group, SWT.CHECK);
- check.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_NARROW_SEARCH_SCOPE_RESOURCE"));
- GridData gd = new GridData();
- gd.horizontalSpan = 3;
- check.setLayoutData(gd);
- check.setEnabled(false);
-
- return parent;
- } /*
- * Returns the selected search scope.
- */
- public String getSearchScope() {
- return currentSearchScope;
- }
-
- 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 ScopeChangeListener extends SelectionAdapter {
- public void widgetSelected(SelectionEvent e) {
-
- if (e.widget instanceof Button) {
- Button b = (Button) e.widget;
- if ((b.getStyle() & SWT.RADIO) != 0) {
- currentSearchScope = b.getText();
- populateMasterComponentList();
- refreshTreeViewer(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/xml/XMLComponentSelectionProvider.java b/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java
deleted file mode 100644
index aef0a011aa..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSelectionProvider.java
+++ /dev/null
@@ -1,141 +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.xml;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentList;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider;
-
-public abstract class XMLComponentSelectionProvider implements IComponentSelectionProvider {
- public List getQualifiers(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();
- qualifiers.add(createQualifierText(spec));
- }
- }
-
- return qualifiers;
- }
-
- protected String createQualifierText(XMLComponentSpecification spec) {
- IPath path = new Path(spec.getFileLocation());
- return spec.getTargetNamespace() + " - " + path.lastSegment();
- }
-
- protected void addDataItemToTreeNode(IComponentList 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.addComponent(containingTreeObject);
- }
- else {
- // Only add to the tree object if the qualifier text differs than existing
- // qualifier information contained in the tree object.
- Iterator existingQualifiers = getQualifiers(containingTreeObject).iterator();
- boolean alreadyExists = false;
- while (existingQualifiers.hasNext()) {
- String existingText = (String) existingQualifiers.next();
- String newItemText = createQualifierText(dataItem);
- if (existingText.equals(newItemText)) {
- alreadyExists = true;
- break;
- }
- }
-
- if (!alreadyExists) {
- containingTreeObject.addXMLComponentSpecification(dataItem);
- }
- }
- }
-
- protected 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;
- }
-
-
- /*
- * 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;
- }
- }
-
- /*
- * Used to provide labels to the ComponentSeletionDialog
- */
- public class XMLComponentSelectionLabelProvider extends LabelProvider {
- public String getText(Object element) {
- XMLComponentTreeObject specification = (XMLComponentTreeObject) element;
- return specification.getName();
- }
- }
-}
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
deleted file mode 100644
index 04c2546485..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLComponentSpecification.java
+++ /dev/null
@@ -1,57 +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.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
deleted file mode 100644
index 30409c23d9..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xml/XMLQuickScan.java
+++ /dev/null
@@ -1,130 +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.xml;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-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
- Thread.currentThread().setContextClassLoader(XMLQuickScan.class.getClassLoader());
-
- 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);
- }
-
- 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
deleted file mode 100644
index 7f9fc7d20b..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentFinder.java
+++ /dev/null
@@ -1,70 +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.xsd;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-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 XSDComponentFinder() {
- validExtensions.add("xsd");
- }
-
- 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];
- nameAttr[0] = "name";
- attributes.add(nameAttr);
- attributes.add(nameAttr);
-
- 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;
- }
-}
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
deleted file mode 100644
index b66e13c777..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionDialog.java
+++ /dev/null
@@ -1,28 +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.xsd;
-
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.common.IComponentSelectionProvider;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSelectionDialog;
-
-public class XSDComponentSelectionDialog extends XMLComponentSelectionDialog {
-
- public static final int ELEMENT = 1;
- public static final int TYPE = 2;
-
- public XSDComponentSelectionDialog(Shell shell, String dialogTitle,
- IComponentSelectionProvider provider) {
- super(shell, dialogTitle, provider);
- }
-
-
-}
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
deleted file mode 100644
index d1936d485a..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDComponentSelectionProvider.java
+++ /dev/null
@@ -1,346 +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.xsd;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.viewers.ILabelProvider;
-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.xml.XMLComponentFinder;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSelectionProvider;
-import org.eclipse.wst.xsd.ui.internal.dialogs.types.xml.XMLComponentSpecification;
-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;
-
-/*
- *
- */
-public class XSDComponentSelectionProvider extends XMLComponentSelectionProvider {
- private XSDComponentFinder xsdComponentFinder;
- private XSDComponentSelectionDialog dialog;
- private XSDSchema schema;
- private XSDComponentLabelProvider labelProvider;
-
- 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;
- labelProvider = new XSDComponentLabelProvider();
- }
-
- public void setDialog(XSDComponentSelectionDialog dialog) {
- this.dialog = dialog;
- }
-
- public void showComplexTypes(boolean show) {
- showComplexTypes = show;
- }
-
- public String getType(Object element) {
- return null;
- }
-
- /*
- * The return value is a List of XMLComponentTreeObjects.
- *
- */
- public void getComponents(IComponentList list, boolean quick) {
- if (quick) {
- // Populate IComponentList list with components most easily accessible (fastest)
- // Grab Built-In types
- Iterator builtInIt = getBuiltInTypes().iterator();
- while (builtInIt.hasNext()) {
- XMLComponentSpecification tagItem = (XMLComponentSpecification) builtInIt.next();
- addDataItemToTreeNode(list, tagItem);
- }
-
- // Create current Schema's complex and simple types
- createComplexTypes(list);
- createSimpleTypes(list);
- }
- else {
- getComponents(list);
- }
- }
-
- /*
- * TODO: Need to revisit how we build up our treeObject list....
- * And it's somewhat messy, clean this up.
- */
- private void getComponents(IComponentList list) {
- List extensions = new ArrayList();
- extensions.add("xsd");
-
- String scope = "";
- if (dialog != null) {
- scope = dialog.getSearchScope();
- }
-
- List comps = new ArrayList();
- if (scope.equals(XSDComponentSelectionDialog.SCOPE_ENCLOSING_PROJECT)) {
- comps = xsdComponentFinder.getWorkbenchResourceComponents(XMLComponentFinder.ENCLOSING_PROJECT_SCOPE);
- }
- else if (scope.equals(XSDComponentSelectionDialog.SCOPE_WORKSPACE)) {
- comps = xsdComponentFinder.getWorkbenchResourceComponents(XMLComponentFinder.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();
- if (showComplexTypes) {
- while (complexIt.hasNext()) {
- XMLComponentSpecification item = (XMLComponentSpecification) complexIt.next();
- addDataItemToTreeNode(list, item);
- }
- }
-
- while (simpleIt.hasNext()) {
- XMLComponentSpecification item = (XMLComponentSpecification) simpleIt.next();
- addDataItemToTreeNode(list, item);
- }
-
- // Create from imports, includes, and redefines
- createFromImport(list);
- createFromInclude(list);
- createFromRedefine(list);
- }
-
-////////////////////////////////////////////////////////////////////////////////
- private List getBuiltInTypes() {
- List items = new ArrayList();
- for (int i = 0; i < XSDDOMHelper.dataType.length; i++) {
- items.add(XSDDOMHelper.dataType[i][0]);
- }
- Iterator it = items.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(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
-// String normalizedFile = getNormalizedLocation(schema.getSchemaLocation());
-// builtInTypeItem.setFileLocation(normalizedFile);
- builtInTypeItem.setFileLocation("Built-In");
-
- builtInComponentSpecs.add(builtInTypeItem);
- }
-
- return builtInComponentSpecs;
- }
-
- private void createComplexTypes(IComponentList treeObjectList) {
- TypesHelper typesHelper = new TypesHelper(schema);
- List complexTypes = typesHelper.getUserComplexTypes();
- createComplexSimpleTreeObject(treeObjectList, complexTypes, true);
- }
-
- private void createSimpleTypes(IComponentList treeObjectList) {
- TypesHelper typesHelper = new TypesHelper(schema);
- List complexTypes = typesHelper.getUserSimpleTypes();
- createComplexSimpleTreeObject(treeObjectList, complexTypes, true);
- }
-
-
- private void createFromImport(IComponentList 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(IComponentList 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(IComponentList 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(IComponentList 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);
- }
- }
- }
- }
-
-
- public ILabelProvider getLabelProvider() {
- return labelProvider;
- }
-
-
- public class XSDComponentLabelProvider extends XMLComponentSelectionLabelProvider {
- 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 getListTitle() {
- return XSDEditorPlugin.getXSDString("_UI_LABEL_MATCHING_TYPES");
- }
-
- public String getNameFieldTitle() {
- return XSDEditorPlugin.getXSDString("_UI_LABEL_TYPE_NAME");
- }
-}
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
deleted file mode 100644
index a5b8e170fa..0000000000
--- a/bundles/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/dialogs/types/xsd/XSDSetTypeHelper.java
+++ /dev/null
@@ -1,358 +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.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.common.uriresolver.internal.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;
-
-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) {
- 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) {
-
- // Get the new type --> typeObject
- if (spec != null) {
- String itemType = spec.getTagPath();
-
- 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(new Path(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");
-
- 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);
- 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);
- }
- }
-
- // 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

Back to the top