[136942] improve the XML Schema 'extensions' view
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoAttributeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java
similarity index 94%
rename from bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoAttributeCommand.java
rename to bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java
index a426135..c5c6229 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoAttributeCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java
@@ -19,7 +19,7 @@
import org.eclipse.xsd.XSDConcreteComponent;
import org.w3c.dom.Element;
-public class AddAppInfoAttributeCommand extends AddAppInfoCommand
+public class AddExtensionAttributeCommand extends AddExtensionCommand
{
private static DOMNamespaceInfoManager manager = new DOMNamespaceInfoManager();
private XSDAttributeDeclaration attribute;
@@ -31,7 +31,7 @@
XSDConcreteComponent component;
- public AddAppInfoAttributeCommand(String label, XSDConcreteComponent component,
+ public AddExtensionAttributeCommand(String label, XSDConcreteComponent component,
XSDAttributeDeclaration attribute)
{
super(label);
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java
similarity index 84%
rename from bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoCommand.java
rename to bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java
index 078e042..49d94f0 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java
@@ -6,11 +6,11 @@
import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema;
import org.eclipse.xsd.XSDConcreteComponent;
-public class AddAppInfoCommand extends Command
+public class AddExtensionCommand extends Command
{
protected SpecificationForExtensionsSchema extensionsSchemaSpec;
- protected AddAppInfoCommand(String label)
+ protected AddExtensionCommand(String label)
{
super(label);
}
@@ -32,4 +32,9 @@
}
return prefix;
}
+
+ public Object getNewObject()
+ {
+ return null;
+ }
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
similarity index 90%
rename from bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoElementCommand.java
rename to bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
index 640eacb..ec92524 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddAppInfoElementCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java
@@ -22,13 +22,14 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class AddAppInfoElementCommand extends AddAppInfoCommand
+public class AddExtensionElementCommand extends AddExtensionCommand
{
XSDConcreteComponent input;
XSDElementDeclaration element;
Element appInfo;
+ Element newElement;
- public AddAppInfoElementCommand(String label, XSDConcreteComponent input, XSDElementDeclaration element)
+ public AddExtensionElementCommand(String label, XSDConcreteComponent input, XSDElementDeclaration element)
{
super(label);
this.input = input;
@@ -75,7 +76,8 @@
String prefix = createUniquePrefix(input);
rootElement.setPrefix(prefix);
-
+ newElement = rootElement;
+
Attr nsURIAttribute = doc.createAttribute("xmlns:"+prefix);
nsURIAttribute.setValue(spec.getNamespaceURI());
rootElement.setAttributeNode(nsURIAttribute);
@@ -87,4 +89,9 @@
xsdAnnotation.updateElement();
}
}
+
+ public Object getNewObject()
+ {
+ return newElement;
+ }
}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoAttrCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.java
similarity index 86%
rename from bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoAttrCommand.java
rename to bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.java
index b69f48c..74f37d6 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoAttrCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.java
@@ -14,12 +14,12 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
-public class RemoveAppInfoAttrCommand extends Command
+public class RemoveExtensionAttributerCommand extends Command
{
Element hostElement;
Attr attr;
- public RemoveAppInfoAttrCommand(String label, Element hostElement, Attr attr)
+ public RemoveExtensionAttributerCommand(String label, Element hostElement, Attr attr)
{
super(label);
this.hostElement = hostElement;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java
similarity index 88%
rename from bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoElementCommand.java
rename to bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java
index e489ea7..c89db27 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveAppInfoElementCommand.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java
@@ -14,12 +14,12 @@
import org.eclipse.xsd.XSDAnnotation;
import org.w3c.dom.Node;
-public class RemoveAppInfoElementCommand extends Command
+public class RemoveExtensionElementCommand extends Command
{
XSDAnnotation xsdAnnotation;
Node appInfo;
- public RemoveAppInfoElementCommand(String label, XSDAnnotation xsdAnnotation, Node appInfo)
+ public RemoveExtensionElementCommand(String label, XSDAnnotation xsdAnnotation, Node appInfo)
{
super(label);
this.xsdAnnotation = xsdAnnotation;
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java
new file mode 100644
index 0000000..b93bb57
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java
@@ -0,0 +1,28 @@
+package org.eclipse.wst.xsd.ui.internal.common.commands;
+
+import org.eclipse.gef.commands.Command;
+import org.w3c.dom.Element;
+
+/*
+ * This command is used from the extension view to edit extension elements
+ * and attributes which are implemented as DOM objects (not part of the EMF model)
+ */
+public class UpdateAttributeValueCommand extends Command
+{
+ Element element;
+ String attributeName;
+ String attributeValue;
+
+ public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue)
+ {
+ this.element = element;
+ this.attributeName = attributeName;
+ this.attributeValue = attributeValue;
+ }
+
+
+ public void execute()
+ {
+ element.setAttribute(attributeName, attributeValue);
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractExtensionsSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractExtensionsSection.java
new file mode 100644
index 0000000..04cd81b
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractExtensionsSection.java
@@ -0,0 +1,485 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections;
+
+import java.util.List;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.MouseTrackAdapter;
+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.Label;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.AddExtensionsComponentDialog;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.DOMExtensionDetailsContentProvider;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.DOMExtensionItemEditManager;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.DOMExtensionItemMenuListener;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.ExtensionDetailsViewer;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.ExtensionsSchemasRegistry;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema;
+import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
+import org.w3c.dom.Element;
+
+public abstract class AbstractExtensionsSection extends AbstractSection
+{
+ protected ExtensionDetailsViewer extensionDetailsViewer;
+ protected TreeViewer extensionTreeViewer;
+ protected ITreeContentProvider extensionTreeContentProvider;
+ protected ILabelProvider extensionTreeLabelProvider;
+ protected Label contentLabel;
+ protected ISelectionChangedListener elementSelectionChangedListener;
+ protected IDocumentChangedNotifier documentChangeNotifier;
+ protected INodeAdapter internalNodeAdapter = new InternalNodeAdapter();
+
+ private Composite page, pageBook2;
+ private Button addButton, removeButton;
+ private PageBook pageBook;
+
+ /**
+ *
+ */
+ public AbstractExtensionsSection()
+ {
+ super();
+ }
+
+ class InternalNodeAdapter implements INodeAdapter
+ {
+
+ public boolean isAdapterForType(Object type)
+ {
+ // we don't really need to implement this
+ return true;
+ }
+
+ public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos)
+ {
+ extensionTreeViewer.refresh();
+ }
+ }
+
+ public void createContents(Composite parent)
+ {
+ // TODO (cs) add assertion
+ if (extensionTreeContentProvider == null)
+ return;
+
+ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ documentChangeNotifier = (IDocumentChangedNotifier)editor.getAdapter(IDocumentChangedNotifier.class);
+
+ if (documentChangeNotifier != null)
+ {
+ documentChangeNotifier.addListener(internalNodeAdapter);
+ }
+
+ composite = getWidgetFactory().createFlatFormComposite(parent);
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.marginTop = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.numColumns = 1;
+ composite.setLayout(gridLayout);
+
+ GridData gridData = new GridData();
+
+ page = getWidgetFactory().createComposite(composite);
+ gridLayout = new GridLayout();
+ gridLayout.marginTop = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.numColumns = 1;
+ page.setLayout(gridLayout);
+
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ page.setLayoutData(gridData);
+
+ pageBook = new PageBook(page, SWT.FLAT);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ pageBook.setLayoutData(gridData);
+
+ pageBook2 = getWidgetFactory().createComposite(pageBook, SWT.FLAT);
+
+ gridLayout = new GridLayout();
+ gridLayout.marginHeight = 2;
+ gridLayout.marginWidth = 2;
+ gridLayout.numColumns = 1;
+ pageBook2.setLayout(gridLayout);
+
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ pageBook2.setLayoutData(gridData);
+
+ SashForm sashForm = new SashForm(pageBook2, SWT.HORIZONTAL);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ sashForm.setLayoutData(gridData);
+ sashForm.setForeground(ColorConstants.white);
+ sashForm.setBackground(ColorConstants.white);
+ Control[] children = sashForm.getChildren();
+ for (int i = 0; i < children.length; i++)
+ {
+ children[i].setVisible(false);
+ }
+ Composite leftContent = getWidgetFactory().createComposite(sashForm, SWT.FLAT);
+ gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ leftContent.setLayout(gridLayout);
+
+ Section section = getWidgetFactory().createSection(leftContent, SWT.FLAT | Section.TITLE_BAR);
+ section.setText("Extensions");
+ section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Composite tableAndButtonComposite = getWidgetFactory().createComposite(leftContent, SWT.FLAT);
+ tableAndButtonComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ tableAndButtonComposite.setLayout(gridLayout);
+
+ extensionTreeViewer = new TreeViewer(tableAndButtonComposite, SWT.FLAT | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LINE_SOLID);
+ MenuManager menuManager = new MenuManager();
+ extensionTreeViewer.getTree().setMenu(menuManager.createContextMenu(extensionTreeViewer.getTree()));
+ menuManager.addMenuListener(new DOMExtensionItemMenuListener(extensionTreeViewer));
+
+ gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ extensionTreeViewer.getTree().setLayout(gridLayout);
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+
+ extensionTreeViewer.getTree().setLayoutData(gridData);
+ extensionTreeViewer.setContentProvider(extensionTreeContentProvider);
+ extensionTreeViewer.setLabelProvider(extensionTreeLabelProvider);
+ elementSelectionChangedListener = new ElementSelectionChangedListener();
+ extensionTreeViewer.addSelectionChangedListener(elementSelectionChangedListener);
+ extensionTreeViewer.getTree().addMouseTrackListener(new MouseTrackAdapter()
+ {
+ public void mouseHover(org.eclipse.swt.events.MouseEvent e)
+ {
+ ISelection selection = extensionTreeViewer.getSelection();
+ if (selection instanceof StructuredSelection)
+ {
+ Object obj = ((StructuredSelection) selection).getFirstElement();
+ if (obj instanceof Element)
+ {
+ Element element = (Element) obj;
+ ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
+ // ApplicationSpecificSchemaProperties[] properties =
+ // registry.getAllApplicationSpecificSchemaProperties();
+ // ApplicationSpecificSchemaProperties[] properties =
+ // (ApplicationSpecificSchemaProperties[])
+ // registry.getAllApplicationSpecificSchemaProperties().toArray(new
+ // ApplicationSpecificSchemaProperties[0]);
+ List properties = registry.getAllExtensionsSchemasContribution();
+
+ int length = properties.size();
+ for (int i = 0; i < length; i++)
+ {
+ SpecificationForExtensionsSchema current = (SpecificationForExtensionsSchema) properties.get(i);
+ if (current.getNamespaceURI().equals(element.getNamespaceURI()))
+ {
+ extensionTreeViewer.getTree().setToolTipText(current.getDescription());
+ break;
+ }
+ }
+ }
+ }
+ };
+
+ });
+
+ Composite buttonComposite = getWidgetFactory().createComposite(tableAndButtonComposite, SWT.FLAT);
+ //ColumnLayout columnLayout = new ColumnLayout();
+ //buttonComposite.setLayout(columnLayout);
+ buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+ gridLayout = new GridLayout();
+ gridLayout.marginTop = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.numColumns = 1;
+ gridLayout.makeColumnsEqualWidth = true;
+ buttonComposite.setLayout(gridLayout);
+
+ addButton = getWidgetFactory().createButton(buttonComposite, "Add...", SWT.FLAT);
+ addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ addButton.addSelectionListener(this);
+ addButton.setToolTipText("Add Extension Component");
+ //addButton.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL));
+ addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ removeButton = getWidgetFactory().createButton(buttonComposite, "Remove", SWT.FLAT);
+ removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ removeButton.addSelectionListener(this);
+ removeButton.setToolTipText("Remove Extension Component");
+ //removeButton.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL));
+
+ Button up = getWidgetFactory().createButton(buttonComposite, "Up", SWT.FLAT);
+ //up.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL));
+ up.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Button down = getWidgetFactory().createButton(buttonComposite, "Down", SWT.FLAT);
+ //down.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL));
+ down.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Composite rightContent = getWidgetFactory().createComposite(sashForm, SWT.FLAT);
+ Section section2 = getWidgetFactory().createSection(rightContent, SWT.FLAT | Section.TITLE_BAR);
+ section2.setText("Extension Details");
+ section2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ //contentLabel = getWidgetFactory().createLabel(rightContent, "Content");
+
+ Composite testComp = getWidgetFactory().createComposite(rightContent, SWT.FLAT);
+
+ gridLayout = new GridLayout();
+ gridLayout.marginTop = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.marginLeft = 0;
+ gridLayout.marginRight = 0;
+ gridLayout.numColumns = 1;
+ gridLayout.marginHeight = 3;
+ gridLayout.marginWidth = 3;
+ rightContent.setLayout(gridLayout);
+
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ rightContent.setLayoutData(gridData);
+
+ gridLayout = new GridLayout();
+ gridLayout.marginTop = 0;
+ gridLayout.marginLeft = 0;
+ gridLayout.marginRight = 0;
+ gridLayout.marginBottom = 0;
+ gridLayout.marginHeight = 3;
+ gridLayout.marginWidth = 3;
+ gridLayout.numColumns = 2;
+ testComp.setLayout(gridLayout);
+
+ gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalAlignment = GridData.FILL;
+ testComp.setLayoutData(gridData);
+
+ createElementContentWidget(testComp);
+
+ int[] weights = { 50, 50 };
+ sashForm.setWeights(weights);
+
+ pageBook.showPage(pageBook2);
+ }
+
+ protected void createElementContentWidget(Composite parent)
+ {
+ extensionDetailsViewer = new ExtensionDetailsViewer(parent, getWidgetFactory());
+ extensionDetailsViewer.setEditManager(new DOMExtensionItemEditManager());
+ extensionDetailsViewer.setContentProvider(new DOMExtensionDetailsContentProvider());
+ extensionDetailsViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
+ }
+
+ /*
+ * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
+ */
+ public void refresh()
+ {
+ setListenerEnabled(false);
+ if (input != null)
+ {
+ extensionDetailsViewer.setInput(null);
+ //extensionDetailsViewer.getTree().removeAll();
+ extensionTreeViewer.getTree().removeAll();
+
+ extensionTreeViewer.setInput(input);
+
+ if (extensionTreeViewer.getTree().getSelectionCount() == 0)
+ {
+ TreeItem treeItem = extensionTreeViewer.getTree().getItem(0);
+ if (treeItem != null)
+ {
+ extensionDetailsViewer.setInput(treeItem.getData());
+ extensionDetailsViewer.refresh();
+ }
+ }
+
+ }
+ setListenerEnabled(true);
+
+ }
+
+ public Composite getPage()
+ {
+ return page;
+ }
+
+ protected abstract AddExtensionCommand getAddExtensionCommand(Object o);
+ protected abstract Command getRemoveExtensionCommand(Object o);
+
+ public void widgetSelected(SelectionEvent event)
+ {
+ if (event.widget == addButton)
+ {
+ ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
+ AddExtensionsComponentDialog dialog = new AddExtensionsComponentDialog(composite.getShell(), registry);
+
+ List properties = registry.getAllExtensionsSchemasContribution();
+
+ dialog.setInput(properties);
+ dialog.setBlockOnOpen(true);
+
+ if (dialog.open() == Window.OK)
+ {
+ Object newSelection = null;
+ Object[] result = dialog.getResult();
+ if (result != null)
+ {
+ SpecificationForExtensionsSchema extensionsSchemaSpec = (SpecificationForExtensionsSchema) result[1];
+ AddExtensionCommand addExtensionCommand = getAddExtensionCommand(result[0]);
+ if (addExtensionCommand != null)
+ {
+ addExtensionCommand.setSchemaProperties(extensionsSchemaSpec);
+ if (getCommandStack() != null)
+ {
+ getCommandStack().execute(addExtensionCommand);
+ newSelection = addExtensionCommand.getNewObject();
+ }
+ }
+ }
+ extensionTreeViewer.refresh();
+ refresh();
+ if (newSelection != null)
+ {
+ extensionTreeViewer.setSelection(new StructuredSelection(newSelection));
+ }
+ }
+
+ }
+ else if (event.widget == removeButton)
+ {
+ ISelection selection = extensionTreeViewer.getSelection();
+
+ if (selection instanceof StructuredSelection)
+ {
+ Object o = ((StructuredSelection) selection).getFirstElement();
+ Command command = getRemoveExtensionCommand(o);
+ if (getCommandStack() != null)
+ {
+ getCommandStack().execute(command);
+ extensionTreeViewer.setInput(input);
+ extensionTreeViewer.refresh();
+
+ if (extensionTreeViewer.getTree().getItemCount() > 0)
+ {/*
+ // TODO (cs) I think this code is intended to set a selection
+ // now that an object can been removed ... need to fix this
+ Object object = extensionTreeViewer.get
+ if (object != null)
+ {
+ extensionTreeViewer.setSelection(new StructuredSelection(object));
+ }
+ */
+ }
+ else
+ {
+ extensionDetailsViewer.setInput(null);
+ }
+ }
+ }
+ }
+ else if (event.widget == extensionTreeViewer.getTree())
+ {
+
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent event)
+ {
+
+ }
+
+ public boolean shouldUseExtraSpace()
+ {
+ return true;
+ }
+
+ public void dispose()
+ {
+ documentChangeNotifier.removeListener(internalNodeAdapter);
+ }
+
+
+ Element selectedElement;
+
+ class ElementSelectionChangedListener implements ISelectionChangedListener
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ ISelection selection = event.getSelection();
+ if (selection instanceof StructuredSelection)
+ {
+ Object obj = ((StructuredSelection) selection).getFirstElement();
+ if (obj instanceof Element)
+ {
+ selectedElement = (Element) obj;
+ extensionDetailsViewer.setInput(obj);
+ //extensionDetailsViewer.setASIElement(selectedElement);
+ //extensionDetailsViewer.setCommandStack(getCommandStack());
+ }
+ }
+ }
+ }
+
+ public ITreeContentProvider getExtensionTreeContentProvider()
+ {
+ return extensionTreeContentProvider;
+ }
+
+ public void setExtensionTreeContentProvider(ITreeContentProvider extensionTreeContentProvider)
+ {
+ this.extensionTreeContentProvider = extensionTreeContentProvider;
+ }
+
+ public ILabelProvider getExtensionTreeLabelProvider()
+ {
+ return extensionTreeLabelProvider;
+ }
+
+ public void setExtensionTreeLabelProvider(ILabelProvider extensionTreeLabelProvider)
+ {
+ this.extensionTreeLabelProvider = extensionTreeLabelProvider;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/ExtensionsSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/ExtensionsSection.java
index f56e24b..9da71df 100644
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/ExtensionsSection.java
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/ExtensionsSection.java
@@ -10,572 +10,61 @@
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.common.properties.sections;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.gef.commands.Command;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-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.Label;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.wst.xsd.ui.internal.common.commands.AddAppInfoAttributeCommand;
-import org.eclipse.wst.xsd.ui.internal.common.commands.AddAppInfoCommand;
-import org.eclipse.wst.xsd.ui.internal.common.commands.AddAppInfoElementCommand;
-import org.eclipse.wst.xsd.ui.internal.common.commands.RemoveAppInfoAttrCommand;
-import org.eclipse.wst.xsd.ui.internal.common.commands.RemoveAppInfoElementCommand;
-import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.AddExtensionsComponentDialog;
-import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.ExtensionsComponentTableTreeViewer;
-import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.ExtensionsSchemasRegistry;
-import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema;
-import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils;
-import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
+import org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionAttributeCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionElementCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.RemoveExtensionAttributerCommand;
+import org.eclipse.wst.xsd.ui.internal.common.commands.RemoveExtensionElementCommand;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.DOMExtensionTreeLabelProvider;
+import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.XSDExtensionTreeContentProvider;
import org.eclipse.xsd.XSDAnnotation;
import org.eclipse.xsd.XSDAttributeDeclaration;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.util.XSDConstants;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-public class ExtensionsSection extends AbstractSection
+public class ExtensionsSection extends AbstractExtensionsSection
{
- protected static final Image DEFAULT_ELEMENT_ICON = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif");
- protected static final Image DEFAULT_ATTR_ICON = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif");
- protected ExtensionsComponentTableTreeViewer tableTree;
- protected TableViewer extensibleElementsTable;
- protected Label extensibilityElementsLabel, contentLabel;
- protected ISelectionChangedListener elementSelectionChangedListener;
-
- private Composite page, pageBook2;
- private Button addButton, removeButton;
- private PageBook pageBook;
-
- /**
- *
- */
public ExtensionsSection()
{
super();
+ setExtensionTreeLabelProvider(new DOMExtensionTreeLabelProvider());
+ setExtensionTreeContentProvider(new XSDExtensionTreeContentProvider());
}
- public void createContents(Composite parent)
+ protected AddExtensionCommand getAddExtensionCommand(Object o)
{
- composite = getWidgetFactory().createFlatFormComposite(parent);
-
- GridLayout gridLayout = new GridLayout();
- gridLayout.marginTop = 0;
- gridLayout.marginBottom = 0;
- gridLayout.numColumns = 1;
- composite.setLayout(gridLayout);
-
- GridData gridData = new GridData();
-
- page = getWidgetFactory().createComposite(composite);
- gridLayout = new GridLayout();
- gridLayout.marginTop = 0;
- gridLayout.marginBottom = 0;
- gridLayout.numColumns = 1;
- page.setLayout(gridLayout);
-
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- page.setLayoutData(gridData);
-
- pageBook = new PageBook(page, SWT.FLAT);
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- pageBook.setLayoutData(gridData);
-
- pageBook2 = getWidgetFactory().createComposite(pageBook, SWT.FLAT);
-
- gridLayout = new GridLayout();
- gridLayout.marginHeight = 2;
- gridLayout.marginWidth = 2;
- gridLayout.numColumns = 1;
- pageBook2.setLayout(gridLayout);
-
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- pageBook2.setLayoutData(gridData);
-
- SashForm sashForm = new SashForm(pageBook2, SWT.HORIZONTAL);
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- sashForm.setLayoutData(gridData);
-
- Composite leftContent = getWidgetFactory().createComposite(sashForm, SWT.FLAT);
- gridLayout = new GridLayout();
- gridLayout.numColumns = 1;
- leftContent.setLayout(gridLayout);
-
- extensibilityElementsLabel = getWidgetFactory().createLabel(leftContent, "Extensibility Items");
- extensibleElementsTable = new TableViewer(leftContent, SWT.FLAT | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LINE_SOLID);
- gridLayout = new GridLayout();
- gridLayout.numColumns = 1;
- extensibleElementsTable.getTable().setLayout(gridLayout);
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- extensibleElementsTable.getTable().setLayoutData(gridData);
- extensibleElementsTable.setContentProvider(new ElementTableContentProvider());
- extensibleElementsTable.setLabelProvider(new ElementTableLabelProvider());
- elementSelectionChangedListener = new ElementSelectionChangedListener();
- extensibleElementsTable.addSelectionChangedListener(elementSelectionChangedListener);
- extensibleElementsTable.getTable().addMouseTrackListener(new MouseTrackAdapter()
+ AddExtensionCommand addExtensionCommand = null;
+ if (o instanceof XSDElementDeclaration)
{
- public void mouseHover(org.eclipse.swt.events.MouseEvent e)
- {
- ISelection selection = extensibleElementsTable.getSelection();
- if (selection instanceof StructuredSelection)
- {
- Object obj = ((StructuredSelection) selection).getFirstElement();
- if (obj instanceof Element)
- {
- Element element = (Element) obj;
- ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
- // ApplicationSpecificSchemaProperties[] properties =
- // registry.getAllApplicationSpecificSchemaProperties();
- // ApplicationSpecificSchemaProperties[] properties =
- // (ApplicationSpecificSchemaProperties[])
- // registry.getAllApplicationSpecificSchemaProperties().toArray(new
- // ApplicationSpecificSchemaProperties[0]);
- List properties = registry.getAllExtensionsSchemasContribution();
-
- int length = properties.size();
- for (int i = 0; i < length; i++)
- {
- SpecificationForExtensionsSchema current = (SpecificationForExtensionsSchema) properties.get(i);
- if (current.getNamespaceURI().equals(element.getNamespaceURI()))
- {
- extensibleElementsTable.getTable().setToolTipText(current.getDescription());
- break;
- }
- }
- }
- }
- };
-
- });
-
- Composite rightContent = getWidgetFactory().createComposite(sashForm, SWT.FLAT);
-
- contentLabel = getWidgetFactory().createLabel(rightContent, "Content");
-
- Composite testComp = getWidgetFactory().createComposite(rightContent, SWT.FLAT);
-
- gridLayout = new GridLayout();
- gridLayout.marginTop = 0;
- gridLayout.marginBottom = 0;
- gridLayout.marginLeft = 0;
- gridLayout.marginRight = 0;
- gridLayout.numColumns = 1;
- gridLayout.marginHeight = 3;
- gridLayout.marginWidth = 3;
- rightContent.setLayout(gridLayout);
-
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- rightContent.setLayoutData(gridData);
-
- gridLayout = new GridLayout();
- gridLayout.marginTop = 0;
- gridLayout.marginLeft = 0;
- gridLayout.marginRight = 0;
- gridLayout.marginBottom = 0;
- gridLayout.marginHeight = 3;
- gridLayout.marginWidth = 3;
- gridLayout.numColumns = 1;
- testComp.setLayout(gridLayout);
-
- gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- testComp.setLayoutData(gridData);
-
- createElementContentWidget(testComp);
-
- int[] weights = { 30, 70 };
- sashForm.setWeights(weights);
-
- Composite buttonComposite = getWidgetFactory().createComposite(pageBook2, SWT.FLAT);
- gridLayout = new GridLayout();
- gridLayout.marginTop = 0;
- gridLayout.marginBottom = 0;
- gridLayout.numColumns = 2;
- gridLayout.makeColumnsEqualWidth = true;
- buttonComposite.setLayout(gridLayout);
- addButton = getWidgetFactory().createButton(buttonComposite, "Add...", SWT.FLAT);
- addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- addButton.addSelectionListener(this);
- addButton.setToolTipText("Add Extension Component");
- removeButton = getWidgetFactory().createButton(buttonComposite, "Remove", SWT.FLAT);
- removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- removeButton.addSelectionListener(this);
- removeButton.setToolTipText("Remove Extension Component");
-
- pageBook.showPage(pageBook2);
+ XSDElementDeclaration element = (XSDElementDeclaration) o;
+ addExtensionCommand = new AddExtensionElementCommand("Add AppInfo Element", (XSDConcreteComponent) input, element);
+ }
+ else if (o instanceof XSDAttributeDeclaration)
+ {
+ XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
+ addExtensionCommand = new AddExtensionAttributeCommand("Add AppInfo Attribute", (XSDConcreteComponent) input, attribute);
+ }
+ return addExtensionCommand;
}
- protected void createElementContentWidget(Composite parent)
+ protected Command getRemoveExtensionCommand(Object o)
{
- tableTree = new ExtensionsComponentTableTreeViewer(parent);
- GridData gridData = new GridData();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
-
- tableTree.getControl().setLayoutData(gridData);
- }
-
- /*
- * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh()
- */
- public void refresh()
- {
- setListenerEnabled(false);
- if (input != null)
+ Command command = null;
+ if (o instanceof Element)
{
- tableTree.setInput(null);
- tableTree.getTree().removeAll();
- extensibleElementsTable.getTable().removeAll();
-
- extensibleElementsTable.setInput(input);
-
- if (extensibleElementsTable.getTable().getSelectionCount() == 0)
- {
- Object o = extensibleElementsTable.getElementAt(0);
- if (o != null)
- {
- extensibleElementsTable.setSelection(new StructuredSelection(o));
- if (o instanceof Element)
- {
- tableTree.setInput(((Element) o).getParentNode());
- }
- }
- tableTree.refresh();
- }
-
+ XSDAnnotation xsdAnnotation = (XSDAnnotation) extensionTreeViewer.getInput();
+ Node appInfoElement = ((Element) o).getParentNode();
+ command = new RemoveExtensionElementCommand("Remove AppInfo Element", xsdAnnotation, appInfoElement);
}
- setListenerEnabled(true);
-
- }
-
- public Composite getPage()
- {
- return page;
- }
-
- public void widgetSelected(SelectionEvent event)
- {
- if (event.widget == addButton)
+ else if (o instanceof Attr)
{
- ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
- AddExtensionsComponentDialog dialog = new AddExtensionsComponentDialog(composite.getShell(), registry);
-
- List properties = registry.getAllExtensionsSchemasContribution();
-
- dialog.setInput(properties);
- dialog.setBlockOnOpen(true);
-
- if (dialog.open() == Window.OK)
- {
- Object[] result = dialog.getResult();
- if (result != null)
- {
- SpecificationForExtensionsSchema extensionsSchemaSpec = (SpecificationForExtensionsSchema) result[1];
- if (input instanceof XSDConcreteComponent)
- {
- AddAppInfoCommand addAppInfo = null;
- if (result[0] instanceof XSDElementDeclaration)
- {
- XSDElementDeclaration element = (XSDElementDeclaration) result[0];
- addAppInfo = new AddAppInfoElementCommand("Add AppInfo Element", (XSDConcreteComponent) input, element);
- }
- else if (result[0] instanceof XSDAttributeDeclaration)
- {
- XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) result[0];
- addAppInfo = new AddAppInfoAttributeCommand("Add AppInfo Attribute", (XSDConcreteComponent) input, attribute);
- }
- else
- return;
-
- addAppInfo.setSchemaProperties(extensionsSchemaSpec);
- if (getCommandStack() != null)
- {
- getCommandStack().execute(addAppInfo);
- }
- }
- }
- extensibleElementsTable.refresh();
- refresh();
- }
-
+ Element hostElement = ((Attr) o).getOwnerElement();
+ command = new RemoveExtensionAttributerCommand("Remove AppInfo Attribute", hostElement, (Attr) o);
}
- else if (event.widget == removeButton)
- {
- ISelection selection = extensibleElementsTable.getSelection();
-
- if (selection instanceof StructuredSelection)
- {
- Command command = null;
- Object o = ((StructuredSelection) selection).getFirstElement();
- if (o instanceof Element)
- {
- XSDAnnotation xsdAnnotation = (XSDAnnotation) extensibleElementsTable.getInput();
- Node appInfoElement = ((Element) o).getParentNode();
- command = new RemoveAppInfoElementCommand("Remove AppInfo Element",
- xsdAnnotation, appInfoElement);
- }
- else if (o instanceof Attr){
- Element hostElement = ((Attr) o).getOwnerElement();
- command = new RemoveAppInfoAttrCommand("Remove AppInfo Attribute",
- hostElement, (Attr) o);
- }
- else
- return;
- if (getCommandStack() != null)
- {
- getCommandStack().execute(command);
- extensibleElementsTable.setInput(input);
- extensibleElementsTable.refresh();
-
- if (extensibleElementsTable.getTable().getItemCount() > 0)
- {
- Object object = extensibleElementsTable.getElementAt(0);
- if (object != null)
- {
- extensibleElementsTable.setSelection(new StructuredSelection(object));
- }
- }
- else
- {
- tableTree.setInput(null);
- }
- }
- }
- }
- else if (event.widget == extensibleElementsTable.getTable())
- {
-
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent event)
- {
-
- }
-
- public boolean shouldUseExtraSpace()
- {
- return true;
- }
-
- public void dispose()
- {
-
- }
-
- static class ElementTableContentProvider implements IStructuredContentProvider
- {
- protected String facet;
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
- {
- }
-
- public java.lang.Object[] getElements(java.lang.Object inputElement)
- {
- if (inputElement instanceof XSDConcreteComponent)
- {
- XSDConcreteComponent component = (XSDConcreteComponent) inputElement;
- List elementsAndAttributes = new ArrayList();
-
- /** Construct elements list */
- XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
- if (xsdAnnotation != null)
- {
- List appInfoList = xsdAnnotation.getApplicationInformation();
- Element appInfoElement = null;
- if (appInfoList.size() > 0)
- {
- appInfoElement = (Element) appInfoList.get(0);
- }
- if (appInfoElement != null)
- {
- for (Iterator it = appInfoList.iterator(); it.hasNext();)
- {
- Object obj = it.next();
- if (obj instanceof Element)
- {
- Element appInfo = (Element) obj;
- NodeList nodeList = appInfo.getChildNodes();
- int length = nodeList.getLength();
- for (int i = 0; i < length; i++)
- {
- Node node = nodeList.item(i);
- if (node instanceof Element)
- {
- elementsAndAttributes.add(node);
- }
- }
- }
- }
- }
- }
-
- /** Construct attributes list */
- NamedNodeMap attributes = component.getElement().getAttributes();
- if ( attributes != null ){
- //String defaultNamespace = (String)component.getSchema().getQNamePrefixToNamespaceMap().get("");
- int length = attributes.getLength();
- for (int i = 0; i < length; i++){
- Node oneAttribute = attributes.item(i);
- if (!isXmlnsAttribute(oneAttribute))
- {
- String namespace = oneAttribute.getNamespaceURI();
- boolean isExtension = true;
- if (namespace == null && oneAttribute.getPrefix() == null)
- {
- isExtension = false;
- }
- else if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace))
- {
- isExtension = true;
- }
- if (isExtension)
- {
- elementsAndAttributes.add(oneAttribute);
- }
- }
- }
- }
- return elementsAndAttributes.toArray();
- }
- return Collections.EMPTY_LIST.toArray();
- }
-
- private static boolean isXmlnsAttribute(Node attribute)
- {
- String prefix = attribute.getPrefix();
- if (prefix != null)
- {
- // this handle the xmlns:foo="blah" case
- return "xmlns".equals(prefix);
- }
- else
- {
- // this handles the xmlns="blah" case
- return "xmlns".equals(attribute.getNodeName());
- }
- }
-
- public void dispose()
- {
-
- }
- }
-
- static class ElementTableLabelProvider extends LabelProvider implements ITableLabelProvider
- {
- public Image getColumnImage(Object element, int columnIndex)
- {
- ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
- if (element instanceof Element)
- {
- Element domElement = (Element) element;
- ILabelProvider lp = registry.getLabelProvider(domElement);
- if (lp != null)
- {
- Image img = lp.getImage(domElement);
- if (img != null)
- return img;
- }
- return DEFAULT_ELEMENT_ICON;
- }
- if (element instanceof Attr)
- return DEFAULT_ATTR_ICON;
- return null;
- }
-
- public String getColumnText(Object input, int columnIndex)
- {
- if (input instanceof Element)
- {
- Element domElement = (Element) input;
- return domElement.getLocalName();
- }
- if ( input instanceof Attr){
- return ((Attr) input).getLocalName();
- }
- return "";
- }
- }
-
- Element selectedElement;
-
- class ElementSelectionChangedListener implements ISelectionChangedListener
- {
- public void selectionChanged(SelectionChangedEvent event)
- {
- ISelection selection = event.getSelection();
- if (selection instanceof StructuredSelection)
- {
- Object obj = ((StructuredSelection) selection).getFirstElement();
- if (obj instanceof Element)
- {
- selectedElement = (Element) obj;
- tableTree.setInput(selectedElement.getParentNode());
- tableTree.setASIElement(selectedElement);
- tableTree.setCommandStack(getCommandStack());
- contentLabel.setText("Structure of " + selectedElement.getLocalName());
- contentLabel.getParent().layout();
- }
- }
- }
-
- }
-
-}
+ return command;
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/IDocumentChangedNotifier.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/IDocumentChangedNotifier.java
new file mode 100644
index 0000000..d5fb565
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/IDocumentChangedNotifier.java
@@ -0,0 +1,9 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections;
+
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
+
+public interface IDocumentChangedNotifier
+{
+ public void addListener(INodeAdapter adapter);
+ public void removeListener(INodeAdapter adapter);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionDetailsContentProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionDetailsContentProvider.java
new file mode 100644
index 0000000..b4568b3
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionDetailsContentProvider.java
@@ -0,0 +1,105 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import java.util.Collection;
+import java.util.HashMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+
+public class DOMExtensionDetailsContentProvider implements ExtensionDetailsContentProvider
+{
+ private static Object[] EMPTY_ARRAY = {};
+ private static String[] EMPTY_STRING_ARRAY = {};
+ public Object[] getItems(Object input)
+ {
+ HashMap resultMap = new HashMap();
+ if (input instanceof Element)
+ {
+ Element element = (Element)input;
+ NamedNodeMap attributes = element.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++)
+ {
+ Attr attr = (Attr)attributes.item(i);
+ if (!"xmlns".equals(attr.getName()) && !"xmlns".equals(attr.getPrefix()))
+ {
+ resultMap.put(attr.getName(), new DOMExtensionItem(attr));
+ }
+ }
+ ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
+ if (modelQuery != null)
+ {
+ CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element);
+ if (ed != null)
+ {
+ CMNamedNodeMap attrMap = ed.getAttributes();
+ if (attrMap != null)
+ {
+ int attrMapLength = attrMap.getLength();
+ for (int i = 0; i < attrMapLength; i++)
+ {
+ CMAttributeDeclaration ad = (CMAttributeDeclaration) attrMap.item(i);
+ if (resultMap.get(ad.getNodeName()) == null)
+ {
+ resultMap.put(ad.getNodeName(), new DOMExtensionItem(element, ad));
+ }
+ }
+ }
+ //
+ int contentType = ed.getContentType();
+ if ((contentType == CMElementDeclaration.PCDATA ||
+ contentType == CMElementDeclaration.PCDATA) &&
+ ed.getDataType() != null)
+ {
+ resultMap.put("text()", new DOMExtensionItem(element, ed));
+ }
+ }
+ }
+ Collection collection = resultMap.values();
+ DOMExtensionItem[] items = new DOMExtensionItem[collection.size()];
+ resultMap.values().toArray(items);
+ return items;
+ }
+ else if (input instanceof Attr)
+ {
+ Attr attr = (Attr)input;
+ DOMExtensionItem item = new DOMExtensionItem(attr);
+ DOMExtensionItem[] items = {item};
+ return items;
+ }
+ return EMPTY_ARRAY;
+ }
+
+
+ public String getName(Object item)
+ {
+ if (item instanceof DOMExtensionItem)
+ {
+ return ((DOMExtensionItem)item).getName();
+ }
+ return "";
+ }
+
+ public String getValue(Object item)
+ {
+ if (item instanceof DOMExtensionItem)
+ {
+ return ((DOMExtensionItem)item).getValue();
+ }
+ return "";
+ }
+
+ public String[] getPossibleValues(Object item)
+ {
+ if (item instanceof DOMExtensionItem)
+ {
+ return ((DOMExtensionItem)item).getPossibleValues();
+ }
+ return EMPTY_STRING_ARRAY;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItem.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItem.java
new file mode 100644
index 0000000..2f8be97
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItem.java
@@ -0,0 +1,127 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import org.eclipse.gef.commands.Command;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+class DOMExtensionItem
+{
+ Node node;
+ Element parent;
+ CMNode cmNode;
+
+ DOMExtensionItem(Node node)
+ {
+ this.node = node;
+ }
+
+ DOMExtensionItem(Element parent, CMElementDeclaration ed)
+ {
+ this.parent = parent;
+ this.cmNode = ed;
+ }
+
+ DOMExtensionItem(Element parent, CMAttributeDeclaration ad)
+ {
+ this.parent = parent;
+ this.cmNode = ad;
+ }
+
+ public String getName()
+ {
+ if (node instanceof Attr)
+ {
+ Attr attr = (Attr)node;
+ return attr.getName();
+ }
+ else if (cmNode instanceof CMAttributeDeclaration)
+ {
+ CMAttributeDeclaration ad = (CMAttributeDeclaration)cmNode;
+ return ad.getNodeName() + "*";
+ }
+ else if (cmNode instanceof CMDataType)
+ {
+ return "text()";
+ }
+ return "";
+ }
+
+ public String getValue()
+ {
+ if (node instanceof Attr)
+ {
+ Attr attr = (Attr)node;
+ return attr.getValue();
+ }
+ return "";
+ }
+
+ public String[] getPossibleValues()
+ {
+ String[] result = {};
+ if (node instanceof Attr)
+ {
+ Attr attr = (Attr)node;
+ ModelQuery modelQuery = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());
+ if (modelQuery != null)
+ {
+ CMAttributeDeclaration ad = modelQuery.getCMAttributeDeclaration(attr);
+ if (ad != null)
+ {
+ result = modelQuery.getPossibleDataTypeValues(attr.getOwnerElement(), ad);
+ }
+ }
+ }
+ else if (parent != null)
+ {
+ if (cmNode == null || cmNode instanceof CMDataType)
+ {
+ // TODO
+ //
+ }
+ else if (cmNode instanceof CMAttributeDeclaration)
+ {
+ CMAttributeDeclaration ad = (CMAttributeDeclaration)cmNode;
+ ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
+ if (modelQuery != null)
+ {
+ result = modelQuery.getPossibleDataTypeValues(parent, ad);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Command getUpdateValueCommand(String newValue)
+ {
+ if (node instanceof Attr)
+ {
+ Attr attr = (Attr)node;
+ return new UpdateAttributeValueCommand(attr.getOwnerElement(), attr.getNodeName(), newValue);
+ }
+ else if (parent != null)
+ {
+ if (cmNode == null || cmNode instanceof CMDataType)
+ {
+ // in this case we need to update the parent's text
+ //
+ }
+ else if (cmNode instanceof CMAttributeDeclaration)
+ {
+ // TODO (cs) add namespace prefix to attribute name if req'd
+ //
+ CMAttributeDeclaration ad = (CMAttributeDeclaration)cmNode;
+ return new UpdateAttributeValueCommand(parent, ad.getAttrName(), newValue);
+ }
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemEditManager.java
new file mode 100644
index 0000000..6c771e1
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemEditManager.java
@@ -0,0 +1,80 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import org.eclipse.gef.commands.Command;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
+
+public class DOMExtensionItemEditManager implements ExtensionItemEditManager
+{
+ public void handleEdit(Object item, Widget widget)
+ {
+ if (item instanceof DOMExtensionItem)
+ {
+ DOMExtensionItem extensionItem = (DOMExtensionItem)item;
+ String value = null;
+ if (widget instanceof Text)
+ {
+ Text text = (Text)widget;
+ value = text.getText();
+ }
+ else if (widget instanceof CCombo)
+ {
+ CCombo combo = (CCombo)widget;
+ int index = combo.getSelectionIndex();
+ if (index != -1)
+ {
+ value = combo.getItem(index);
+ }
+ }
+ if (value != null)
+ {
+ Command command = extensionItem.getUpdateValueCommand(value);
+ if (command != null)
+ {
+ // TODO (cs) add command stack handling stuff
+ command.execute();
+ }
+ }
+ }
+ }
+
+ public Control createCustomButtonControl(Composite composite, Object item)
+ {
+ Button button = new Button(composite, SWT.NONE);
+ button.setText("...");
+ return button;
+ }
+
+ public Control createCustomTextControl(Composite composite, Object item)
+ {
+ return null;
+ }
+
+ public String getButtonControlStyle(Object object)
+ {
+ /*
+ DOMExtensionItem item = (DOMExtensionItem)object;
+ if (item.getName().startsWith("n"))
+ {
+ return ExtensionItemEditManager.STYLE_CUSTOM;
+ }*/
+ return ExtensionItemEditManager.STYLE_NONE;
+ }
+
+ public String getTextControlStyle(Object object)
+ {
+ DOMExtensionItem item = (DOMExtensionItem)object;
+ String[] values = item.getPossibleValues();
+
+ if (values != null && values.length > 1)
+ {
+ return ExtensionItemEditManager.STYLE_COMBO;
+ }
+ return ExtensionItemEditManager.STYLE_TEXT;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemMenuListener.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemMenuListener.java
new file mode 100644
index 0000000..1c8bcf5
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemMenuListener.java
@@ -0,0 +1,117 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.document.ElementImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class DOMExtensionItemMenuListener implements IMenuListener
+{
+ TreeViewer treeViewer;
+
+ public DOMExtensionItemMenuListener(TreeViewer treeViewer)
+ {
+ this.treeViewer = treeViewer;
+ }
+
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ manager.removeAll();
+ ISelection selection = treeViewer.getSelection();
+ if (selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ if (structuredSelection.getFirstElement() instanceof ElementImpl)
+ {
+ ElementImpl elementImpl = (ElementImpl) structuredSelection.getFirstElement();
+ IDOMDocument domDocument = (IDOMDocument) elementImpl.getOwnerDocument();
+ InternalNodeActionManager actionManager = new InternalNodeActionManager(domDocument.getModel(), treeViewer);
+ actionManager.fillContextMenu(manager, structuredSelection);
+ }
+ }
+ }
+
+
+ class InternalNodeActionManager extends XMLNodeActionManager
+ {
+ public InternalNodeActionManager(IStructuredModel model, Viewer viewer)
+ {
+ super(model, viewer);
+ }
+
+ public void contributeActions(IMenuManager menu, List selection)
+ {
+ //menu.add(new Action("there"){});
+ try
+ {
+ int editMode = modelQuery.getEditMode();
+ int ic = ModelQuery.INCLUDE_CHILD_NODES;
+ int vc = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.VALIDITY_STRICT : ModelQuery.VALIDITY_NONE;
+ List implicitlySelectedNodeList = null;
+
+ if (selection.size() == 1)
+ {
+ Node node = (Node) selection.get(0);
+ // contribute add child actions
+ contributeAddChildActions(menu, node, ic, vc);
+ }
+ if (selection.size() > 0)
+ {
+ implicitlySelectedNodeList = getSelectedNodes(selection, true);
+ // contribute delete actions
+ contributeDeleteActions(menu, implicitlySelectedNodeList, ic, vc);
+ }
+ }
+ catch(Exception e)
+ {
+ menu.add(new Action(e.getMessage()){});
+ }
+ /*
+ if (selection.size() > 0)
+ {
+ // contribute replace actions
+ contributeReplaceActions(menu, implicitlySelectedNodeList, ic, vc);
+ }*/
+ }
+
+ protected void contributeAddChildActions(IMenuManager menu, Node node, int ic, int vc)
+ {
+ int nodeType = node.getNodeType();
+ if (nodeType == Node.ELEMENT_NODE)
+ {
+ // 'Add Child...' and 'Add Attribute...' actions
+ //
+ Element element = (Element) node;
+ MyMenuManager newMenu = new MyMenuManager("New"){
+ public boolean isVisible() { return true; }
+ };//$NON-NLS-1$
+ newMenu.setVisible(true);
+ menu.add(newMenu);
+
+ CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element);
+ if (ed != null)
+ {
+ List modelQueryActionList = new ArrayList();
+ // add insert child node actions
+ //
+ modelQueryActionList = new ArrayList();
+ modelQuery.getInsertActions(element, ed, -1, ic, vc, modelQueryActionList);
+ addActionHelper(newMenu, modelQueryActionList);
+ }
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeContentProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeContentProvider.java
new file mode 100644
index 0000000..d76c5f3
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeContentProvider.java
@@ -0,0 +1,55 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class DOMExtensionTreeContentProvider implements ITreeContentProvider
+{
+ protected String facet;
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ }
+
+
+ public Object[] getChildren(Object parentElement)
+ {
+ if (parentElement instanceof Element)
+ {
+ Element element = (Element)parentElement;
+ ArrayList list = new ArrayList();
+ for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling())
+ {
+ if (node.getNodeType() == Node.ELEMENT_NODE)
+ {
+ list.add(node);
+ }
+ }
+ return list.toArray();
+ }
+ return Collections.EMPTY_LIST.toArray();
+ }
+
+ public boolean hasChildren(Object element)
+ {
+ Object[] children = getChildren(element);
+ return children.length > 0;
+ }
+
+ public Object getParent(Object element)
+ {
+ return null;
+ }
+
+ public java.lang.Object[] getElements(java.lang.Object inputElement)
+ {
+ return getChildren(inputElement);
+ }
+
+ public void dispose()
+ {
+ }
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeLabelProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeLabelProvider.java
new file mode 100644
index 0000000..3f48f92
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeLabelProvider.java
@@ -0,0 +1,51 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+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.editor.XSDEditorPlugin;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
+public class DOMExtensionTreeLabelProvider extends LabelProvider
+{
+ protected static final Image DEFAULT_ELEMENT_ICON = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif");
+ protected static final Image DEFAULT_ATTR_ICON = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif");
+
+ public DOMExtensionTreeLabelProvider()
+ {
+ }
+
+ public Image getImage(Object element)
+ {
+ ExtensionsSchemasRegistry registry = XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry();
+ if (element instanceof Element)
+ {
+ Element domElement = (Element) element;
+ ILabelProvider lp = registry.getLabelProvider(domElement);
+ if (lp != null)
+ {
+ Image img = lp.getImage(domElement);
+ if (img != null)
+ return img;
+ }
+ return DEFAULT_ELEMENT_ICON;
+ }
+ if (element instanceof Attr)
+ return DEFAULT_ATTR_ICON;
+ return null;
+ }
+
+ public String getText(Object input)
+ {
+ if (input instanceof Element)
+ {
+ Element domElement = (Element) input;
+ return domElement.getLocalName();
+ }
+ if ( input instanceof Attr){
+ return ((Attr) input).getLocalName();
+ }
+ return "";
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsContentProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsContentProvider.java
new file mode 100644
index 0000000..254d105
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsContentProvider.java
@@ -0,0 +1,9 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+public interface ExtensionDetailsContentProvider
+{
+ Object[] getItems(Object input);
+ String getName(Object item);
+ String getValue(Object item);
+ String[] getPossibleValues(Object item);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsViewer.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsViewer.java
new file mode 100644
index 0000000..50568b4
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsViewer.java
@@ -0,0 +1,183 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+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.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+
+public class ExtensionDetailsViewer extends Viewer
+{
+ private final static String ITEM_DATA = "ITEM_DATA";
+ Composite control;
+ Composite composite;
+ ExtensionDetailsContentProvider contentProvider;
+ TabbedPropertySheetWidgetFactory widgetFactory;
+ InternalFocusListener internalFocusListener;
+ ExtensionItemEditManager editManager;
+
+ public ExtensionDetailsViewer(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory)
+ {
+ this.widgetFactory = widgetFactory;
+ control = widgetFactory.createComposite(parent);
+ internalFocusListener = new InternalFocusListener();
+ control.setLayout(new GridLayout());
+ }
+ public Control getControl()
+ {
+ return control;
+ }
+
+
+ public Object getInput()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ISelection getSelection()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void refresh()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setInput(Object input)
+ {
+ // TODO (cs) add assertions
+ //
+ if (editManager == null)
+ return;
+
+ if (contentProvider == null)
+ return;
+
+ if (composite != null)
+ {/*
+ for (Iterator i = controlsThatWeAreListeningTo.iterator(); i.hasNext(); )
+ {
+ Control control = (Control)i.next();
+ if (control != null)
+ {
+ control.removeFocusListener(internalFocusListener);
+ }
+ } */
+ composite.dispose();
+ }
+
+ composite = widgetFactory.createComposite(control);
+ composite.setBackground(ColorConstants.white);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ composite.setLayout(gridLayout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Object[] items = contentProvider.getItems(input);
+
+ for (int i = 0; i < items.length; i++)
+ {
+ Object item = items[i];
+ String name = contentProvider.getName(item);
+ String value = contentProvider.getValue(item);
+ Label label = widgetFactory.createLabel(composite, name + ":");
+ label.setLayoutData(new GridData());
+
+ Control control = null;
+ String style = editManager.getTextControlStyle(item);
+
+ if (style == ExtensionItemEditManager.STYLE_COMBO)
+ {
+ CCombo combo = widgetFactory.createCCombo(composite);
+ combo.setText(value);
+ String[] values = contentProvider.getPossibleValues(item);
+ for (int j = 0; j < values.length; j++)
+ {
+ combo.add(values[j]);
+ }
+ control = combo;
+ }
+ else if (style == ExtensionItemEditManager.STYLE_CUSTOM)
+ {
+ control = editManager.createCustomTextControl(composite, item);
+ }
+ else // (style == ExtensionItemEditManager.STYLE_TEXT)
+ {
+ Text text = widgetFactory.createText(composite,value);
+ control = text;
+ }
+ control.setData(ITEM_DATA, item);
+ control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ control.addFocusListener(internalFocusListener);
+
+ String buttongStyle = editManager.getButtonControlStyle(item);
+ if (buttongStyle == ExtensionItemEditManager.STYLE_CUSTOM)
+ {
+ editManager.createCustomButtonControl(composite, item);
+ }
+ else
+ {
+ Control placeHolder = new Label(composite, SWT.NONE);
+ placeHolder.setVisible(false);
+ placeHolder.setEnabled(false);
+ placeHolder.setLayoutData(new GridData());
+ }
+ }
+ control.layout(true);
+ }
+
+ public void setSelection(ISelection selection, boolean reveal)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ public ExtensionDetailsContentProvider getContentProvider()
+ {
+ return contentProvider;
+ }
+ public void setContentProvider(ExtensionDetailsContentProvider contentProvider)
+ {
+ this.contentProvider = contentProvider;
+ }
+
+ class InternalFocusListener implements FocusListener
+ {
+ public void focusGained(FocusEvent e)
+ {
+ }
+
+ public void focusLost(FocusEvent e)
+ {
+ if (editManager != null)
+ {
+ Object item = e.widget.getData(ITEM_DATA);
+ if (item != null)
+ {
+ editManager.handleEdit(item, e.widget);
+ }
+ }
+ }
+ }
+
+ public ExtensionItemEditManager getEditManager()
+ {
+ return editManager;
+ }
+ public void setEditManager(ExtensionItemEditManager editManager)
+ {
+ this.editManager = editManager;
+ }
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemEditManager.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemEditManager.java
new file mode 100644
index 0000000..40dda9f
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemEditManager.java
@@ -0,0 +1,19 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Widget;
+
+public interface ExtensionItemEditManager
+{
+ public final static String STYLE_NONE = "none";
+ public final static String STYLE_TEXT = "text";
+ public final static String STYLE_COMBO = "combo";
+ public final static String STYLE_CUSTOM = "custom";
+
+ void handleEdit(Object item, Widget widget);
+ String getTextControlStyle(Object item);
+ String getButtonControlStyle(Object item);
+ Control createCustomTextControl(Composite composite, Object item);
+ Control createCustomButtonControl(Composite composite, Object item);
+}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsComponentTableTreeViewer.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsComponentTableTreeViewer.java
deleted file mode 100644
index 856ad24..0000000
--- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsComponentTableTreeViewer.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.gef.commands.CommandStack;
-import org.eclipse.gef.ui.actions.ActionRegistry;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.wst.xml.core.internal.document.ElementImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper;
-import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeContentProvider;
-import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer;
-import org.eclipse.wst.xml.ui.internal.tabletree.XMLTreeExtension;
-import org.eclipse.wst.xsd.ui.internal.common.properties.sections.XSDActionManager;
-import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-public class ExtensionsComponentTableTreeViewer extends XMLTableTreeViewer
-{
- private CommandStack commandStack;
-
- public ExtensionsComponentTableTreeViewer(Composite parent)
- {
- super(parent);
-
- getTree().setLinesVisible(true);
-
- treeExtension.setCellModifier(null);
- getTree().removePaintListener(treeExtension);
- treeExtension = new MyXMLTreeExtension(getTree());
-
- AppInfoContentProvider provider = new AppInfoContentProvider();
- setContentProvider(provider);
- setLabelProvider(provider);
- }
-
- public void setCommandStack(CommandStack commandStack) {
- this.commandStack = commandStack;
- }
-
- Element asiElement;
-
- public void setASIElement(Element asiElement)
- {
- this.asiElement = asiElement;
- }
-
- class AppInfoContentProvider extends XMLTableTreeContentProvider
- {
- MyTreeContentHelper treeContentHelper;
- public AppInfoContentProvider()
- {
- treeContentHelper = new MyTreeContentHelper();
- }
-
- public Object[] getChildren(Object element)
- {
- if (element instanceof List)
- {
- return ((List) element).toArray();
- }
- else if (element instanceof Element)
- {
-
- }
- return treeContentHelper.getChildren(element);
-
- //return super.getChildren(element);
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
- {
- if (oldInput instanceof Element)
- oldInput = ((Element) oldInput).getOwnerDocument();
-
- if (newInput instanceof Element)
- newInput = ((Element) newInput).getOwnerDocument();
-
- super.inputChanged(viewer, oldInput, newInput);
-
- }
- }
-
- class ASIActionMenuListener implements IMenuListener
- {
- public void menuAboutToShow(IMenuManager menuManager)
- {
- // used to disable NodeSelection listening while running NodeAction
- // ASIActionManager nodeActionManager = new ASIActionManager(fModel,
- // ASITableTreeViewer.this);
- // nodeActionManager.setCommandStack(commandStack);
- IDOMModel model = null;
- try
- {
- if (asiElement instanceof ElementImpl)
- {
- model = ((ElementImpl)asiElement).getModel();
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- // if the model is not the XML model, then we can't support the table viewer.
- if (model != null)
- {
- XSDActionManager actionManager = new XSDActionManager(model, ExtensionsComponentTableTreeViewer.this);
- actionManager.setCommandStack(commandStack);
-
- // add general actions
- ActionRegistry registry = (ActionRegistry) XSDEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getAdapter(ActionRegistry.class);
-
- if (registry != null) // an editor may not use the registry
- {
- // add undo, redo, revert
- IAction undo = registry.getAction(ActionFactory.UNDO.getId());
- if (undo != null)
- {
- menuManager.add(new Separator());
- menuManager.add(undo);
- }
- IAction redo = registry.getAction(ActionFactory.REDO.getId());
- if (redo != null)
- {
- menuManager.add(redo);
- }
- menuManager.add(new Separator());
- }
- actionManager.fillContextMenu(menuManager, getSelection());
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.xmleditor.internal.tabletree.XMLTableTreeViewer#createContextMenu()
- */
- protected void createContextMenu()
- {
- MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
- contextMenu.add(new Separator("additions")); //$NON-NLS-1$
- contextMenu.setRemoveAllWhenShown(true);
-
- // This is the line we have to modify
- contextMenu.addMenuListener(new ASIActionMenuListener());
- Menu menu = contextMenu.createContextMenu(getControl());
- getControl().setMenu(menu);
- }
-
-
-
-
-
- static String EMPTY_STRING = ""; //$NON-NLS-1$
- static String XML_NS_STRING = "xmlns"; //$NON-NLS-1$
- static String APPINFO = "appinfo"; //$NON-NLS-1$
-
- public class MyTreeContentHelper extends TreeContentHelper {
- public void setNodeValue(Node node, String value) {
- String oldValue = getNodeValue(node);
- // The command stack was being populated with changes like an empty string to a null value
- // So we weed those out as well
-// if (value != null && !value.equals(oldValue) && (!(value.equals(EMPTY_STRING) && oldValue ==null))) {
-// ModifyNodeCommand command = new ModifyNodeCommand(node, value, this);
-// commandStack.execute(command);
-// }
- }
-
- // TODO - Remove this method when Bugzilla 6738 is fixed
- public List getElementTextContent(Element element) {
- List result = null;
- if (!element.hasAttributes()) {
- Node node = element.getFirstChild();
-
- // TODO - Hack to workaround problem that a text cell editor appears on the first
- // click and not the enumerated cell editor
- if (node == null) {
- result = new Vector();
- Text txt = element.getOwnerDocument().createTextNode("");
- element.appendChild(txt);
- result.add(txt);
- }
- // end of workaround
-
- for (; node != null; node = node.getNextSibling()) {
- if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
- if (result == null) {
- result = new Vector();
- }
- result.add(node);
- } else {
- result = null;
- break;
- }
- }
- }
- return result;
- }
-
- public void executeSetNodeValue(Node node, String value) {
- super.setNodeValue(node, value);
- }
-
- public boolean isEditable(Node node) {
- int nodeType = node.getNodeType();
- boolean result = false;
- switch (nodeType) {
- case Node.ATTRIBUTE_NODE :
- {
- // Prevent the editing of the namespace attribute
- Attr attr = (Attr)node;
- result = !attr.getName().startsWith(XML_NS_STRING);
- break;
- }
- default:
- {
- result = super.isEditable(node);
- }
- }
- return result;
- }
-
- // Need to override since I don't want to see the source attribute
- public Object[] getChildren(Object element) {
- Object[] result = null;
-
- if (element instanceof List) {
- result = ((List)element).toArray();
- } else if (element instanceof Node) {
- Node node = (Node) element;
- List list = new ArrayList();
- boolean textContentOnly = true;
-
- // Don't want to see any attributes for the input element
- if (!(element instanceof Element && (element == getInput()))) {
- NamedNodeMap map = node.getAttributes();
- if (map != null) {
- int length = map.getLength();
- for (int i = 0; i < length; i++) {
- list.add(map.item(i));
- textContentOnly = false;
- }
- }
- }
-
- Node prevIncludedNode = null;
- for (Node childNode = node.getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
- int childNodeType = childNode.getNodeType();
- boolean includeNode = true;
-
- if (includeNode && hasStyleFlag(HIDE_WHITE_SPACE_TEXT_NODES)) {
- if (isIgnorableText(childNode)) {
- // filter out the ignorable text node
- includeNode = false;
- }
- }
-
- if (includeNode && hasStyleFlag(COMBINE_ADJACENT_TEXT_AND_ENTITY_REFERENCES)) {
- if (isTextOrEntityReferenceNode(childNode) && prevIncludedNode != null && isTextOrEntityReferenceNode(prevIncludedNode)) {
- // we only show the first of a list of adjacent text or entity reference node in the tree
- // so we filter out this subsequent one
- includeNode = false;
- }
- }
-
- if (hasStyleFlag(HIDE_ELEMENT_CHILD_TEXT_NODES)) {
- if (childNodeType != Node.TEXT_NODE && childNodeType != Node.ENTITY_REFERENCE_NODE) {
- textContentOnly = false;
- }
- }
-
- if (includeNode) {
- list.add(childNode);
- prevIncludedNode = childNode;
- }
- }
-
- if (hasStyleFlag(HIDE_ELEMENT_CHILD_TEXT_NODES) && textContentOnly) {
- result = new Object[0];
- }
- else {
- result = list.toArray();
- }
- }
- return result;
- }
-
- }
-
- class MyXMLTreeExtension extends XMLTreeExtension {
-
- public MyXMLTreeExtension(Tree tree) {
- super(tree);
- this.treeContentHelper = new MyTreeContentHelper();
- this.columnPosition = 200;
-// this.setRefreshAll(true);
- }
-
-
- // Do not wish to display any of the helper text
- public String getElementValueHelper(Element element) {
- return EMPTY_STRING;
- }
-
-
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/XSDExtensionTreeContentProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/XSDExtensionTreeContentProvider.java
new file mode 100644
index 0000000..981da69
--- /dev/null
+++ b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/XSDExtensionTreeContentProvider.java
@@ -0,0 +1,104 @@
+package org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils;
+import org.eclipse.xsd.XSDAnnotation;
+import org.eclipse.xsd.XSDConcreteComponent;
+import org.eclipse.xsd.util.XSDConstants;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class XSDExtensionTreeContentProvider extends DOMExtensionTreeContentProvider
+{
+ public Object[] getElements(Object inputElement)
+ {
+ if (inputElement instanceof XSDConcreteComponent)
+ {
+ XSDConcreteComponent component = (XSDConcreteComponent) inputElement;
+ List elementsAndAttributes = new ArrayList();
+ /** Construct elements list */
+ XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false);
+ if (xsdAnnotation != null)
+ {
+ List appInfoList = xsdAnnotation.getApplicationInformation();
+ Element appInfoElement = null;
+ if (appInfoList.size() > 0)
+ {
+ appInfoElement = (Element) appInfoList.get(0);
+ }
+ if (appInfoElement != null)
+ {
+ for (Iterator it = appInfoList.iterator(); it.hasNext();)
+ {
+ Object obj = it.next();
+ if (obj instanceof Element)
+ {
+ Element appInfo = (Element) obj;
+ NodeList nodeList = appInfo.getChildNodes();
+ int length = nodeList.getLength();
+ for (int i = 0; i < length; i++)
+ {
+ Node node = nodeList.item(i);
+ if (node instanceof Element)
+ {
+ elementsAndAttributes.add(node);
+ }
+ }
+ }
+ }
+ }
+ }
+ /** Construct attributes list */
+ NamedNodeMap attributes = component.getElement().getAttributes();
+ if (attributes != null)
+ {
+ // String defaultNamespace =
+ // (String)component.getSchema().getQNamePrefixToNamespaceMap().get("");
+ int length = attributes.getLength();
+ for (int i = 0; i < length; i++)
+ {
+ Node oneAttribute = attributes.item(i);
+ if (!isXmlnsAttribute(oneAttribute))
+ {
+ String namespace = oneAttribute.getNamespaceURI();
+ boolean isExtension = true;
+ if (namespace == null && oneAttribute.getPrefix() == null)
+ {
+ isExtension = false;
+ }
+ else if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(namespace))
+ {
+ isExtension = true;
+ }
+ if (isExtension)
+ {
+ elementsAndAttributes.add(oneAttribute);
+ }
+ }
+ }
+ }
+ return elementsAndAttributes.toArray();
+ }
+ return Collections.EMPTY_LIST.toArray();
+ }
+
+ private static boolean isXmlnsAttribute(Node attribute)
+ {
+ String prefix = attribute.getPrefix();
+ if (prefix != null)
+ {
+ // this handle the xmlns:foo="blah" case
+ return "xmlns".equals(prefix);
+ }
+ else
+ {
+ // this handles the xmlns="blah" case
+ return "xmlns".equals(attribute.getNodeName());
+ }
+ }
+}