diff options
author | nitind | 2007-11-07 22:44:08 +0000 |
---|---|---|
committer | nitind | 2007-11-07 22:44:08 +0000 |
commit | c03c0256ca5b69ac81b12862e579299899527212 (patch) | |
tree | d6f46610b3f57b36acaadbb9cc1bd86bb7ec5aec /bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties | |
parent | af2da589265ab060ee42cfc95c2ca4a72550e0d3 (diff) | |
download | webtools.sourceediting-Root_jsdtDev11082007.tar.gz webtools.sourceediting-Root_jsdtDev11082007.tar.xz webtools.sourceediting-Root_jsdtDev11082007.zip |
This commit was manufactured by cvs2svn to create tagRoot_jsdtDev11082007
'Root_jsdtDev11082007'.
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties')
56 files changed, 0 insertions, 14189 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/providers/XSDSectionLabelProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/providers/XSDSectionLabelProvider.java deleted file mode 100644 index 31f82167ed..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/providers/XSDSectionLabelProvider.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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.providers; - -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDAdapterFactory; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDSectionLabelProvider extends LabelProvider -{ - /** - * - */ - public XSDSectionLabelProvider() - { - super(); - } - - /** - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object object) - { - if (object == null || object.equals(StructuredSelection.EMPTY)) - { - return null; - } - Image result = null; - if (object instanceof StructuredSelection) - { - Object selected = ((StructuredSelection) object).getFirstElement(); - - if (selected instanceof XSDConcreteComponent) - { - XSDBaseAdapter adapter = (XSDBaseAdapter)XSDAdapterFactory.getInstance().adapt((XSDConcreteComponent)selected); - return ((ITreeElement)adapter).getImage(); - } - } - return result; - } - - /** - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object object) - { - if (object == null || object.equals(StructuredSelection.EMPTY)) - { - return org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NO_ITEMS_SELECTED; - } - - String result = null; - - boolean isReference = false; - Object selected = null; - if (object instanceof StructuredSelection) - { - selected = ((StructuredSelection) object).getFirstElement(); - - if (selected instanceof XSDConcreteComponent) - { - if (selected instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) selected; - if (xsdElementDeclaration.isElementDeclarationReference()) - { - isReference = true; - } - } else if (selected instanceof XSDAttributeDeclaration) - { - if (((XSDAttributeDeclaration) selected).isAttributeDeclarationReference()) - { - isReference = true; - } - } else if (selected instanceof XSDModelGroupDefinition) - { - if (((XSDModelGroupDefinition) selected).isModelGroupDefinitionReference()) - { - isReference = true; - } - } - StringBuffer sb = new StringBuffer(); - Element element = ((XSDConcreteComponent) selected).getElement(); - if (element != null) - { - sb.append(((XSDConcreteComponent) selected).getElement().getLocalName()); - - if (isReference) - { - sb.append(" ref");//$NON-NLS-1$ - // This string is not easily translatable to other languages. - // For now, make it english-only since we use the element tag as the title anyway -// sb.append(Messages.UI_PAGE_HEADING_REFERENCE); - } - - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); - if (workbenchWindow != null) - { - IWorkbenchPage page = workbenchWindow.getActivePage(); - if (page != null) - { - IEditorPart editorPart = page.getActiveEditor(); - XSDSchema xsdSchema = ((XSDConcreteComponent) selected).getSchema(); - if (editorPart != null && xsdSchema != editorPart.getAdapter(XSDSchema.class)) - { - sb.append(" (" + Messages.UI_LABEL_READ_ONLY + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - return sb.toString(); - } - else - { - // If the element is null, then let's use the model object to find - // an appropriate name - if ((XSDConcreteComponent) selected instanceof XSDNamedComponent) - { - return ((XSDNamedComponent)selected).getName(); - } - else if ((XSDConcreteComponent) selected instanceof XSDSchema) - { - return XSDConstants.SCHEMA_ELEMENT_TAG; - } - // last resort.... - return "(" + Messages.UI_LABEL_READ_ONLY + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - if (object instanceof Element) - { - return ((Element) object).getLocalName(); - } - } - - return result; - } -} 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 deleted file mode 100644 index 4abc23d294..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractExtensionsSection.java +++ /dev/null @@ -1,609 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -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.preference.IPreferenceStore; -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.custom.ScrolledComposite; -import org.eclipse.swt.events.MouseTrackAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -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.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.Section; -import org.eclipse.ui.views.properties.PropertySheet; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -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.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.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -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; - protected Button addButton, removeButton; - private Object prevInput; - private SpecificationForExtensionsSchema prevCategory; - - /** - * - */ - public AbstractExtensionsSection() - { - super(); - } - - class InternalNodeAdapter implements INodeAdapter - { - - public boolean isAdapterForType(Object type) - { - // this method should never be called - // we don't use objects of this class as 'standard' adapters - return true; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) - { - boolean isRoot = false; - if (notifier instanceof Element) - { - if (isTreeViewerInputElement((Element)notifier))// TODO - { - isRoot = true; - extensionTreeViewer.refresh(extensionTreeViewer.getInput()); - } - } - if (!isRoot) - { - extensionTreeViewer.refresh(notifier); - if ( newValue instanceof Element) - { - extensionTreeViewer.expandToLevel(notifier, 1); - extensionTreeViewer.setSelection(new StructuredSelection(newValue)); - } - } - } - } - - protected boolean isTreeViewerInputElement(Element element) - { - return false; - } - - 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); - - SashForm sashForm = new SashForm(page, SWT.HORIZONTAL); - // Try to limit the initial width of the section - - int w = SWT.DEFAULT; - try - { - IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); - - // Find the width of the Tabbed Property Sheet's composite excluding the tab - if (part instanceof PropertySheet) - { - PropertySheet sheet = (PropertySheet)part; - if (sheet.getCurrentPage() instanceof TabbedPropertySheetPage) - { - TabbedPropertySheetPage tabbedPage = (TabbedPropertySheetPage)sheet.getCurrentPage(); - Composite targetComposite = null; - if (tabbedPage.getControl() instanceof Composite) - { - Composite c = (Composite)tabbedPage.getControl(); - int length = c.getChildren().length; - for (int i = 0; i < length; i++) - { - Control ctrl = c.getChildren()[i]; - int length2 = (((Composite)ctrl).getChildren()).length; - for (int j = 0; j < length2; j++ ) - { - if ((((Composite)ctrl).getChildren())[j] instanceof ScrolledComposite) - { - targetComposite = (Composite)(((Composite)ctrl).getChildren())[j]; - break; - } - } - } - } - if (targetComposite != null) - { - w = targetComposite.getSize().x - 20; // ensure scrollbars don't show - } - // The above can be accomplished by the following code - // but because TabbedPropertyComposite is in an internal package, I will get a discouraged - // access warning. - // w = ((TabbedPropertyComposite)(tabbedPage.getControl())).getTabComposite().getSize().x; - } - } - } - catch(Exception e) - { - w = SWT.DEFAULT; - } - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.verticalAlignment = GridData.FILL; - gridData.horizontalAlignment = GridData.FILL; - // The initial size should be set, not the widthHint, which forces the width - // to remain constant. - sashForm.setSize(w, SWT.DEFAULT); - 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 | ExpandableComposite.TITLE_BAR); - section.setText(Messages._UI_LABEL_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 = 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; - } - } - } - } - } - - }); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(extensionTreeViewer.getControl(), - XSDEditorCSHelpIds.EXTENSIONS_TAB__EXTENSIONS); - - 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, Messages._UI_ACTION_ADD_WITH_DOTS, SWT.FLAT); - addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - addButton.addSelectionListener(this); - addButton.setToolTipText(Messages._UI_ACTION_ADD_EXTENSION_COMPONENT); - //addButton.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL)); - addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(addButton, - XSDEditorCSHelpIds.EXTENSIONS_TAB__ADD); - - removeButton = getWidgetFactory().createButton(buttonComposite, Messages._UI_ACTION_DELETE, SWT.FLAT); - removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - removeButton.addSelectionListener(this); - removeButton.setToolTipText(Messages._UI_ACTION_DELETE_EXTENSION_COMPONENT); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(removeButton, - XSDEditorCSHelpIds.EXTENSIONS_TAB__DELETE); - - //removeButton.setLayoutData(new ColumnLayoutData(ColumnLayoutData.FILL)); - - // TODO (cs) uncomment the up/down button when we have time to implement - // - //Button up = getWidgetFactory().createButton(buttonComposite, Messages._UI_LABEL_UP, SWT.FLAT); - //up.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - //Button down = getWidgetFactory().createButton(buttonComposite, Messages._UI_LABEL_DOWN, SWT.FLAT); - //down.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Composite rightContent = getWidgetFactory().createComposite(sashForm, SWT.FLAT); - Section section2 = getWidgetFactory().createSection(rightContent, SWT.FLAT | ExpandableComposite.TITLE_BAR); - section2.setText(Messages._UI_LABEL_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 = { 40, 60 }; - sashForm.setWeights(weights); - } - - protected void createElementContentWidget(Composite parent) - { - extensionDetailsViewer = new ExtensionDetailsViewer(parent, getWidgetFactory()); - extensionDetailsViewer.setContentProvider(new DOMExtensionDetailsContentProvider()); - extensionDetailsViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(extensionDetailsViewer.getControl(), - XSDEditorCSHelpIds.EXTENSIONS_TAB__EXTENSIONS_DETAILS); - } - - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - setListenerEnabled(false); - if (input != null) - { - if ( prevInput == input) - return; - else - prevInput = input; - - Tree tree = extensionTreeViewer.getTree(); - extensionDetailsViewer.setInput(null); - tree.removeAll(); - - addButton.setEnabled(!isReadOnly); - - extensionTreeViewer.setInput(input); - if (tree.getSelectionCount() == 0 && tree.getItemCount() > 0) - { - TreeItem treeItem = tree.getItem(0); - extensionTreeViewer.setSelection(new StructuredSelection(treeItem.getData())); - } - removeButton.setEnabled(tree.getSelectionCount() > 0 && !isReadOnly); - // Bugzilla 197315. Make this bulletproof for maintenance release. - Control detailsViewerControl = extensionDetailsViewer.getControl(); - if (detailsViewerControl != null && !detailsViewerControl.isDisposed()) - { - detailsViewerControl.setEnabled(!isReadOnly); - } - } - setListenerEnabled(true); - } - - public Composite getPage() - { - return page; - } - - protected abstract AddExtensionCommand getAddExtensionCommand(Object o); - protected abstract Command getRemoveExtensionCommand(Object o); - protected abstract ExtensionsSchemasRegistry getExtensionsSchemasRegistry(); - - protected AddExtensionsComponentDialog createAddExtensionsComponentDialog() - { - return new AddExtensionsComponentDialog(composite.getShell(), getExtensionsSchemasRegistry()); - } - - public void widgetSelected(SelectionEvent event) - { - if (event.widget == addButton) - { - ExtensionsSchemasRegistry registry = getExtensionsSchemasRegistry(); - AddExtensionsComponentDialog dialog = createAddExtensionsComponentDialog(); - - List properties = registry.getAllExtensionsSchemasContribution(); - - dialog.setInput(properties); - dialog.setBlockOnOpen(true); - dialog.setPrefStore( getPrefStore() ); - - if (prevCategory != null) - dialog.setInitialCategorySelection(prevCategory); - - 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(); - } - } - } - //refresh(); - if (newSelection != null) - { - extensionTreeViewer.setSelection(new StructuredSelection(newSelection)); - } - } - - prevCategory = dialog.getSelectedCategory(); - } - 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); - } - } - } - else if (event.widget == extensionTreeViewer.getTree()) - { - - } - } - - // TODO make this one an abstract method. XSDEditor and WSDLEditor should return - // diferent IpreferenceStore objects - protected IPreferenceStore getPrefStore() { - return null; - } - - public void widgetDefaultSelected(SelectionEvent event) - { - - } - - public boolean shouldUseExtraSpace() - { - return true; - } - - public void dispose() - { - if (documentChangeNotifier != null) - documentChangeNotifier.removeListener(internalNodeAdapter); - } - - - Node selectedNode; - - class ElementSelectionChangedListener implements ISelectionChangedListener - { - public void selectionChanged(SelectionChangedEvent event) - { - boolean isDeleteEnabled = false; - ISelection selection = event.getSelection(); - if (selection instanceof StructuredSelection) - { - StructuredSelection structuredSelection = (StructuredSelection)selection; - if (structuredSelection.size() > 0) - { - Object obj = structuredSelection.getFirstElement(); - if (obj instanceof Node) - { - selectedNode = (Node) obj; - extensionDetailsViewer.setInput(obj); - isDeleteEnabled = true; - } - } - else - { - // if nothing is selected then don't show any details - // - extensionDetailsViewer.setInput(null); - } - - // Upon element selection, the details view populates fine, but there is no vertical scrollbar, - // so it misleads the user into thinking there are no other attributes available - // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=174073 - // This is a workaround to force a layout of the tab composite - IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); - if (part instanceof PropertySheet) - { - PropertySheet sheet = (PropertySheet)part; - if (sheet.getCurrentPage() instanceof TabbedPropertySheetPage) - { - TabbedPropertySheetPage tabbedPage = (TabbedPropertySheetPage)sheet.getCurrentPage(); - if (tabbedPage.getControl() instanceof Composite) - { - Composite c = (Composite)tabbedPage.getControl(); - Point p = c.getSize(); - // c.layout(true, true) doesn't appear to work. - // But this forces a relayout: - c.setSize(p.x, p.y + 1); - // Change the size back to the original - c.setSize(p.x, p.y); - } - } - } - } - removeButton.setEnabled(isDeleteEnabled && !isReadOnly); - } - } - - 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; - } -}
\ 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/AbstractSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSection.java deleted file mode 100644 index c90c0a99fa..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSection.java +++ /dev/null @@ -1,365 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gef.commands.CommandStack; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.SubContributionManager; -import org.eclipse.jface.action.SubStatusLineManager; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.FormColors; -import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public abstract class AbstractSection extends AbstractPropertySection implements SelectionListener, Listener -{ - protected Composite composite; - protected PaintListener painter; - protected XSDSchema xsdSchema; - protected Object input; - protected boolean isReadOnly; - protected boolean listenerEnabled = true; - protected boolean isSimple; - protected CustomListener customListener = new CustomListener(); - protected IEditorPart owningEditor; - private IStatusLineManager statusLine; - - public static final Image ICON_ERROR = XSDEditorPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - - public AbstractSection() - { - super(); - } - - public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) - { - super.createControls(parent, aTabbedPropertySheetPage); - isSimple = getIsSimple(); - createContents(parent); - } - - protected abstract void createContents(Composite parent); - - protected PaintListener createPainter() { - return new PaintListener() { - - public void paintControl(PaintEvent e) { -// Rectangle bounds = composite.getClientArea(); - GC gc = e.gc; - - gc.setForeground(gc.getBackground()); - gc.setBackground(getWidgetFactory().getColors().getColor( - FormColors.TB_BG)); - -// gc.fillGradientRectangle(4 + bounds.width / 2, 0, -// bounds.width / 2 - 9, bounds.height, false); - - gc.setForeground(getWidgetFactory().getColors().getColor( - FormColors.TB_BORDER)); -// gc.drawLine(bounds.width - 5, 0, bounds.width - 5, -// bounds.height); - } - - }; - - } - - public void dispose() - { - if (composite != null && ! composite.isDisposed() && painter != null) - composite.removePaintListener(painter); - - super.dispose(); - } - - public void setInput(IWorkbenchPart part, ISelection selection) { - super.setInput(part, selection); - isSimple = getIsSimple(); - Object input = ((IStructuredSelection)selection).getFirstElement(); - this.input = input; - - if (input instanceof XSDConcreteComponent) - { - xsdSchema = ((XSDConcreteComponent)input).getSchema(); - } - - // set owning editor of this section - if (part!=null) - { - if (part instanceof IEditorPart) - { - owningEditor = (IEditorPart)part; - } - else - { - owningEditor = part.getSite().getWorkbenchWindow().getActivePage().getActiveEditor(); - } - } - if (xsdSchema == owningEditor.getAdapter(XSDSchema.class)) - { - isReadOnly = false; - } - else - { - isReadOnly = true; - } - - } - - public void refresh() - { - super.refresh(); - - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } - } - - public void applyAllListeners(Control control) - { - control.addListener(SWT.Modify, customListener); - control.addListener(SWT.FocusOut, customListener); - control.addListener(SWT.KeyDown, customListener); - } - - public void applyModifyListeners(Control control) - { - control.addListener(SWT.Modify, customListener); - control.addListener(SWT.FocusOut, customListener); - } - - public void applyKeyListener(Control control) - { - control.addListener(SWT.KeyDown, customListener); - } - - public void removeListeners(Control control) - { - control.removeListener(SWT.Modify, customListener); - control.removeListener(SWT.FocusOut, customListener); - control.removeListener(SWT.KeyDown, customListener); - } - - public void doWidgetDefaultSelected(SelectionEvent e) - {} - - public void doWidgetSelected(SelectionEvent e) - {} - - public void widgetSelected(SelectionEvent e) - { - if (isListenerEnabled() && - input != null && - !isReadOnly) - { - doWidgetSelected(e); - } - } - - public void widgetDefaultSelected(SelectionEvent e) - { - if (isListenerEnabled() && - input != null && - !isReadOnly) - { - doWidgetDefaultSelected(e); - } - } - - /** - * Get the value of listenerEnabled. - * @return value of listenerEnabled. - */ - public boolean isListenerEnabled() - { - return listenerEnabled; - } - - /** - * Set the value of listenerEnabled. - * @param v Value to assign to listenerEnabled. - */ - public void setListenerEnabled(boolean v) - { - this.listenerEnabled = v; - } - - /** - * Sent when an event that the receiver has registered for occurs. - * - * @param event the event which occurred - */ - public void handleEvent(Event event) - { - if (isListenerEnabled() && !isReadOnly) - { - doHandleEvent(event); - } - } - - /** - * Subclasses should override - * @param event - */ - protected void doHandleEvent(Event event) - { - } - - protected IEditorPart getActiveEditor() - { - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); - IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor(); - this.owningEditor = editorPart; - return editorPart; - } - - public CommandStack getCommandStack() - { - Object commandStack = owningEditor.getAdapter(CommandStack.class); - - if (commandStack==null) - return null; - else - return (CommandStack)commandStack; - } - - public boolean getIsSimple() - { - return false; - } - - - - /** - * Intended to display error messages. - * @return - */ - private IStatusLineManager getStatusLineManager() - { - if (statusLine==null && getPart()!=null) - { - if(getPart().getSite() instanceof IEditorSite) - statusLine = ((IEditorSite)getPart().getSite()).getActionBars().getStatusLineManager(); - else if (getPart().getSite() instanceof IViewSite) - statusLine = ((IViewSite)getPart().getSite()).getActionBars().getStatusLineManager(); - - /* - * We must manually set the visibility of the status line since the action bars are from the editor - * which means the status line only shows up when the editor is in focus (by default). - * Note only a SubStatusLineManager can set the visibility. - */ - if (statusLine instanceof SubStatusLineManager) - ((SubStatusLineManager)statusLine).setVisible(true); - } - - return statusLine; - } - - /** - * Display an error message in the status line. - * Call setErrorMessage(null) to clear the status line. - * @param text - */ - public void setErrorMessage(String text) - { - IStatusLineManager statusLine = getStatusLineManager(); - - if (statusLine!=null) - { - if (text==null || text.length()<1) - statusLine.setErrorMessage(null); - else - statusLine.setErrorMessage(ICON_ERROR, text); - - // ensure our message gets displayed - if (statusLine instanceof SubContributionManager) - ((SubContributionManager)statusLine).setVisible(true); - - statusLine.update(true); - } - } - - - protected EObject getModel() - { - return (XSDComponent)input; - } - - - class CustomListener implements Listener - { - boolean handlingEvent = false; - public void handleEvent(Event event) - { - if (isListenerEnabled() && !isReadOnly) - { - switch (event.type) - { - case SWT.KeyDown : - { - if (event.character == SWT.CR) - { - if (!handlingEvent) - { - handlingEvent = true; - doHandleEvent(event); - handlingEvent = false; - } - } - break; - } - case SWT.FocusOut : - { - if (!handlingEvent) - { - handlingEvent = true; - doHandleEvent(event); - handlingEvent = false; - } - break; - } - } - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSectionDescriptor.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSectionDescriptor.java deleted file mode 100644 index e0b33bb5c0..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSectionDescriptor.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.viewers.IFilter; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.views.properties.tabbed.ISection; -import org.eclipse.ui.views.properties.tabbed.ISectionDescriptor; -import org.eclipse.xsd.XSDConcreteComponent; -import org.w3c.dom.Element; - -public class AbstractSectionDescriptor implements ISectionDescriptor -{ - /** - * - */ - public AbstractSectionDescriptor() - { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getId() - */ - public String getId() - { - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getFilter() - */ - public IFilter getFilter() - { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getInputTypes() - */ - public List getInputTypes() - { - List list = new ArrayList(); - list.add(XSDConcreteComponent.class); - return list; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getSectionClass() - */ - public ISection getSectionClass() - { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getTargetTab() - */ - public String getTargetTab() - { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#appliesTo(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) - */ - public boolean appliesTo(IWorkbenchPart part, ISelection selection) - { - Object object = null; - if (selection instanceof StructuredSelection) - { - StructuredSelection structuredSelection = (StructuredSelection)selection; - object = structuredSelection.getFirstElement(); - if (object instanceof XSDConcreteComponent || object instanceof Element) - { - return true; - } - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISectionDescriptor#getAfterSection() - */ - public String getAfterSection() - { - return ""; //$NON-NLS-1$ - } - - - public int getEnablesFor() - { - return ENABLES_FOR_ANY; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AnnotationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AnnotationSection.java deleted file mode 100644 index 2215338173..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AnnotationSection.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.io.IOException; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddDocumentationCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDConcreteComponent; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class AnnotationSection extends AbstractSection -{ - Text simpleText; - - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - simpleText = getWidgetFactory().createText(composite, "", SWT.V_SCROLL | SWT.H_SCROLL); //$NON-NLS-1$ - simpleText.addListener(SWT.Modify, this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(simpleText, - XSDEditorCSHelpIds.DOCUMENTATION_TAB__NO_LABEL); - - - FormData data = new FormData(); - data.left = new FormAttachment(0, 1); - data.right = new FormAttachment(100, -1); - data.top = new FormAttachment(0, 1); - data.bottom = new FormAttachment(100, -1); - simpleText.setLayoutData(data); - } - - public AnnotationSection() - { - super(); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - super.refresh(); - - if (simpleText.isFocusControl()) return; - setListenerEnabled(false); - if (input instanceof XSDConcreteComponent) - { - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation((XSDConcreteComponent) input, false); - setInitialText(xsdAnnotation); - } - setListenerEnabled(true); - } - - public void doHandleEvent(Event event) - { - if (input instanceof XSDConcreteComponent) - { - if (event.widget == simpleText) - { - AddDocumentationCommand command = new AddDocumentationCommand(Messages._UI_ACTION_ADD_DOCUMENTATION, null, (XSDConcreteComponent) input, simpleText.getText(), ""); //$NON-NLS-1$ - getCommandStack().execute(command); - } - } - - } - - public boolean shouldUseExtraSpace() - { - return true; - } - - public void dispose() - { - - } - - private void setInitialText(XSDAnnotation an) - { - if (an != null) - { - try - { - List documentationList = an.getUserInformation(); - if (documentationList.size() > 0) - { - Element docElement = (Element) documentationList.get(0); - if (docElement != null) - { - simpleText.setText(doSerialize(docElement)); - } - } - } - catch (Exception e) - { - - } - } - else - { - simpleText.setText(""); //$NON-NLS-1$ - } - } - - private String doSerialize(Element element) throws IOException - { - String source = ""; //$NON-NLS-1$ - - Node firstChild = element.getFirstChild(); - Node lastChild = element.getLastChild(); - int start = 0; - int end = 0; - - if (element instanceof IDOMElement) - { - IDOMElement domElement = (IDOMElement) element; - IDOMModel model = domElement.getModel(); - IDOMDocument doc = model.getDocument(); - - if (firstChild instanceof IDOMNode) - { - IDOMNode first = (IDOMNode) firstChild; - start = first.getStartOffset(); - } - if (lastChild instanceof IDOMNode) - { - IDOMNode last = (IDOMNode) lastChild; - end = last.getEndOffset(); - } - source = doc.getSource().substring(start, end); - } - - return source; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/CommonDirectivesSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/CommonDirectivesSection.java deleted file mode 100644 index 652d247c09..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/CommonDirectivesSection.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.emf.common.util.URI; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDParser; - -public abstract class CommonDirectivesSection extends AbstractSection -{ - Text schemaLocationText; - Button wizardButton; - StyledText errorText; - Color red; - protected boolean isValidSchemaLocation = true; - - // TODO: common up code with XSDSelectIncludeFileWizard - public void doHandleEvent(Event event) - { - errorText.setText(""); //$NON-NLS-1$ - - if (event.widget == schemaLocationText) - { - String errorMessage = ""; //$NON-NLS-1$ - isValidSchemaLocation = true; - String xsdModelFile = schemaLocationText.getText(); - String namespace = ""; //$NON-NLS-1$ - XSDSchema externalSchema = null; - - if (xsdModelFile.length() == 0) - { - handleSchemaLocationChange(xsdModelFile, "", null); //$NON-NLS-1$ - return; - } - - try - { - IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile(); - - URI newURI = URI.createURI(xsdModelFile); - String xsdFile = URIHelper.getRelativeURI(newURI.toString(), currentIFile.getFullPath().toString()); - final String normalizedXSDFile = URIHelper.normalize(xsdFile, currentIFile.getLocation().toString(), ""); //$NON-NLS-1$ - - XSDParser parser = new XSDParser(); - parser.parse(normalizedXSDFile); - - externalSchema = parser.getSchema(); - - if (externalSchema != null) - { - String extNamespace = externalSchema.getTargetNamespace(); - if (extNamespace == null) extNamespace = ""; //$NON-NLS-1$ - namespace = extNamespace; - - if (externalSchema.getDiagnostics() != null && - externalSchema.getDiagnostics().size() > 0) - { - isValidSchemaLocation = false; - errorMessage = XSDEditorPlugin.getResourceString("_UI_INCORRECT_XML_SCHEMA", xsdModelFile); //$NON-NLS-1$ - } - else - { - String currentNameSpace = xsdSchema.getTargetNamespace(); - if (input instanceof XSDInclude || input instanceof XSDRedefine) - { - // Check the namespace to make sure they are the same as current file - if (extNamespace != null) - { - if (currentNameSpace != null && !extNamespace.equals(currentNameSpace)) - { - errorMessage = XSDEditorPlugin.getResourceString("_UI_DIFFERENT_NAME_SPACE", xsdModelFile); //$NON-NLS-1$ - isValidSchemaLocation = false; - } - } - } - else - { - // Check the namespace to make sure they are different from the current file - if (extNamespace != null) - { - if (currentNameSpace != null && extNamespace.equals(currentNameSpace)) - { - errorMessage = XSDEditorPlugin.getResourceString("_UI_SAME_NAME_SPACE", xsdModelFile); //$NON-NLS-1$ - isValidSchemaLocation = false; - } - } - } - } - } - else - { - errorMessage = Messages._UI_ERROR_INVALID_FILE; - isValidSchemaLocation = false; - } - } - catch(Exception e) - { - errorMessage = Messages._UI_ERROR_INVALID_FILE; - isValidSchemaLocation = false; - } - finally - { - if (!isValidSchemaLocation) - { - errorText.setText(errorMessage); - int length = errorText.getText().length(); - red = new Color(null, 255, 0, 0); - StyleRange style = new StyleRange(0, length, red, schemaLocationText.getBackground()); - errorText.setStyleRange(style); - } - else - { - handleSchemaLocationChange(xsdModelFile, namespace, externalSchema); - } - } - } - } - - protected void handleSchemaLocationChange(String schemaFileString, String namespace, XSDSchema externalSchema) - { - - } - - - public void dispose() - { - super.dispose(); - if (red != null) - { - red.dispose(); - red = null; - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/EnumerationsSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/EnumerationsSection.java deleted file mode 100644 index e33e4a18ac..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/EnumerationsSection.java +++ /dev/null @@ -1,405 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.common.ui.internal.viewers.NavigableTableViewer; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.SetXSDFacetValueCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.widgets.EnumerationsDialog; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; - -public class EnumerationsSection extends AbstractSection -{ - private EnumerationsTableViewer enumerationsTable; - private Button addButton; - private Button addManyButton; - private Button deleteButton; - - /** - * - */ - public EnumerationsSection() - { - super(); - } - - public void widgetSelected(SelectionEvent e) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; - - if (e.widget == addButton) - { - List enumList = st.getEnumerationFacets(); - StringBuffer newName = new StringBuffer("value1"); //$NON-NLS-1$ - int suffix = 1; - for (Iterator i = enumList.iterator(); i.hasNext();) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next(); - String value = enumFacet.getLexicalValue(); - if (value != null) - { - if (value.equals(newName.toString())) - { - suffix++; - newName = new StringBuffer("value" + String.valueOf(suffix)); //$NON-NLS-1$ - } - } - } - - AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, (XSDSimpleTypeDefinition) input); - command.setValue(newName.toString()); - getCommandStack().execute(command); - - enumerationsTable.refresh(); - int newItemIndex = enumerationsTable.getTable().getItemCount() - 1; - enumerationsTable.editElement(enumerationsTable.getElementAt(newItemIndex), 0); - } - else if (e.widget == addManyButton) - { - Display display = Display.getCurrent(); - // if it is null, get the default one - display = display == null ? Display.getDefault() : display; - Shell parentShell = display.getActiveShell(); - EnumerationsDialog dialog = new EnumerationsDialog(parentShell); - dialog.setBlockOnOpen(true); - int result = dialog.open(); - - if (result == Window.OK) - { - String text = dialog.getText(); - String delimiter = dialog.getDelimiter(); - StringTokenizer tokenizer = new StringTokenizer(text, delimiter); - CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS); - while (tokenizer.hasMoreTokens()) - { - String token = tokenizer.nextToken(); - if (dialog.isPreserveWhitespace() == false) - { - token = token.trim(); - } - AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATIONS, (XSDSimpleTypeDefinition) input); - command.setValue(token); - compoundCommand.add(command); - } - getCommandStack().execute(compoundCommand); - } - enumerationsTable.refresh(); - } - else if (e.widget == deleteButton) - { - StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection(); - if (selection != null) - { - Iterator i = selection.iterator(); - CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_DELETE_ENUMERATION); - while (i.hasNext()) - { - Object obj = i.next(); - if (obj != null) - { - if (obj instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj; - - DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet); - compoundCommand.add(deleteCommand); - } - } - } - getCommandStack().execute(compoundCommand); - enumerationsTable.refresh(); - } - } - else if (e.widget == enumerationsTable.getTable()) - { - StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection(); - if (selection.getFirstElement() != null) - { - deleteButton.setEnabled(true); - } - else - { - deleteButton.setEnabled(false); - } - } - - } - - public void widgetDefaultSelected(SelectionEvent e) - { - - } - - public void createContents(Composite parent) - { - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - composite = factory.createFlatFormComposite(parent); - - enumerationsTable = new EnumerationsTableViewer(getWidgetFactory().createTable(composite, SWT.MULTI | SWT.FULL_SELECTION)); - enumerationsTable.setInput(input); - Table table = enumerationsTable.getTable(); - table.addSelectionListener(this); - - addButton = getWidgetFactory().createButton(composite, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_ADD_BUTTON_LABEL"), SWT.PUSH); //$NON-NLS-1$ - addManyButton = getWidgetFactory().createButton(composite, XSDEditorPlugin.getXSDString("_UI_REGEX_WIZARD_ADD_BUTTON_LABEL") + "...", SWT.PUSH); //$NON-NLS-1$ //$NON-NLS-2$ - deleteButton = getWidgetFactory().createButton(composite, XSDEditorPlugin.getXSDString("_UI_ACTION_DELETE_INCLUDE"), SWT.PUSH); //$NON-NLS-1$ - - FormData data2 = new FormData(); - data2.top = new FormAttachment(0, 0); - data2.left = new FormAttachment(100, -100); - data2.right = new FormAttachment(100, 0); - // data2.width = 50; - addButton.setLayoutData(data2); - addButton.addSelectionListener(this); - - FormData data = new FormData(); - data.left = new FormAttachment(addButton, 0, SWT.LEFT); - data.right = new FormAttachment(100, 0); - data.top = new FormAttachment(addButton, 0); - addManyButton.setLayoutData(data); - addManyButton.addSelectionListener(this); - - data = new FormData(); - data.left = new FormAttachment(addButton, 0, SWT.LEFT); - data.right = new FormAttachment(100, 0); - data.top = new FormAttachment(addManyButton, 0); - deleteButton.setLayoutData(data); - deleteButton.setEnabled(false); - deleteButton.addSelectionListener(this); - - data = new FormData(); - data.top = new FormAttachment(0, 0); - data.left = new FormAttachment(0, 0); - data.right = new FormAttachment(addButton, 0); - data.bottom = new FormAttachment(100, 0); - data.width = 50; - table.setLayoutData(data); - table.addListener(SWT.Resize, this); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; - - Iterator validFacets = st.getValidFacets().iterator(); - - boolean isApplicable = false; - while (validFacets.hasNext()) - { - String aValidFacet = (String) validFacets.next(); - if (aValidFacet.equals(XSDConstants.ENUMERATION_ELEMENT_TAG)) - { - isApplicable = true; - } - } - - if (isApplicable) - { - addButton.setEnabled(true); - addManyButton.setEnabled(true); - } - else - { - addButton.setEnabled(false); - addManyButton.setEnabled(false); - } - enumerationsTable.setInput(input); - } - - public void handleEvent(Event event) - { - Table table = enumerationsTable.getTable(); - if (event.type == SWT.Resize && event.widget == table) - { - TableColumn tableColumn = table.getColumn(0); - tableColumn.setWidth(table.getSize().x); - } - } - - public void dispose() - { - } - - public boolean shouldUseExtraSpace() - { - return true; - } - - class EnumerationsTableViewer extends NavigableTableViewer implements ICellModifier - { - protected String[] columnProperties = { XSDConstants.ENUMERATION_ELEMENT_TAG }; - - protected CellEditor[] cellEditors; - - Table table; - - public EnumerationsTableViewer(Table table) - { - super(table); - table = getTable(); - - table.setLinesVisible(true); - - setContentProvider(new EnumerationsTableContentProvider()); - setLabelProvider(new EnumerationsTableLabelProvider()); - setColumnProperties(columnProperties); - - setCellModifier(this); - - TableColumn column = new TableColumn(table, SWT.NONE, 0); - column.setText(columnProperties[0]); - column.setAlignment(SWT.LEFT); - column.setResizable(true); - - cellEditors = new CellEditor[1]; - - TableLayout layout = new TableLayout(); - ColumnWeightData data = new ColumnWeightData(100); - - layout.addColumnData(data); - cellEditors[0] = new TextCellEditor(table); - - getTable().setLayout(layout); - setCellEditors(cellEditors); - } - - public boolean canModify(Object element, String property) - { - return true; - } - - public void modify(Object element, String property, Object value) - { - if (element instanceof TableItem && (value != null)) - { - TableItem item = (TableItem) element; - - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) item.getData(); - SetXSDFacetValueCommand command = new SetXSDFacetValueCommand(Messages._UI_ACTION_SET_ENUMERATION_VALUE, enumFacet); - command.setValue((String) value); - getCommandStack().execute(command); - item.setData(enumFacet); - item.setText((String) value); - } - } - - public Object getValue(Object element, String property) - { - if (element instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) element; - String value = enumFacet.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - return ""; //$NON-NLS-1$ - } - - } - - class EnumerationsTableContentProvider implements IStructuredContentProvider - { - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - } - - public java.lang.Object[] getElements(java.lang.Object inputElement) - { - java.util.List list = new ArrayList(); - if (inputElement instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) inputElement; - return st.getEnumerationFacets().toArray(); - } - return list.toArray(); - } - - public void dispose() - { - } - } - - class EnumerationsTableLabelProvider extends LabelProvider implements ITableLabelProvider - { - public EnumerationsTableLabelProvider() - { - - } - - public Image getColumnImage(Object element, int columnIndex) - { - return XSDEditorPlugin.getXSDImage("icons/XSDSimpleEnum.gif"); //$NON-NLS-1$ - } - - public String getColumnText(Object element, int columnIndex) - { - if (element instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) element; - String value = enumFacet.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - return ""; //$NON-NLS-1$ - } - - } - -} 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 deleted file mode 100644 index 1fad5105af..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/ExtensionsSection.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.ui.IWorkbenchPart; -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.ExtensibleAddExtensionCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleRemoveExtensionNodeCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.RemoveExtensionNodeCommand; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.AddExtensionsComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.CategoryProvider; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.DOMExtensionTreeLabelProvider; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.ExtensionItemFilter; -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.properties.sections.appinfo.XSDExtensionTreeContentProvider; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeFilter; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; -import org.eclipse.wst.xsd.ui.internal.util.ModelReconcileAdapter; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class ExtensionsSection extends AbstractExtensionsSection -{ - XSDModelAdapter adapter = null; - - public ExtensionsSection() - { - super(); - setExtensionTreeLabelProvider(new DOMExtensionTreeLabelProvider()); - setExtensionTreeContentProvider(new XSDExtensionTreeContentProvider()); - } - - protected AddExtensionsComponentDialog createAddExtensionsComponentDialog() - { - AddExtensionsComponentDialog dialog = new AddExtensionsComponentDialog(composite.getShell(), getExtensionsSchemasRegistry()) - { - protected IStructuredContentProvider getCategoryContentProvider() - { - return new XSDCategoryContentProvider(); - } - }; - dialog.addElementsTableFilter(new AddExtensionsComponentDialogFilter(input, dialog)); - return dialog; - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - if (adapter == null) - { - if (selection instanceof StructuredSelection) - { - Object obj = ((StructuredSelection) selection).getFirstElement(); - if (obj instanceof XSDConcreteComponent) - { - Element element = ((XSDConcreteComponent)obj).getElement(); - if (element != null) - { - adapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument()); - if (adapter != null) - { - ModelReconcileAdapter modelReconcileAdapter = adapter.getModelReconcileAdapter(); - if (modelReconcileAdapter != null) - { - modelReconcileAdapter.addListener(internalNodeAdapter); - } - } - } - } - } - } - extensionTreeViewer.expandToLevel(2); - } - - public void dispose() - { - super.dispose(); - if (adapter != null) - { - ModelReconcileAdapter modelReconcileAdapter = adapter.getModelReconcileAdapter(); - if (modelReconcileAdapter != null) - { - modelReconcileAdapter.removeListener(internalNodeAdapter); - } - } - } - - protected AddExtensionCommand getAddExtensionCommand(Object o) - { - AddExtensionCommand addExtensionCommand = null; - if (o instanceof XSDElementDeclaration) - { - XSDElementDeclaration element = (XSDElementDeclaration) o; - ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace()); - if (extensibleAddExtensionCommand != null) - { - extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element); - addExtensionCommand = extensibleAddExtensionCommand; - } - else - { - addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element); - } - } - else if (o instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o; - addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute); - } - return addExtensionCommand; - } - - protected Command getRemoveExtensionCommand(Object o) - { - Command command = null; - try - { - if (o instanceof Node) - { - Node node = (Node)o; - ExtensibleRemoveExtensionNodeCommand removeCommand = getExtensionsSchemasRegistry().getRemoveExtensionNodeCommand(node.getNamespaceURI()); - if (removeCommand != null) - { - removeCommand.setInput((XSDConcreteComponent)input); - removeCommand.setNode(node); - return removeCommand; - } - else - { - command = new RemoveExtensionNodeCommand(Messages._UI_ACTION_DELETE_APPINFO_ELEMENT, node); - // command.execute(); - } - } - } - catch (Exception e) - { - } - return command; - } - - protected ExtensionsSchemasRegistry getExtensionsSchemasRegistry() - { - return XSDEditorPlugin.getDefault().getExtensionsSchemasRegistry(); - } - - protected boolean isTreeViewerInputElement(Element element) - { - if (input instanceof XSDConcreteComponent) - { - XSDConcreteComponent component = (XSDConcreteComponent)input; - Element componentElement = component.getElement(); - Node parent = element.getParentNode(); - Node grandParent = parent != null ? parent.getParentNode() : null; - return componentElement == element || componentElement == parent || componentElement == grandParent; - } - return false; - } - - protected IPreferenceStore getPrefStore() - { - return XSDEditorPlugin.getPlugin().getPreferenceStore(); - } - - static class XSDCategoryContentProvider implements IStructuredContentProvider - { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object inputElement) - { - SpecificationForExtensionsSchema[] extensionsSchemaSpecs = null; - try - { - List inputList = (List) inputElement; - - List total = new ArrayList(); - total.addAll(inputList); - - List dynamicCategories = XSDEditorPlugin.getPlugin().getExtensionsSchemasRegistry().getCategoryProviders(); - for (Iterator iter = dynamicCategories.iterator(); iter.hasNext(); ) - { - CategoryProvider categoryProvider = (CategoryProvider)iter.next(); - for (Iterator it = categoryProvider.getCategories().iterator(); it.hasNext(); ) - { - SpecificationForExtensionsSchema sp = (SpecificationForExtensionsSchema)it.next(); - total.add(sp); - } - } - - extensionsSchemaSpecs = (SpecificationForExtensionsSchema[]) total.toArray(new SpecificationForExtensionsSchema[0]); - } - catch (Exception e) - { - } - return extensionsSchemaSpecs; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() - { - // Do nothing - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, - * java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - // Do nothing - - } - } - - /** - * This filter is to be used by the dialog invoked when addButton is pressed - */ - protected class AddExtensionsComponentDialogFilter extends ViewerFilter - { - private Object input; - private AddExtensionsComponentDialog dialog; - - public AddExtensionsComponentDialogFilter(Object input, AddExtensionsComponentDialog dialog) - { - this.input = input; - this.dialog = dialog; - } - - public boolean select(Viewer viewer, Object parentElement, Object element) - { - if (input instanceof XSDConcreteComponent && - element instanceof XSDConcreteComponent) - { - SpecificationForExtensionsSchema spec = dialog.getSelectedCategory(); - // here we obtain the node filter that was registered for the applicable namespace - // notied - NodeFilter filter = XSDEditorPlugin.getPlugin().getNodeCustomizationRegistry().getNodeFilter(spec.getNamespaceURI()); - - if (filter == null) - { - // Check if a node filter has been specified, if so, then use it - filter = spec.getNodeFilter(); - } - - if (filter instanceof ExtensionItemFilter) - { - ExtensionItemFilter extensionItemFilter = (ExtensionItemFilter)filter; - return extensionItemFilter.isApplicableContext((XSDConcreteComponent)input, (XSDConcreteComponent)element); - } - else - { - // TODO cs: even if it's just a plain old NodeFilter we should still be able to use it! - } - } - return true; - } - } - -}
\ 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/FacetViewer.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/FacetViewer.java deleted file mode 100644 index e13d74d745..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/FacetViewer.java +++ /dev/null @@ -1,559 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -//import java.util.ArrayList; -//import java.util.Iterator; -//import java.util.List; -// -//import org.eclipse.jface.viewers.CellEditor; -//import org.eclipse.jface.viewers.ColumnWeightData; -//import org.eclipse.jface.viewers.ICellModifier; -//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.TableLayout; -//import org.eclipse.jface.viewers.TextCellEditor; -//import org.eclipse.jface.viewers.Viewer; -//import org.eclipse.swt.SWT; -//import org.eclipse.swt.events.MouseEvent; -//import org.eclipse.swt.events.MouseTrackAdapter; -//import org.eclipse.swt.graphics.Image; -//import org.eclipse.swt.graphics.Point; -//import org.eclipse.swt.widgets.Composite; -//import org.eclipse.swt.widgets.Table; -//import org.eclipse.swt.widgets.TableColumn; -//import org.eclipse.swt.widgets.TableItem; -//import org.eclipse.wst.common.ui.internal.viewers.NavigableTableViewer; -//import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -//import org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute; -//import org.eclipse.wst.xsd.ui.internal.properties.XSDComboBoxPropertyDescriptor; -//import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper; -//import org.eclipse.xsd.XSDConstrainingFacet; -//import org.eclipse.xsd.XSDFactory; -//import org.eclipse.xsd.XSDMaxExclusiveFacet; -//import org.eclipse.xsd.XSDMaxFacet; -//import org.eclipse.xsd.XSDMaxInclusiveFacet; -//import org.eclipse.xsd.XSDMinExclusiveFacet; -//import org.eclipse.xsd.XSDMinFacet; -//import org.eclipse.xsd.XSDMinInclusiveFacet; -//import org.eclipse.xsd.XSDSimpleTypeDefinition; -//import org.eclipse.xsd.util.XSDConstants; -//import org.eclipse.xsd.util.XSDSchemaBuildingTools; -//import org.w3c.dom.Element; - -public class FacetViewer //extends NavigableTableViewer implements ICellModifier -{ -// public static final String FACET_NAME = XSDEditorPlugin.getXSDString("_UI_FACET_NAME"); // "Name"; -// public static final String FACET_VALUE = XSDEditorPlugin.getXSDString("_UI_FACET_VALUE"); // "Value"; -// public static final String FACET_OTHER = XSDEditorPlugin.getXSDString("_UI_FACET_FIXED"); // "Fixed"; -// -// protected FacetsTableLabelProvider facetsTableLabelProvider = new FacetsTableLabelProvider(); -// protected FacetsTableContentProvider facetsTableContentProvider = new FacetsTableContentProvider(); -// protected String[] columnProperties = { FACET_NAME, FACET_VALUE, FACET_OTHER }; -// protected CellEditor[] cellEditors; // these cellEditors are used when -// // non-whitespace facet is selected -// protected CellEditor[] altCellEditors; // these cellEditors are used when -// // whitespace facet is selected -// -// protected String[] whiteSpaceValues = new String[] { "", "preserve", "replace", "collapse" }; -// protected String[] trueFalseValues = new String[] { "", "false", "true" }; -// -// /** -// * @param parent -// */ -// public FacetViewer(Composite parent) -// { -// super(new Table(parent, SWT.FULL_SELECTION | SWT.SINGLE)); -// -// getTable().setLinesVisible(true); -// getTable().setHeaderVisible(true); -// -// addSelectionChangedListener(new SelectionChangedListener()); -// getTable().addMouseTrackListener(new MyMouseTrackListener()); -// -// setContentProvider(facetsTableContentProvider); -// setLabelProvider(facetsTableLabelProvider); -// setColumnProperties(columnProperties); -// -// setCellModifier(this); -// -// for (int i = 0; i < 3; i++) -// { -// TableColumn column = new TableColumn(getTable(), SWT.NONE, i); -// column.setText(columnProperties[i]); -// column.setAlignment(SWT.LEFT); -// column.setResizable(true); -// } -// -// cellEditors = new CellEditor[3]; -// altCellEditors = new CellEditor[3]; -// -// TableLayout layout = new TableLayout(); -// ColumnWeightData data = new ColumnWeightData(60, 80, true); -// layout.addColumnData(data); -// cellEditors[0] = null; -// -// ColumnWeightData data2 = new ColumnWeightData(120, 80, true); -// layout.addColumnData(data2); -// -// cellEditors[1] = new TextCellEditor(getTable()); -// XSDComboBoxPropertyDescriptor pd = new XSDComboBoxPropertyDescriptor("combo", "whitespace", whiteSpaceValues); -// altCellEditors[1] = pd.createPropertyEditor(getTable()); -// -// ColumnWeightData data3 = new ColumnWeightData(60, 60, true); -// layout.addColumnData(data3); -// -// XSDComboBoxPropertyDescriptor pd2 = new XSDComboBoxPropertyDescriptor("combo", "other", trueFalseValues); -// cellEditors[2] = pd2.createPropertyEditor(getTable()); -// altCellEditors[2] = pd2.createPropertyEditor(getTable()); -// -// getTable().setLayout(layout); -// setCellEditors(cellEditors); -// -// } -// -// /* -// * (non-Javadoc) -// * -// * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, -// * java.lang.String) -// */ -// public boolean canModify(Object element, String property) -// { -// return property.equals(FACET_VALUE) || property.equals(FACET_OTHER); -// } -// -// /* -// * (non-Javadoc) -// * -// * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, -// * java.lang.String) -// */ -// public Object getValue(Object element, String property) -// { -// int column = 0; -// if (property.equals(columnProperties[0])) -// { -// column = 0; -// } -// else if (property.equals(columnProperties[1])) -// { -// column = 1; -// } -// else if (property.equals(columnProperties[2])) -// { -// column = 2; -// } -// -// return facetsTableLabelProvider.getColumnText(element, column); -// } -// -// /* -// * (non-Javadoc) -// * -// * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, -// * java.lang.String, java.lang.Object) -// */ -// public void modify(Object element, String property, Object value) -// { -// XSDSimpleTypeDefinition xsdSimpleType = (XSDSimpleTypeDefinition) getInput(); -// TableItem item = (TableItem) element; -// if (item != null) -// { -// Object o = item.getData(); -// if (o != null) -// { -// if (o instanceof String) -// { -// String facet = (String) o; -// -// Element simpleTypeElement = xsdSimpleType.getElement(); -// XSDDOMHelper xsdDOMHelper = new XSDDOMHelper(); -// Element derivedByElement = xsdDOMHelper.getDerivedByElement(simpleTypeElement); -// -// String prefix = simpleTypeElement.getPrefix(); -// prefix = (prefix == null) ? "" : (prefix + ":"); -// -// Element childNodeElement = null; -// DOMAttribute valueAttr = null; -// -// XSDConstrainingFacet targetFacet = getXSDConstrainingFacet(facet); -// -// String newValue = ""; -// if (value != null && value instanceof String) -// { -// newValue = (String) value; -// } -// -// if (property.equals(columnProperties[1])) -// { -// if (targetFacet == null && newValue.length() > 0) -// { -// targetFacet = createFacet(facet); -// childNodeElement = (derivedByElement.getOwnerDocument()).createElementNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, prefix + facet); -// valueAttr = new DOMAttribute(XSDConstants.VALUE_ATTRIBUTE, newValue); -// childNodeElement.setAttribute(valueAttr.getName(), valueAttr.getValue()); -// // add and format child -// derivedByElement.appendChild(childNodeElement); -// targetFacet.setElement(childNodeElement); -// XSDDOMHelper.formatChild(childNodeElement); -// -// // XSDSchemaHelper.updateElement(xsdSimpleType); -// } -// if (targetFacet == null) -// { -// return; -// } -// -// if (newValue.length() > 0) -// { -// targetFacet.setLexicalValue(newValue); -// -// if (targetFacet instanceof XSDMaxFacet || targetFacet instanceof XSDMinFacet) -// { -// if (targetFacet instanceof XSDMaxFacet) -// { -// if (targetFacet instanceof XSDMaxExclusiveFacet) -// { -// XSDMaxInclusiveFacet xsdMaxInclusiveFacet = xsdSimpleType.getMaxInclusiveFacet(); -// if (xsdMaxInclusiveFacet != null) -// { -// Element xsdMaxInclusiveFacetElement = xsdMaxInclusiveFacet.getElement(); -// XSDDOMHelper.removeNodeAndWhitespace(xsdMaxInclusiveFacetElement); -// } -// } -// else if (targetFacet instanceof XSDMaxInclusiveFacet) -// { -// XSDMaxExclusiveFacet xsdMaxExclusiveFacet = xsdSimpleType.getMaxExclusiveFacet(); -// if (xsdMaxExclusiveFacet != null) -// { -// Element xsdMaxExclusiveFacetElement = xsdMaxExclusiveFacet.getElement(); -// XSDDOMHelper.removeNodeAndWhitespace(xsdMaxExclusiveFacetElement); -// } -// } -// } -// else if (targetFacet instanceof XSDMinFacet) -// { -// if (targetFacet instanceof XSDMinExclusiveFacet) -// { -// XSDMinInclusiveFacet xsdMinInclusiveFacet = xsdSimpleType.getMinInclusiveFacet(); -// if (xsdMinInclusiveFacet != null) -// { -// Element xsdMinInclusiveFacetElement = xsdMinInclusiveFacet.getElement(); -// XSDDOMHelper.removeNodeAndWhitespace(xsdMinInclusiveFacetElement); -// } -// } -// else if (targetFacet instanceof XSDMinInclusiveFacet) -// { -// XSDMinExclusiveFacet xsdMinExclusiveFacet = xsdSimpleType.getMinExclusiveFacet(); -// if (xsdMinExclusiveFacet != null) -// { -// Element xsdMinExclusiveFacetElement = xsdMinExclusiveFacet.getElement(); -// XSDDOMHelper.removeNodeAndWhitespace(xsdMinExclusiveFacetElement); -// } -// } -// } -// } -// } -// else -// // newValue.length == 0 -// { -// Element targetFacetElement = targetFacet.getElement(); -// XSDDOMHelper.removeNodeAndWhitespace(targetFacetElement); -// } -// } -// else if (property.equals(columnProperties[2])) -// { -// if (targetFacet != null) -// { -// if (newValue.length() > 0) -// { -// targetFacet.getElement().setAttribute(XSDConstants.FIXED_ATTRIBUTE, newValue); -// } -// else -// { -// targetFacet.getElement().removeAttribute(XSDConstants.FIXED_ATTRIBUTE); -// } -// } -// } -// xsdSimpleType.setElement(simpleTypeElement); -// // xsdSimpleType.updateElement(); -// refresh(); -// } -// } -// } -// } -// -// private XSDConstrainingFacet getXSDConstrainingFacet(String facetString) -// { -// XSDSimpleTypeDefinition xsdSimpleType = (XSDSimpleTypeDefinition) getInput(); -// List list = xsdSimpleType.getFacetContents(); -// if (list == null) -// { -// return null; -// } -// Iterator iter = list.iterator(); -// XSDConstrainingFacet targetFacet = null; -// -// while (iter.hasNext()) -// { -// XSDConstrainingFacet xsdConstrainingFacet = (XSDConstrainingFacet) iter.next(); -// if (xsdConstrainingFacet.getFacetName().equals(facetString)) -// { -// targetFacet = xsdConstrainingFacet; -// break; -// } -// } -// return targetFacet; -// } -// -// private XSDConstrainingFacet createFacet(String facet) -// { -// XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); -// XSDConstrainingFacet xsdFacet = null; -// if (facet.equals("length")) -// { -// xsdFacet = factory.createXSDLengthFacet(); -// } -// else if (facet.equals("minLength")) -// { -// xsdFacet = factory.createXSDMinLengthFacet(); -// } -// else if (facet.equals("maxLength")) -// { -// xsdFacet = factory.createXSDMaxLengthFacet(); -// } -// else if (facet.equals("minInclusive")) -// { -// xsdFacet = factory.createXSDMinInclusiveFacet(); -// } -// else if (facet.equals("minExclusive")) -// { -// xsdFacet = factory.createXSDMinExclusiveFacet(); -// } -// else if (facet.equals("maxInclusive")) -// { -// xsdFacet = factory.createXSDMaxInclusiveFacet(); -// } -// else if (facet.equals("maxExclusive")) -// { -// xsdFacet = factory.createXSDMaxExclusiveFacet(); -// } -// -// else if (facet.equals("totalDigits")) -// { -// xsdFacet = factory.createXSDTotalDigitsFacet(); -// } -// else if (facet.equals("fractionDigits")) -// { -// xsdFacet = factory.createXSDFractionDigitsFacet(); -// } -// else if (facet.equals("whiteSpace")) -// { -// xsdFacet = factory.createXSDWhiteSpaceFacet(); -// } -// return xsdFacet; -// } -// -// /** -// * Get the tooltip for the facet -// */ -// public String getToolTip(String facet) -// { -// String key = ""; -// if (facet.equals("length")) -// { -// key = "_UI_TOOLTIP_LENGTH"; -// } -// else if (facet.equals("minLength")) -// { -// key = "_UI_TOOLTIP_MIN_LEN"; -// } -// else if (facet.equals("maxLength")) -// { -// key = "_UI_TOOLTIP_MAX_LEN"; -// } -// -// else if (facet.equals("minInclusive")) -// { -// key = "_UI_TOOLTIP_MIN_INCLUSIVE"; -// } -// else if (facet.equals("minExclusive")) -// { -// key = "_UI_TOOLTIP_MIN_EXCLUSIVE"; -// } -// -// else if (facet.equals("maxInclusive")) -// { -// key = "_UI_TOOLTIP_MAX_INCLUSIVE"; -// } -// else if (facet.equals("maxExclusive")) -// { -// key = "_UI_TOOLTIP_MAX_EXCLUSIVE"; -// } -// -// else if (facet.equals("totalDigits")) -// { -// key = "_UI_TOOLTIP_TOTAL_DIGITS"; -// } -// else if (facet.equals("fractionDigits")) -// { -// key = "_UI_TOOLTIP_FRACTION_DIGITS"; -// } -// -// else if (facet.equals("whiteSpace")) -// { -// key = "_UI_TOOLTIP_WHITE_SPACE"; -// } -// -// return (key != null) ? XSDEditorPlugin.getXSDString(key) : ""; -// } -// -// /** -// * This listener detects which row is selected and add a tool tip for that row -// */ -// public class MyMouseTrackListener extends MouseTrackAdapter -// { -// public void mouseHover(MouseEvent e) -// { -// TableItem item = getTable().getItem(new Point(e.x, e.y)); -// if (item != null) -// { -// Object o = item.getData(); -// if (o != null) -// { -// String facetName = (String) o; -// getTable().setToolTipText(getToolTip(facetName)); -// } -// } -// } -// } -// -// /** -// * Based on the selection, detects if it is a white space or not, and add the -// * corresponding cell editors -// */ -// public class SelectionChangedListener implements ISelectionChangedListener -// { -// public void selectionChanged(SelectionChangedEvent event) -// { -// Object selection = event.getSelection(); -// if (selection instanceof StructuredSelection) -// { -// Object o = ((StructuredSelection) selection).getFirstElement(); -// if (o != null) -// { -// String facet = (String) o; -// if (facet.equals("whiteSpace")) -// { -// setCellEditors(altCellEditors); -// } -// else -// { -// setCellEditors(cellEditors); -// } -// } -// } -// } -// } -// -// class FacetsTableContentProvider implements IStructuredContentProvider -// { -// protected String facet; -// -// public void inputChanged(Viewer viewer, Object oldInput, Object newInput) -// { -// } -// -// public java.lang.Object[] getElements(java.lang.Object inputElement) -// { -// List v = new ArrayList(); -// XSDSimpleTypeDefinition inputXSDSimpleType = (XSDSimpleTypeDefinition) inputElement; -// XSDSimpleTypeDefinition base = inputXSDSimpleType.getPrimitiveTypeDefinition(); -// -// if (base != null) -// { -// Iterator validFacets = inputXSDSimpleType.getValidFacets().iterator(); -// while (validFacets.hasNext()) -// { -// String aValidFacet = (String) validFacets.next(); -// if (!(aValidFacet.equals("pattern") || aValidFacet.equals("enumeration"))) -// { -// v.add(aValidFacet); -// } -// } -// } -// return v.toArray(); -// } -// -// public void dispose() -// { -// } -// } -// -// class FacetsTableLabelProvider extends LabelProvider implements ITableLabelProvider -// { -// public Image getColumnImage(Object element, int columnIndex) -// { -// return null; -// } -// -// public String getColumnText(Object element, int columnIndex) -// { -// if (element instanceof String) -// { -// String value = null; -// XSDConstrainingFacet targetFacet = getXSDConstrainingFacet((String) element); -// switch (columnIndex) -// { -// case 0: -// { -// value = (String) element; -// break; -// } -// case 1: -// { -// if (targetFacet == null) -// { -// value = ""; -// } -// else -// { -// value = targetFacet.getLexicalValue(); -// } -// -// break; -// } -// case 2: -// { -// if (targetFacet == null) -// { -// value = ""; -// } -// else -// { -// Element elem = targetFacet.getElement(); -// value = elem.getAttribute(XSDConstants.FIXED_ATTRIBUTE); -// if (value == null) -// value = ""; -// } -// } -// } -// return value; -// } -// return ""; -// } -// } -} 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 deleted file mode 100644 index a72e632f4e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/IDocumentChangedNotifier.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -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/MultiplicitySection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/MultiplicitySection.java deleted file mode 100644 index 94593d4068..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/MultiplicitySection.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateMaxOccursCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateMinOccursCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDParticleContent; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - - -public class MultiplicitySection extends RefactoringSection -{ - protected CCombo minCombo, maxCombo; - - public MultiplicitySection() - { - super(); - } - - protected void createContents(Composite parent) - { - } - - - public void doHandleEvent(Event event) - { - if (event.widget == minCombo) - { - updateMinAttribute(); - } - else if (event.widget == maxCombo) - { - updateMaxAttribute(); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == minCombo) - { - updateMinAttribute(); - } - else if (e.widget == maxCombo) - { - updateMaxAttribute(); - } - super.doWidgetSelected(e); - } - - protected void updateMaxAttribute() - { - setErrorMessage(null); - XSDParticle particle = null; - - if (input instanceof XSDParticleContent) - { - particle = getAssociatedParticle((XSDParticleContent) input); - } - if (particle != null) - { - String newValue = maxCombo.getText().trim(); - - if (newValue.length() == 0) - { - particle.unsetMaxOccurs(); - return; - } - try - { - int newMax = 1; - if (newValue.equals("unbounded") || newValue.equals("*")) //$NON-NLS-1$ //$NON-NLS-2$ - { - newMax = XSDParticle.UNBOUNDED; - } - else - { - if (newValue.length() > 0) - { - newMax = Integer.parseInt(newValue); - } - } - setListenerEnabled(false); - UpdateMaxOccursCommand command = new UpdateMaxOccursCommand(Messages._UI_ACTION_CHANGE_MAXIMUM_OCCURRENCE, particle, newMax); - getCommandStack().execute(command); - setListenerEnabled(true); - - } - catch (NumberFormatException e) - { - setErrorMessage(Messages._UI_ERROR_INVALID_VALUE_FOR_MAXIMUM_OCCURRENCE); - } - } - } - - protected void updateMinAttribute() - { - setErrorMessage(null); - XSDParticle particle = null; - - if (input instanceof XSDParticleContent) - { - particle = getAssociatedParticle((XSDParticleContent) input); - } - if (particle != null) - { - String newValue = minCombo.getText(); - if (newValue.length() == 0) - { - particle.unsetMinOccurs(); - } - try - { - int newMin = 1; - if (newValue.equals("unbounded") || newValue.equals("*")) //$NON-NLS-1$ //$NON-NLS-2$ - { - newMin = XSDParticle.UNBOUNDED; - } - else - { - newMin = Integer.parseInt(newValue); - } - UpdateMinOccursCommand command = new UpdateMinOccursCommand(Messages._UI_ACTION_CHANGE_MINIMUM_OCCURRENCE, particle, newMin); - getCommandStack().execute(command); - } - catch (NumberFormatException e) - { - - } - } - } - - protected void refreshMinMax() - { - boolean refreshMinText = true; - boolean refreshMaxText = true; - if (minCombo.isFocusControl()) - { - refreshMinText = false; - } - if (maxCombo.isFocusControl()) - { - refreshMaxText = false; - } - if (refreshMinText) - { - minCombo.setText(""); //$NON-NLS-1$ - } - if (refreshMaxText) - { - maxCombo.setText(""); //$NON-NLS-1$ - } - - if (input != null) - { - if (input instanceof XSDParticleContent) - { - XSDParticle particle = getAssociatedParticle((XSDParticleContent) input); - if (particle != null) - { - // minText.setText(String.valueOf(particle.getMinOccurs())); - // maxText.setText(String.valueOf(particle.getMaxOccurs())); - Element element = particle.getElement(); - if (element != null) - { - String min = element.getAttribute(XSDConstants.MINOCCURS_ATTRIBUTE); - String max = element.getAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE); - if (min != null && refreshMinText) - { - minCombo.setText(min); - } - if (max != null && refreshMaxText) - { - maxCombo.setText(max); - } - } - } - } - } - } - - protected XSDParticle getAssociatedParticle(XSDParticleContent particleContent) - { - XSDConcreteComponent xsdComp = particleContent.getContainer(); - if (xsdComp instanceof XSDParticle) - { - return (XSDParticle) xsdComp; - } - return null; - } - - public void dispose() - { - if (minCombo != null && !minCombo.isDisposed()) - removeListeners(minCombo); - if (maxCombo != null && !maxCombo.isDisposed()) - removeListeners(maxCombo); - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java deleted file mode 100644 index 1a915a3596..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.events.IHyperlinkListener; -import org.eclipse.ui.forms.widgets.ImageHyperlink; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.ISelectionMapper; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.refactor.actions.RenameComponentAction; -import org.eclipse.xsd.XSDSchema; - -public abstract class RefactoringSection extends AbstractSection implements IHyperlinkListener -{ - /** - * Clicking on it invokes the refactor->rename action. - */ - private ImageHyperlink renameHyperlink; - - /** - * Invokes the refactor->rename action on the current selection. - */ - private void invokeRenameRefactoring() - { - IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - XSDSchema schema = (XSDSchema) editor.getAdapter(XSDSchema.class); - ISelection selection = editor.getSite().getSelectionProvider().getSelection(); - ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class); - selection = mapper != null ? mapper.mapSelection(selection) : selection; - RenameComponentAction action = new RenameComponentAction(selection, schema); - action.update(selection); - action.run(); - } - - /** - * Creates the refactor/rename hyperlink shown beside a component name. - * Clicking on the hyperlink invokes the refactor/rename action. - * - * @param parent - * the parent composite. Must not be null. - */ - protected void createRenameHyperlink(Composite parent) - { - renameHyperlink = getWidgetFactory().createImageHyperlink(parent, SWT.NONE); - - renameHyperlink.setImage(XSDEditorPlugin.getXSDImage("icons/quickassist.gif")); //$NON-NLS-1$ - renameHyperlink.setToolTipText(Messages._UI_TOOLTIP_RENAME_REFACTOR); - renameHyperlink.addHyperlinkListener(this); - } - - protected void setRenameHyperlinkEnabled(boolean isEnabled) - { - renameHyperlink.setEnabled(isEnabled); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent) - */ - public void linkActivated(HyperlinkEvent e) - { - invokeRenameRefactoring(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent) - */ - public void linkEntered(HyperlinkEvent e) - { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.forms.events.IHyperlinkListener#linkExited(org.eclipse.ui.forms.events.HyperlinkEvent) - */ - public void linkExited(HyperlinkEvent e) - { - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SchemaLocationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SchemaLocationSection.java deleted file mode 100644 index 129eafd5ab..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SchemaLocationSection.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.viewers.ResourceFilter; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.wizards.XSDSelectIncludeFileWizard; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.impl.XSDIncludeImpl; -import org.eclipse.xsd.impl.XSDRedefineImpl; -import org.w3c.dom.Element; - -public class SchemaLocationSection extends CommonDirectivesSection -{ - IWorkbenchPart part; - - /** - * - */ - public SchemaLocationSection() - { - super(); - } - - /** - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory) - */ - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - GridData data = new GridData(); - - // Create Schema Location Label - CLabel schemaLocationLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_SCHEMA_LOCATION")); //$NON-NLS-1$ - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - schemaLocationLabel.setLayoutData(data); - - // Create Schema Location Text - schemaLocationText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - schemaLocationText.setEditable(true); - applyAllListeners(schemaLocationText); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - schemaLocationText.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(schemaLocationText, - XSDEditorCSHelpIds.GENERAL_TAB__INCLUDE_REDEFINE__SCHEMALOCATION); - - // Create Wizard Button - wizardButton = getWidgetFactory().createButton(composite, "", SWT.NONE); //$NON-NLS-1$ - wizardButton.setImage(XSDEditorPlugin.getXSDImage("icons/browsebutton.gif")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - wizardButton.setLayoutData(data); - wizardButton.addSelectionListener(this); - - // error text - errorText = new StyledText(composite, SWT.FLAT); - errorText.setEditable(false); - errorText.setEnabled(false); - errorText.setText(""); //$NON-NLS-1$ - - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 3; - data.grabExcessHorizontalSpace = true; - errorText.setLayoutData(data); - - } - - public void doWidgetSelected(SelectionEvent event) - { - if (event.widget == wizardButton) - { - Shell shell = Display.getCurrent().getActiveShell(); - - IFile currentIFile = ((IFileEditorInput)getActiveEditor().getEditorInput()).getFile(); - ViewerFilter filter = new ResourceFilter(new String[] { ".xsd" }, //$NON-NLS-1$ - new IFile[] { currentIFile }, - null); - - XSDSelectIncludeFileWizard fileSelectWizard = - new XSDSelectIncludeFileWizard(xsdSchema, true, - XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_SCHEMA"), //$NON-NLS-1$ - XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_DESC"), //$NON-NLS-1$ - filter, - (IStructuredSelection) getSelection()); - - WizardDialog wizardDialog = new WizardDialog(shell, fileSelectWizard); - wizardDialog.create(); - wizardDialog.setBlockOnOpen(true); - int result = wizardDialog.open(); - - String value = schemaLocationText.getText(); - if (result == Window.OK) - { - errorText.setText(""); //$NON-NLS-1$ - IFile selectedIFile = fileSelectWizard.getResultFile(); - String schemaFileString = value; - if (selectedIFile != null) - { - schemaFileString = URIHelper.getRelativeURI(selectedIFile.getLocation(), currentIFile.getLocation()); - } - else - { - schemaFileString = fileSelectWizard.getURL(); - } - - handleSchemaLocationChange(schemaFileString, fileSelectWizard.getNamespace(), null); - refresh(); - } - } - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - setListenerEnabled(false); - - Element element = null; - if (input instanceof XSDInclude) - { - element = ((XSDIncludeImpl) input).getElement(); - } - else if (input instanceof XSDRedefine) - { - element = ((XSDRedefineImpl) input).getElement(); - } - - if (element != null) - { - String location = ""; //$NON-NLS-1$ - location = element.getAttribute("schemaLocation"); //$NON-NLS-1$ - if (location == null) - { - location = ""; //$NON-NLS-1$ - } - schemaLocationText.setText(location); - } - - setListenerEnabled(true); - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISection#shouldUseExtraSpace() - */ - public boolean shouldUseExtraSpace() - { - return true; - } - - protected void handleSchemaLocationChange(String schemaFileString, String namespace, XSDSchema externalSchema) - { - if (input instanceof XSDInclude) - { - Element element = ((XSDIncludeImpl) input).getElement(); - element.setAttribute("schemaLocation", schemaFileString); //$NON-NLS-1$ - } - else if (input instanceof XSDRedefine) - { - Element element = ((XSDRedefineImpl) input).getElement(); - element.setAttribute("schemaLocation", schemaFileString); //$NON-NLS-1$ - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SimpleContentUnionMemberTypesDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SimpleContentUnionMemberTypesDialog.java deleted file mode 100644 index a090be1f09..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SimpleContentUnionMemberTypesDialog.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.wst.xsd.ui.internal.util.ViewUtility; -import org.eclipse.wst.xsd.ui.internal.widgets.TypeSection; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; - - -public class SimpleContentUnionMemberTypesDialog extends Dialog implements SelectionListener -{ - XSDSimpleTypeDefinition simpleType; - /** - * @param parentShell - */ - public SimpleContentUnionMemberTypesDialog(Shell parentShell, XSDSimpleTypeDefinition simpleType) - { - super(parentShell); - this.simpleType = simpleType; - } - - Table table; - TypeSection typeSection; - Button addButton, removeButton; - org.eclipse.swt.widgets.List memberTypesList; - - private String result; - - protected void configureShell(Shell shell) - { - super.configureShell(shell); - } - - protected void buttonPressed(int buttonId) - { - if (buttonId == Window.OK) - { - StringBuffer sb = new StringBuffer(); - int length = memberTypesList.getItemCount(); - for (int i=0 ; i < length; i++) - { - sb.append(memberTypesList.getItem(i)); - if (i < length - 1) - { - sb.append(" "); //$NON-NLS-1$ - } - } - result = sb.toString(); - } - super.buttonPressed(buttonId); - } - - public String getResult() { return result; } - - // - // Create the controls - // - public Control createDialogArea(Composite parent) - { - Composite client = (Composite)super.createDialogArea(parent); - getShell().setText("Union " + XSDConstants.MEMBERTYPES_ATTRIBUTE); //$NON-NLS-1$ - - Label instructions = new Label(client, SWT.LEFT | SWT.WRAP); - instructions.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_SELECT_MEMBERTYPES")); //$NON-NLS-1$ - - Composite columnsComposite = new Composite(client, SWT.NONE); - GridLayout ccGL = new GridLayout(); - ccGL.verticalSpacing = 0; - ccGL.horizontalSpacing = 0; - ccGL.marginHeight = 0; - ccGL.marginWidth = 0; - ccGL.makeColumnsEqualWidth = true; - ccGL.numColumns = 3; - columnsComposite.setLayout(ccGL); - - GridData ccGD = new GridData(); - ccGD.grabExcessHorizontalSpace = true; - ccGD.horizontalAlignment = GridData.FILL; - columnsComposite.setLayoutData(ccGD); - - typeSection = new TypeSection(columnsComposite); - typeSection.setShowUserComplexType(false); - - typeSection.createClient(columnsComposite); - typeSection.getSimpleType().setSelection(false); - typeSection.getSimpleType().addSelectionListener(this); - typeSection.getUserSimpleType().addSelectionListener(this); - - ViewUtility.createHorizontalFiller(columnsComposite, 1); - - Label memberListLabel = new Label(columnsComposite, SWT.LEFT); - memberListLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES_VALUE")); //$NON-NLS-1$ - - Composite dataComposite = new Composite(client, SWT.NONE); - GridLayout dcGL = new GridLayout(); - dcGL.verticalSpacing = 0; - dcGL.marginHeight = 0; - dcGL.marginWidth = 0; - dcGL.numColumns = 3; - dataComposite.setLayout(dcGL); - - GridData dcGD = new GridData(); - dcGD.grabExcessHorizontalSpace = true; - dcGD.grabExcessVerticalSpace = true; - dataComposite.setLayoutData(dcGD); - - table = new Table(dataComposite, - SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - table.setHeaderVisible(false); - table.setLinesVisible(true); - GridData gd2 = new GridData(); - gd2.grabExcessHorizontalSpace = true; - gd2.grabExcessVerticalSpace = true; - gd2.horizontalAlignment = GridData.FILL; - gd2.verticalAlignment = GridData.FILL; - gd2.heightHint = 200; - gd2.widthHint = 200; - table.setLayoutData(gd2); - - // Fill table - handleSetInput(); - table.getItemCount(); - - TableColumn tc = new TableColumn(table, SWT.LEFT); - tc.setWidth(200); - tc.setResizable(true); - - Composite buttonComposite = new Composite(dataComposite, SWT.NONE); - GridLayout bcGL = new GridLayout(); - bcGL.numColumns = 1; - buttonComposite.setLayout(bcGL); - addButton = new Button(buttonComposite, SWT.PUSH); - addButton.setText(">"); //$NON-NLS-1$ - addButton.addSelectionListener(this); - removeButton = new Button(buttonComposite, SWT.PUSH); - removeButton.setText("<"); //$NON-NLS-1$ - removeButton.addSelectionListener(this); - - Composite listComposite = new Composite(dataComposite, SWT.NONE); - GridLayout mtGL = new GridLayout(); - mtGL.numColumns = 1; - mtGL.marginHeight = 0; - mtGL.marginWidth = 0; - mtGL.horizontalSpacing = 0; - mtGL.verticalSpacing = 0; - listComposite.setLayout(mtGL); - - GridData mtGD = new GridData(); - mtGD.grabExcessHorizontalSpace = true; - mtGD.grabExcessVerticalSpace = true; - mtGD.verticalAlignment = GridData.FILL; - mtGD.horizontalAlignment = GridData.FILL; - listComposite.setLayoutData(mtGD); - - memberTypesList = new org.eclipse.swt.widgets.List(listComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - GridData mtlGD = new GridData(); - mtlGD.grabExcessHorizontalSpace = true; - mtlGD.grabExcessVerticalSpace = true; - mtlGD.verticalAlignment = GridData.FILL; - mtlGD.horizontalAlignment = GridData.FILL; - mtlGD.heightHint = 200; - mtlGD.widthHint = 200; - memberTypesList.setLayoutData(mtlGD); - - initializeMemberListContent(); - return client; - } - - private void initializeMemberListContent() - { -// String result = element.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE); -// if (result == null) -// { -// return; -// } -// StringTokenizer token = new StringTokenizer(result); -// while (token.hasMoreTokens()) -// { -// memberTypesList.add(token.nextToken()); -// } - XSDSchema schema = simpleType.getSchema(); - for (Iterator i = simpleType.getMemberTypeDefinitions().iterator(); i.hasNext(); ) - { - String name = ((XSDSimpleTypeDefinition)i.next()).getQName(schema); - if (name != null) - memberTypesList.add(name); - } - } - - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetSelected(SelectionEvent e) - { - if (e.widget == typeSection.getSimpleType() && typeSection.getSimpleType().getSelection()) - { - populateBuiltInType(); - } - else if (e.widget == typeSection.getUserSimpleType() && typeSection.getUserSimpleType().getSelection()) - { - populateUserSimpleType(false); - } - else if (e.widget == addButton) - { - TableItem[] items = table.getItems(); - int selection = table.getSelectionIndex(); - if (items != null && items.length > 0 && selection >= 0) - { - String typeToAdd = items[selection].getData().toString(); - if (memberTypesList.indexOf(typeToAdd) < 0) - { - memberTypesList.add(items[selection].getData().toString()); - } - } - } - else if (e.widget == removeButton) - { - String[] typesToRemove = memberTypesList.getSelection(); - for (int i=0; i < typesToRemove.length; i++) - { - memberTypesList.remove(typesToRemove[i]); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetDefaultSelected(SelectionEvent e) - { - } - - public void handleSetInput() - { - populateBuiltInType(); - } - - public void populateBuiltInType() - { - table.removeAll(); - List items = getBuiltInTypeNamesList(); - for (int i = 0; i < items.size(); i++) - { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(items.get(i).toString()); - item.setImage(XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif")); //$NON-NLS-1$ - item.setData(items.get(i)); - } - } - - public void populateUserSimpleType(boolean showAnonymous) - { - table.removeAll(); - if (showAnonymous) - { - TableItem anonymousItem = new TableItem(table, SWT.NONE); - anonymousItem.setText("**anonymous**"); //$NON-NLS-1$ - anonymousItem.setData("**anonymous**"); //$NON-NLS-1$ - } - List items = getUserSimpleTypeNamesList(); - for (int i = 0; i < items.size(); i++) - { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(items.get(i).toString()); - item.setImage(XSDEditorPlugin.getXSDImage("icons/XSDSimpleType.gif")); //$NON-NLS-1$ - item.setData(items.get(i)); - } - } - - public java.util.List getBuiltInTypeNamesList() - { - TypesHelper helper = new TypesHelper(simpleType.getSchema()); - return helper.getBuiltInTypeNamesList(); - } - - public java.util.List getUserSimpleTypeNamesList() - { - TypesHelper helper = new TypesHelper(simpleType.getSchema()); - return helper.getUserSimpleTypeNamesList(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SpecificConstraintsWidget.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SpecificConstraintsWidget.java deleted file mode 100644 index 4d9baa0d41..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SpecificConstraintsWidget.java +++ /dev/null @@ -1,692 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import com.ibm.icu.util.StringTokenizer; - -import org.eclipse.gef.commands.CommandStack; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.common.ui.internal.viewers.NavigableTableViewer; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.DeleteCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.SetXSDFacetValueCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDPatternFacetCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -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.widgets.EnumerationsDialog; -import org.eclipse.wst.xsd.ui.internal.wizards.RegexWizard; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDFacet; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDPatternFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class SpecificConstraintsWidget implements SelectionListener, Listener -{ - public static int ENUMERATION = 0; - public static int PATTERN = 1; - - int kind; - ConstraintsTableViewer constraintsTableViewer; - Button addButton; - Button addUsingDialogButton; - Button deleteButton; - Button editButton; - Composite composite; - boolean isEnabled; - TabbedPropertySheetWidgetFactory factory; - XSDSimpleTypeDefinition input; - XSDFeature feature; - boolean isReadOnly; - CommandStack commandStack; - XSDFacetSection facetSection; - - public SpecificConstraintsWidget(Composite composite, TabbedPropertySheetWidgetFactory factory, XSDFeature feature, XSDSimpleTypeDefinition input, XSDFacetSection facetSection) - { - this.factory = factory; - this.input = input; - this.composite = composite; - this.feature = feature; - this.facetSection = facetSection; - createControl(composite); - } - - public void setCommandStack(CommandStack commandStack) - { - this.commandStack = commandStack; - } - - public void setIsReadOnly(boolean isReadOnly) - { - this.isReadOnly = isReadOnly; - } - - public TabbedPropertySheetWidgetFactory getWidgetFactory() - { - return factory; - } - - public Control getControl() - { - return composite; - } - - public void setEnabled(boolean isEnabled) - { - this.isEnabled = isEnabled; - addButton.setEnabled(isEnabled); - addUsingDialogButton.setEnabled(isEnabled); - editButton.setEnabled(isEnabled); - constraintsTableViewer.getTable().setEnabled(isEnabled); - composite.setEnabled(isEnabled); - } - - public Control createControl(Composite parent) - { - composite = factory.createFlatFormComposite(parent); - GridData data = new GridData(); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - constraintsTableViewer = new ConstraintsTableViewer(getWidgetFactory().createTable(composite, SWT.MULTI | SWT.FULL_SELECTION)); - constraintsTableViewer.setInput(input); - Table table = constraintsTableViewer.getTable(); - table.addSelectionListener(this); - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - data.widthHint = 150; - data.grabExcessVerticalSpace = true; - table.setLayoutData(data); - table.addListener(SWT.Resize, this); - - Composite buttonComposite = getWidgetFactory().createComposite(composite, SWT.FLAT); - GridLayout buttonCompositeLayout = new GridLayout(); - buttonCompositeLayout.marginTop = 0; - buttonCompositeLayout.marginBottom = 0; - buttonCompositeLayout.numColumns = 1; - buttonComposite.setLayout(buttonCompositeLayout); - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = false; - buttonComposite.setLayoutData(data); - - - addButton = getWidgetFactory().createButton(buttonComposite, Messages._UI_ACTION_ADD, SWT.PUSH); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - addButton.setLayoutData(data); - addButton.addSelectionListener(this); - - addUsingDialogButton = getWidgetFactory().createButton(buttonComposite, Messages._UI_ACTION_ADD_WITH_DOTS, SWT.PUSH); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - addUsingDialogButton.setLayoutData(data); - addUsingDialogButton.addSelectionListener(this); - - editButton = getWidgetFactory().createButton(buttonComposite, Messages._UI_ACTION_EDIT_WITH_DOTS, SWT.PUSH); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - editButton.setLayoutData(data); - editButton.setEnabled(false); - editButton.addSelectionListener(this); - - - deleteButton = getWidgetFactory().createButton(buttonComposite, Messages._UI_ACTION_DELETE, SWT.PUSH); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - deleteButton.setLayoutData(data); - deleteButton.setEnabled(false); - deleteButton.addSelectionListener(this); - - - return composite; - } - - public void handleEvent(Event event) - { - Table table = constraintsTableViewer.getTable(); - if (event.type == SWT.Resize && event.widget == table) - { - TableColumn tableColumn = table.getColumn(0); - tableColumn.setWidth(table.getSize().x); - } - } - - public void setInput(Object input) - { - constraintsTableViewer.setInput(input); - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } -// constraintsTableViewer.refresh(); - } - - public void widgetSelected(SelectionEvent e) - { - XSDSimpleTypeDefinition st = input; - Element element = st.getElement(); - - if (e.widget == addButton) - { - List enumList = st.getEnumerationFacets(); - StringBuffer newName = new StringBuffer("value1"); //$NON-NLS-1$ - int suffix = 1; - for (Iterator i = enumList.iterator(); i.hasNext();) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next(); - String value = enumFacet.getLexicalValue(); - if (value != null) - { - if (value.equals(newName.toString())) - { - suffix++; - newName = new StringBuffer("value" + String.valueOf(suffix)); //$NON-NLS-1$ - } - } - } - - if (kind == ENUMERATION) - { - CompoundCommand compoundCommand = new CompoundCommand(); - XSDSimpleTypeDefinition targetSimpleType = null; - if (feature != null) - { - XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input); - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(input); - - ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CHANGE_PATTERN, feature); - changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); - compoundCommand.add(changeToAnonymousCommand); - input = anonymousSimpleType; - } - targetSimpleType = anonymousSimpleType; - } - else - { - targetSimpleType = input; - } - - AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, targetSimpleType); - command.setValue(newName.toString()); - compoundCommand.add(command); - commandStack.execute(compoundCommand); - setInput(input); - constraintsTableViewer.refresh(); - int newItemIndex = constraintsTableViewer.getTable().getItemCount() - 1; - constraintsTableViewer.editElement(constraintsTableViewer.getElementAt(newItemIndex), 0); - } - } - else if (e.widget == addUsingDialogButton) - { - Display display = Display.getCurrent(); - // if it is null, get the default one - display = display == null ? Display.getDefault() : display; - Shell shell = display.getActiveShell(); - - if (kind == PATTERN) - { - String initialValue = ""; //$NON-NLS-1$ - RegexWizard wizard = new RegexWizard(initialValue); - - WizardDialog wizardDialog = new WizardDialog(shell, wizard); - wizardDialog.setBlockOnOpen(true); - wizardDialog.create(); - - int result = wizardDialog.open(); - - if (result == Window.OK) - { - String newPattern = wizard.getPattern(); - CompoundCommand compoundCommand = new CompoundCommand(); - XSDSimpleTypeDefinition targetSimpleType = null; - if (feature != null) - { - XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input); - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(input); - - ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CHANGE_PATTERN, feature); - changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); - compoundCommand.add(changeToAnonymousCommand); - input = anonymousSimpleType; - } - targetSimpleType = anonymousSimpleType; - } - else - { - targetSimpleType = input; - } - - UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand(Messages._UI_ACTION_ADD_PATTERN, targetSimpleType, UpdateXSDPatternFacetCommand.ADD); - command.setValue(newPattern); - setInput(input); - compoundCommand.add(command); - commandStack.execute(compoundCommand); - facetSection.doSetInput(); - } - constraintsTableViewer.refresh(); - } - else - { - EnumerationsDialog dialog = new EnumerationsDialog(shell); - dialog.setBlockOnOpen(true); - int result = dialog.open(); - - if (result == Window.OK) - { - String text = dialog.getText(); - String delimiter = dialog.getDelimiter(); - StringTokenizer tokenizer = new StringTokenizer(text, delimiter); - CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS); - - XSDSimpleTypeDefinition targetSimpleType = null; - if (feature != null) - { - XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input); - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(input); - - ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand("", feature); //$NON-NLS-1$ - changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); - compoundCommand.add(changeToAnonymousCommand); - input = anonymousSimpleType; - } - targetSimpleType = anonymousSimpleType; - } - else - { - targetSimpleType = input; - } - - while (tokenizer.hasMoreTokens()) - { - String token = tokenizer.nextToken(); - if (dialog.isPreserveWhitespace() == false) - { - token = token.trim(); - } - AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATIONS, targetSimpleType); - command.setValue(token); - compoundCommand.add(command); - } - commandStack.execute(compoundCommand); - } - //setInput(input); - facetSection.doSetInput(); - constraintsTableViewer.refresh(); - } - } - else if (e.widget == deleteButton) - { - StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); - CompoundCommand compoundCommand = new CompoundCommand(); - if (selection != null) - { - Iterator i = selection.iterator(); - if (selection.size() > 0) - { - compoundCommand.setLabel(Messages._UI_ACTION_DELETE_CONSTRAINTS); - } - else - { - compoundCommand.setLabel(Messages._UI_ACTION_DELETE_PATTERN); - } - while (i.hasNext()) - { - Object obj = i.next(); - if (obj != null) - { - if (obj instanceof XSDPatternFacet) - { - UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand("", input, UpdateXSDPatternFacetCommand.DELETE); //$NON-NLS-1$ - command.setPatternToEdit((XSDPatternFacet)obj); - compoundCommand.add(command); - } - else if (obj instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj; - DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet); - compoundCommand.add(deleteCommand); - } - } - } - commandStack.execute(compoundCommand); - constraintsTableViewer.refresh(); - - if (constraintsTableViewer.getTable().getItemCount() == 0) - { - editButton.setEnabled(false); - deleteButton.setEnabled(false); - } - } - } - else if (e.widget == editButton) - { - StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); - if (selection != null) - { - Object obj = selection.getFirstElement(); - if (obj instanceof XSDPatternFacet) - { - XSDPatternFacet pattern = (XSDPatternFacet) obj; - String initialValue = pattern.getLexicalValue(); - if (initialValue == null) - { - initialValue = ""; //$NON-NLS-1$ - } - - Shell shell = Display.getCurrent().getActiveShell(); - - RegexWizard wizard = new RegexWizard(initialValue); - - WizardDialog wizardDialog = new WizardDialog(shell, wizard); - wizardDialog.setBlockOnOpen(true); - wizardDialog.create(); - - int result = wizardDialog.open(); - - if (result == Window.OK) - { - String newPattern = wizard.getPattern(); - element.setAttribute(XSDConstants.VALUE_ATTRIBUTE, newPattern); - pattern.setLexicalValue(newPattern); - constraintsTableViewer.refresh(); - } - } - } - } - else if (e.widget == constraintsTableViewer.getTable()) - { - StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); - if (selection.getFirstElement() != null) - { - editButton.setEnabled(true); - deleteButton.setEnabled(true); - } - else - { - editButton.setEnabled(false); - deleteButton.setEnabled(false); - } - } - } - - public void widgetDefaultSelected(SelectionEvent e) - { - - } - - - public void setConstraintKind(int kind) - { - this.kind = kind; - constraintsTableViewer.setInput(input); - constraintsTableViewer.refresh(); - } - - public void doModify(Object element, String property, Object value) - { - if (element instanceof TableItem && (value != null)) - { - TableItem item = (TableItem) element; - - if (item.getData() instanceof XSDPatternFacet) - { - XSDPatternFacet patternFacet = (XSDPatternFacet) item.getData(); - patternFacet.setLexicalValue((String) value); - - item.setData(patternFacet); - item.setText((String) value); - } - else if (item.getData() instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) item.getData(); - SetXSDFacetValueCommand command = new SetXSDFacetValueCommand(Messages._UI_ACTION_SET_ENUMERATION_VALUE, enumFacet); - command.setValue((String) value); - commandStack.execute(command); - item.setData(enumFacet); - item.setText((String) value); - } - } - } - - public Object doGetValue(Object element, String property) - { - if (element instanceof XSDPatternFacet) - { - XSDPatternFacet patternFacet = (XSDPatternFacet) element; - String value = patternFacet.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - else if (element instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) element; - String value = enumFacet.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - - return ""; //$NON-NLS-1$ - } - - class ConstraintsTableViewer extends NavigableTableViewer implements ICellModifier - { - protected String[] columnProperties = { Messages._UI_LABEL_PATTERN }; - - protected CellEditor[] cellEditors; - - Table table; - - public ConstraintsTableViewer(Table table) - { - super(table); - table = getTable(); - - table.setLinesVisible(true); - - setContentProvider(new ConstraintsContentProvider()); - setLabelProvider(new ConstraintsTableLabelProvider()); - setColumnProperties(columnProperties); - - setCellModifier(this); - - TableColumn column = new TableColumn(table, SWT.NONE, 0); - column.setText(columnProperties[0]); - column.setAlignment(SWT.LEFT); - column.setResizable(true); - - cellEditors = new CellEditor[1]; - - TableLayout layout = new TableLayout(); - ColumnWeightData data = new ColumnWeightData(100); - - layout.addColumnData(data); - cellEditors[0] = new TextCellEditor(table); - - getTable().setLayout(layout); - setCellEditors(cellEditors); - } - - public boolean canModify(Object element, String property) - { - return true; - } - - public void modify(Object element, String property, Object value) - { - doModify(element, property, value); - } - - public Object getValue(Object element, String property) - { - return doGetValue(element, property); - } - - } - - class ConstraintsContentProvider implements IStructuredContentProvider - { - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - } - - public java.lang.Object[] getElements(java.lang.Object inputElement) - { - java.util.List list = new ArrayList(); - if (inputElement instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) inputElement; - boolean isDefined = false; - Iterator iter; - if (kind == PATTERN) - { - iter = st.getPatternFacets().iterator(); - } - else - { - iter = st.getEnumerationFacets().iterator(); - } - - while (iter.hasNext()) - { - XSDFacet facet = (XSDFacet) iter.next(); - isDefined = (facet.getRootContainer() == facetSection.xsdSchema); - } - - if (kind == PATTERN) - { - if (isDefined) - { - return st.getPatternFacets().toArray(); - } - } - else - { - if (isDefined) - { - return st.getEnumerationFacets().toArray(); - } - } - } - return list.toArray(); - } - - public void dispose() - { - } - } - - class ConstraintsTableLabelProvider extends LabelProvider implements ITableLabelProvider - { - public ConstraintsTableLabelProvider() - { - - } - - public Image getColumnImage(Object element, int columnIndex) - { - if (kind == PATTERN) - { - return XSDEditorPlugin.getXSDImage("icons/XSDSimplePattern.gif"); //$NON-NLS-1$ - } - else - { - return XSDEditorPlugin.getXSDImage("icons/XSDSimpleEnum.gif"); //$NON-NLS-1$ - } - } - - public String getColumnText(Object element, int columnIndex) - { - if (element instanceof XSDPatternFacet) - { - XSDPatternFacet pattern = (XSDPatternFacet) element; - String value = pattern.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - else if (element instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) element; - String value = enumFacet.getLexicalValue(); - if (value == null) - value = ""; //$NON-NLS-1$ - return value; - } - return ""; //$NON-NLS-1$ - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDActionManager.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDActionManager.java deleted file mode 100644 index b31fa6c429..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDActionManager.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CommandStack; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -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.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.actions.EditAttributeAction; -import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class XSDActionManager extends XMLNodeActionManager { - - private CommandStack commandStack; - - public XSDActionManager(IStructuredModel model, Viewer viewer) { - super(model, viewer); - } - - public void setCommandStack(CommandStack commandStack) { - this.commandStack = commandStack; - } - - protected Action createAddCDataSectionAction(Node parent, int index) - { - return null; - } - - protected Action createAddPCDataAction(Node parent, CMDataType dataType, int index) { - return null; - } - - - protected void contributeAddDocumentChildActions(IMenuManager menu, Document document, int ic, int vc) { - } - - protected void contributeEditGrammarInformationActions(IMenuManager menu, Node node) { - } - - protected void contributePIAndCommentActions(IMenuManager menu, Document document, int index) { - } - - protected void contributePIAndCommentActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) { - } - - protected void contributeTextNodeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) { - super.contributeTextNodeActions(menu, parentElement, parentEd, index); - } - - protected Action createAddAttributeAction(Element parent, CMAttributeDeclaration ad) { - Action action = null; - if (ad == null) { - action = new EditAttributeAction(this, parent, null, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE, XMLUIMessages._UI_MENU_NEW_ATTRIBUTE_TITLE); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - action = new AddNodeAction(ad, parent, -1); - } - - WrapperCommand command = new WrapperCommand(action, parent, ad); - WrapperAction wrapperAction = new WrapperAction(command); - return wrapperAction; - } - - class WrapperAction extends Action - { - WrapperCommand command; - - public WrapperAction(WrapperCommand command) - { - super(); - this.command = command; - } - - public String getText() - { - return command.getAction().getText(); - } - - public void run() - { - // Some editors may not use a command stack - if (commandStack != null) - { - commandStack.execute(command); - } - else - { - command.execute(); - } - } - } - - class WrapperCommand extends Command - { - Action action; - Element parent; - CMAttributeDeclaration ad; - public WrapperCommand(Action action, Element parent, CMAttributeDeclaration ad) - { - super(); - this.action = action; - this.parent = parent; - this.ad = ad; - } - - public String getLabel() - { - return action.getText(); - } - - public Action getAction() - { - return action; - } - - public void execute() - { - action.run(); - } - - public void undo() { - -// ((Element)parent).removeAttribute(ad.getAttrName()); - - getModel().getUndoManager().undo(); - - } - - - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAnyElementContentsSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAnyElementContentsSection.java deleted file mode 100644 index 63e4898bd9..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAnyElementContentsSection.java +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.Iterator; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDProcessContents; -import org.eclipse.xsd.XSDWildcard; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDAnyElementContentsSection extends MultiplicitySection -{ - CCombo namespaceCombo; - CCombo processContentsCombo; - - private String[] namespaceComboValues = { "", //$NON-NLS-1$ - "##any", //$NON-NLS-1$ - "##other", //$NON-NLS-1$ - "##targetNamespace", //$NON-NLS-1$ - "##local" //$NON-NLS-1$ - }; - - /** - * - */ - public XSDAnyElementContentsSection() - { - super(); - } - - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridData data = new GridData(); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - CLabel namespaceLabel = getWidgetFactory().createCLabel(composite, XSDConstants.NAMESPACE_ATTRIBUTE); - namespaceLabel.setLayoutData(data); - - namespaceCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - namespaceCombo.setLayoutData(data); - namespaceCombo.setItems(namespaceComboValues); - namespaceCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(namespaceCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ANYELEMENT__NAMESPACE); - - CLabel processContentsLabel = getWidgetFactory().createCLabel(composite, XSDConstants.PROCESSCONTENTS_ATTRIBUTE); - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - processContentsLabel.setLayoutData(data); - - processContentsCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - processContentsCombo.setLayoutData(data); - Iterator list = XSDProcessContents.VALUES.iterator(); - processContentsCombo.add(""); //$NON-NLS-1$ - while (list.hasNext()) - { - processContentsCombo.add(((XSDProcessContents) list.next()).getName()); - } - processContentsCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(processContentsCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ANYELEMENT__PROCESSCONTENTS); - - // ------------------------------------------------------------------ - // min property - // ------------------------------------------------------------------ - - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MINOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - minCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - minCombo.setLayoutData(data); - minCombo.add("0"); //$NON-NLS-1$ - minCombo.add("1"); //$NON-NLS-1$ - applyAllListeners(minCombo); - minCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(minCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ANYELEMENT__MIN_OCCURENCE); - - // ------------------------------------------------------------------ - // max property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MAXOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - maxCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - maxCombo.setLayoutData(data); - maxCombo.add("0"); //$NON-NLS-1$ - maxCombo.add("1"); //$NON-NLS-1$ - maxCombo.add("unbounded"); //$NON-NLS-1$ - applyAllListeners(maxCombo); - maxCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(maxCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ANYELEMENT__MAX_OCCURENCE); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - setListenerEnabled(false); - namespaceCombo.setText(""); //$NON-NLS-1$ - processContentsCombo.setText(""); //$NON-NLS-1$ - if (input != null) - { - if (input instanceof XSDWildcard) - { - XSDWildcard wildcard = (XSDWildcard) input; - if (wildcard.isSetLexicalNamespaceConstraint()) - { - namespaceCombo.setText(wildcard.getStringLexicalNamespaceConstraint()); - } - else - { - namespaceCombo.setText(""); - } - if (wildcard.isSetProcessContents()) - { - XSDProcessContents pc = wildcard.getProcessContents(); - processContentsCombo.setText(pc.getName()); - } - - if (wildcard.eContainer() instanceof XSDParticle) - { - minCombo.setEnabled(!isReadOnly); - maxCombo.setEnabled(!isReadOnly); - } - else - { - minCombo.setEnabled(false); - maxCombo.setEnabled(false); - } - } - } - refreshMinMax(); - setListenerEnabled(true); - } - - public boolean shouldUseExtraSpace() - { - return false; - } - - public void doWidgetSelected(SelectionEvent e) - { - XSDConcreteComponent concreteComponent = (XSDConcreteComponent) input; - if (concreteComponent instanceof XSDWildcard) - { - XSDWildcard wildcard = (XSDWildcard) concreteComponent; - if (e.widget == namespaceCombo) - { - String newValue = namespaceCombo.getText(); - boolean removeAttribute = false; - if (newValue.length() == 0) - { - removeAttribute = true; - } - // TODO use commands - // beginRecording(XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE"), - // element); //$NON-NLS-1$ - if (removeAttribute) - { - wildcard.unsetLexicalNamespaceConstraint(); - } - else - { - wildcard.setStringLexicalNamespaceConstraint(newValue); - } - // endRecording(element); - } - else if (e.widget == processContentsCombo) - { - String newValue = processContentsCombo.getText(); - boolean removeAttribute = false; - if (newValue.length() == 0) - { - removeAttribute = true; - } - // beginRecording(XSDEditorPlugin.getXSDString("_UI_PROCESSCONTENTS_CHANGE"), - // element); //$NON-NLS-1$ - if (removeAttribute) - { - wildcard.unsetProcessContents(); - } - else - { - wildcard.setProcessContents(XSDProcessContents.get(processContentsCombo.getItem(processContentsCombo.getSelectionIndex()))); - } - // endRecording(element); - } - } - super.doWidgetSelected(e); - } - - public void dispose() - { - if (minCombo != null && !minCombo.isDisposed()) - minCombo.removeSelectionListener(this); - if (maxCombo != null && !maxCombo.isDisposed()) - maxCombo.removeSelectionListener(this); - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java deleted file mode 100644 index b3c09168e4..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java +++ /dev/null @@ -1,761 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.dialogs.NewTypeDialog; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDAttributeReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDAttributeDeclarationSection extends RefactoringSection -{ - protected Text nameText, defaultOrFixedText; - protected CCombo componentNameCombo, typeCombo, usageCombo, formCombo; - protected Button defaultButton, fixedButton; - protected String typeName = "", refName = ""; //$NON-NLS-1$ - boolean isAttributeReference; - - public XSDAttributeDeclarationSection() - { - super(); - } - - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - String typeLabel = Messages.UI_LABEL_TYPE; //$NON-NLS-1$ - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - nameText.setEnabled(!isAttributeReference); - applyAllListeners(nameText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__NAME); - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isAttributeReference); - - // ------------------------------------------------------------------ - // Ref Label - // ------------------------------------------------------------------ - if (isAttributeReference) - { - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel refLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_REFERENCE); - refLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Ref Combo - // ------------------------------------------------------------------ - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - componentNameCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - componentNameCombo.addSelectionListener(this); - componentNameCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__NAME); - - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - } - - // ------------------------------------------------------------------ - // typeLabel - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, typeLabel); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // typeCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - typeCombo = getWidgetFactory().createCCombo(composite); - typeCombo.setLayoutData(data); - typeCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(typeCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__TYPE); - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // UsageLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel useLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_USAGE")); - useLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // UsageCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - usageCombo = getWidgetFactory().createCCombo(composite); - usageCombo.setLayoutData(data); - usageCombo.addSelectionListener(this); - usageCombo.add(""); - usageCombo.add("required"); //$NON-NLS-1$ - usageCombo.add("optional"); //$NON-NLS-1$ - usageCombo.add("prohibited"); //$NON-NLS-1$ - usageCombo.addSelectionListener(this); - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // defaultLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel defaultLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_VALUE_COLON); - defaultLabel.setLayoutData(data); - - Composite radio = getWidgetFactory().createComposite(composite); - radio.setLayout(new RowLayout()); - - defaultButton = new Button(radio, SWT.RADIO); - defaultButton.setText(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT); - defaultButton.setBackground(parent.getBackground()); - defaultButton.addSelectionListener(this); - - fixedButton = new Button(radio, SWT.RADIO); - fixedButton.setText(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED); - fixedButton.setBackground(parent.getBackground()); - fixedButton.addSelectionListener(this); - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // defaultText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - defaultOrFixedText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - defaultOrFixedText.setLayoutData(data); - applyAllListeners(defaultOrFixedText); - - //PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - // XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__DEFAULT); - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // FormLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel formLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FORM); - formLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // FormCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - formCombo = getWidgetFactory().createCCombo(composite); - formCombo.setLayoutData(data); - formCombo.addSelectionListener(this); - formCombo.add(""); - formCombo.add("qualified"); //$NON-NLS-1$ - formCombo.add("unqualified"); //$NON-NLS-1$ - formCombo.addSelectionListener(this); - - // dummy - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - } - - private void fillTypesCombo() - { - IEditorPart editor = getActiveEditor(); - XSDTypeReferenceEditManager manager = (XSDTypeReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - ComponentSpecification[] items = manager.getQuickPicks(); - - typeCombo.removeAll(); - typeCombo.add(Messages._UI_ACTION_BROWSE); - typeCombo.add(Messages._UI_ACTION_NEW); - for (int i = 0; i < items.length; i++) - { - typeCombo.add(items[i].getName()); - } - - XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration(); - XSDTypeDefinition namedComponentType = namedComponent.getType(); - if (namedComponentType != null) - { - String currentTypeName = namedComponentType.getQName(xsdSchema); // no prefix - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager); - if (ret == null) //not in quickPick - typeCombo.add(currentTypeName); - } - } - - private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) - { - if (editManager != null) - { - ComponentSpecification[] quickPicks = editManager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - if (value.equals(componentSpecification.getName())) - { - return componentSpecification; - } - } - } - } - return null; - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - super.refresh(); - - setListenerEnabled(false); - - // refresh name - - nameText.setText(""); //$NON-NLS-1$ - if (input instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration(); - - String name = namedComponent.getName(); - if (name != null) - { - nameText.setText(name); - } - } - - if (isAttributeReference) - { - refreshRefCombo(); - } - - // refresh type - - typeCombo.setText(""); //$NON-NLS-1$ - if (input != null) - { - if (input instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input; - isAttributeReference = ((XSDAttributeDeclaration)input).isAttributeDeclarationReference(); - XSDTypeDefinition typeDef = xsdAttribute.getResolvedAttributeDeclaration().getTypeDefinition(); - boolean isAnonymous = xsdAttribute.getAnonymousTypeDefinition() != null; - - if (isAnonymous) - { - typeCombo.setText("**anonymous**"); //$NON-NLS-1$ - } - else - { - fillTypesCombo(); - if (typeDef != null) - { - typeName = typeDef.getQName(xsdSchema); - if (typeName == null) - { - typeName = ""; //$NON-NLS-1$ - } - typeCombo.setText(typeName); - } - else - { - typeCombo.setText(Messages.UI_NO_TYPE); //$NON-NLS-1$ - } - } - - usageCombo.setText(""); - usageCombo.setEnabled(!xsdAttribute.isGlobal()); - - Element element = xsdAttribute.getElement(); - boolean hasUseAttribute = false; - if (element != null) - { - hasUseAttribute = element.hasAttribute(XSDConstants.USE_ATTRIBUTE); - if (hasUseAttribute) - { - String usage = element.getAttribute(XSDConstants.USE_ATTRIBUTE); - usageCombo.setText(usage); - } - } - - defaultOrFixedText.setText(""); //$NON-NLS-1$ - - boolean hasDefaultAttribute = false, hasFixedAttribute = false; - if (element != null) - { - hasDefaultAttribute = element.hasAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - hasFixedAttribute = element.hasAttribute(XSDConstants.FIXED_ATTRIBUTE); - - // Case where no fixed or default attributes exist, so ensure one of the radio buttons is selected - if (!hasDefaultAttribute && !hasFixedAttribute) - { - if (!defaultButton.getSelection() && !fixedButton.getSelection()) // if none are selected then pick fixed - fixedButton.setSelection(true); - } - else - { - // if both are present in source (an error!), assume that *fixed* takes "precedence" - defaultButton.setSelection(!hasFixedAttribute && hasDefaultAttribute); - fixedButton.setSelection(hasFixedAttribute); - if (hasDefaultAttribute) - { - String theDefault = element.getAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - defaultOrFixedText.setText(theDefault); - } - if (hasFixedAttribute) // will overwrite default if both present - { - String fixed = element.getAttribute(XSDConstants.FIXED_ATTRIBUTE); - defaultOrFixedText.setText(fixed); - } - } - } - - formCombo.setText(""); - formCombo.setEnabled(!xsdAttribute.isGlobal() && !isAttributeReference); - boolean hasFormAttribute = false; - if (element != null) - { - hasFormAttribute = element.hasAttribute(XSDConstants.FORM_ATTRIBUTE); - if (hasFormAttribute) - { - String form = element.getAttribute(XSDConstants.FORM_ATTRIBUTE); - formCombo.setText(form); - } - } - } - } - - setListenerEnabled(true); - } - - public boolean shouldUseExtraSpace() - { - return false; - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - - String selection = typeCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - ((NewTypeDialog) dialog).allowComplexType(false); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - XSDAttributeDeclaration xsdAttribute = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration(); - manager.modifyComponentReference(xsdAttribute, newValue); - } - else{ - typeCombo.setText(typeName); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - } - else if (e.widget == componentNameCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDAttributeReferenceEditManager.class); - - String selection = componentNameCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(input, newValue); - } - else - { - componentNameCombo.setText(refName); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - - } - else - { - XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input; - Element element = xsdAttribute.getElement(); - if (e.widget == usageCombo) - { - String newValue = usageCombo.getText(); - - if (element != null) - { - if (newValue.length() == 0) - element.removeAttribute(XSDConstants.USE_ATTRIBUTE); - else - element.setAttribute(XSDConstants.USE_ATTRIBUTE, newValue); - } - } - else if (e.widget == formCombo) - { - String newValue = formCombo.getText(); - if (element != null) - { - if (newValue.length() == 0) - element.removeAttribute(XSDConstants.FORM_ATTRIBUTE); - else - element.setAttribute(XSDConstants.FORM_ATTRIBUTE, newValue); - } - } - else if (e.widget == defaultButton) - { - boolean newValue = defaultButton.getSelection(); - if (element != null) - { - if (newValue) - { - if (element.hasAttribute(XSDConstants.FIXED_ATTRIBUTE)) - { - String value = element.getAttribute(XSDConstants.FIXED_ATTRIBUTE); - element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE); - element.setAttribute(XSDConstants.DEFAULT_ATTRIBUTE, value); - } - } - } - } - else if (e.widget == fixedButton) - { - boolean newValue = fixedButton.getSelection(); - if (element != null) - { - if (newValue) - { - if (element.hasAttribute(XSDConstants.DEFAULT_ATTRIBUTE)) - { - String value = element.getAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - element.setAttribute(XSDConstants.FIXED_ATTRIBUTE, value); - } - } - } - } - } - super.doWidgetSelected(e); - } - - protected void doHandleEvent(Event event) - { - super.doHandleEvent(event); - if (event.widget == nameText) - { - if (!nameText.getEditable()) - return; - - String newValue = nameText.getText().trim(); - if (input instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration(); - - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - - if (isAttributeReference) - { - XSDAttributeDeclaration attrRef = (XSDAttributeDeclaration)input; - String qname = attrRef.getResolvedAttributeDeclaration().getQName(); - attrRef.getElement().setAttribute(XSDConstants.REF_ATTRIBUTE, qname); - -// TypesHelper helper = new TypesHelper(xsdSchema); -// List items = new ArrayList(); -// items = helper.getGlobalElements(); -// items.add(0, ""); -// componentNameCombo.setItems((String [])items.toArray(new String[0])); -// -// refreshRefCombo(); - } - - } - } - else if (event.widget == defaultOrFixedText) - { - XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input; - String newValue = defaultOrFixedText.getText(); - Element element = xsdAttribute.getElement(); - if (element != null) - { - if (newValue.length() == 0) - { - element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE); - } - else - { - element.removeAttribute(fixedButton.getSelection() - ? XSDConstants.DEFAULT_ATTRIBUTE : XSDConstants.FIXED_ATTRIBUTE); - element.setAttribute(fixedButton.getSelection() - ? XSDConstants.FIXED_ATTRIBUTE : XSDConstants.DEFAULT_ATTRIBUTE, newValue); - } - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - public void dispose() - { - if (componentNameCombo != null && !componentNameCombo.isDisposed()) - componentNameCombo.removeSelectionListener(this); - if (nameText != null && !nameText.isDisposed()) - removeListeners(nameText); - if (typeCombo != null && !typeCombo.isDisposed()) - typeCombo.removeSelectionListener(this); - super.dispose(); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - setListenerEnabled(false); - init(); - relayout(); - - setListenerEnabled(true); - } - - protected void init() - { - if (input instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input; - isAttributeReference = xsdAttribute.isAttributeDeclarationReference(); - } - } - - protected void relayout() - { - Composite parentComposite = composite.getParent(); - parentComposite.getParent().setRedraw(false); - - if (parentComposite != null && !parentComposite.isDisposed()) - { - Control[] children = parentComposite.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - - // Now initialize the new handler - createContents(parentComposite); - parentComposite.getParent().layout(true, true); - - // Now turn painting back on - parentComposite.getParent().setRedraw(true); - refresh(); - } - - protected void refreshRefCombo() - { - componentNameCombo.setText(""); //$NON-NLS-1$ - fillComponentNameCombo(); - } - - private void fillComponentNameCombo() - { - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDAttributeReferenceEditManager.class); - - componentNameCombo.removeAll(); - componentNameCombo.add(Messages._UI_ACTION_BROWSE); - componentNameCombo.add(Messages._UI_ACTION_NEW); - ComponentSpecification[] quickPicks = manager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - componentNameCombo.add(componentSpecification.getName()); - } - } - ComponentSpecification[] history = manager.getHistory(); - if (history != null) - { - for (int i=0; i < history.length; i++) - { - ComponentSpecification componentSpecification = history[i]; - componentNameCombo.add(componentSpecification.getName()); - } - } - - XSDAttributeDeclaration namedComponent = (XSDAttributeDeclaration) input; - Element element = namedComponent.getElement(); - if (element != null) - { - String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE); - if (attrValue == null) - { - attrValue = ""; //$NON-NLS-1$ - } - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(attrValue, manager); - if (ret == null) - { - componentNameCombo.add(attrValue); - } - componentNameCombo.setText(attrValue); - refName = attrValue; - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeGroupDefinitionSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeGroupDefinitionSection.java deleted file mode 100644 index 7a077ff288..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeGroupDefinitionSection.java +++ /dev/null @@ -1,284 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDAttributeGroupDefinitionSection extends RefactoringSection -{ - protected Text nameText; - protected CCombo refCombo; - boolean isReference; - - public XSDAttributeGroupDefinitionSection() - { - super(); - } - - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - if (isReference) - { - // ------------------------------------------------------------------ - // Ref Label - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel refLabel = getWidgetFactory().createCLabel(composite, XSDConstants.REF_ATTRIBUTE + ":"); //$NON-NLS-1$ - refLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Ref Combo - // ------------------------------------------------------------------ - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - refCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - refCombo.addSelectionListener(this); - refCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(refCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTEGROUP_REFS__REF); - } - else - { - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - applyAllListeners(nameText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTEGROUP__NAME); - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - } - } - - public void refresh() - { - super.refresh(); - - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } - - setListenerEnabled(false); - - XSDNamedComponent namedComponent = (XSDNamedComponent)input; - - if (isReference) - { - Element element = namedComponent.getElement(); - if (element != null) - { - String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE); - if (attrValue == null) - { - attrValue = ""; //$NON-NLS-1$ - } - refCombo.setText(attrValue); - } - } - else - { - // refresh name - nameText.setText(""); //$NON-NLS-1$ - - String name = namedComponent.getName(); - if (name != null) - { - nameText.setText(name); - } - } - setListenerEnabled(true); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - init(); - relayout(); - - if (isReference) - { - TypesHelper helper = new TypesHelper(xsdSchema); - List items = new ArrayList(); - items = helper.getGlobalAttributeGroups(); - items.add(0, ""); //$NON-NLS-1$ - refCombo.setItems((String [])items.toArray(new String[0])); - } - } - - protected void relayout() - { - Composite parentComposite = composite.getParent(); - parentComposite.getParent().setRedraw(false); - - if (parentComposite != null && !parentComposite.isDisposed()) - { - Control[] children = parentComposite.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - - // Now initialize the new handler - createContents(parentComposite); - parentComposite.getParent().layout(true, true); - - // Now turn painting back on - parentComposite.getParent().setRedraw(true); - refresh(); - } - - protected void init() - { - if (input instanceof XSDAttributeGroupDefinition) - { - XSDAttributeGroupDefinition group = (XSDAttributeGroupDefinition) input; - isReference = group.isAttributeGroupDefinitionReference(); - } - } - - public void doHandleEvent(Event event) - { - super.doHandleEvent(event); - if (event.widget == nameText) - { - String newValue = nameText.getText().trim(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent) input; - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - // doReferentialIntegrityCheck(namedComponent, newValue); - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == refCombo) - { - String newValue = refCombo.getText(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent)input; - Element element = namedComponent.getElement(); - - if (namedComponent instanceof XSDAttributeGroupDefinition) - { - element.setAttribute(XSDConstants.REF_ATTRIBUTE, newValue); - } - } - } - super.doWidgetSelected(e); - } - - - public void dispose() - { - if (nameText != null && !nameText.isDisposed()) - removeListeners(nameText); - super.dispose(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeAdvancedSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeAdvancedSection.java deleted file mode 100644 index ceff57cfe1..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeAdvancedSection.java +++ /dev/null @@ -1,276 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDComplexTypeAdvancedSection extends AbstractSection -{ - private static final String EMPTY = ""; //$NON-NLS-1$ - private static final String FALSE = "false"; //$NON-NLS-1$ - private static final String TRUE = "true"; //$NON-NLS-1$ - protected CCombo blockCombo; - protected CCombo finalCombo; - protected CCombo mixedCombo; - protected CCombo abstractCombo; - - private String finalValues[] = { EMPTY, XSDConstants.RESTRICTION_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG, "#" + XSDConstants.ALL_ELEMENT_TAG }; //$NON-NLS-1$ - - private String blockValues[] = { EMPTY, XSDConstants.RESTRICTION_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG, "#" + XSDConstants.ALL_ELEMENT_TAG }; //$NON-NLS-1$ - - private String booleanValues[] = { EMPTY, TRUE, FALSE }; // TODO use some - // external string - // here instead - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // AbstractLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel abstractLabel = getWidgetFactory().createCLabel(composite, XSDConstants.ABSTRACT_ATTRIBUTE + ":"); - abstractLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // AbstractCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - abstractCombo = getWidgetFactory().createCCombo(composite); - abstractCombo.setLayoutData(data); - abstractCombo.setEditable(false); - - abstractCombo.setItems(booleanValues); - abstractCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // BlockLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel blockLabel = getWidgetFactory().createCLabel(composite, XSDConstants.BLOCK_ATTRIBUTE + ":"); - blockLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // BlockCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - blockCombo = getWidgetFactory().createCCombo(composite); - blockCombo.setLayoutData(data); - blockCombo.setEditable(false); - - blockCombo.setItems(blockValues); - blockCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // FinalLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel finalLabel = getWidgetFactory().createCLabel(composite, XSDConstants.FINAL_ATTRIBUTE + ":"); - finalLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // FinalCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - finalCombo = getWidgetFactory().createCCombo(composite); - finalCombo.setLayoutData(data); - finalCombo.setEditable(false); - - finalCombo.setItems(finalValues); - finalCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // Mixed Label - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel mixedLabel = getWidgetFactory().createCLabel(composite, XSDConstants.MIXED_ATTRIBUTE + ":"); - mixedLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Mixed Combo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - mixedCombo = getWidgetFactory().createCCombo(composite); - mixedCombo.setLayoutData(data); - mixedCombo.setEditable(false); - - mixedCombo.setItems(booleanValues); - mixedCombo.addSelectionListener(this); - - } - - public void doWidgetSelected(SelectionEvent e) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - if (e.widget == blockCombo) - { - String value = blockCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(complexType.getElement(), XSDConstants.BLOCK_ATTRIBUTE, value); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == finalCombo) - { - String value = finalCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(complexType.getElement(), XSDConstants.FINAL_ATTRIBUTE, value); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == abstractCombo) - { - String value = abstractCombo.getText(); - - if (value.equals(EMPTY)) - complexType.getElement().removeAttribute(XSDConstants.ABSTRACT_ATTRIBUTE); - else - { - if (value.equals(TRUE)) - complexType.setAbstract(true); - else if (value.equals(FALSE)) - complexType.setAbstract(false); - } - } - else if (e.widget == mixedCombo) - { - String value = mixedCombo.getText(); - - if (value.equals(EMPTY)) - complexType.getElement().removeAttribute(XSDConstants.MIXED_ATTRIBUTE); - else - { - if (value.equals(TRUE)) - complexType.setMixed(true); - else if (value.equals(FALSE)) - complexType.setMixed(false); - } - } - } - - public void refresh() - { - super.refresh(); - - setListenerEnabled(false); - try - { - if (input instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - - boolean enabled = true; - if (complexType.getContainer() instanceof XSDSchema) - { - enabled = !isReadOnly; - } - else - { - enabled = false; - } - - String blockAttValue = complexType.getElement().getAttribute(XSDConstants.BLOCK_ATTRIBUTE); - if (blockAttValue != null) - { - blockCombo.setText(blockAttValue); - } - else - { - blockCombo.setText(EMPTY); - } - blockCombo.setEnabled(enabled); - - String finalAttValue = complexType.getElement().getAttribute(XSDConstants.FINAL_ATTRIBUTE); - if (finalAttValue != null) - { - finalCombo.setText(finalAttValue); - } - else - { - finalCombo.setText(EMPTY); - } - finalCombo.setEnabled(enabled); - - if (complexType.getElement().hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) - { - boolean absAttValue = complexType.isAbstract(); - if (absAttValue) - abstractCombo.setText(TRUE); - else - abstractCombo.setText(FALSE); - } - else - { - abstractCombo.setText(EMPTY); - } - abstractCombo.setEnabled(enabled); - - if (complexType.getElement().hasAttribute(XSDConstants.MIXED_ATTRIBUTE)) - { - boolean mixedValue = complexType.isMixed(); - if (mixedValue) - mixedCombo.setText(TRUE); - else - mixedCombo.setText(FALSE); - } - else - { - mixedCombo.setText(EMPTY); - } - - } - } - catch (Exception e) - { - } - setListenerEnabled(true); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeSection.java deleted file mode 100644 index 0da2f51af1..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeSection.java +++ /dev/null @@ -1,357 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateComplexTypeDerivationBy; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDComplexTypeSection extends RefactoringSection implements SelectionListener -{ - protected Text nameText; - protected CCombo baseTypeCombo; - protected CCombo derivedByCombo; - private String derivedByChoicesComboValues[] = { "", XSDConstants.RESTRICTION_ELEMENT_TAG, XSDConstants.EXTENSION_ELEMENT_TAG }; //$NON-NLS-1$ - - public XSDComplexTypeSection() - { - super(); - } - - /** - * Contents of the property tab - * - * NameLabel NameText DummyLabel BaseTypeLabel BaseTypeCombo BaseTypeButton - * DerivedByLabel DerivedByCombo - */ - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - applyAllListeners(nameText); - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__COMPLEX_TYPE__NAME); - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - - // ------------------------------------------------------------------ - // BaseTypeLabel - // ------------------------------------------------------------------ - - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_INHERIT_FROM); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // BaseTypeCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - baseTypeCombo = getWidgetFactory().createCCombo(composite); - baseTypeCombo.setEditable(false); - baseTypeCombo.setLayoutData(data); - baseTypeCombo.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(baseTypeCombo, - XSDEditorCSHelpIds.GENERAL_TAB__COMPLEX_TYPE__INHERIT_FROM); - - - // ------------------------------------------------------------------ - // Spacer label - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, ""); - - // ------------------------------------------------------------------ - // DerivedByLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - CLabel derivedByLabel = getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_INHERIT_BY); //$NON-NLS-1$ - derivedByLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // DerivedByCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - derivedByCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - derivedByCombo.setLayoutData(data); - derivedByCombo.setItems(derivedByChoicesComboValues); - derivedByCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(derivedByCombo, - XSDEditorCSHelpIds.GENERAL_TAB__COMPLEX_TYPE__INHERIT_BY); - - // ------------------------------------------------------------------ - // Spacer label - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, ""); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - super.refresh(); - if (Display.getCurrent() == null) - return; - - setListenerEnabled(false); - - try - { - nameText.setText(""); //$NON-NLS-1$ - baseTypeCombo.setText(""); //$NON-NLS-1$ - fillTypesCombo(); - - if (input instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - String name = complexType.getName(); - if (name == null) - name = ""; //$NON-NLS-1$ - - boolean isAnonymousType = name.equals("") ? true : false; //$NON-NLS-1$ - if (isAnonymousType) - { - nameText.setText("**anonymous**"); //$NON-NLS-1$ - nameText.setEditable(false); - } - else - { - nameText.setText(name); - nameText.setEditable(true); - } - - XSDTypeDefinition baseTypeDefinition = complexType.getBaseTypeDefinition(); - String baseType = ""; //$NON-NLS-1$ - if (baseTypeDefinition != null) - { - baseType = baseTypeDefinition.getName(); - if (baseType == null) - { - baseType = ""; //$NON-NLS-1$ - } - else if (baseType.equals("anyType")) - { - baseType = ""; //$NON-NLS-1$ - } - } - baseTypeCombo.setText(baseType); - - derivedByCombo.setText(""); //$NON-NLS-1$ - int derivationMethod = complexType.getDerivationMethod().getValue(); - if (derivationMethod == XSDDerivationMethod.EXTENSION) - { - derivedByCombo.setText(XSDConstants.EXTENSION_ELEMENT_TAG); - } - else if (derivationMethod == XSDDerivationMethod.RESTRICTION) - { - derivedByCombo.setText(XSDConstants.RESTRICTION_ELEMENT_TAG); - } - } - - } - finally - { - setListenerEnabled(true); - } - } - - /** - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent) - */ - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == baseTypeCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class); - - String selection = baseTypeCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(input, newValue); - } - else - { - refresh(); - } - } - } - else if (e.widget == derivedByCombo) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - String value = derivedByCombo.getText(); - Command command = new UpdateComplexTypeDerivationBy(complexType, value); - - if (getCommandStack() != null) - { - getCommandStack().execute(command); - } - } - super.doWidgetSelected(e); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISection#shouldUseExtraSpace() - */ - public boolean shouldUseExtraSpace() - { - return false; - } - - public void dispose() - { - super.dispose(); - } - - public void doHandleEvent(Event event) - { - super.doHandleEvent(event); - if (event.widget == nameText) - { - if (!nameText.getEditable()) - return; - - String newValue = nameText.getText().trim(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent) input; - - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - // doReferentialIntegrityCheck(namedComponent, newValue); - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - private void fillTypesCombo() - { - baseTypeCombo.removeAll(); - baseTypeCombo.add(Messages._UI_ACTION_BROWSE); - baseTypeCombo.add(Messages._UI_ACTION_NEW); - // Add the current Type of this attribute if needed - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - XSDTypeDefinition baseType = complexType.getBaseType(); - if (baseType != null && baseType.getQName() != null) - { - String currentTypeName = baseType.getQName(xsdSchema); //no prefix - if (currentTypeName != null && !currentTypeName.equals("anyType")) - baseTypeCombo.add(currentTypeName); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationAdvancedSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationAdvancedSection.java deleted file mode 100644 index 53ad36f1d5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationAdvancedSection.java +++ /dev/null @@ -1,367 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.jface.window.Window; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDSubstitutionGroupEditManager; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDElementDeclarationAdvancedSection extends AbstractSection -{ - private static final String EMPTY = ""; //$NON-NLS-1$ - private static final String FALSE = "false"; //$NON-NLS-1$ - private static final String TRUE = "true"; //$NON-NLS-1$ - protected CCombo blockCombo; - protected CCombo finalCombo; - protected CCombo abstractCombo; - protected CCombo substGroupCombo; - - private String blockValues[] = { EMPTY, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG, - "substitution" }; //$NON-NLS-1$ - - private String finalValues[] = { EMPTY, "#" + XSDConstants.ALL_ELEMENT_TAG, XSDConstants.EXTENSION_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.RESTRICTION_ELEMENT_TAG }; //$NON-NLS-1$ - - private String abstractValues[] = { EMPTY, TRUE, FALSE }; // TODO use some external string here instead - - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // AbstractLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel abstractLabel = getWidgetFactory().createCLabel(composite, XSDConstants.ABSTRACT_ATTRIBUTE + ":"); - abstractLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // AbstractCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - abstractCombo = getWidgetFactory().createCCombo(composite); - abstractCombo.setLayoutData(data); - abstractCombo.setEditable(false); - - abstractCombo.setItems(abstractValues); - abstractCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // BlockLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel blockLabel = getWidgetFactory().createCLabel(composite, XSDConstants.BLOCK_ATTRIBUTE + ":"); - blockLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // BlockCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - blockCombo = getWidgetFactory().createCCombo(composite); - blockCombo.setLayoutData(data); - blockCombo.setEditable(false); - - blockCombo.setItems(blockValues); - blockCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // FinalLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel finalLabel = getWidgetFactory().createCLabel(composite, XSDConstants.FINAL_ATTRIBUTE + ":"); - finalLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // FinalCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - finalCombo = getWidgetFactory().createCCombo(composite); - finalCombo.setLayoutData(data); - finalCombo.setEditable(false); - - finalCombo.setItems(finalValues); - finalCombo.addSelectionListener(this); - - // ------------------------------------------------------------------ - // Substitution Group Label - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - // TODO Should be a translatable string here - CLabel subGroupLabel = getWidgetFactory().createCLabel(composite, XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE + ":"); - subGroupLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Substitution Group Combo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - substGroupCombo = getWidgetFactory().createCCombo(composite); - substGroupCombo.setLayoutData(data); - substGroupCombo.setEditable(true); - substGroupCombo.addSelectionListener(this); - applyAllListeners(substGroupCombo); - } - - public void doHandleEvent(Event e) - { - if (e.widget == substGroupCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = substGroupCombo.getText(); - String oldValue = eleDec.getElement().getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE); - if (oldValue == null) - oldValue = EMPTY; - if (value.equals(oldValue)) - return; - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE, value); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == blockCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = blockCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.BLOCK_ATTRIBUTE, value); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == finalCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = finalCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.FINAL_ATTRIBUTE, value); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == abstractCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = abstractCombo.getText(); - - if (value.equals(EMPTY)) - eleDec.getElement().removeAttribute(XSDConstants.ABSTRACT_ATTRIBUTE); - else - { - if (value.equals(TRUE)) - eleDec.setAbstract(true); - else if (value.equals(FALSE)) - eleDec.setAbstract(false); - } - } - else if (e.widget == substGroupCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDSubstitutionGroupEditManager.class); - - String selection = substGroupCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(input, newValue); - } - else - { - substGroupCombo.setText(""); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - } - } - - public void refresh() - { - super.refresh(); - fillSubstitutionGroupCombo(); - setListenerEnabled(false); - try - { - if (input instanceof XSDElementDeclaration) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - - composite.setEnabled(!isReadOnly); - if (eleDec.getContainer() instanceof XSDSchema) // global element - { - abstractCombo.setEnabled(true); - finalCombo.setEnabled(true); - substGroupCombo.setEnabled(true); - } - else - { - abstractCombo.setEnabled(false); - finalCombo.setEnabled(false); - substGroupCombo.setEnabled(false); - } - - Element element = eleDec.getElement(); - String blockAttValue = element.getAttribute(XSDConstants.BLOCK_ATTRIBUTE); - if (blockAttValue != null) - { - blockCombo.setText(blockAttValue); - } - else - { - blockCombo.setText(EMPTY); - } - - String finalAttValue = element.getAttribute(XSDConstants.FINAL_ATTRIBUTE); - if (finalAttValue != null) - { - finalCombo.setText(finalAttValue); - } - else - { - finalCombo.setText(EMPTY); - } - - if (element.hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) - { - boolean absAttValue = eleDec.isAbstract(); - if (absAttValue) - abstractCombo.setText(TRUE); - else - abstractCombo.setText(FALSE); - } - else - abstractCombo.setText(EMPTY); - - if (element.hasAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) - { - substGroupCombo.setText(element.getAttribute(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)); - } - else - { - substGroupCombo.setText(EMPTY); - } - } - } - catch (Exception e) - { - } - setListenerEnabled(true); - } - - private void fillSubstitutionGroupCombo() - { - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDSubstitutionGroupEditManager.class); - ComponentSpecification[] items = manager.getQuickPicks(); - - substGroupCombo.removeAll(); - substGroupCombo.add(Messages._UI_ACTION_BROWSE); - substGroupCombo.add(Messages._UI_ACTION_NEW); - for (int i = 0; i < items.length; i++) - { - substGroupCombo.add(items[i].getName()); - } - // Add the current substitution group if needed - XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getSubstitutionGroupAffiliation(); - if (namedComponent != null) - { - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(namedComponent.getName(),manager); - if (ret == null) - { - substGroupCombo.add(namedComponent.getQName(xsdSchema)); - } - } - } - - private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) - { - if (editManager != null) - { - ComponentSpecification[] quickPicks = editManager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - if (value != null && value.equals(componentSpecification.getName())) - { - return componentSpecification; - } - } - } - } - return null; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java deleted file mode 100644 index fbae5a1aaa..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java +++ /dev/null @@ -1,586 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.dialogs.NewTypeDialog; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDElementReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDElementDeclarationSection extends MultiplicitySection -{ - protected Text nameText; - protected CCombo typeCombo; - protected CCombo componentNameCombo; - boolean isElementReference; - protected String typeName = ""; //$NON-NLS-1$ - - private XSDTypeDefinition typeDefinition; - - public XSDElementDeclarationSection() - { - super(); - } - - /** - * Contents of the property tab - */ - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - - String typeLabel = Messages.UI_LABEL_TYPE; //$NON-NLS-1$ - - GridData data = new GridData(); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = factory.createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - nameText.setEnabled(!isElementReference); - applyAllListeners(nameText); - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__NAME); - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isElementReference); - - // ------------------------------------------------------------------ - // Ref Label - // ------------------------------------------------------------------ - if (isElementReference) - { - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel refLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_REFERENCE); - refLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Ref Combo - // ------------------------------------------------------------------ - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - componentNameCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - componentNameCombo.addSelectionListener(this); - componentNameCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__REFERENCE); - - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - } - - // ------------------------------------------------------------------ - // typeLabel - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, typeLabel); - - // ------------------------------------------------------------------ - // typeCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - typeCombo = getWidgetFactory().createCCombo(composite); //$NON-NLS-1$ - typeCombo.setEditable(false); - typeCombo.setLayoutData(data); - typeCombo.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(typeCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__TYPE); - - // ------------------------------------------------------------------ - // DummyLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // min property - // ------------------------------------------------------------------ - - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MINOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - minCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - minCombo.setLayoutData(data); - minCombo.add("0"); //$NON-NLS-1$ - minCombo.add("1"); //$NON-NLS-1$ - applyAllListeners(minCombo); - minCombo.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(minCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__MIN_OCCURENCE); - - // ------------------------------------------------------------------ - // DummyLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // max property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MAXOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - maxCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - maxCombo.setLayoutData(data); - maxCombo.add("0"); //$NON-NLS-1$ - maxCombo.add("1"); //$NON-NLS-1$ - maxCombo.add("unbounded"); //$NON-NLS-1$ - applyAllListeners(maxCombo); - maxCombo.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(maxCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__MAX_OCCURENCE); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - setListenerEnabled(false); - init(); - relayout(); - - setListenerEnabled(true); - } - - protected void init() - { - if (input instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) input; - isElementReference = xsdElementDeclaration.isElementDeclarationReference(); - - typeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition(); - } - } - - private void fillTypesCombo() - { - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - ComponentSpecification[] items = manager.getQuickPicks(); - - typeCombo.removeAll(); - typeCombo.add(Messages._UI_ACTION_BROWSE); - typeCombo.add(Messages._UI_ACTION_NEW); - for (int i = 0; i < items.length; i++) - { - typeCombo.add(items[i].getName()); - } - // Add the current Type of this element if needed - XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration(); - XSDTypeDefinition td = namedComponent.getType(); - if (td != null) - { - String currentTypeName = td.getQName(xsdSchema); - if (currentTypeName == null) // anonymous type - currentTypeName = "**Anonymous**"; - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName,manager); - if (ret == null && currentTypeName != null) //not in quickPick - { - typeCombo.add(currentTypeName); - } - } - } - - private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) - { - if (editManager != null) - { - ComponentSpecification[] quickPicks = editManager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - if (value != null && value.equals(componentSpecification.getName())) - { - return componentSpecification; - } - } - } - } - return null; - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - setListenerEnabled(false); - - super.refresh(); - - XSDElementDeclaration xsdElementDeclaration = ((XSDElementDeclaration) input).getResolvedElementDeclaration(); - - // refresh name - nameText.setText(""); //$NON-NLS-1$ - typeCombo.setText(""); //$NON-NLS-1$ - String name = xsdElementDeclaration.getName(); - if (name != null) - { - nameText.setText(name); - } - - if (isElementReference) - { - refreshRefCombo(); - } - - // refresh type - if (input != null) - { - if (input instanceof XSDElementDeclaration) - { - boolean isAnonymous = xsdElementDeclaration.getAnonymousTypeDefinition() != null; - //XSDTypeDefinition typeDef = XSDUtils.getResolvedType(xsdElementDeclaration); - XSDTypeDefinition typeDef = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition(); - - if (typeDef != null) - typeName = typeDef.getQName(xsdSchema); - - if (typeName == null) - { - typeName = ""; //$NON-NLS-1$ - } - - fillTypesCombo(); - if (isAnonymous) - { - typeCombo.setText("**Anonymous**"); - typeName = "**Anonymous**"; - } - else - { - if (typeDefinition != null) - { - typeCombo.setText(typeName); - } - else - { - typeCombo.setText(Messages.UI_NO_TYPE); //$NON-NLS-1$ - } - } - - maxCombo.setEnabled(!xsdElementDeclaration.isGlobal() || isElementReference); - minCombo.setEnabled(!xsdElementDeclaration.isGlobal() || isElementReference); - } - } - - // refresh min max - refreshMinMax(); - - setListenerEnabled(true); - - } - - public boolean shouldUseExtraSpace() - { - return false; - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - - String selection = typeCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(true); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - ((NewTypeDialog) dialog).allowComplexType(true); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - XSDElementDeclaration elementDeclaration = ((XSDElementDeclaration) input).getResolvedElementDeclaration(); - manager.modifyComponentReference(elementDeclaration, newValue); - } - else - { - typeCombo.setText(typeName ); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - } - else if (e.widget == componentNameCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDElementReferenceEditManager.class); - - String selection = componentNameCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(input, newValue); - } - else - { - componentNameCombo.setText(""); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - - } - else if (e.widget == maxCombo) - { - updateMaxAttribute(); - } - else if (e.widget == minCombo) - { - updateMinAttribute(); - } - } - - protected void relayout() - { - Composite parentComposite = composite.getParent(); - parentComposite.getParent().setRedraw(false); - - if (parentComposite != null && !parentComposite.isDisposed()) - { - Control[] children = parentComposite.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - - // Now initialize the new handler - createContents(parentComposite); - parentComposite.getParent().layout(true, true); - - // Now turn painting back on - parentComposite.getParent().setRedraw(true); - refresh(); - } - - public void doHandleEvent(Event event) - { - super.doHandleEvent(event); - if (event.widget == nameText) - { - String newValue = nameText.getText().trim(); - if (input instanceof XSDElementDeclaration) - { - XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration(); - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - - // doReferentialIntegrityCheck(namedComponent, newValue); - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - public void dispose() - { - if (componentNameCombo != null && !componentNameCombo.isDisposed()) - componentNameCombo.removeSelectionListener(this); - if (minCombo != null && !minCombo.isDisposed()) - minCombo.removeSelectionListener(this); - if (maxCombo != null && !maxCombo.isDisposed()) - maxCombo.removeSelectionListener(this); - if (typeCombo != null && !typeCombo.isDisposed()) - typeCombo.removeSelectionListener(this); - if (nameText != null && !nameText.isDisposed()) - removeListeners(nameText); - super.dispose(); - } - - protected void refreshRefCombo() - { - componentNameCombo.setText(""); //$NON-NLS-1$ - fillElementsCombo(); - } - - private void fillElementsCombo() - { - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDElementReferenceEditManager.class); - - componentNameCombo.removeAll(); - componentNameCombo.add(Messages._UI_ACTION_BROWSE); - componentNameCombo.add(Messages._UI_ACTION_NEW); - ComponentSpecification[] quickPicks = manager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - componentNameCombo.add(componentSpecification.getName()); - } - } - ComponentSpecification[] history = manager.getHistory(); - if (history != null) - { - for (int i=0; i < history.length; i++) - { - ComponentSpecification componentSpecification = history[i]; - componentNameCombo.add(componentSpecification.getName()); - } - } - - XSDElementDeclaration namedComponent = (XSDElementDeclaration) input; - Element element = namedComponent.getElement(); - if (element != null) - { - String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE); - if (attrValue == null) - { - attrValue = ""; //$NON-NLS-1$ - } - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(attrValue, manager); - if (ret == null) - { - componentNameCombo.add(attrValue); - } - componentNameCombo.setText(attrValue); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSection.java deleted file mode 100644 index afb80ddfbc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSection.java +++ /dev/null @@ -1,974 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.commands.CompoundCommand; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -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.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.xsd.ui.internal.common.commands.ChangeToLocalSimpleTypeCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNumericBoundsFacetCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateStringLengthFacetCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateXSDWhiteSpaceFacetCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDLengthFacet; -import org.eclipse.xsd.XSDMaxExclusiveFacet; -import org.eclipse.xsd.XSDMaxFacet; -import org.eclipse.xsd.XSDMaxInclusiveFacet; -import org.eclipse.xsd.XSDMaxLengthFacet; -import org.eclipse.xsd.XSDMinExclusiveFacet; -import org.eclipse.xsd.XSDMinFacet; -import org.eclipse.xsd.XSDMinInclusiveFacet; -import org.eclipse.xsd.XSDMinLengthFacet; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDWhiteSpace; -import org.eclipse.xsd.XSDWhiteSpaceFacet; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDFacetSection extends AbstractSection -{ - private String minLengthString, maxLengthString, titleString; - Font titleFont; - CLabel title; - Label minLengthLabel; - Text minLengthText; - Label maxLengthLabel; - Text maxLengthText; - Group simpleTypeModifierGroup; - String simpleTypeModifierGroupTitle = ""; //$NON-NLS-1$ - Button collapseWhitespaceButton; - Button useEnumerationsButton, usePatternsButton; - Button minimumInclusiveCheckbox; - Button maximumInclusiveCheckbox; - boolean isNumericBaseType; - private XSDTypeDefinition typeDefinition; - private XSDSimpleTypeDefinition xsdSimpleTypeDefinition; - private XSDSimpleTypeDefinition currentPrimitiveType, previousPrimitiveType; - private XSDElementDeclaration xsdElementDeclaration; - private XSDAttributeDeclaration xsdAttributeDeclaration; - private XSDFeature xsdFeature; - boolean hasMaxMinFacets; - - SpecificConstraintsWidget constraintsWidget; - - public XSDFacetSection() - { - super(); - } - - protected void createContents(Composite parent) - { - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - composite = factory.createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 1; - composite.setLayout(gridLayout); - - title = factory.createCLabel(composite, ""); //$NON-NLS-1$ - FontData fontData = composite.getFont().getFontData()[0]; - title.setFont(JFaceResources.getFontRegistry().getBold(fontData.getName())); - title.setText(titleString + (isReadOnly ? " - " + Messages._UI_LABEL_READONLY : "")); //$NON-NLS-1$ //$NON-NLS-2$ - - Composite facetComposite = factory.createComposite(composite, SWT.FLAT); - - GridData data = new GridData(); - gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 2; - facetComposite.setLayout(gridLayout); - data.grabExcessVerticalSpace = true; - data.grabExcessHorizontalSpace = true; - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - facetComposite.setLayoutData(data); - - data = new GridData(); - data.grabExcessVerticalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - - simpleTypeModifierGroup = getWidgetFactory().createGroup(facetComposite, simpleTypeModifierGroupTitle); - GridLayout groupGrid = new GridLayout(); - groupGrid.marginTop = 0; - groupGrid.marginBottom = 0; - groupGrid.numColumns = 1; - simpleTypeModifierGroup.setLayoutData(data); - simpleTypeModifierGroup.setLayout(groupGrid); - - Composite simpleTypeModifierComposite = getWidgetFactory().createFlatFormComposite(simpleTypeModifierGroup); - data = new GridData(); - data.grabExcessVerticalSpace = true; - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - - GridLayout grid = new GridLayout(); - grid.marginTop = 0; - grid.marginBottom = 0; - grid.numColumns = 3; - simpleTypeModifierComposite.setLayout(grid); - simpleTypeModifierComposite.setLayoutData(data); - if (hasMaxMinFacets) - { - boolean isLinux = java.io.File.separator.equals("/"); - minLengthLabel = factory.createLabel(simpleTypeModifierComposite, minLengthString); - minLengthText = factory.createText(simpleTypeModifierComposite, ""); //$NON-NLS-1$ - if (isLinux) - { - minLengthText.addListener(SWT.Modify, customListener); - minLengthText.addListener(SWT.KeyDown, customListener); - } - else - applyAllListeners(minLengthText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(minLengthText, - XSDEditorCSHelpIds.CONSTRAINTS_TAB__MINIMUM_LENGTH); - - GridData minGridData = new GridData(); - minGridData.widthHint = 100; - minLengthText.setLayoutData(minGridData); - minimumInclusiveCheckbox = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_INCLUSIVE, SWT.CHECK); - minimumInclusiveCheckbox.addSelectionListener(this); - - maxLengthLabel = factory.createLabel(simpleTypeModifierComposite, maxLengthString); - maxLengthText = factory.createText(simpleTypeModifierComposite, ""); //$NON-NLS-1$ - if (isLinux) - { - maxLengthText.addListener(SWT.Modify, customListener); - maxLengthText.addListener(SWT.KeyDown, customListener); - } - else - applyAllListeners(maxLengthText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(maxLengthText, - XSDEditorCSHelpIds.CONSTRAINTS_TAB__MAXIMUM_LENGTH); - - GridData maxGridData = new GridData(); - maxGridData.widthHint = 100; - maxLengthText.setLayoutData(maxGridData); - - maximumInclusiveCheckbox = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_INCLUSIVE, SWT.CHECK); - maximumInclusiveCheckbox.addSelectionListener(this); - - minimumInclusiveCheckbox.setVisible(isNumericBaseType); - maximumInclusiveCheckbox.setVisible(isNumericBaseType); - } - collapseWhitespaceButton = factory.createButton(simpleTypeModifierComposite, Messages._UI_LABEL_COLLAPSE_WHITESPACE, SWT.CHECK); - collapseWhitespaceButton.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(collapseWhitespaceButton, - XSDEditorCSHelpIds.CONSTRAINTS_TAB__COLLAPSE_WHITESPACE); - - Group specificValueConstraintsGroup = factory.createGroup(facetComposite, Messages._UI_LABEL_SPECIFIC_CONSTRAINT_VALUES); - gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 2; - specificValueConstraintsGroup.setLayout(gridLayout); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - specificValueConstraintsGroup.setLayoutData(data); - - Composite compositeForButtons = factory.createFlatFormComposite(specificValueConstraintsGroup); - gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.verticalSpacing = 1; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 1; - compositeForButtons.setLayout(gridLayout); - data = new GridData(); - data.verticalAlignment = GridData.BEGINNING; - compositeForButtons.setLayoutData(data); - - factory.createCLabel(compositeForButtons, Messages._UI_LABEL_RESTRICT_VALUES_BY); -// useDefinedValuesButton = factory.createButton(compositeForButtons, "Only permit certain values", SWT.CHECK); -// useDefinedValuesButton.addSelectionListener(this); - - Composite compositeForRadioButtons = factory.createFlatFormComposite(compositeForButtons); - gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginLeft = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 1; - compositeForRadioButtons.setLayout(gridLayout); - useEnumerationsButton = factory.createButton(compositeForRadioButtons, Messages._UI_LABEL_ENUMERATIONS, SWT.RADIO); - useEnumerationsButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(useEnumerationsButton, - XSDEditorCSHelpIds.CONSTRAINTS_TAB__ENUMERATIONS); - usePatternsButton = factory.createButton(compositeForRadioButtons, Messages._UI_LABEL_PATTERNS, SWT.RADIO); - usePatternsButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(usePatternsButton, - XSDEditorCSHelpIds.CONSTRAINTS_TAB__PATTERNS); - - constraintsWidget = new SpecificConstraintsWidget(specificValueConstraintsGroup, factory, (input instanceof XSDFeature) ? (XSDFeature)input : null, xsdSimpleTypeDefinition, this); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.grabExcessVerticalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.FILL; - constraintsWidget.getControl().setLayoutData(data); - PlatformUI.getWorkbench().getHelpSystem().setHelp(constraintsWidget.getControl(), - XSDEditorCSHelpIds.CONSTRAINTS_TAB__NO_LABEL); - } - - public void doSetInput() - { - setInput(getPart(), getSelection()); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - init(); - - XSDSchema schemaOfType = null; - - if (!isReadOnly) - { - schemaOfType = xsdSimpleTypeDefinition.getSchema(); - } - if (schemaOfType == owningEditor.getAdapter(XSDSchema.class)) - { - isReadOnly = false; - } - else - { - if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) - isReadOnly = true; - } - if (hasMaxMinFacets) - { - title.setText(titleString + (isReadOnly ? " - " + Messages._UI_LABEL_READONLY : "")); //$NON-NLS-1$ //$NON-NLS-2$ - } - relayout(); - constraintsWidget.setCommandStack(getCommandStack()); - } - - protected void init() - { - hasMaxMinFacets = false; - try - { - updateInput(); - - if (xsdSimpleTypeDefinition != null) - { - XSDSimpleTypeDefinition targetST = xsdSimpleTypeDefinition; - - while (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(targetST.getTargetNamespace()) && targetST != null) - { - targetST = targetST.getBaseTypeDefinition(); - } - - minLengthString = ""; //$NON-NLS-1$ - maxLengthString = ""; //$NON-NLS-1$ - if (targetST.getValidFacets().contains("length")) //$NON-NLS-1$ - { - minLengthString = Messages._UI_LABEL_MINIMUM_LENGTH; - maxLengthString = Messages._UI_LABEL_MAXIMUM_LENGTH; - simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONSTRAINTS_ON_LENGTH_OF + targetST.getName(); - isNumericBaseType = false; - hasMaxMinFacets = true; - } - else if (targetST.getValidFacets().contains("maxInclusive")) //$NON-NLS-1$ - { - simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONSTRAINTS_ON_VALUE_OF + targetST.getName(); - minLengthString = Messages._UI_LABEL_MINIMUM_VALUE; - maxLengthString = Messages._UI_LABEL_MAXIMUM_VALUE; - isNumericBaseType = true; - hasMaxMinFacets = true; - } - else - { - simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONTRAINTS_ON + (targetST != null ? targetST.getName() : "anyType"); //$NON-NLS-1$ - } - } - } - catch(Exception e) - { - } - } - - private void updateInput() - { - previousPrimitiveType = currentPrimitiveType; - if (input instanceof XSDFeature) - { - xsdFeature = (XSDFeature) input; - typeDefinition = xsdFeature.getResolvedFeature().getType(); - XSDTypeDefinition anonymousTypeDefinition = null; - if (xsdFeature instanceof XSDElementDeclaration) - { - xsdElementDeclaration = (XSDElementDeclaration)xsdFeature; - anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition(); - } - else if (xsdFeature instanceof XSDAttributeDeclaration) - { - xsdAttributeDeclaration = (XSDAttributeDeclaration)xsdFeature; - anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition(); - } - - if (typeDefinition instanceof XSDSimpleTypeDefinition) - { - xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition; - } - - if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) - { - xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition)anonymousTypeDefinition; - } - - if (xsdSimpleTypeDefinition != null) - { - if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) - { - XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition(); - String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : ""; - currentPrimitiveType = basePrimitiveType; - titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - else - { - currentPrimitiveType = xsdSimpleTypeDefinition; - titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()); - } - } - } - else if (input instanceof XSDSimpleTypeDefinition) - { - xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input; - currentPrimitiveType = xsdSimpleTypeDefinition; - titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName(); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - public void refresh() - { - super.refresh(); - init(); - - if (currentPrimitiveType != previousPrimitiveType) - { - relayout(); - } - - setListenerEnabled(false); - - XSDWhiteSpaceFacet whitespaceFacet = xsdSimpleTypeDefinition.getWhiteSpaceFacet(); - if (whitespaceFacet != null) - { - if (xsdSimpleTypeDefinition.getFacetContents().contains(whitespaceFacet)) - { - if (XSDWhiteSpace.COLLAPSE_LITERAL.equals(whitespaceFacet.getValue())) - { - if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) - { - collapseWhitespaceButton.setSelection(true); - } - else - { - collapseWhitespaceButton.setSelection(false); - } - } - } - } - - if (hasMaxMinFacets && !minLengthLabel.isDisposed() && !maxLengthLabel.isDisposed()) - { - minLengthLabel.setText(minLengthString); - maxLengthLabel.setText(maxLengthString); - - if (!isNumericBaseType) - refreshStringLength(); - else - refreshValueLengths(); - } - - if (xsdSimpleTypeDefinition.getEnumerationFacets().size() > 0) - { - usePatternsButton.setSelection(false); - useEnumerationsButton.setSelection(true); - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION); - constraintsWidget.addButton.setEnabled(true); - } - else if (xsdSimpleTypeDefinition.getPatternFacets().size() > 0) - { - usePatternsButton.setSelection(true); - useEnumerationsButton.setSelection(false); - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.PATTERN); - constraintsWidget.addButton.setEnabled(false); - } - else - { - usePatternsButton.setSelection(false); - useEnumerationsButton.setSelection(true); - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION); - constraintsWidget.addButton.setEnabled(true); - } - constraintsWidget.setInput(xsdSimpleTypeDefinition); - - setListenerEnabled(true); - } - - protected void relayout() - { - Composite parent = composite.getParent(); - parent.getParent().setRedraw(false); - - if (parent != null && !parent.isDisposed()) - { - Control[] children = parent.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - createContents(parent); - parent.getParent().layout(true, true); - parent.getParent().setRedraw(true); - refresh(); - } - - public void dispose() - { - if (titleFont != null && !titleFont.isDisposed()) - titleFont.dispose(); - titleFont = null; - - if (minimumInclusiveCheckbox != null && !minimumInclusiveCheckbox.isDisposed()) - minimumInclusiveCheckbox.removeSelectionListener(this); - if (maximumInclusiveCheckbox != null && !maximumInclusiveCheckbox.isDisposed()) - maximumInclusiveCheckbox.removeSelectionListener(this); - - if (collapseWhitespaceButton != null && !collapseWhitespaceButton.isDisposed()) - collapseWhitespaceButton.removeSelectionListener(this); - - if (maxLengthText != null && !maxLengthText.isDisposed()) - removeListeners(maxLengthText); - if (minLengthText != null && !minLengthText.isDisposed()) - removeListeners(minLengthText); - - super.dispose(); - } - - public void refreshStringLength() - { - XSDMinLengthFacet minLengthFacet = xsdSimpleTypeDefinition.getMinLengthFacet(); - XSDMaxLengthFacet maxLengthFacet = xsdSimpleTypeDefinition.getMaxLengthFacet(); - XSDLengthFacet lengthFacet = xsdSimpleTypeDefinition.getLengthFacet(); - - try - { - if (minLengthFacet != null) - { - int minLengthValue = minLengthFacet.getValue(); - if (minLengthValue >= 0 && minLengthFacet.getRootContainer() == xsdSchema) - { - minLengthText.setText(Integer.toString(minLengthValue)); - } - else - { - minLengthText.setText(""); //$NON-NLS-1$ - } - } - if (maxLengthFacet != null) - { - int maxLength = maxLengthFacet.getValue(); - if (maxLength >= 0 && maxLengthFacet.getRootContainer() == xsdSchema) - { - maxLengthText.setText(Integer.toString(maxLength)); - } - else - { - maxLengthText.setText(""); //$NON-NLS-1$ - } - } - if (lengthFacet != null) - { - int length = lengthFacet.getValue(); - if (length >= 0 && lengthFacet.getRootContainer() == xsdSchema) - { - minLengthText.setText(Integer.toString(length)); - maxLengthText.setText(Integer.toString(length)); - } - } - } - catch (Exception e) - { - - } - - } - - public void refreshValueLengths() - { - XSDSimpleTypeDefinition type = xsdSimpleTypeDefinition; - XSDMinFacet minFacet = type.getMinFacet(); - XSDMaxFacet maxFacet = type.getMaxFacet(); - - if (minFacet != null && minFacet.getRootContainer() == xsdSchema) - { - if (minFacet.getElement().getLocalName().equals(XSDConstants.MINEXCLUSIVE_ELEMENT_TAG) || minFacet.getElement().getLocalName().equals(XSDConstants.MININCLUSIVE_ELEMENT_TAG)) - { - minLengthText.setText(minFacet.getLexicalValue()); - minimumInclusiveCheckbox.setSelection(minFacet.isInclusive()); - minimumInclusiveCheckbox.setEnabled(true); - } - else - { - minLengthText.setText(""); //$NON-NLS-1$ - } - } - else - { - minimumInclusiveCheckbox.setSelection(false); - minimumInclusiveCheckbox.setEnabled(false); - } - - if (maxFacet != null && maxFacet.getRootContainer() == xsdSchema) - { - if (maxFacet.getElement().getLocalName().equals(XSDConstants.MAXEXCLUSIVE_ELEMENT_TAG) || maxFacet.getElement().getLocalName().equals(XSDConstants.MAXINCLUSIVE_ELEMENT_TAG)) - { - maxLengthText.setText(maxFacet.getLexicalValue()); - maximumInclusiveCheckbox.setSelection(maxFacet.isInclusive()); - maximumInclusiveCheckbox.setEnabled(true); - } - else - { - maxLengthText.setText(""); //$NON-NLS-1$ - } - } - else - { - maximumInclusiveCheckbox.setSelection(false); - maximumInclusiveCheckbox.setEnabled(false); - } - } - - protected void doHandleEvent(Event event) - { - super.doHandleEvent(event); - Command command = null; - boolean doUpdateMax = false, doUpdateMin = false; - boolean doSetInput = false; - - String minValue = minLengthText.getText().trim(); - String maxValue = maxLengthText.getText().trim(); - - XSDLengthFacet lengthFacet = xsdSimpleTypeDefinition.getLengthFacet(); - XSDMinLengthFacet minLengthFacet = xsdSimpleTypeDefinition.getMinLengthFacet(); - XSDMaxLengthFacet maxLengthFacet = xsdSimpleTypeDefinition.getMaxLengthFacet(); - - XSDMinInclusiveFacet minInclusiveFacet = xsdSimpleTypeDefinition.getMinInclusiveFacet(); - XSDMinExclusiveFacet minExclusiveFacet = xsdSimpleTypeDefinition.getMinExclusiveFacet(); - XSDMaxInclusiveFacet maxInclusiveFacet = xsdSimpleTypeDefinition.getMaxInclusiveFacet(); - XSDMaxExclusiveFacet maxExclusiveFacet = xsdSimpleTypeDefinition.getMaxExclusiveFacet(); - - String currentMinInclusive = null, currentMinExclusive = null, currentMaxInclusive = null, currentMaxExclusive = null; - if (minInclusiveFacet != null) - { - currentMinInclusive = minInclusiveFacet.getLexicalValue(); - } - if (minExclusiveFacet != null) - { - currentMinExclusive = minExclusiveFacet.getLexicalValue(); - } - if (maxInclusiveFacet != null) - { - currentMaxInclusive = maxInclusiveFacet.getLexicalValue(); - } - if (maxExclusiveFacet != null) - { - currentMaxExclusive = maxExclusiveFacet.getLexicalValue(); - } - - - String currentLength = null, currentMin = null, currentMax = null; - if (lengthFacet != null) - { - currentLength = lengthFacet.getLexicalValue(); - } - if (minLengthFacet != null) - { - currentMin = minLengthFacet.getLexicalValue(); - } - if (maxLengthFacet != null) - { - currentMax = maxLengthFacet.getLexicalValue(); - } - - if (event.widget == minLengthText) - { - try - { - if (minValue.length() > 0) - { - if (!isNumericBaseType) - { - Number big = new BigInteger(minValue); - big.toString(); - if (minLengthFacet != null) - { - if (minValue.equals(currentMin) || minValue.equals(currentLength)) - return; - } - else - { - if (maxValue != null && minValue.equals(maxValue) && lengthFacet != null) - { - return; - } - } - } - else - { - if (xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition)) //$NON-NLS-1$ - { - BigDecimal bigDecimal = new BigDecimal(minValue); - bigDecimal.toString(); - if ( (currentMinInclusive != null && minValue.equals(currentMinInclusive)) || - (currentMinExclusive != null && minValue.equals(currentMinExclusive)) ) - { - return; - } - } - else - { - Number big = new BigInteger(minValue); - big.toString(); - } - minimumInclusiveCheckbox.setEnabled(true); - } - } - else - { - if (!isNumericBaseType) - { - if (currentMin == null && currentLength == null) - return; - } - else - { - if (currentMinInclusive == null && minimumInclusiveCheckbox.getSelection()) - { - return; - } - else if (currentMinExclusive == null && !minimumInclusiveCheckbox.getSelection()) - { - return; - } - } - minimumInclusiveCheckbox.setEnabled(false); - minValue = null; - } - doUpdateMin = true; - } - catch (NumberFormatException e) - { - // TODO show error message - doUpdateMin = false; - } - } - if (event.widget == maxLengthText) - { - try - { - if (maxValue.length() > 0) - { - if (!isNumericBaseType) - { - Number big = new BigInteger(maxValue); - big.toString(); - if (maxLengthFacet != null) - { - if (maxValue.equals(currentMax) || maxValue.equals(currentLength)) - return; - } - else - { - if (minValue != null && maxValue.equals(minValue) && lengthFacet != null) - { - return; - } - } - } - else - { - if (xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("double").equals(xsdSimpleTypeDefinition) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition)) //$NON-NLS-1$ - { - BigDecimal bigDecimal = new BigDecimal(maxValue); - bigDecimal.toString(); - } - else - { - Number big = new BigInteger(maxValue); - big.toString(); - } - maximumInclusiveCheckbox.setEnabled(true); - } - } - else - { - if (!isNumericBaseType) - { - if (currentMax == null && currentLength == null) - return; - } - else - { - if (currentMaxInclusive == null && maximumInclusiveCheckbox.getSelection()) - { - return; - } - else if (currentMaxExclusive == null && !maximumInclusiveCheckbox.getSelection()) - { - return; - } - maximumInclusiveCheckbox.setEnabled(false); - } - maxValue = null; - } - - doUpdateMax = true; - } - catch (NumberFormatException e) - { - doUpdateMax = false; - // TODO show error message - } - } - - if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace()) && (doUpdateMax || doUpdateMin)) - { - XSDSimpleTypeDefinition anonymousSimpleType = null; - CompoundCommand compoundCommand = new CompoundCommand(); - ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = null; - if (input instanceof XSDFeature) - { - anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature)input, xsdSimpleTypeDefinition); - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition); - - changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature)input); - changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); - compoundCommand.add(changeToAnonymousCommand); - doSetInput = true; - } - - if (!isNumericBaseType) - { - UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", anonymousSimpleType); //$NON-NLS-1$ - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - compoundCommand.add(updateCommand); - } - else - { - UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, anonymousSimpleType, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection()); - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - compoundCommand.add(updateCommand); - } - command = compoundCommand; - getCommandStack().execute(command); - } - else if (input instanceof XSDSimpleTypeDefinition) - { - if (!isNumericBaseType) - { - UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition); //$NON-NLS-1$ - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - command = updateCommand; - } - else - { - UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection()); - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - command = updateCommand; - } - getCommandStack().execute(command); - } - } - else - { - if (!isNumericBaseType) - { - UpdateStringLengthFacetCommand updateCommand = new UpdateStringLengthFacetCommand("", xsdSimpleTypeDefinition); //$NON-NLS-1$ - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - getCommandStack().execute(updateCommand); - } - else - { - UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection()); - if (doUpdateMax) - { - updateCommand.setMax(maxValue); - } - if (doUpdateMin) - { - updateCommand.setMin(minValue); - } - getCommandStack().execute(updateCommand); - } - - } - refresh(); - if (doSetInput) - setInput(getPart(), getSelection()); - } - - public void widgetSelected(SelectionEvent e) - { - if (e.widget == collapseWhitespaceButton) - { - CompoundCommand compoundCommand = new CompoundCommand(); - XSDSimpleTypeDefinition anonymousSimpleType = null; - if (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) - { - if (input instanceof XSDFeature) - { - anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType((XSDFeature)input, xsdSimpleTypeDefinition); - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(xsdSimpleTypeDefinition); - - ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand(Messages._UI_ACTION_CONSTRAIN_LENGTH, (XSDFeature)input); - changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); - compoundCommand.add(changeToAnonymousCommand); - } - - UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, anonymousSimpleType, collapseWhitespaceButton.getSelection()); - compoundCommand.add(whiteSpaceCommand); - - getCommandStack().execute(compoundCommand); - } - setInput(getPart(), getSelection()); - } - else - { - UpdateXSDWhiteSpaceFacetCommand whiteSpaceCommand = new UpdateXSDWhiteSpaceFacetCommand(Messages._UI_ACTION_COLLAPSE_WHITESPACE, xsdSimpleTypeDefinition, collapseWhitespaceButton.getSelection()); - getCommandStack().execute(whiteSpaceCommand); - } - } - else if (e.widget == minimumInclusiveCheckbox) - { - String minValue = minLengthText.getText().trim(); - if (minValue.length() == 0) minValue = null; - - UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection()); - updateCommand.setMin(minValue); - - if (minValue != null) - getCommandStack().execute(updateCommand); - } - else if (e.widget == maximumInclusiveCheckbox) - { - String maxValue = maxLengthText.getText().trim(); - if (maxValue.length() == 0) maxValue = null; - UpdateNumericBoundsFacetCommand updateCommand = new UpdateNumericBoundsFacetCommand(Messages._UI_ACTION_UPDATE_BOUNDS, xsdSimpleTypeDefinition, minimumInclusiveCheckbox.getSelection(), maximumInclusiveCheckbox.getSelection()); - updateCommand.setMax(maxValue); - if (maxValue != null) - getCommandStack().execute(updateCommand); - } - else if (e.widget == useEnumerationsButton) - { - constraintsWidget.addButton.setEnabled(true); - if (isListenerEnabled()) - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION); - } - else if (e.widget == usePatternsButton) - { - constraintsWidget.addButton.setEnabled(false); - if (isListenerEnabled()) - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.PATTERN); - } - } - - public boolean shouldUseExtraSpace() - { - return true; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSectionFilter.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSectionFilter.java deleted file mode 100644 index bdc57c5a8d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSectionFilter.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.jface.viewers.IFilter; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; - -public class XSDFacetSectionFilter implements IFilter -{ - public boolean select(Object toTest) - { - if (toTest instanceof XSDFeature) - { - XSDTypeDefinition type = ((XSDFeature)toTest).getResolvedFeature().getType(); - if (type instanceof XSDSimpleTypeDefinition) - { - return true; - } - } - else if (toTest instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)toTest; - if (st.eContainer() instanceof XSDSchema || - st.eContainer() instanceof XSDFeature) - { - return true; - } - } - return false; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDImportSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDImportSection.java deleted file mode 100644 index ee6da6a07c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDImportSection.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.Map; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.viewers.ResourceFilter; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.wst.xsd.ui.internal.wizards.XSDSelectIncludeFileWizard; -import org.eclipse.xsd.XSDImport; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDImportSection extends SchemaLocationSection -{ - protected Text namespaceText, prefixText; - protected String oldPrefixValue; - - public XSDImportSection() - { - super(); - } - - /** - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite, - * org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory) - */ - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - GridData data = new GridData(); - - // Create Schema Location Label - CLabel namespaceLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_NAMESPACE")); //$NON-NLS-1$ - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - namespaceLabel.setLayoutData(data); - - namespaceText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - namespaceText.setEditable(false); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - applyAllListeners(namespaceText); - namespaceText.setLayoutData(data); - - // ------------------------------------------------------------------ - // DummyLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - CLabel prefixLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_PREFIX")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - prefixLabel.setLayoutData(data); - - prefixText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - prefixText.setEditable(true); - applyAllListeners(prefixText); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - prefixText.setLayoutData(data); - - // ------------------------------------------------------------------ - // DummyLabel - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // Create Schema Location Label - CLabel schemaLocationLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_SCHEMA_LOCATION")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - schemaLocationLabel.setLayoutData(data); - - // Create Schema Location Text - schemaLocationText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - schemaLocationText.setEditable(true); - applyAllListeners(schemaLocationText); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - schemaLocationText.setLayoutData(data); - - // Create Wizard Button - wizardButton = getWidgetFactory().createButton(composite, "", SWT.NONE); //$NON-NLS-1$ - wizardButton.setImage(XSDEditorPlugin.getXSDImage("icons/browsebutton.gif")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - wizardButton.setLayoutData(data); - wizardButton.addSelectionListener(this); - - // error text - errorText = new StyledText(composite, SWT.FLAT); - errorText.setEditable(false); - errorText.setEnabled(false); - errorText.setText(""); //$NON-NLS-1$ - - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 3; - data.grabExcessHorizontalSpace = true; - errorText.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(schemaLocationText, - XSDEditorCSHelpIds.GENERAL_TAB__IMPORT__SCHEMALOCATION); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(namespaceText, - XSDEditorCSHelpIds.GENERAL_TAB__IMPORT__NAMESPACE); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(prefixText, - XSDEditorCSHelpIds.GENERAL_TAB__IMPORT__PREFIX); - - } - - public void refresh() - { - setListenerEnabled(false); - - errorText.setText(""); - Element element = null; - if (input instanceof XSDImport) - { - element = ((XSDImport) input).getElement(); - - String namespace = element.getAttribute("namespace"); //$NON-NLS-1$ - String schemaLocation = element.getAttribute("schemaLocation"); //$NON-NLS-1$ - - TypesHelper helper = new TypesHelper(xsdSchema); - String prefix = helper.getPrefix(element.getAttribute(XSDConstants.NAMESPACE_ATTRIBUTE), false); - - if (namespace == null) - { - namespace = ""; //$NON-NLS-1$ - } - - if (prefix == null) - { - prefix = ""; //$NON-NLS-1$ - } - - if (schemaLocation == null) - { - schemaLocation = ""; //$NON-NLS-1$ - } - - namespaceText.setText(namespace); - prefixText.setText(prefix); - schemaLocationText.setText(schemaLocation); - oldPrefixValue = prefixText.getText(); - } - - setListenerEnabled(true); - } - - public void widgetSelected(SelectionEvent event) - { - if (event.widget == wizardButton) - { - setListenerEnabled(false); - Shell shell = Display.getCurrent().getActiveShell(); - - IFile currentIFile = ((IFileEditorInput) getActiveEditor().getEditorInput()).getFile(); - ViewerFilter filter = new ResourceFilter(new String[] { ".xsd" }, //$NON-NLS-1$ - new IFile[] { currentIFile }, null); - - XSDSelectIncludeFileWizard fileSelectWizard = new XSDSelectIncludeFileWizard(xsdSchema, false, XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_SCHEMA"), //$NON-NLS-1$ - XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_DESC"), //$NON-NLS-1$ - filter, (IStructuredSelection) getSelection()); - - WizardDialog wizardDialog = new WizardDialog(shell, fileSelectWizard); - wizardDialog.create(); - wizardDialog.setBlockOnOpen(true); - int result = wizardDialog.open(); - - String value = schemaLocationText.getText(); - prefixText.removeListener(SWT.Modify, this); - if (result == Window.OK) - { - errorText.setText(""); - IFile selectedIFile = fileSelectWizard.getResultFile(); - String schemaFileString = value; - if (selectedIFile != null) - { - schemaFileString = URIHelper.getRelativeURI(selectedIFile.getLocation(), currentIFile.getLocation()); - } - else - { - schemaFileString = fileSelectWizard.getURL(); - } - - String namespace = fileSelectWizard.getNamespace(); - if (namespace == null) - namespace = ""; - - XSDSchema externalSchema = fileSelectWizard.getExternalSchema(); - handleSchemaLocationChange(schemaFileString, namespace, externalSchema); - } - setListenerEnabled(true); - prefixText.addListener(SWT.Modify, this); - } - } - - protected void handleSchemaLocationChange(String schemaFileString, String namespace, XSDSchema externalSchema) - { - if (input instanceof XSDImport) - { - XSDImport xsdImport = (XSDImport) input; - - xsdImport.setNamespace(namespace); - xsdImport.setSchemaLocation(schemaFileString); - xsdImport.setResolvedSchema(externalSchema); - - java.util.Map map = xsdSchema.getQNamePrefixToNamespaceMap(); - - // 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); - } - prefixText.setText(prefix); - } - else - { - prefixText.setText(""); - namespaceText.setText(""); - } - } - refresh(); - } - - public void doHandleEvent(Event event) - { - setErrorMessage(null); - super.doHandleEvent(event); - if (event.widget == prefixText) - { - String newPrefix = prefixText.getText(); - if (oldPrefixValue.equals(newPrefix) || !isValidSchemaLocation) - return; - Map map = xsdSchema.getQNamePrefixToNamespaceMap(); - String key = prefixText.getText(); - if (key.length() == 0) key = null; - - if (validatePrefix(newPrefix) && schemaLocationText.getText().trim().length() > 0) - { - if (map.containsKey(key)) - { - setErrorMessage(XSDEditorPlugin.getXSDString("_ERROR_LABEL_PREFIX_EXISTS")); - } - else - { - Element schemaElement = xsdSchema.getElement(); - - if (key != null) { - if (oldPrefixValue.length() == 0) - schemaElement.removeAttribute("xmlns"); - else - schemaElement.removeAttribute("xmlns:"+oldPrefixValue); - - schemaElement.setAttribute("xmlns:" + newPrefix, namespaceText.getText()); - } - else { - schemaElement.removeAttribute("xmlns:"+oldPrefixValue); - schemaElement.setAttribute("xmlns", namespaceText.getText()); - } - xsdSchema.updateElement(); - setErrorMessage(null); - oldPrefixValue = newPrefix; - } - } - else - { - setErrorMessage(XSDEditorPlugin.getXSDString("_ERROR_LABEL_INVALID_PREFIX")); - } - } - } - - public void aboutToBeHidden() - { - setErrorMessage(null); - super.aboutToBeHidden(); - } - - protected boolean validatePrefix(String prefix) - { - if (prefix.length() == 0) return true; - return XMLChar.isValidNCName(prefix); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupDefinitionSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupDefinitionSection.java deleted file mode 100644 index 0a67effdb7..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupDefinitionSection.java +++ /dev/null @@ -1,349 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDModelGroupDefinitionSection extends MultiplicitySection -{ - protected Text nameText; - protected CCombo componentNameCombo; - boolean isReference; - - public XSDModelGroupDefinitionSection() - { - super(); - } - - protected void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - if (isReference) - { - // ------------------------------------------------------------------ - // Ref Label - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel refLabel = getWidgetFactory().createCLabel(composite, XSDConstants.REF_ATTRIBUTE + ":"); //$NON-NLS-1$ - refLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // Ref Combo - // ------------------------------------------------------------------ - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - - componentNameCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - componentNameCombo.addSelectionListener(this); - componentNameCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP_REFS__REF); - - // ------------------------------------------------------------------ - // min property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, - org.eclipse.wst.xsd.ui.internal.editor.Messages.UI_LABEL_MINOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - - minCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - minCombo.setLayoutData(data); - minCombo.add("0"); //$NON-NLS-1$ - minCombo.add("1"); //$NON-NLS-1$ - applyAllListeners(minCombo); - minCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(minCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP__MIN_OCCURENCE); - - // ------------------------------------------------------------------ - // max property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, - org.eclipse.wst.xsd.ui.internal.editor.Messages.UI_LABEL_MAXOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - - maxCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - maxCombo.setLayoutData(data); - maxCombo.add("0"); //$NON-NLS-1$ - maxCombo.add("1"); //$NON-NLS-1$ - maxCombo.add("unbounded"); //$NON-NLS-1$ - applyAllListeners(maxCombo); - maxCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(maxCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP__MAX_OCCURENCE); - - } - else - { - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - applyAllListeners(nameText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP_DEFINITION__NAME); - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - } - } - - public void refresh() - { - super.refresh(); - - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } - - setListenerEnabled(false); - - XSDNamedComponent namedComponent = (XSDNamedComponent) input; - - if (isReference) - { - Element element = namedComponent.getElement(); - if (element != null) - { - String attrValue = element.getAttribute(XSDConstants.REF_ATTRIBUTE); - if (attrValue == null) - { - attrValue = ""; //$NON-NLS-1$ - } - componentNameCombo.setText(attrValue); - - // refresh min max - if (minCombo != null && maxCombo != null) - { - refreshMinMax(); - } - } - } - else - { - // refresh name - nameText.setText(""); //$NON-NLS-1$ - - String name = namedComponent.getName(); - if (name != null) - { - nameText.setText(name); - } - } - - setListenerEnabled(true); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - init(); - relayout(); - - if (isReference) - { - TypesHelper helper = new TypesHelper(xsdSchema); - List items = new ArrayList(); - items = helper.getModelGroups(); - if (input instanceof XSDModelGroupDefinition) - { - XSDModelGroupDefinition group = (XSDModelGroupDefinition) input; - XSDConcreteComponent parent = group.getContainer(); - while (parent != null) - { - if (parent instanceof XSDModelGroupDefinition) - { - items.remove(((XSDModelGroupDefinition)parent).getQName()); - break; - } - parent = parent.getContainer(); - } - } - items.add(0, ""); //$NON-NLS-1$ - componentNameCombo.setItems((String [])items.toArray(new String[0])); - } - } - - protected void init() - { - if (input instanceof XSDModelGroupDefinition) - { - XSDModelGroupDefinition group = (XSDModelGroupDefinition) input; - isReference = group.isModelGroupDefinitionReference(); - } - } - - protected void relayout() - { - Composite parentComposite = composite.getParent(); - parentComposite.getParent().setRedraw(false); - - if (parentComposite != null && !parentComposite.isDisposed()) - { - Control[] children = parentComposite.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - - // Now initialize the new handler - createContents(parentComposite); - parentComposite.getParent().layout(true, true); - - // Now turn painting back on - parentComposite.getParent().setRedraw(true); - refresh(); - } - - public void doHandleEvent(Event event) - { - super.doHandleEvent(event); - if (event.widget == nameText) - { - String newValue = nameText.getText().trim(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent) input; - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - // doReferentialIntegrityCheck(namedComponent, newValue); - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == componentNameCombo) - { - String newValue = componentNameCombo.getText(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent)input; - Element element = namedComponent.getElement(); - - if (namedComponent instanceof XSDModelGroupDefinition) - { - element.setAttribute(XSDConstants.REF_ATTRIBUTE, newValue); - } - } - } - super.doWidgetSelected(e); - } - - public void dispose() - { - if (nameText != null && !nameText.isDisposed()) - removeListeners(nameText); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupSection.java deleted file mode 100644 index c695f7cd5f..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupSection.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateContentModelCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; - -public class XSDModelGroupSection extends MultiplicitySection -{ - protected CCombo modelGroupCombo; - private String[] modelGroupComboValues = { "sequence", "choice", "all" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - public XSDModelGroupSection() - { - super(); - } - - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_KIND); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - modelGroupCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - modelGroupCombo.setLayoutData(data); - modelGroupCombo.addSelectionListener(this); - modelGroupCombo.setItems(modelGroupComboValues); - PlatformUI.getWorkbench().getHelpSystem().setHelp(modelGroupCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP__KIND); - - - // ------------------------------------------------------------------ - // min property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MINOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - minCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - minCombo.setLayoutData(data); - minCombo.add("0"); //$NON-NLS-1$ - minCombo.add("1"); //$NON-NLS-1$ - applyAllListeners(minCombo); - minCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(minCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP__MIN_OCCURENCE); - - // ------------------------------------------------------------------ - // max property - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, Messages.UI_LABEL_MAXOCCURS); - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - maxCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - maxCombo.setLayoutData(data); - maxCombo.add("0"); //$NON-NLS-1$ - maxCombo.add("1"); //$NON-NLS-1$ - maxCombo.add("unbounded"); //$NON-NLS-1$ - applyAllListeners(maxCombo); - maxCombo.addSelectionListener(this); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(maxCombo, - XSDEditorCSHelpIds.GENERAL_TAB__MODELGROUP__MAX_OCCURENCE); - } - - - public void refresh() - { - super.refresh(); - - if (isReadOnly) - { - composite.setEnabled(false); - } - else - { - composite.setEnabled(true); - } - - setListenerEnabled(false); - - if (input != null) - { - if (input instanceof XSDModelGroup) - { - XSDModelGroup particle = (XSDModelGroup)input; - String modelType = particle.getCompositor().getName(); - modelGroupCombo.setText(modelType); - - minCombo.setEnabled(!(particle.eContainer() instanceof XSDModelGroupDefinition)); - maxCombo.setEnabled(!(particle.eContainer() instanceof XSDModelGroupDefinition)); - } - } - - refreshMinMax(); - - setListenerEnabled(true); - } - - public void doWidgetSelected(SelectionEvent e) - { - XSDModelGroup particle = (XSDModelGroup)input; - if (e.widget == modelGroupCombo) - { - XSDCompositor newValue = XSDCompositor.get(modelGroupCombo.getText()); - UpdateContentModelCommand command = new UpdateContentModelCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_CHANGE_CONTENT_MODEL, particle, newValue); - getCommandStack().execute(command); - } - super.doWidgetSelected(e); - } - - public void dispose() - { - if (minCombo != null && !minCombo.isDisposed()) - minCombo.removeSelectionListener(this); - if (maxCombo != null && !maxCombo.isDisposed()) - maxCombo.removeSelectionListener(this); - super.dispose(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaSection.java deleted file mode 100644 index 562071e488..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaSection.java +++ /dev/null @@ -1,316 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.common.properties.sections; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.osgi.util.TextProcessor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.document.DocumentImpl; -import org.eclipse.wst.xsd.ui.internal.actions.XSDEditNamespacesAction; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNamespaceInformationCommand; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.nsedit.TargetNamespaceChangeHandler; -import org.eclipse.wst.xsd.ui.internal.util.TypesHelper; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class XSDSchemaSection extends AbstractSection -{ - IWorkbenchPart part; - Text prefixText; - Text targetNamespaceText; - Button editButton; - StyledText errorText; - Color red; - - /** - * - */ - public XSDSchemaSection() - { - super(); - } - - /** - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySection#createControls(org.eclipse.swt.widgets.Composite, - * org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetWidgetFactory) - */ - public void createContents(Composite parent) - { - composite = getWidgetFactory().createFlatFormComposite(parent); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 2; - composite.setLayout(gridLayout); - - GridData data = new GridData(); - - // Create Prefix Label - CLabel prefixLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_SCHEMA_PREFIX")); //$NON-NLS-1$ - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - prefixLabel.setLayoutData(data); - - // Create Prefix Text - prefixText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - prefixText.setLayoutData(data); - applyAllListeners(prefixText); - PlatformUI.getWorkbench().getHelpSystem().setHelp(prefixText, - XSDEditorCSHelpIds.GENERAL_TAB__SCHEMA__PREFIX); - - // Create TargetNamespace Label - CLabel targetNamespaceLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_TARGET_NAME_SPACE")); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - targetNamespaceLabel.setLayoutData(data); - - // Create TargetNamespace Text - targetNamespaceText = getWidgetFactory().createText(composite, "", SWT.NONE); //$NON-NLS-1$ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - targetNamespaceText.setLayoutData(data); - applyAllListeners(targetNamespaceText); - PlatformUI.getWorkbench().getHelpSystem().setHelp(targetNamespaceText, - XSDEditorCSHelpIds.GENERAL_TAB__SCHEMA__TARGETNAMESPACE); - - // Advanced Button - editButton = getWidgetFactory().createButton(composite, XSDEditorPlugin.getXSDString("_UI_SECTION_ADVANCED_ATTRIBUTES") + "...", SWT.PUSH); //$NON-NLS-1$ //$NON-NLS-2$ - data = new GridData(SWT.END, SWT.CENTER, true, false); - data.horizontalSpan = 2; - editButton.setLayoutData(data); - editButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(editButton, - XSDEditorCSHelpIds.GENERAL_TAB__SCHEMA__ADVANCED); - - // error text - errorText = new StyledText(composite, SWT.FLAT); - errorText.setEditable(false); - errorText.setEnabled(false); - errorText.setText(""); //$NON-NLS-1$ - data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.horizontalSpan = 2; - data.grabExcessHorizontalSpace = true; - errorText.setLayoutData(data); - Dialog.applyDialogFont(parent); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - setListenerEnabled(false); - - Element element = xsdSchema.getElement(); - - if (element != null) - { - // Handle prefixText - TypesHelper helper = new TypesHelper(xsdSchema); - String aPrefix = helper.getPrefix(element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE), false); - - if (aPrefix != null && aPrefix.length() > 0) - { - prefixText.setText(aPrefix); - } - else - { - prefixText.setText(""); //$NON-NLS-1$ - } - - // Handle TargetNamespaceText - String tns = element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE); - if (tns != null && tns.length() > 0) - { - String processedString = TextProcessor.process(tns); - targetNamespaceText.setText(processedString); - } - else - { - targetNamespaceText.setText(""); //$NON-NLS-1$ - } - errorText.setText(""); //$NON-NLS-1$ - } - setListenerEnabled(true); - } - - public void doHandleEvent(Event event) - { - errorText.setText(""); //$NON-NLS-1$ - String prefixValue = prefixText.getText(); - String tnsValue = targetNamespaceText.getText(); - - Element element = xsdSchema.getElement(); - TypesHelper helper = new TypesHelper(xsdSchema); - String currentPrefix = helper.getPrefix(element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE), false); - String currentNamespace = xsdSchema.getTargetNamespace(); - - if (tnsValue.trim().length() == 0) - { - if (prefixValue.trim().length() > 0) - { - errorText.setText(XSDEditorPlugin.getXSDString("_ERROR_TARGET_NAMESPACE_AND_PREFIX")); //$NON-NLS-1$ - int length = errorText.getText().length(); - red = new Color(null, 255, 0, 0); - StyleRange style = new StyleRange(0, length, red, targetNamespaceText.getBackground()); - errorText.setStyleRange(style); - return; - } - } - - if (event.widget == prefixText) - { - // If the prefix is the same, just return. This may happen if the - // widget loses focus. - if (prefixValue.equals(currentPrefix)) - return; - updateNamespaceInfo(prefixValue, tnsValue); - } - else if (event.widget == targetNamespaceText) - { - // If the ns is the same, just return. This may happen if the - // widget loses focus. - if (tnsValue.equals(currentNamespace)) - return; - - DOMNamespaceInfoManager namespaceInfoManager = new DOMNamespaceInfoManager(); - List namespaceInfoList = namespaceInfoManager.getNamespaceInfoList(xsdSchema.getElement()); - - Element xsdSchemaElement = xsdSchema.getElement(); - DocumentImpl doc = (DocumentImpl) xsdSchemaElement.getOwnerDocument(); - - try - { - doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_NAMESPACE_CHANGE")); - - if (tnsValue.trim().length() == 0 ) //remove the targetNamespace attribute - { - xsdSchemaElement.removeAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE); - return; - } - - // Now replace the namespace for the xmlns entry - for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) - { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (info.uri.equals(currentNamespace)) - { - info.uri = tnsValue; - } - } - - xsdSchema.setIncrementalUpdate(false); - // set the new xmlns entries - namespaceInfoManager.removeNamespaceInfo(element); - namespaceInfoManager.addNamespaceInfo(element, namespaceInfoList, false); - xsdSchema.setIncrementalUpdate(true); - - // set the targetNamespace attribute - xsdSchema.setTargetNamespace(tnsValue); - - TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, currentNamespace, tnsValue); - targetNamespaceChangeHandler.resolve(); - } - catch (Exception e) - { - - } - finally - { - try - { - xsdSchema.update(); - } - finally - { - doc.getModel().endRecording(this); - } - } - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == editButton) - { - XSDEditNamespacesAction nsAction = new XSDEditNamespacesAction(XSDEditorPlugin.getXSDString("_UI_ACTION_EDIT_NAMESPACES"), xsdSchema.getElement(), null, xsdSchema); //$NON-NLS-1$ - nsAction.run(); - refresh(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.ui.properties.internal.provisional.ISection#shouldUseExtraSpace() - */ - public boolean shouldUseExtraSpace() - { - return true; - } - - private void updateNamespaceInfo(String newPrefix, String newTargetNamespace) - { - UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand("", xsdSchema, newPrefix, newTargetNamespace); - command.execute(); - } - - public void dispose() - { - if (prefixText != null && !prefixText.isDisposed()) - removeListeners(prefixText); - if (targetNamespaceText != null && !targetNamespaceText.isDisposed()) - removeListeners(targetNamespaceText); - - if (red != null) - { - red.dispose(); - red = null; - } - super.dispose(); - } - - /** - * @deprecated - */ - protected boolean validatePrefix(String prefix) - { - return true; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeSection.java deleted file mode 100644 index b17c3fdbd7..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeSection.java +++ /dev/null @@ -1,752 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -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.adt.edit.ComponentReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.dialogs.NewTypeDialog; -import org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; -import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDVariety; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import com.ibm.icu.util.StringTokenizer; - -public class XSDSimpleTypeSection extends RefactoringSection -{ - protected Text nameText; - CCombo varietyCombo; - CCombo typesCombo; - CLabel typesLabel; - - XSDSimpleTypeDefinition memberTypeDefinition, itemTypeDefinition, baseTypeDefinition; - - public XSDSimpleTypeSection() - { - super(); - } - - protected void createContents(Composite parent) - { - TabbedPropertySheetWidgetFactory factory = getWidgetFactory(); - composite = factory.createFlatFormComposite(parent); - - GridData data = new GridData(); - - GridLayout gridLayout = new GridLayout(); - gridLayout.marginTop = 0; - gridLayout.marginBottom = 0; - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - - // ------------------------------------------------------------------ - // NameLabel - // ------------------------------------------------------------------ - - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - CLabel nameLabel = factory.createCLabel(composite, Messages._UI_LABEL_NAME); - nameLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NameText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nameText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - nameText.setLayoutData(data); - applyAllListeners(nameText); - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.GENERAL_TAB__SIMPLE_TYPE__NAME); - - - // ------------------------------------------------------------------ - // Refactor/rename hyperlink - // ------------------------------------------------------------------ - createRenameHyperlink(composite); - - // Variety Label - CLabel label = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_VARIETY")); //$NON-NLS-1$ - - // Variety Combo - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - label.setLayoutData(data); - - varietyCombo = getWidgetFactory().createCCombo(composite, SWT.FLAT); - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - - List list = XSDVariety.VALUES; - Iterator iter = list.iterator(); - while (iter.hasNext()) - { - varietyCombo.add(((XSDVariety) iter.next()).getName()); - } - varietyCombo.addSelectionListener(this); - varietyCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(varietyCombo, - XSDEditorCSHelpIds.GENERAL_TAB__SIMPLE_TYPE__VARIETY); - - - // ------------------------------------------------------------------ - // DummyLabel - // ------------------------------------------------------------------ - getWidgetFactory().createCLabel(composite, ""); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // Types Label - // ------------------------------------------------------------------ - typesLabel = getWidgetFactory().createCLabel(composite, XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES")); //$NON-NLS-1$ - - // ------------------------------------------------------------------ - // Types Combo - // ------------------------------------------------------------------ - typesCombo = getWidgetFactory().createCCombo(composite); - typesCombo.setEditable(false); - typesCombo.setLayoutData(data); - typesCombo.addSelectionListener(this); - - - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - typesCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(typesCombo, - XSDEditorCSHelpIds.GENERAL_TAB__SIMPLE_TYPE__BASE_TYPE); - - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - relayout(); - } - - protected void relayout() - { - Composite parentComposite = composite.getParent(); - parentComposite.getParent().setRedraw(false); - - if (parentComposite != null && !parentComposite.isDisposed()) - { - Control[] children = parentComposite.getChildren(); - for (int i = 0; i < children.length; i++) - { - children[i].dispose(); - } - } - - // Now initialize the new handler - createContents(parentComposite); - parentComposite.getParent().layout(true, true); - - // Now turn painting back on - parentComposite.getParent().setRedraw(true); - refresh(); - } - - public void refresh() - { - super.refresh(); - - setListenerEnabled(false); - - nameText.setText(""); //$NON-NLS-1$ - varietyCombo.setText(""); //$NON-NLS-1$ - typesCombo.setText(""); //$NON-NLS-1$ - fillTypesCombo(); - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON")); //$NON-NLS-1$ - - if (input instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; - String simpleTypeName = st.getName(); - if (simpleTypeName != null) - { - nameText.setText(simpleTypeName); - } - else - { - nameText.setText("**anonymous**"); //$NON-NLS-1$ - } - - String variety = st.getVariety().getName(); - int intVariety = st.getVariety().getValue(); - - if (variety != null) - { - varietyCombo.setText(variety); - if (intVariety == XSDVariety.ATOMIC) - { - baseTypeDefinition = st.getBaseTypeDefinition(); - String name = ""; //$NON-NLS-1$ - if (baseTypeDefinition != null) - { - name = baseTypeDefinition.getName(); - } - typesCombo.setText(name); - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON")); //$NON-NLS-1$ - } - else if (intVariety == XSDVariety.LIST) - { - itemTypeDefinition = st.getItemTypeDefinition(); - String name = ""; //$NON-NLS-1$ - if (itemTypeDefinition != null) - { - name = itemTypeDefinition.getName(); - } - typesCombo.setText(name); - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_ITEM_TYPE")); //$NON-NLS-1$ - } - else if (intVariety == XSDVariety.UNION) - { - List memberTypesList = st.getMemberTypeDefinitions(); - StringBuffer sb = new StringBuffer(); - for (Iterator i = memberTypesList.iterator(); i.hasNext();) - { - XSDSimpleTypeDefinition typeObject = (XSDSimpleTypeDefinition) i.next(); - String name = typeObject.getQName(); - if (name != null) - { - sb.append(name); - if (i.hasNext()) - { - sb.append(" "); //$NON-NLS-1$ - } - } - } - String memberTypes = sb.toString(); - typesCombo.setText(memberTypes); - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES")); //$NON-NLS-1$ - } - } - } - setListenerEnabled(true); - - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typesCombo) - { - IEditorPart editor = getActiveEditor(); - if (editor == null) return; - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class); - - String selection = typesCombo.getText(); - ComponentSpecification newValue; - IComponentDialog dialog= null; - if ( selection.equals(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); - } - else if ( selection.equals(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_NEW)) - { - dialog = manager.getNewDialog(); - ((NewTypeDialog) dialog).allowComplexType(false); - } - - if (dialog != null) - { - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(input, newValue); - } - } - else //use the value from selected quickPick item - { - newValue = getComponentSpecFromQuickPickForValue(selection, manager); - if (newValue != null) - manager.modifyComponentReference(input, newValue); - } - } - else if (e.widget == varietyCombo) - { - if (input != null) - { - if (input instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; - Element parent = st.getElement(); - - String variety = varietyCombo.getText(); - if (variety.equals(XSDVariety.ATOMIC_LITERAL.getName())) - { - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON")); //$NON-NLS-1$ - st.setVariety(XSDVariety.ATOMIC_LITERAL); - addCreateElementActionIfNotExist(XSDConstants.RESTRICTION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_RESTRICTION"), parent, null); //$NON-NLS-1$ - } - else if (variety.equals(XSDVariety.UNION_LITERAL.getName())) - { - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES")); //$NON-NLS-1$ - st.setVariety(XSDVariety.UNION_LITERAL); - addCreateElementActionIfNotExist(XSDConstants.UNION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_UNION"), parent, null); //$NON-NLS-1$ - } - else if (variety.equals(XSDVariety.LIST_LITERAL.getName())) - { - typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_ITEM_TYPE")); //$NON-NLS-1$ - st.setVariety(XSDVariety.LIST_LITERAL); - addCreateElementActionIfNotExist(XSDConstants.LIST_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_LIST"), parent, null); //$NON-NLS-1$ - } - } - } - } -// else if (e.widget == button) -// { -// Shell shell = Display.getCurrent().getActiveShell(); -// Element element = ((XSDConcreteComponent) input).getElement(); -// Dialog dialog = null; -// String property = ""; -// Element secondaryElement = null; - -// IFile currentIFile = ((IFileEditorInput) getActiveEditor().getEditorInput()).getFile(); - - // issue (cs) need to move to common.ui's selection dialog -/* - XSDComponentSelectionProvider provider = new XSDComponentSelectionProvider(currentIFile, xsdSchema); - dialog = new XSDComponentSelectionDialog(shell, XSDEditorPlugin.getXSDString("_UI_LABEL_SET_TYPE"), provider); - provider.setDialog((XSDComponentSelectionDialog) dialog); -*/ -// if (input instanceof XSDSimpleTypeDefinition) -// { -// XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; -// Element simpleTypeElement = st.getElement(); -// if (st.getVariety() == XSDVariety.LIST_LITERAL) -// { -// Element listElement = (Element) itemTypeDefinition.getElement(); -// // dialog = new TypesDialog(shell, listElement, -// // XSDConstants.ITEMTYPE_ATTRIBUTE, xsdSchema); -// // dialog.showComplexTypes = false; -// provider.showComplexTypes(false); -// -// secondaryElement = listElement; -// property = XSDConstants.ITEMTYPE_ATTRIBUTE; -// } -// else if (st.getVariety() == XSDVariety.ATOMIC_LITERAL) -// { -// Element derivedByElement = (Element) baseTypeDefinition.getElement(); -// if (derivedByElement != null) -// { -// // dialog = new TypesDialog(shell, derivedByElement, -// // XSDConstants.BASE_ATTRIBUTE, xsdSchema); -// // dialog.showComplexTypes = false; -// provider.showComplexTypes(false); -// -// secondaryElement = derivedByElement; -// property = XSDConstants.BASE_ATTRIBUTE; -// } -// else -// { -// return; -// } -// } -// if (st.getVariety() == XSDVariety.UNION_LITERAL) -// { -// SimpleContentUnionMemberTypesDialog unionDialog = new SimpleContentUnionMemberTypesDialog(shell, st); -// unionDialog.setBlockOnOpen(true); -// unionDialog.create(); -// -// int result = unionDialog.open(); -// if (result == Window.OK) -// { -// String newValue = unionDialog.getResult(); -// // beginRecording(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES_CHANGE"), -// // element); //$NON-NLS-1$ -// Element unionElement = memberTypeDefinition.getElement(); -// unionElement.setAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, newValue); -// -// if (newValue.length() > 0) -// { -// unionElement.setAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, newValue); -// } -// else -// { -// unionElement.removeAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE); -// } -// // endRecording(unionElement); -// refresh(); -// } -// return; -// } -// else -// { -// property = "type"; -// } -// } -// else -// { -// property = "type"; -// } - // beginRecording(XSDEditorPlugin.getXSDString("_UI_TYPE_CHANGE"), - // element); //$NON-NLS-1$ -// dialog.setBlockOnOpen(true); -// dialog.create(); -// int result = dialog.open(); -// -// if (result == Window.OK) -// { -// if (secondaryElement == null) -// { -// secondaryElement = element; -// } -// XSDSetTypeHelper helper = new XSDSetTypeHelper(currentIFile, xsdSchema); -// helper.setType(secondaryElement, property, ((XSDComponentSelectionDialog) dialog).getSelection()); - -// XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; -// st.setElement(element); -// updateSimpleTypeFacets();*/ -// } - // endRecording(element); -// } -// refresh(); - } - - public boolean shouldUseExtraSpace() - { - return false; - } - - // issue (cs) this method seems to be utilizing 'old' classes, can we reimplement? - // (e.g. ChangeElementAction, XSDDOMHelper, etc) - protected boolean addCreateElementActionIfNotExist(String elementTag, String label, Element parent, Node relativeNode) - { - XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; - List attributes = new ArrayList(); - String reuseType = null; - - // beginRecording(XSDEditorPlugin.getXSDString("_UI_LABEL_VARIETY_CHANGE"), - // parent); //$NON-NLS-1$ - if (elementTag.equals(XSDConstants.RESTRICTION_ELEMENT_TAG)) - { - Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false); - if (listNode != null) - { - reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE); - XSDDOMHelper.removeNodeAndWhitespace(listNode); - } - - Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false); - if (unionNode != null) - { - String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE); - if (memberAttr != null) - { - StringTokenizer stringTokenizer = new StringTokenizer(memberAttr); - reuseType = stringTokenizer.nextToken(); - } - XSDDOMHelper.removeNodeAndWhitespace(unionNode); - } - - if (reuseType == null) - { - reuseType = getBuiltInStringQName(); - } - attributes.add(new DOMAttribute(XSDConstants.BASE_ATTRIBUTE, reuseType)); - st.setItemTypeDefinition(null); - } - else if (elementTag.equals(XSDConstants.LIST_ELEMENT_TAG)) - { - Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false); - if (restrictionNode != null) - { - reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE); - XSDDOMHelper.removeNodeAndWhitespace(restrictionNode); - } - Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false); - if (unionNode != null) - { - String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE); - if (memberAttr != null) - { - StringTokenizer stringTokenizer = new StringTokenizer(memberAttr); - reuseType = stringTokenizer.nextToken(); - } - XSDDOMHelper.removeNodeAndWhitespace(unionNode); - } - attributes.add(new DOMAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE, reuseType)); - } - else if (elementTag.equals(XSDConstants.UNION_ELEMENT_TAG)) - { - Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false); - if (listNode != null) - { - reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE); - XSDDOMHelper.removeNodeAndWhitespace(listNode); - } - Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false); - if (restrictionNode != null) - { - reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE); - XSDDOMHelper.removeNodeAndWhitespace(restrictionNode); - } - attributes.add(new DOMAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, reuseType)); - st.setItemTypeDefinition(null); - } - - if (getFirstChildNodeIfExists(parent, elementTag, false) == null) - { - Action action = addCreateElementAction(elementTag, label, attributes, parent, relativeNode); - action.run(); - } - - st.setElement(parent); - st.updateElement(); - // endRecording(parent); - return true; - } - - protected Action addCreateElementAction(String elementTag, String label, List attributes, Element parent, Node relativeNode) - { - CreateElementAction action = new CreateElementAction(label); - action.setElementTag(elementTag); - action.setAttributes(attributes); - action.setParentNode(parent); - action.setRelativeNode(relativeNode); - return action; - } - - protected Element getFirstChildNodeIfExists(Node parent, String elementTag, boolean isRef) - { - NodeList children = parent.getChildNodes(); - Element targetNode = null; - for (int i = 0; i < children.getLength(); i++) - { - Node child = children.item(i); - if (child != null && child instanceof Element) - { - if (XSDDOMHelper.inputEquals(child, elementTag, isRef)) - { - targetNode = (Element) child; - break; - } - } - } - return targetNode; - } - - protected String getBuiltInStringQName() - { - String stringName = "string"; //$NON-NLS-1$ - - if (xsdSchema != null) - { - String schemaForSchemaPrefix = xsdSchema.getSchemaForSchemaQNamePrefix(); - if (schemaForSchemaPrefix != null && schemaForSchemaPrefix.length() > 0) - { - String prefix = xsdSchema.getSchemaForSchemaQNamePrefix(); - if (prefix != null && prefix.length() > 0) - { - stringName = prefix + ":" + stringName; //$NON-NLS-1$ - } - } - } - return stringName; - } - -// private void updateSimpleTypeFacets() -// { -// XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; -// Element simpleTypeElement = st.getElement(); -// Element derivedByElement = baseTypeDefinition.getElement(); -// if (derivedByElement != null) -// { -// List nodesToRemove = new ArrayList(); -// NodeList childList = derivedByElement.getChildNodes(); -// int length = childList.getLength(); -// for (int i = 0; i < length; i++) -// { -// Node child = childList.item(i); -// if (child instanceof Element) -// { -// Element elementChild = (Element) child; -// if (!(elementChild.getLocalName().equals("pattern") || elementChild.getLocalName().equals("enumeration") || //$NON-NLS-1$ //$NON-NLS-2$ -// XSDDOMHelper.inputEquals(elementChild, XSDConstants.SIMPLETYPE_ELEMENT_TAG, false) || XSDDOMHelper.inputEquals(elementChild, XSDConstants.ANNOTATION_ELEMENT_TAG, false) -// || XSDDOMHelper.inputEquals(elementChild, XSDConstants.ATTRIBUTE_ELEMENT_TAG, false) || XSDDOMHelper.inputEquals(elementChild, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true) -// || XSDDOMHelper.inputEquals(elementChild, XSDConstants.ATTRIBUTEGROUP_ELEMENT_TAG, false) || XSDDOMHelper.inputEquals(elementChild, XSDConstants.ATTRIBUTEGROUP_ELEMENT_TAG, true) || XSDDOMHelper.inputEquals(elementChild, -// XSDConstants.ANYATTRIBUTE_ELEMENT_TAG, false))) -// { -// nodesToRemove.add(child); -// } -// } -// } -// Iterator iter = nodesToRemove.iterator(); -// while (iter.hasNext()) -// { -// Element facetToRemove = (Element) iter.next(); -// String facetName = facetToRemove.getLocalName(); -// Iterator it = st.getValidFacets().iterator(); -// boolean doRemove = true; -// while (it.hasNext()) -// { -// String aValidFacet = (String) it.next(); -// if (aValidFacet.equals(facetName)) -// { -// doRemove = false; -// break; -// } -// } -// if (doRemove) -// { -// XSDDOMHelper.removeNodeAndWhitespace(facetToRemove); -// } -// } -// } -// } - - // TODO: Common this up with element declaration - public void doHandleEvent(Event event) - { - if (event.widget == nameText) - { - String newValue = nameText.getText().trim(); - if (input instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent)input; - if (!validateSection()) - return; - - Command command = null; - - // Make sure an actual name change has taken place - String oldName = namedComponent.getName(); - if (!newValue.equals(oldName)) - { - command = new UpdateNameCommand(Messages._UI_ACTION_RENAME, namedComponent, newValue); - } - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - } - - } - } - } - - protected boolean validateSection() - { - if (nameText == null || nameText.isDisposed()) - return true; - - setErrorMessage(null); - - String name = nameText.getText().trim(); - - // validate against NCName - if (name.length() < 1 || !XMLChar.isValidNCName(name)) - { - setErrorMessage(Messages._UI_ERROR_INVALID_NAME); - return false; - } - - return true; - } - - - private void fillTypesCombo() - { - typesCombo.removeAll(); - - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - ComponentSpecification[] items = manager.getQuickPicks(); - - typesCombo.add(org.eclipse.wst.xsd.ui.internal.adt.editor.Messages._UI_ACTION_BROWSE); - typesCombo.add(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_NEW); - - for (int i = 0; i < items.length; i++) - { - typesCombo.add(items[i].getName()); - } - - // Add the current Type of this attribute if needed - XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input; - XSDTypeDefinition baseType = simpleType.getBaseType(); - if (baseType != null && baseType.getQName() != null) - { - String currentTypeName = baseType.getQName(xsdSchema); //no prefix - ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName,manager); - if (ret == null && currentTypeName != null) //not in quickPick - { - typesCombo.add(currentTypeName); - } - } - } - - // TODO: common this up with XSDElementDeclarationSection - private ComponentSpecification getComponentSpecFromQuickPickForValue(String value, ComponentReferenceEditManager editManager) - { - if (editManager != null) - { - ComponentSpecification[] quickPicks = editManager.getQuickPicks(); - if (quickPicks != null) - { - for (int i=0; i < quickPicks.length; i++) - { - ComponentSpecification componentSpecification = quickPicks[i]; - if (value != null && value.equals(componentSpecification.getName())) - { - return componentSpecification; - } - } - } - } - return null; - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDTableTreeViewer.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDTableTreeViewer.java deleted file mode 100644 index 0b04e7b5aa..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDTableTreeViewer.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -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.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeContentProvider; -import org.eclipse.wst.xml.ui.internal.tabletree.XMLTableTreeViewer; -import org.w3c.dom.Element; - -public class XSDTableTreeViewer extends XMLTableTreeViewer -{ - - String filter = ""; //$NON-NLS-1$ - - class XSDActionMenuListener implements IMenuListener - { - public void menuAboutToShow(IMenuManager menuManager) - { - // used to disable NodeSelection listening while running NodeAction - // XSDActionManager nodeActionManager = new XSDActionManager(fModel, - // XSDTableTreeViewer.this); - // nodeActionManager.setCommandStack(commandStack); - // nodeActionManager.fillContextMenu(menuManager, getSelection()); - - // used to disable NodeSelection listening while running NodeAction - // XMLNodeActionManager nodeActionManager = new - // XMLNodeActionManager(((IDOMDocument) getInput()).getModel(), - // XMLTableTreeViewer.this) { - if (getInput() != null) - { - XSDActionManager nodeActionManager = new XSDActionManager(((IDOMDocument) (((Element) getInput()).getOwnerDocument())).getModel(), XSDTableTreeViewer.this); - // nodeActionManager.setCommandStack(commandStack); - nodeActionManager.fillContextMenu(menuManager, getSelection()); - } - - } - } - - public XSDTableTreeViewer(Composite parent) - { - super(parent); - // treeExtension.setCellModifier(null); - getTree().setLinesVisible(true); - - // treeExtension = new XMLTreeExtension(getTree()); - - // Reassign the content provider - XMLTableTreeContentProvider provider = new MyContentProvider(); - // provider.addViewer(this); - - setContentProvider(provider); - setLabelProvider(provider); - - // setViewerSelectionManager(new ViewerSelectionManagerImpl(null)); - } - - protected Object getRoot() - { - return super.getRoot(); - } - - public void setFilter(String filter) - { - this.filter = filter; - } - - protected void createContextMenu() - { - // TODO Verify if this is okay to override the MenuManager - 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 XSDActionMenuListener()); - Menu menu = contextMenu.createContextMenu(getControl()); - getControl().setMenu(menu); - } - - boolean added = false; - - class MyContentProvider extends XMLTableTreeContentProvider - { - - // public Object[] getChildren(Object element) { - // - // if (!added) { - // if (element instanceof Element) { - // added = true; - // Element elem = (Element)element; - // if (elem instanceof INodeNotifier) { - // viewerNotifyingAdapterFactory.adapt((INodeNotifier) elem); - // } - // // return new Object[] {elem}; - // } - // } - // return super.getChildren(element); - // } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - added = false; - if (oldInput instanceof Element) - oldInput = ((Element) oldInput).getOwnerDocument(); - - if (newInput instanceof Element) - newInput = ((Element) newInput).getOwnerDocument(); - super.inputChanged(viewer, oldInput, newInput); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddExtensionsComponentDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddExtensionsComponentDialog.java deleted file mode 100644 index 3b309bf7ee..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddExtensionsComponentDialog.java +++ /dev/null @@ -1,785 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.HashMap; -import java.util.List; -import java.util.StringTokenizer; - -import org.apache.xerces.dom.DocumentImpl; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -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.IStructuredSelection; -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.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -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.MessageBox; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.wst.xsd.contentmodel.internal.XSDImpl; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class AddExtensionsComponentDialog extends SelectionDialog implements ISelectionChangedListener, SelectionListener -{ - protected static final Image DEFAULT_ELEMENT_ICON = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif"); //$NON-NLS-1$ - protected static final Image DEFAULT_ATTRIBUTE_ICON = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif"); //$NON-NLS-1$ - - /** A temporary Document in which we create temporary DOM element for each element in the - * Element view. (required by LabelProvider) */ - protected static Document tempDoc = new DocumentImpl(); - - Button addButton, removeButton, editButton; - - public AddExtensionsComponentDialog(Shell parent, ExtensionsSchemasRegistry schemaRegistry) - { - super(parent); - setTitle(Messages._UI_ACTION_ADD_EXTENSION_COMPONENTS); - setShellStyle(SWT.APPLICATION_MODAL | SWT.RESIZE | SWT.CLOSE); - } - - private List fInput; - - private TableViewer categoryTableViewer, elementTableViewer; - private ArrayList existingNames; - - private ViewerFilter elementTableViewerFilter; - private SpecificationForExtensionsSchema currentExtCategory; - private HashMap specToComponentsList = new HashMap(); - private IPreferenceStore prefStore; - - public void setInput(List input) - { - this.fInput = input; - } - - public SpecificationForExtensionsSchema getSelectedCategory(){ - return currentExtCategory; - } - - public void setInitialCategorySelection(SpecificationForExtensionsSchema spec){ - currentExtCategory = spec; - } - - protected IStructuredContentProvider getCategoryContentProvider() - { - return new CategoryContentProvider(); - } - - protected Control createDialogArea(Composite container) - { - Composite parent = (Composite) super.createDialogArea(container); - - Composite categoryComposite = new Composite(parent, SWT.NONE); - GridLayout gl = new GridLayout(); - gl.numColumns = 2; - gl.marginHeight = 0; - gl.marginWidth = 0; - GridData data = new GridData(GridData.FILL_BOTH); - categoryComposite.setLayoutData(data); - categoryComposite.setLayout(gl); - - Label label = new Label(categoryComposite, SWT.LEFT); - label.setText(Messages._UI_LABEL_EXTENSION_CATEGORIES); - - new Label(categoryComposite, SWT.NONE); - - categoryTableViewer = new TableViewer(categoryComposite, getTableStyle()); - categoryTableViewer.setContentProvider(getCategoryContentProvider()); - categoryTableViewer.setLabelProvider(new CategoryLabelProvider()); - categoryTableViewer.setInput(fInput); - categoryTableViewer.addSelectionChangedListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(categoryTableViewer.getControl(), XSDEditorCSHelpIds.ADD_EXTENSIONS_COMPONENTS__EXTENSION_CATEGORIES); - - GridData gd = new GridData(GridData.FILL_BOTH); - Table table = categoryTableViewer.getTable(); - table.setLayoutData(gd); - table.setFont(container.getFont()); - - Composite buttonComposite = new Composite(categoryComposite, SWT.NONE); - gl = new GridLayout(); - gl.makeColumnsEqualWidth = true; - gl.numColumns = 1; - data = new GridData(); - data.horizontalAlignment = SWT.FILL; - buttonComposite.setLayoutData(data); - buttonComposite.setLayout(gl); - - addButton = new Button(buttonComposite, SWT.PUSH); - addButton.setText(Messages._UI_LABEL_ADD_WITH_DOTS); - addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - addButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(addButton, - XSDEditorCSHelpIds.ADD_EXTENSIONS_COMPONENTS__ADD); - - removeButton = new Button(buttonComposite, SWT.PUSH); - removeButton.setText(Messages._UI_LABEL_DELETE); - removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - removeButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(removeButton, - XSDEditorCSHelpIds.ADD_EXTENSIONS_COMPONENTS__DELETE); - - - editButton = new Button(buttonComposite, SWT.PUSH); - editButton.setText(Messages._UI_LABEL_EDIT); - editButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - editButton.addSelectionListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(editButton, - XSDEditorCSHelpIds.ADD_EXTENSIONS_COMPONENTS__EDIT); - - - List initialSelection = getInitialElementSelections(); - if (initialSelection != null) - categoryTableViewer.setSelection(new StructuredSelection(initialSelection)); - - Label elementLabel = new Label(categoryComposite, SWT.LEFT); - elementLabel.setText(Messages._UI_LABEL_AVAILABLE_COMPONENTS_TO_ADD); - - new Label(categoryComposite, SWT.NONE); - - elementTableViewer = new TableViewer(categoryComposite, getTableStyle()); - elementTableViewer.setContentProvider(new ElementContentProvider()); - elementTableViewer.setLabelProvider(new ElementLabelProvider()); - elementTableViewer.setInput(null); - elementTableViewer.addDoubleClickListener(new IDoubleClickListener() - { - public void doubleClick(DoubleClickEvent event) - { - okPressed(); - } - }); - if ( elementTableViewerFilter != null){ - elementTableViewer.addFilter(elementTableViewerFilter); - } - - gd = new GridData(GridData.FILL_BOTH); - table = elementTableViewer.getTable(); - table.setLayoutData(gd); - table.setFont(container.getFont()); - - elementTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - getButton(IDialogConstants.OK_ID).setEnabled(true); - } - }); - PlatformUI.getWorkbench().getHelpSystem().setHelp(elementTableViewer.getControl(), XSDEditorCSHelpIds.ADD_EXTENSIONS_COMPONENTS__AVAILABLE_COMPONENTS_TO_ADD); - - return parent; - } - - public void create() - { - super.create(); - if (categoryTableViewer.getTable().getItemCount() > 0) - { - categoryTableViewer.getTable().select(0); - - StructuredSelection structuredSelection; - if (currentExtCategory != null){ - structuredSelection = new StructuredSelection(currentExtCategory); - } - else{ - structuredSelection = - new StructuredSelection(categoryTableViewer.getElementAt(0)); - } - - categoryTableViewer.setSelection(structuredSelection); - } - - // Setup the list of category names that already exist - // and contructs the XSDSchema for each category - existingNames = new ArrayList(); - TableItem[] categories = categoryTableViewer.getTable().getItems(); - for (int i = 0; i < categories.length; i++ ){ - existingNames.add(categories[i].getText()); - - SpecificationForExtensionsSchema spec = - (SpecificationForExtensionsSchema) categories[i].getData(); - XSDSchema schema = getASISchemaModel(spec); - - if (schema == null) - { - continue; - } - - List components = buildInput(schema); - specToComponentsList.put(spec, components); - - // mark category as gray/empty if applicable - Object[] remains = components.toArray(); - if ( elementTableViewerFilter != null) - remains = elementTableViewerFilter.filter(elementTableViewer, - elementTableViewer.getTable(), remains); - if ( remains.length == 0) - { - categories[i].setForeground( - getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY)); - } - } - - getButton(IDialogConstants.OK_ID).setEnabled(false); - } - - public void addElementsTableFilter(ViewerFilter filter){ - elementTableViewerFilter = filter; - } - - public void setPrefStore(IPreferenceStore prefStore) - { - this.prefStore = prefStore; - } - - protected Point getInitialSize() - { - return getShell().computeSize(400, 300); - } - - /** - * Return the style flags for the table viewer. - * - * @return int - */ - protected int getTableStyle() - { - return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; - } - - /* - * Overrides method from Dialog - */ - protected void okPressed() - { - // Build a list of selected children. - getShell().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT)); - IStructuredSelection elementSelection = (IStructuredSelection) elementTableViewer.getSelection(); - IStructuredSelection categorySelection = (IStructuredSelection) categoryTableViewer.getSelection(); - List result = new ArrayList(); - result.add(elementSelection.getFirstElement()); - result.add(categorySelection.getFirstElement()); - if (elementSelection.getFirstElement() != null) - { - setResult(result); - } - else - { - setResult(null); - } - super.okPressed(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetSelected(SelectionEvent e) - { - if (e.widget == addButton) - { - AddNewCategoryDialog addNewCategoryDialog - = new AddNewCategoryDialog(getShell()); - - addNewCategoryDialog.setUnavailableCategoryNames(existingNames); - - if ( addNewCategoryDialog.open() == Window.OK ){ - SpecificationForExtensionsSchema schemaSpec = - new SpecificationForExtensionsSchema(); - schemaSpec.setDisplayName(addNewCategoryDialog.getNewCategoryName() ); - schemaSpec.setLocation(addNewCategoryDialog.getCategoryLocation() ); - schemaSpec.setSourceHint(addNewCategoryDialog.getSource()); - schemaSpec.setFromCatalog(addNewCategoryDialog.getFromCatalog() ); - - fInput.add(schemaSpec); - existingNames.add(schemaSpec.getDisplayName()); - - // refresh without updating labels of existing TableItems - categoryTableViewer.refresh(false); - - categoryTableViewer.setSelection(new StructuredSelection(schemaSpec)); - getButton(IDialogConstants.OK_ID).setEnabled(false); - - storeSpecInPref(schemaSpec); // must store after selection changed is called ie. 2 lines above (trung) - } - } - else if (e.widget == removeButton) - { - TableItem[] selections = categoryTableViewer.getTable().getSelection(); - for (int i =0; i < selections.length; i++){ - SpecificationForExtensionsSchema spec = - (SpecificationForExtensionsSchema) selections[i].getData(); - - fInput.remove(spec ); - existingNames.remove(spec.getDisplayName()); - specToComponentsList.remove(spec); - - removeFromPref(spec); - } - categoryTableViewer.refresh(false); - - elementTableViewer.setInput(null); - elementTableViewer.refresh(); - - // TODO auto select either the prev category, the next category or the first category in the Table - getButton(IDialogConstants.OK_ID).setEnabled(false); - } - else if (e.widget == editButton) - { - // use this dialog not for adding but for editing purpose. - AddNewCategoryDialog dialog = new AddNewCategoryDialog(getShell(), Messages._UI_LABEL_EDIT_CATEGORY); - - TableItem[] selections = categoryTableViewer.getTable().getSelection(); - if (selections.length == 0) - return; - - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema) selections[0].getData(); - - String displayName = spec.getDisplayName(); - - dialog.setCategoryName(displayName ); - dialog.setFromCatalog(spec.isFromCatalog() ); - dialog.setSource(spec.getSourceHint() ); - dialog.setCategoryLocation(spec.getLocation() ); - - specToComponentsList.remove(spec); - dialog.setUnavailableCategoryNames(existingNames); - - if ( dialog.open() == Window.OK){ - existingNames.remove(displayName); - String newDisplayName = dialog.getNewCategoryName(); - - spec.setDisplayName(newDisplayName); - spec.setLocation(dialog.getCategoryLocation()); - spec.setSourceHint(dialog.getSource()); - spec.setFromCatalog(dialog.getFromCatalog()); - spec.setNamespaceURI(null); - - existingNames.add(newDisplayName); - - categoryTableViewer.update(spec, null); - refreshElementsViewer(spec); - - editSpecInPref(displayName, spec); - } - } - } - -/* - * (non-Javadoc) - * - * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) - */ - public void widgetDefaultSelected(SelectionEvent event) - { - - } - - public void selectionChanged(SelectionChangedEvent event) - { - if (event.getSource() == categoryTableViewer) - { - ISelection selection = event.getSelection(); - if (selection instanceof StructuredSelection) - { - Object obj = ((StructuredSelection) selection).getFirstElement(); - if (obj instanceof SpecificationForExtensionsSchema) - { - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema) obj; - currentExtCategory = spec; - refreshElementsViewer(spec); - - if ( spec.isDefautSchema() ){ - editButton.setEnabled(false); - removeButton.setEnabled(false); - } - else{ - editButton.setEnabled(true); - removeButton.setEnabled(true); - } - - getButton(IDialogConstants.OK_ID).setEnabled(false); - } - } - } - } - - private void refreshElementsViewer(SpecificationForExtensionsSchema spec) { - List components = (List) specToComponentsList.get(spec); - if ( components != null){ - elementTableViewer.setInput(components); - return; - } - - XSDSchema xsdSchema = getASISchemaModel(spec); - - if (xsdSchema == null){ - MessageBox errDialog = new MessageBox(getShell(), SWT.ICON_ERROR); - errDialog.setText(Messages._UI_ERROR_INVALID_CATEGORY); - // TODO (trung) I was forced to use a String in Messages to make the error clearer - // When we are back to development phase, use another string: "Extension Category: " - // not "Extension Categories:" + " " like we are using here - errDialog.setMessage(Messages._UI_LABEL_EXTENSION_CATEGORIES + " " + spec.getDisplayName() //$NON-NLS-1$ - + "\n" //$NON-NLS-1$ - + Messages._UI_ERROR_FILE_CANNOT_BE_PARSED - + "\n" + Messages._UI_ERROR_VALIDATE_THE_FILE); //$NON-NLS-1$ - errDialog.open(); - - elementTableViewer.setInput(new ArrayList(0)); - return; - } - - components = buildInput(xsdSchema); - specToComponentsList.put(spec, components); - - List allItems = buildInput(xsdSchema); - if ( allItems == null ) - return; - elementTableViewer.setInput(allItems); - } - - private static List buildInput(XSDSchema xsdSchema) - { - if ( xsdSchema ==null ) - return null; - - List elements = xsdSchema.getElementDeclarations(); - List attributes = xsdSchema.getAttributeDeclarations(); - String targetNamespace = xsdSchema.getTargetNamespace(); - - // For safety purpose: We don't append 'attributes' to 'elements' - // ArrayStoreException(or similar one) may occur - List allItems = new ArrayList(attributes.size() + elements.size()); - - { - // getElementDeclarations returns a lot of elements from import - // statement, we - // only add non-imported elements here. (trung) - for (int i = 0; i < elements.size(); i++) - { - XSDElementDeclaration currentElement = (XSDElementDeclaration) elements.get(i); - if (currentElement.getTargetNamespace() != null) - { - if (currentElement.getTargetNamespace().equals(targetNamespace)) - allItems.add(currentElement); - } - else - { - if (targetNamespace == null) - allItems.add(currentElement); - } - } - // getAttributeDeclarations also returns a lot of elements from - // import statement, we - // only add non-imported elements here. (trung) - for (int i = 0; i < attributes.size(); i++) - { - XSDAttributeDeclaration currentAttribute = (XSDAttributeDeclaration) attributes.get(i); - if (currentAttribute.getTargetNamespace() != null) - { - if (currentAttribute.isGlobal() && currentAttribute.getTargetNamespace().equals(targetNamespace)) - allItems.add(currentAttribute); - } - else - { - if (targetNamespace == null) - allItems.add(currentAttribute); - } - } - } - return allItems; - } - - - private static XSDSchema getASISchemaModel(SpecificationForExtensionsSchema extensionsSchemaSpec) - { - String location = extensionsSchemaSpec.getLocation(); - if ( location == null) - return null; - XSDSchema xsdSchema = XSDImpl.buildXSDModel(location); - - // now that the .xsd file is read, we can retrieve the namespace of this xsd file - // and set the namespace for 'properties' - if ( extensionsSchemaSpec.getNamespaceURI() == null){ - extensionsSchemaSpec.setNamespaceURI( xsdSchema.getTargetNamespace()); - } - - return xsdSchema; - } - - private void storeSpecInPref(SpecificationForExtensionsSchema schemaSpec) { - if (prefStore == null) - return; - - String currentValue = prefStore.getString(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS); - String specDesc = " " + "\t" + schemaSpec.getDisplayName() + "\t"+ - schemaSpec.getNamespaceURI() + "\t" + schemaSpec.getLocation() + "\t" + - schemaSpec.isDefautSchema() + "\t" + schemaSpec.getSourceHint() + "\t" + - schemaSpec.isFromCatalog(); - currentValue += specDesc + "\n"; - - prefStore.setValue(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS, - currentValue); - } - - private void editSpecInPref(String displayName, SpecificationForExtensionsSchema newSpec) { - if (prefStore == null) - return; - - String newValue = ""; - String currentValue = prefStore.getString(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS); - StringTokenizer tokenizer = new StringTokenizer(currentValue, "\n"); - - while (tokenizer.hasMoreTokens()) - { - String oneSpecDesc = tokenizer.nextToken(); - // get the Display name - StringTokenizer _tokenizer_2 = new StringTokenizer(oneSpecDesc, "\t"); - _tokenizer_2.nextToken(); - String dName = _tokenizer_2.nextToken(); - - if ( dName.equals(displayName ) ) - { - oneSpecDesc = " " + "\t" + newSpec.getDisplayName() + "\t"+ - newSpec.getNamespaceURI() + "\t" + newSpec.getLocation() + "\t" + - newSpec.isDefautSchema() + "\t" + newSpec.getSourceHint() + "\t" + - newSpec.isFromCatalog(); - } - - newValue += oneSpecDesc + "\n"; - } - prefStore.setValue(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS, newValue); - - } - - private void removeFromPref(SpecificationForExtensionsSchema spec) { - if (prefStore == null) - return; - - String newValue = ""; - String currentValue = prefStore.getString(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS); - StringTokenizer tokenizer = new StringTokenizer(currentValue, "\n"); - - while (tokenizer.hasMoreTokens()) - { - String oneSpecDesc = tokenizer.nextToken(); - // get the Display name - StringTokenizer _tokenizer_2 = new StringTokenizer(oneSpecDesc, "\t"); - _tokenizer_2.nextToken(); - String dName = _tokenizer_2.nextToken(); - - if ( dName.equals(spec.getDisplayName() ) ) - continue; - newValue += oneSpecDesc + "\n"; - } - prefStore.setValue(ExtensionsSchemasRegistry.USER_ADDED_EXT_SCHEMAS, newValue); - } - -static class CategoryContentProvider implements IStructuredContentProvider - { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object inputElement) - { - SpecificationForExtensionsSchema[] extensionsSchemaSpecs = null; - try - { - List inputList = (List) inputElement; - extensionsSchemaSpecs = (SpecificationForExtensionsSchema[]) inputList.toArray(new SpecificationForExtensionsSchema[0]); - } - catch (Exception e) - { - } - return extensionsSchemaSpecs; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() - { - // Do nothing - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, - * java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - // Do nothing - - } - } - - static class CategoryLabelProvider extends LabelProvider - { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object element) - { - return XSDEditorPlugin.getXSDImage("icons/appinfo_category.gif"); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object element) - { - if (element instanceof SpecificationForExtensionsSchema) - return ((SpecificationForExtensionsSchema) element).getDisplayName(); - - return super.getText(element); - } - } - - static class ElementContentProvider implements IStructuredContentProvider - { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object inputElement) - { - if (inputElement instanceof List) - { - return ((List) inputElement).toArray(); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() - { - // Do nothing - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, - * java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - // Do nothing - - } - } - - class ElementLabelProvider extends LabelProvider - { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object element) - { - if ( element instanceof XSDElementDeclaration){ - - // Workaround trick: (trung) we create a temporary Dom element and put it in the label provider - // to get the image. - String namespace = ((XSDElementDeclaration) element).getSchema().getTargetNamespace(); - String name = ((XSDElementDeclaration) element).getName(); - Element tempElement = tempDoc.createElementNS(namespace, name); - ILabelProvider lp = XSDEditorPlugin.getDefault().getNodeCustomizationRegistry().getLabelProvider(namespace); - if (lp != null){ - Image img = lp.getImage(tempElement); - - if (img != null){ - return img; - } - } - return DEFAULT_ELEMENT_ICON; - } - else if ( element instanceof XSDAttributeDeclaration){ - return DEFAULT_ATTRIBUTE_ICON; - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object element) - { - if (element instanceof XSDElementDeclaration) - return ((XSDElementDeclaration) element).getName(); - if (element instanceof XSDAttributeDeclaration ) - return ((XSDAttributeDeclaration) element).getName(); - return super.getText(element); - } - } - - public boolean close() - { - return super.close(); - } - - protected void enableButtons(boolean value) - { - editButton.setEnabled(value); - addButton.setEnabled(value); - removeButton.setEnabled(value); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddNewCategoryDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddNewCategoryDialog.java deleted file mode 100644 index 8c5d3aa781..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/AddNewCategoryDialog.java +++ /dev/null @@ -1,385 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -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.Menu; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.dialogs.SelectSingleFileDialog; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; - -public class AddNewCategoryDialog extends Dialog -{ - - private static final String SCHEMA_LABEL = Messages._UI_LABEL_SCHEMA; - private static final String NAME_LABEL = Messages._UI_LABEL_NAME; - private String dialogTitle = Messages._UI_LABEL_ADD_CATEGORY; - - protected MenuManager browseMenu; - protected Label name; - protected Text nameText; - protected Label schema; - protected CLabel schemaDisplayer; - protected ToolBar browseToolBar; - protected ToolItem browseItem; - - protected List invalidNames; - - // TODO (cs) rename this field to extensionSchemaLocation in WTP 2.0 - protected String appInfoSchemaLocation; - protected String categoryName; - protected CLabel errDisplayer; - protected boolean isCategoryNameValid; - protected boolean fromCatalog; - - private boolean canOK =false; - - /** Either the location if come from workspace or namespace if come from - * XML Catalog */ - protected String source; - - public AddNewCategoryDialog(Shell parentShell) - { - super(parentShell); - } - - public AddNewCategoryDialog(Shell parentShell, String dialogTitle) - { - super(parentShell); - this.dialogTitle = dialogTitle; - } - - /** - * receive a List of names which have already been added to the category list - * - * @param unavailNames - * Array of unvailable names - */ - public void setUnavailableCategoryNames(List unavailNames) - { - invalidNames = unavailNames; - } - - public String getNewCategoryName() - { - return categoryName.trim(); - } - - public String getCategoryLocation() - { - return appInfoSchemaLocation; - } - - public void setCategoryLocation(String s){ - appInfoSchemaLocation = s; - } - - /** @deprecated */ - public SpecificationForExtensionsSchema getExtensionsSchemaSpec(){ - SpecificationForExtensionsSchema schemaSpec = new SpecificationForExtensionsSchema(); - schemaSpec.setDisplayName(getNewCategoryName()); - schemaSpec.setLocation(getCategoryLocation()); - - return schemaSpec; - } - - public void setCategoryName(String categoryName) { - this.categoryName = categoryName; - } - - public boolean getFromCatalog() { - return fromCatalog; - } - - public void setFromCatalog(boolean b){ - fromCatalog = b; - } - - public String getSource() - { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - protected Control createButtonBar(Composite parent) - { - Control result = super.createButtonBar(parent); - getButton(IDialogConstants.OK_ID).setEnabled(canOK); - return result; - } - - // redudant method to improve speed (according to the compiler) - protected Button getButton(int id) { - return super.getButton(id); - } - - protected Control createDialogArea(Composite parent) - { - getShell().setText(dialogTitle); - - Composite mainComposite = (Composite) super.createDialogArea(parent); - GridLayout layout = new GridLayout(3, false); - layout.marginTop = 10; - mainComposite.setLayout(layout); - mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); - GridData data = new GridData(); - data.widthHint = 400; - - mainComposite.setLayoutData(data); - - // Line 1, name - name = new Label(mainComposite, SWT.NONE); - name.setText(NAME_LABEL); - - nameText = new Text(mainComposite, SWT.BORDER | SWT.SINGLE); - nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - if (categoryName != null) - nameText.setText(categoryName); - PlatformUI.getWorkbench().getHelpSystem().setHelp(nameText, - XSDEditorCSHelpIds.ADD_CATEGORY__NAME); - - Button hidden = new Button(mainComposite, SWT.NONE); - hidden.setVisible(false); - - // Line 2, schema - schema = new Label(mainComposite, SWT.NONE); - schema.setText(SCHEMA_LABEL); - - schemaDisplayer = new CLabel(mainComposite, SWT.BORDER | SWT.SINGLE); - schemaDisplayer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - if (source != null) - { - if (fromCatalog) - schemaDisplayer.setImage( - XSDEditorPlugin.getXSDImage("icons/xmlcatalog_obj.gif")); //$NON-NLS-1$ - else - schemaDisplayer.setImage( - XSDEditorPlugin.getXSDImage("icons/XSDFile.gif")); //$NON-NLS-1$ - schemaDisplayer.setText(source); - - } - PlatformUI.getWorkbench().getHelpSystem().setHelp(schemaDisplayer, - XSDEditorCSHelpIds.ADD_CATEGORY__SCHEMA); - - if (categoryName != null && source != null) - canOK = true; - - browseToolBar = new ToolBar(mainComposite, SWT.FLAT); - browseItem = new ToolItem(browseToolBar, SWT.NONE); - // TODO: Should be able to get the image from the XML plugin. Don't need - // to copy to XSDEditor icons folder like this. - browseItem.setImage(XSDEditorPlugin.getXSDImage("icons/appinfo_browse.gif")); //$NON-NLS-1$ - - browseMenu = new MenuManager(); - - BrowseInWorkspaceAction browseInWorkspace = new BrowseInWorkspaceAction(); - browseMenu.add(browseInWorkspace); - - BrowseCatalogAction browseCatalog = new BrowseCatalogAction(); - browseMenu.add(browseCatalog); - - browseItem.addSelectionListener(new SelectionAdapter() - { - public void widgetSelected(SelectionEvent e) - { - Menu menu = browseMenu.createContextMenu(getShell()); - Rectangle bounds = browseItem.getBounds(); - Point topLeft = new Point(bounds.x, bounds.y + bounds.height); - topLeft = browseToolBar.toDisplay(topLeft); - menu.setLocation(topLeft.x, topLeft.y); - menu.setVisible(true); - } - }); - - // Composite errComp = new Composite(mainComposite, SWT.NONE); - // errComp.setBackground(org.eclipse.draw2d.ColorConstants.white); - // errComp.setLayout(new GridLayout()); - errDisplayer = new CLabel(mainComposite, SWT.FLAT); - // errDisplayer.setText("abd"); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.grabExcessHorizontalSpace = true; - gd.horizontalSpan = 3; - errDisplayer.setLayoutData(gd); - - // errComp.setLayoutData(gd); - // errDisplayer.setLayoutData(gd); - // errMsgContainer.setContent(errDisplayer); - - nameText.addModifyListener(new ModifyListener() - { - // track the nameText and enable/disable the OK button accordingly - public void modifyText(ModifyEvent e) - { - categoryName = nameText.getText(); - - // name is in the invalid List - if (invalidNames != null) - { - if (invalidNames.contains(categoryName.trim())) - { - isCategoryNameValid = false; - - getButton(IDialogConstants.OK_ID).setEnabled(false); - errDisplayer.setText(Messages._UI_ERROR_NAME_ALREADY_USED); - errDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/error_st_obj.gif")); //$NON-NLS-1$ - return; - } - } - // name is empty string - if (categoryName.equals("")) //$NON-NLS-1$ - { - isCategoryNameValid = false; - - getButton(IDialogConstants.OK_ID).setEnabled(false); - errDisplayer.setText(""); //$NON-NLS-1$ - errDisplayer.setImage(null); - return; - } - - /* - * Enable the Ok button if the location field AND the name field are not - * empty - */ - if (!categoryName.equals("")) //$NON-NLS-1$ - { - isCategoryNameValid = true; - errDisplayer.setText(""); //$NON-NLS-1$ - errDisplayer.setImage(null); - } - if (appInfoSchemaLocation != null && !appInfoSchemaLocation.equals("")) //$NON-NLS-1$ - { - getButton(IDialogConstants.OK_ID).setEnabled(true); - } - } - }); - - return parent; - } - - protected void okPressed() - { - super.okPressed(); - } - - protected class BrowseInWorkspaceAction extends Action - { - private static final String XSD_FILE_EXTENSION = ".xsd"; //$NON-NLS-1$ - - public BrowseInWorkspaceAction() - { - super(Messages._UI_ACTION_BROWSE_WORKSPACE); - } - - public void run() - { - SelectSingleFileDialog dialog = new SelectSingleFileDialog(getShell(), null, true); - dialog.addFilterExtensions(new String[] { XSD_FILE_EXTENSION }); - dialog.create(); - dialog.setTitle(Messages._UI_LABEL_SELECT_XSD_FILE); - dialog.setMessage(Messages._UI_DESCRIPTION_CHOOSE_XSD_FILE); - - if (dialog.open() == Window.OK) - { - IFile appInfoSchemaFile = dialog.getFile(); - if (appInfoSchemaFile != null) - { - // remove leading slash from the value to avoid the - // whole leading slash ambiguity problem - String uri = appInfoSchemaFile.getFullPath().toString(); - while (uri.startsWith("/") || uri.startsWith("\\")) { //$NON-NLS-1$ //$NON-NLS-2$ - uri = uri.substring(1); - } - appInfoSchemaLocation = uri.toString(); - source = uri; - fromCatalog = false; - - appInfoSchemaLocation = "file://" + Platform.getLocation().toString() + "/" + appInfoSchemaLocation; //$NON-NLS-1$ //$NON-NLS-2$ - // TODO... be careful how we construct the location - // UNIX related issues here - - schemaDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/XSDFile.gif")); //$NON-NLS-1$ - schemaDisplayer.setText(uri); - - // Enable the OK button if we should.. - if (isCategoryNameValid) - { - getButton(IDialogConstants.OK_ID).setEnabled(true); - errDisplayer.setText(""); //$NON-NLS-1$ - errDisplayer.setImage(null); - } - } - } - } - } - - protected class BrowseCatalogAction extends Action - { - public BrowseCatalogAction() - { - super(Messages._UI_ACTION_BROWSE_CATALOG); - } - - public void run() - { - SelectFromCatalogDialog dialog = new SelectFromCatalogDialog(getShell()); - // dialog.open(); - if (dialog.open() == Window.OK) - { - appInfoSchemaLocation = dialog.getCurrentSelectionLocation(); - source = dialog.getCurrentSelectionNamespace(); - fromCatalog = true; - - schemaDisplayer.setImage(XSDEditorPlugin.getXSDImage("icons/xmlcatalog_obj.gif")); //$NON-NLS-1$ - schemaDisplayer.setText(dialog.getCurrentSelectionNamespace()); - - // Enable the OK button if we should.. - if (isCategoryNameValid && !appInfoSchemaLocation.equals("")) //$NON-NLS-1$ - { - getButton(IDialogConstants.OK_ID).setEnabled(true); - errDisplayer.setText(""); //$NON-NLS-1$ - errDisplayer.setImage(null); - } - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/CategoryProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/CategoryProvider.java deleted file mode 100644 index a3eb64a376..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/CategoryProvider.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; - -public class CategoryProvider -{ - private ICatalog systemCatalog; - - public CategoryProvider() - { - - } - - /** - * Extenders should implement and return a list of - * SpecificationForExtensionsSchema - * @return - */ - public List getCategories() - { - return new ArrayList(); - } - - /** - * Helper method to find the physical location of the schema - * in the XML Catalog - * @param namespaceURI - * @return physical location of the schema - */ - public String locateFileUsingCatalog(String namespaceURI) - { - retrieveCatalog(); - - ICatalogEntry[] entries = systemCatalog.getCatalogEntries(); - for (int i = 0; i < entries.length; i++) - { - if (entries[i].getKey().equals(namespaceURI)) - return entries[i].getURI(); - } - - return null; - } - - private void retrieveCatalog() - { - if (systemCatalog != null) - return; - - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) - { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) - { - if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) - { - systemCatalog = referencedCatalog; - } - } - } - } - -} 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 deleted file mode 100644 index f28e18acbe..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionDetailsContentProvider.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.text.Collator; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -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.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.DefaultListNodeEditorConfiguration; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeCustomizationRegistry; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeEditorConfiguration; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeEditorProvider; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; - -public class DOMExtensionDetailsContentProvider implements ExtensionDetailsContentProvider -{ - private static final Object[] EMPTY_ARRAY = {}; - private static final String[] EMPTY_STRING_ARRAY = {}; - private static final String XMLNS = "xmlns"; //$NON-NLS - private static final String TEXT_NODE_KEY = "text()"; //$NON-NLS - - public Object[] getItems(Object input) - { - HashMap resultMap = new HashMap(); - if (input instanceof Element) - { - Element element = (Element) input; - - // here we compute items for the attributes that physically in the document - // - 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())) //$NON-NLS-1$ //$NON-NLS-2$ - { - resultMap.put(attr.getName(), DOMExtensionItem.createItemForElementAttribute(element, attr)); - } - } - - // here we compute an item for the text node that is physically in the document - // - String textNodeValue = new TreeContentHelper().getNodeValue(element); - if (textNodeValue != null) - { - resultMap.put(TEXT_NODE_KEY, DOMExtensionItem.createItemForElementText(element)); - } - - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (modelQuery != null) - { - CMElementDeclaration ed = modelQuery.getCMElementDeclaration(element); - if (ed != null) - { - // here we compute items for the attributes that may be added to the document according to the grammar - // - List list = modelQuery.getAvailableContent(element, ed, ModelQuery.INCLUDE_ATTRIBUTES); - for (Iterator i = list.iterator(); i.hasNext(); ) - { - CMAttributeDeclaration ad = (CMAttributeDeclaration)i.next(); - if (ad != null && resultMap.get(ad.getNodeName()) == null) - { - resultMap.put(ad.getNodeName(), DOMExtensionItem.createItemForElementAttribute(element, ad)); - } - } - if (resultMap.get(TEXT_NODE_KEY) == null) - { - // here we compute an item for the text node that may be added to the document according to the grammar - // - int contentType = ed.getContentType(); - if (contentType == CMElementDeclaration.PCDATA || contentType == CMElementDeclaration.MIXED) - { - resultMap.put(TEXT_NODE_KEY, DOMExtensionItem.createItemForElementText(element)); - } - } - } - } - Collection collection = resultMap.values(); - // initialize the editor information for each item - // - for (Iterator i = collection.iterator(); i.hasNext();) - { - initPropertyEditorConfiguration((DOMExtensionItem) i.next()); - } - DOMExtensionItem[] items = new DOMExtensionItem[collection.size()]; - resultMap.values().toArray(items); - - // here we sort the list alphabetically - // - if (items.length > 0) - { - Comparator comparator = new Comparator() - { - public int compare(Object arg0, Object arg1) - { - DOMExtensionItem a = (DOMExtensionItem)arg0; - DOMExtensionItem b = (DOMExtensionItem)arg1; - - // begin special case to ensure 'text nodes' come last - if (a.isTextValue() && !b.isTextValue()) - { - return 1; - } - else if (b.isTextValue() && !a.isTextValue()) - { - return -1; - } - // end special case - else - { - return Collator.getInstance().compare(a.getName(), b.getName()); - } - } - }; - Arrays.sort(items, comparator); - } - return items; - } - else if (input instanceof Attr) - { - Attr attr = (Attr) input; - DOMExtensionItem item = DOMExtensionItem.createItemForAttributeText(attr.getOwnerElement(), attr); - DOMExtensionItem[] items = {item}; - return items; - } - return EMPTY_ARRAY; - } - - public String getName(Object item) - { - if (item instanceof DOMExtensionItem) - { - return ((DOMExtensionItem) item).getName(); - } - return ""; //$NON-NLS-1$ - } - - public String getValue(Object item) - { - if (item instanceof DOMExtensionItem) - { - return ((DOMExtensionItem) item).getValue(); - } - return ""; //$NON-NLS-1$ - } - - public String[] getPossibleValues(Object item) - { - if (item instanceof DOMExtensionItem) - { - return ((DOMExtensionItem) item).getPossibleValues(); - } - return EMPTY_STRING_ARRAY; - } - - protected void initPropertyEditorConfiguration(DOMExtensionItem item) - { - String namespace = item.getNamespace(); - String name = item.getName(); - String parentName = item.getParentName(); - NodeEditorConfiguration configuration = null; - if (namespace != null) - { - // TODO (cs) remove reference to XSDEditorPlugin... make generic - // perhaps push down the xml.ui ? - // - NodeCustomizationRegistry registry = XSDEditorPlugin.getDefault().getNodeCustomizationRegistry(); - NodeEditorProvider provider= registry.getNodeEditorProvider(namespace); - if (provider != null) - { - configuration = provider.getNodeEditorConfiguration(parentName, name); - if (configuration != null) - { - configuration.setParentNode(item.getParentNode()); - if (item.getNode() != null) - { - configuration.setNode(item.getNode()); - } - } - } - } - String[] values = item.getPossibleValues(); - if (values != null && values.length > 1) - { - configuration = new DefaultListNodeEditorConfiguration(values); - } - - // Note that it IS expected that the configaration may be null - // - item.setPropertyEditorConfiguration(configuration); - } -} 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 deleted file mode 100644 index 52505251b2..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItem.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 org.eclipse.gef.commands.Command; -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.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTextValueCommand; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -class DOMExtensionItem extends ExtensionItem -{ - private final static int KIND_ELEMENT_ATTR = 1; - private final static int KIND_ELEMENT_TEXT = 2; - private final static int KIND_ELEMENT_CMATTRIBUTE = 3; - private final static int KIND_ATTR_TEXT = 4; - int kind; - Attr attribute; - Element parent; - CMNode cmNode; - - private DOMExtensionItem(int kind, Element parent, Attr node, CMNode cmNode) - { - this.kind = kind; - this.parent = parent; - this.attribute = node; - this.cmNode = cmNode; - } - - public boolean isTextValue() - { - return kind == KIND_ELEMENT_TEXT || kind == KIND_ATTR_TEXT; - } - - static DOMExtensionItem createItemForElementText(Element parent) - { - return new DOMExtensionItem(KIND_ELEMENT_TEXT, parent, null, null); - } - - static DOMExtensionItem createItemForElementAttribute(Element parent, Attr attribute) - { - return new DOMExtensionItem(KIND_ELEMENT_ATTR, parent, attribute, null); - } - - static DOMExtensionItem createItemForElementAttribute(Element parent, CMAttributeDeclaration ad) - { - if (ad == null) - { - System.out.println("null!"); - } - return new DOMExtensionItem(KIND_ELEMENT_CMATTRIBUTE, parent, null, ad); - } - - static DOMExtensionItem createItemForAttributeText(Element parent, Attr attribute) - { - return new DOMExtensionItem(KIND_ATTR_TEXT, parent, attribute, null); - } - - public String getName() - { - String result = null; - switch (kind) - { - case KIND_ATTR_TEXT : { - result = "value"; - break; - } - case KIND_ELEMENT_ATTR : { - result = attribute.getName(); - break; - } - case KIND_ELEMENT_CMATTRIBUTE : { - CMAttributeDeclaration ad = (CMAttributeDeclaration) cmNode; - result = ad.getNodeName(); - break; - } - case KIND_ELEMENT_TEXT : { - result = "text value"; - break; - } - } - return result != null ? result : ""; - } - - public String getValue() - { - switch (kind) - { - case KIND_ATTR_TEXT : - case KIND_ELEMENT_ATTR : { - // note intentional fall-thru!! - return attribute.getNodeValue(); - } - case KIND_ELEMENT_CMATTRIBUTE : { - // CS : one would think that we'd just need to return "" here - // but after editing a item of this kind and giving it value - // the list of item's doesn't get recomputed.. so we need to trick - // one of these items to behave like the KIND_ELEMENT_ATTR case - // - String value = parent.getAttribute(cmNode.getNodeName()); - return (value != null) ? value : ""; - } - case KIND_ELEMENT_TEXT : { - return new TreeContentHelper().getElementTextValue(parent); - } - } - return ""; - } - - - public String[] getPossibleValues() - { - String[] result = {}; - - switch (kind) - { - case KIND_ATTR_TEXT : - case KIND_ELEMENT_ATTR : { - // note intentional fall-thru!! - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - if (modelQuery != null) - { - CMAttributeDeclaration ad = modelQuery.getCMAttributeDeclaration(attribute); - if (ad != null) - { - result = modelQuery.getPossibleDataTypeValues(parent, ad); - } - } - break; - } - case KIND_ELEMENT_CMATTRIBUTE : { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - if (modelQuery != null && cmNode != null) - { - result = modelQuery.getPossibleDataTypeValues(parent, cmNode); - } - break; - } - case KIND_ELEMENT_TEXT : { - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - if (modelQuery != null) - { - CMElementDeclaration ed = modelQuery.getCMElementDeclaration(parent); - if (ed != null) - { - result = modelQuery.getPossibleDataTypeValues(parent, ed); - } - } - break; - } - } - return result; - } - - public Command getUpdateValueCommand(String newValue) - { - switch (kind) - { - case KIND_ATTR_TEXT : - case KIND_ELEMENT_ATTR : { - // note intentional fall-thru!! - return new UpdateAttributeValueCommand(parent, attribute.getNodeName(), newValue, true); - } - case KIND_ELEMENT_CMATTRIBUTE : { - final CMAttributeDeclaration ad = (CMAttributeDeclaration) cmNode; - return new UpdateAttributeValueCommand(parent, ad.getAttrName(), newValue, true); - } - case KIND_ELEMENT_TEXT : { - return new UpdateTextValueCommand(parent, newValue); - } - } - return null; - } - - public String getNamespace() - { - String namespace = null; - if (kind == KIND_ATTR_TEXT) - { - namespace = attribute.getNamespaceURI(); - } - else if (parent != null) - { - namespace = parent.getNamespaceURI(); - } - return namespace; - } - - public Node getParentNode() - { - Node parentNode = null; - if (attribute != null) - { - parentNode = attribute.getOwnerElement(); - } - else if (parent != null) - { - parentNode = parent; - } - return parentNode; - } - - public String getParentName() - { - Node parentNode = getParentNode(); - return parentNode != null ? parentNode.getLocalName() : ""; - } - - public Node getNode() - { - return attribute; - } -} 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 deleted file mode 100644 index aac70ea719..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemEditManager.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Widget; - - -/** - * @deprecated - */ -public class DOMExtensionItemEditManager implements ExtensionItemEditManager -{ - public void handleEdit(Object item, Widget widget) - { - } - - public Control createCustomButtonControl(Composite composite, Object item) - { - Button button = new Button(composite, SWT.NONE); - button.setText("..."); //$NON-NLS-1$ - return button; - } - - public Control createCustomTextControl(Composite composite, Object item) - { - return null; - } - - public String getButtonControlStyle(Object object) - { - return ExtensionItemEditManager.STYLE_NONE; - } - - public String getTextControlStyle(Object object) - { - return ExtensionItemEditManager.STYLE_NONE; - } -} 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 deleted file mode 100644 index fc30c94d0e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionItemMenuListener.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 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 deleted file mode 100644 index bc90293694..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeContentProvider.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.Collections; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; -import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class DOMExtensionTreeContentProvider implements ITreeContentProvider, INodeAdapter -{ - protected String facet; - protected Viewer viewer; - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) - { - this.viewer = viewer; - } - - 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() - { - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) - { - if (viewer != null) - { - viewer.refresh(); - } - } - - public boolean isAdapterForType(Object type) - { - // this method is not used - return false; - } -}
\ 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 deleted file mode 100644 index d173548205..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/DOMExtensionTreeLabelProvider.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeCustomizationRegistry; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.w3c.dom.Attr; -import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; - -public class DOMExtensionTreeLabelProvider extends LabelProvider -{ - protected static final Image DEFAULT_ELEMENT_ICON = XSDEditorPlugin.getXSDImage("icons/XSDElement.gif"); //$NON-NLS-1$ - protected static final Image DEFAULT_ATTR_ICON = XSDEditorPlugin.getXSDImage("icons/XSDAttribute.gif"); //$NON-NLS-1$ - - public DOMExtensionTreeLabelProvider() - { - } - - public Image getImage(Object element) - { - NodeCustomizationRegistry registry = XSDEditorPlugin.getDefault().getNodeCustomizationRegistry(); - if (element instanceof Element) - { - Element domElement = (Element) element; - String namespace = domElement.getNamespaceURI(); - if (namespace != null) - { - ILabelProvider lp = registry.getLabelProvider(namespace); - 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; - String textVal = ""; - - if (domElement.hasChildNodes()) - { - Node node = domElement.getChildNodes().item(0); - if (node instanceof Text) - { - Text textNode = (Text) node; - try - { - if (!textNode.getNodeValue().contains("\n")) - textVal = " [" + textNode.getNodeValue() + "]"; - } - catch (DOMException e) - { - textVal = ""; - } - } - } - return domElement.getLocalName() + textVal; - } - if ( input instanceof Attr){ - return ((Attr) input).getLocalName(); - } - return ""; //$NON-NLS-1$ - } -} 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 deleted file mode 100644 index 6cfaac1e48..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsContentProvider.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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; - -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 deleted file mode 100644 index 5f5162ddee..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionDetailsViewer.java +++ /dev/null @@ -1,326 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 org.eclipse.draw2d.ColorConstants; -import org.eclipse.gef.commands.Command; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.LabelProvider; -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.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.Text; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.DialogNodeEditorConfiguration; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.ListNodeEditorConfiguration; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeEditorConfiguration; - -public class ExtensionDetailsViewer extends Viewer -{ - private final static String ITEM_DATA = "ITEM_DATA"; //$NON-NLS-1$ - private final static String EDITOR_CONFIGURATION_DATA = "EDITOR_CONFIGURATION_DATA"; //$NON-NLS-1$ - - Composite control; - Composite composite; - ExtensionDetailsContentProvider contentProvider; - TabbedPropertySheetWidgetFactory widgetFactory; - InternalControlListener internalControlListener; - - public ExtensionDetailsViewer(Composite parent, TabbedPropertySheetWidgetFactory widgetFactory) - { - this.widgetFactory = widgetFactory; - control = widgetFactory.createComposite(parent); - internalControlListener = new InternalControlListener(); - 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() - { - Control[] children = composite.getChildren(); - for (int i = 0; i < children.length; i++) - { - Control control = children[i]; - if (control instanceof Text) - { - ExtensionItem item = (ExtensionItem)control.getData(ITEM_DATA); - String value = contentProvider.getValue(item); - ((Text)control).setText(value); - } - } - } - - private void createTextOrComboControl(ExtensionItem item, Composite composite) - { - Control control = null; - String value = contentProvider.getValue(item); - NodeEditorConfiguration editorConfiguration = item.getPropertyEditorConfiguration(); - - if (editorConfiguration != null && hasStyle(editorConfiguration, NodeEditorConfiguration.STYLE_COMBO)) - { - ListNodeEditorConfiguration configuration = (ListNodeEditorConfiguration)editorConfiguration; - CCombo combo = widgetFactory.createCCombo(composite); - combo.setText(value); - Object[] values = configuration.getValues(item); - LabelProvider labelProvider = configuration.getLabelProvider(); - for (int j = 0; j < values.length; j++) - { - Object o = values[j]; - String displayName = labelProvider != null ? - labelProvider.getText(o) : - o.toString(); - combo.add(displayName); - } - combo.addSelectionListener(internalControlListener); - control = combo; - } - if (control == null) - { - Text text = widgetFactory.createText(composite,value); - text.addKeyListener(internalControlListener); - control = text; - } - control.setData(ITEM_DATA, item); - control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - control.addFocusListener(internalControlListener); - } - - private void createButtonControl(ExtensionItem item, Composite composite) - { - NodeEditorConfiguration editorConfiguration = item.getPropertyEditorConfiguration(); - if (editorConfiguration != null && hasStyle(editorConfiguration, NodeEditorConfiguration.STYLE_DIALOG)) - { - DialogNodeEditorConfiguration configuration = (DialogNodeEditorConfiguration)editorConfiguration; - Button button = new Button(composite, SWT.NONE); - GridData gridData = new GridData(); - gridData.heightHint = 17; - button.setLayoutData(gridData); - button.addSelectionListener(internalControlListener); - button.setData(ITEM_DATA, item); - button.setData(EDITOR_CONFIGURATION_DATA, configuration); - String text = configuration.getButonText(); - if (text != null) - { - button.setText(text); //$NON-NLS-1$ - } - button.setImage(configuration.getButtonImage()); - } - else - { - Control placeHolder = new Label(composite, SWT.NONE); - placeHolder.setVisible(false); - placeHolder.setEnabled(false); - placeHolder.setLayoutData(new GridData()); - } - } - - public void setInput(Object input) - { - // TODO (cs) add assertions - // - 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); - } - } */ - removeListeners(); - 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++) - { - ExtensionItem item = (ExtensionItem)items[i]; - String name = contentProvider.getName(item); - Label label = widgetFactory.createLabel(composite, name + ":"); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - createTextOrComboControl(item, composite); - createButtonControl(item, composite); - } - control.layout(true); - } - - private boolean hasStyle(NodeEditorConfiguration configuration, int style) - { - return (configuration.getStyle() & style) != 0; - } - - - 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; - } - - private void applyEdit(ExtensionItem item, Widget widget) - { - if (item != null) - { - 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 = item.getUpdateValueCommand(value); - if (command != null) - { - // TODO (cs) add command stack handling stuff - command.execute(); - } - } - } - } - - class InternalControlListener implements FocusListener, SelectionListener, KeyListener - { - public void widgetSelected(SelectionEvent e) - { - // for button controls we handle selection events - // - Object item = e.widget.getData(EDITOR_CONFIGURATION_DATA); - if (item == null) - item = e.widget.getData(ITEM_DATA); - if (item instanceof DialogNodeEditorConfiguration) - { - DialogNodeEditorConfiguration dialogNodeEditorConfiguration = (DialogNodeEditorConfiguration)item; - dialogNodeEditorConfiguration.invokeDialog(); - } - else if (item instanceof ExtensionItem) - { - applyEdit((ExtensionItem)item, e.widget); - } - } - - public void widgetDefaultSelected(SelectionEvent e) - { - // do nothing - } - - public void focusGained(FocusEvent e) - { - } - - public void focusLost(FocusEvent e) - { - // apply edits for text and combo box controls - // via the focusLost event - Object item = e.widget.getData(ITEM_DATA); - if (item instanceof ExtensionItem) - { - applyEdit((ExtensionItem)item, e.widget); - } - } - - public void keyPressed(KeyEvent e) - { - // handle explict ENTER key - Object item = e.widget.getData(ITEM_DATA); - if (item instanceof ExtensionItem) - { - if (e.character == SWT.CR) - applyEdit((ExtensionItem)item, e.widget); - } - } - - public void keyReleased(KeyEvent e) - { - // Ignore these events - } - } - - public void removeListeners() - { - if (composite != null && !composite.isDisposed()) - { - Control [] children = composite.getChildren(); - int length = children.length; - for (int i = 0; i < length; i++) - { - Control o = children[i]; - if (o instanceof CCombo) - { - ((CCombo)o).removeSelectionListener(internalControlListener); - o.removeFocusListener(internalControlListener); - } - else if (o instanceof Text) - { - ((Text)o).removeKeyListener(internalControlListener); - o.removeFocusListener(internalControlListener); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItem.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItem.java deleted file mode 100644 index 4b67808305..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItem.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 org.eclipse.gef.commands.Command; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeEditorConfiguration; - -public abstract class ExtensionItem -{ - NodeEditorConfiguration propertyEditorConfiguration; - - public NodeEditorConfiguration getPropertyEditorConfiguration() - { - return propertyEditorConfiguration; - } - - public void setPropertyEditorConfiguration(NodeEditorConfiguration propertyEditorConfiguration) - { - this.propertyEditorConfiguration = propertyEditorConfiguration; - } - - public abstract Command getUpdateValueCommand(String newValue); -} 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 deleted file mode 100644 index b84ad1c2ea..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemEditManager.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Widget; - -/** - * @deprecated - */ -public interface ExtensionItemEditManager -{ - public final static String STYLE_NONE = "none"; //$NON-NLS-1$ - public final static String STYLE_TEXT = "text"; //$NON-NLS-1$ - public final static String STYLE_COMBO = "combo"; //$NON-NLS-1$ - public final static String STYLE_CUSTOM = "custom"; //$NON-NLS-1$ - - 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/ExtensionItemFilter.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemFilter.java deleted file mode 100644 index b199c37c60..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionItemFilter.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 org.eclipse.xsd.XSDConcreteComponent; - -// cs: This interface is intended to suppliment the NodeFilter class -// that can be specified via the customization extensions point. -// When the initial list of a category's objects is displayed -// we'll use a NodeFilter to prune the list. If the NodeFilter -// implements this interface we'll call this interface's isApplicableContext -// method instead of the NodeFilter's DOM node based method. This provides -// are a more convenient interface for clients who are only interested in -// filter the list presented via the AddExtensionComponentDialog. -// See the class ExtensionsSection for more details. -// -public interface ExtensionItemFilter -{ - public boolean isApplicableContext(XSDConcreteComponent parent, XSDConcreteComponent candidate); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java deleted file mode 100644 index 8fc3af68bc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/ExtensionsSchemasRegistry.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleRemoveExtensionNodeCommand; -import org.w3c.dom.Element; - -public class ExtensionsSchemasRegistry -{ - public static final String USER_ADDED_EXT_SCHEMAS = "USER-ADDED-EXT-SCHEMAS"; // TODO externalize - private static final String LOCATION_PREFIX = "platform:/plugin/"; //$NON-NLS-1$ - public static final String DESCRIPTION = "description"; //$NON-NLS-1$ - public static final String DISPLAYNAME = "displayName"; //$NON-NLS-1$ - public static final String NAMESPACEURI = "namespaceURI"; //$NON-NLS-1$ - public static final String XSDFILEURL = "xsdFileURL"; //$NON-NLS-1$ - public static final String LABELPROVIDER = "labelProviderClass"; //$NON-NLS-1$ - public static final String ADD_COMMAND_CLASS = "addCommandClass"; //$NON-NLS-1$ - public static final String DELETE_COMMAND_CLASS = "deleteCommandClass"; //$NON-NLS-1$ - public static final String CATEGORY_PROVIDER_CLASS = "class"; //$NON-NLS-1$ - - protected IPreferenceStore prefStore; - protected String extensionId; - - protected ArrayList nsURIProperties, categoryProviderList; - private String deprecatedExtensionId; - - public ExtensionsSchemasRegistry(String appinfo_extensionid) - { - extensionId = appinfo_extensionid; - } - - public void __internalSetDeprecatedExtensionId(String deprecatedId) - { - deprecatedExtensionId = deprecatedId; - } - - public void setPrefStore(IPreferenceStore store) - { - prefStore = store; - } - - public List getAllExtensionsSchemasContribution() - { - // If we read the registry, then let's not do it again. - if (nsURIProperties != null) - { - return nsURIProperties; - } - - nsURIProperties = new ArrayList(); - categoryProviderList = new ArrayList(); - - getAllExtensionsSchemasContribution(extensionId); - if (deprecatedExtensionId != null) - { - getAllExtensionsSchemasContribution(deprecatedExtensionId); - } - - // get user-added schemas stored in preference - if (prefStore != null) - { - String value = prefStore.getString(USER_ADDED_EXT_SCHEMAS); - StringTokenizer tokenizer = new StringTokenizer(value, "\n"); - - while ( tokenizer.hasMoreTokens() ) - { - nsURIProperties.add( new SpecificationForExtensionsSchema( tokenizer.nextToken() ) ); - } - } - - return nsURIProperties; - } - - private List getAllExtensionsSchemasContribution(String id) - { - IConfigurationElement[] asiPropertiesList = Platform.getExtensionRegistry().getConfigurationElementsFor(id); - - boolean hasASIProperties = (asiPropertiesList != null) && (asiPropertiesList.length > 0); - - if (hasASIProperties) - { - for (int i = 0; i < asiPropertiesList.length; i++) - { - IConfigurationElement asiPropertiesElement = asiPropertiesList[i]; - String elementName = asiPropertiesElement.getName(); - - if ("category".equals(elementName)) - { - String description = asiPropertiesElement.getAttribute(DESCRIPTION); - String displayName = asiPropertiesElement.getAttribute(DISPLAYNAME); - String namespaceURI = asiPropertiesElement.getAttribute(NAMESPACEURI); - String xsdFileURL = asiPropertiesElement.getAttribute(XSDFILEURL); - String labelProviderClass = asiPropertiesElement.getAttribute(LABELPROVIDER); - String addCommandClass = asiPropertiesElement.getAttribute(ADD_COMMAND_CLASS); - String deleteCommandClass = asiPropertiesElement.getAttribute(DELETE_COMMAND_CLASS); - - if (displayName == null) - { - // If there is no display name, force the user - // to manually create a name. Therefore, we ignore entry without - // a display name. - continue; - } - - if (xsdFileURL == null) - { - xsdFileURL = locateFileUsingCatalog(namespaceURI); - } - - SpecificationForExtensionsSchema extensionsSchemaSpec = createEntry(); - extensionsSchemaSpec.setDescription(description); - extensionsSchemaSpec.setDisplayName(displayName); - extensionsSchemaSpec.setNamespaceURI(namespaceURI); - extensionsSchemaSpec.setDefautSchema(); - - String pluginId = asiPropertiesElement.getDeclaringExtension().getContributor().getName(); - - if (labelProviderClass != null) - { - ILabelProvider labelProvider = null; - try - { - Class theClass = Platform.getBundle(pluginId).loadClass(labelProviderClass); - if (theClass != null) - { - labelProvider = (ILabelProvider) theClass.newInstance(); - if (labelProvider != null) - { - extensionsSchemaSpec.setLabelProvider(labelProvider); - } - } - } - catch (Exception e) - { - - } - } - - if (addCommandClass != null) - { - try - { - ExtensibleAddExtensionCommand addCommand = (ExtensibleAddExtensionCommand)asiPropertiesElement.createExecutableExtension(ADD_COMMAND_CLASS); - if (addCommand != null) - { - extensionsSchemaSpec.setExtensibleAddExtensionCommand(addCommand); - } - } - catch (Exception e) - { - } - } - - if (deleteCommandClass != null) - { - try - { - ExtensibleRemoveExtensionNodeCommand deleteCommand = (ExtensibleRemoveExtensionNodeCommand)asiPropertiesElement.createExecutableExtension(DELETE_COMMAND_CLASS); - if (deleteCommand != null) - { - extensionsSchemaSpec.setExtensibleRemoveExtensionNodeCommand(deleteCommand); - } - } - catch (Exception e) - { - } - } - - extensionsSchemaSpec.setLocation(LOCATION_PREFIX + pluginId + "/" + xsdFileURL); //$NON-NLS-1$ - - nsURIProperties.add(extensionsSchemaSpec); - - } - else if ("categoryProvider".equals(elementName)) - { - String categoryProviderClass = asiPropertiesElement.getAttribute(CATEGORY_PROVIDER_CLASS); - - if (categoryProviderClass != null) - { - try - { - CategoryProvider categoryProvider = (CategoryProvider)asiPropertiesElement.createExecutableExtension(CATEGORY_PROVIDER_CLASS); - if (categoryProvider != null) - { - categoryProviderList.add(categoryProvider); - } - } - catch (Exception e) - { - } - } - - } - - } - - } - - return nsURIProperties; - } - - public ExtensibleAddExtensionCommand getAddExtensionCommand(String namespace) - { - // Didn't retrieve the config elements yet. - if (nsURIProperties == null) - { - getAllExtensionsSchemasContribution(); - } - - for (Iterator i = nsURIProperties.iterator(); i.hasNext(); ) - { - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema)i.next(); - String nsURI = spec.getNamespaceURI(); - if (nsURI != null && nsURI.equals(namespace)) - { - return spec.getExtensibleAddExtensionCommand(); - } - } - - for (Iterator i = categoryProviderList.iterator(); i.hasNext(); ) - { - CategoryProvider categoryProvider = (CategoryProvider)i.next(); - for (Iterator j = categoryProvider.getCategories().iterator(); j.hasNext(); ) - { - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema) j.next(); - String namespaceURI = spec.getNamespaceURI(); - if (namespaceURI != null && namespaceURI.equals(namespace)) - { - return spec.getExtensibleAddExtensionCommand(); - } - } - } - - return null; - } - - public ExtensibleRemoveExtensionNodeCommand getRemoveExtensionNodeCommand(String namespace) - { - // Didn't retrieve the config elements yet. - if (nsURIProperties == null) - { - getAllExtensionsSchemasContribution(); - } - - for (Iterator i = nsURIProperties.iterator(); i.hasNext(); ) - { - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema)i.next(); - String nsURI = spec.getNamespaceURI(); - if (nsURI != null && nsURI.equals(namespace)) - { - return spec.getExtensibleRemoveExtensionNodeCommand(); - } - } - - for (Iterator i = categoryProviderList.iterator(); i.hasNext(); ) - { - CategoryProvider categoryProvider = (CategoryProvider)i.next(); - for (Iterator j = categoryProvider.getCategories().iterator(); j.hasNext(); ) - { - SpecificationForExtensionsSchema spec = (SpecificationForExtensionsSchema) j.next(); - String namespaceURI = spec.getNamespaceURI(); - if (namespaceURI != null && namespaceURI.equals(namespace)) - { - return spec.getExtensibleRemoveExtensionNodeCommand(); - } - } - } - - return null; - } - - public List getCategoryProviders() - { - if (nsURIProperties == null) - { - getAllExtensionsSchemasContribution(); - } - - return categoryProviderList; - } - - /** - * @deprecated - */ - public ILabelProvider getLabelProvider(Element element) - { - return null; - } - - public SpecificationForExtensionsSchema createEntry() - { - return new SpecificationForExtensionsSchema(); - } - - /** - * Returns the String location for the schema with the given namespaceURI by - * looking at the XML catalog. We look only in the plugin specified entries of - * the catalog. - * - * @param namespaceURI - * @return String representing the location of the schema. - */ - private String locateFileUsingCatalog(String namespaceURI) - { - URIResolver resolver = URIResolverPlugin.createResolver(); - String result = resolver.resolve("", namespaceURI, ""); - return resolver.resolvePhysicalLocation("", namespaceURI, result); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SelectFromCatalogDialog.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SelectFromCatalogDialog.java deleted file mode 100644 index 1f2737a523..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SelectFromCatalogDialog.java +++ /dev/null @@ -1,212 +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 org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -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.Group; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogEntriesView; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogEntryDetailsView; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogMessages; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogTreeViewer; - -public class SelectFromCatalogDialog extends Dialog -{ - - private ICatalog workingUserCatalog; - private ICatalog userCatalog; - private ICatalog defaultCatalog; - private XMLCatalogEntriesView catalogEntriesView; - private ICatalog systemCatalog; - - private String currentSelectionLocation; - private String currentSelectionNamespace; - - public SelectFromCatalogDialog(Shell parentShell) - { - super(parentShell); - - defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) - { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) - { - if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) - { - systemCatalog = referencedCatalog; - } - else if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) - { - userCatalog = referencedCatalog; - } - } - } - } - - protected Control createDialogArea(Composite parent) - { - // we create a working copy of the 'User Settings' for the Catalog - // that we can modify - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - // TODO: add entries from the nested catalogs as well - workingUserCatalog.addEntriesFromCatalog(userCatalog); - - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout()); - GridData gridData = new GridData(GridData.FILL_BOTH); - gridData.heightHint = 500; - composite.setLayoutData(gridData); - createCatalogEntriesView(composite); - createCatalogDetailsView(composite); - - return composite; - } - - protected void createCatalogEntriesView(Composite parent) - { - Group group = new Group(parent, SWT.NONE); - group.setLayout(new GridLayout()); - GridData gridData = new GridData(GridData.FILL_BOTH); - gridData.widthHint = 370; - group.setLayoutData(gridData); - group.setText(XMLCatalogMessages.UI_LABEL_USER_ENTRIES); - group.setToolTipText(XMLCatalogMessages.UI_LABEL_USER_ENTRIES_TOOL_TIP); - - /* - * create a subclass of XMLCatalogEntriesView which suppresses - the - * creation of 'Add', 'Edit', 'Delete' buttons - any method involving the - * above buttons - */ - catalogEntriesView = new XMLCatalogEntriesView(group, workingUserCatalog, systemCatalog) - { - protected void createButtons(Composite parent) - { - } - - protected void updateWidgetEnabledState() - { - } - - }; - - // Only XML Schema entry is selectable - catalogEntriesView.setLayoutData(gridData); - XMLCatalogTreeViewer catalogTreeViewer = ((XMLCatalogTreeViewer) catalogEntriesView.getViewer()); - catalogTreeViewer.resetFilters(); - - catalogTreeViewer.addFilter(new XMLCatalogTableViewerFilter(new String[] { ".xsd" })); - } - - // Bug in the filter of the XML plugin, have to give a correct version here - // TODO: Waiting for the fix to be commited to XML plugin and - // be used by constellation - private class XMLCatalogTableViewerFilter extends ViewerFilter - { - private static final String W3_XMLSCHEMA_NAMESPACE = "http://www.w3.org/2001/"; - protected String[] extensions; - - public XMLCatalogTableViewerFilter(String[] extensions1) - { - this.extensions = extensions1; - } - - public boolean isFilterProperty(Object element, Object property) - { - return false; - } - - public boolean select(Viewer viewer, Object parent, Object element) - { - boolean result = false; - if (element instanceof ICatalogEntry) - { - ICatalogEntry catalogEntry = (ICatalogEntry) element; - for (int i = 0; i < extensions.length; i++) - { - // if the extension is correct and the namespace indicates - // that this entry is not the W3 XML Schema - if (catalogEntry.getURI().endsWith(extensions[i]) && !catalogEntry.getKey().startsWith(W3_XMLSCHEMA_NAMESPACE)) - { - result = true; - break; - } - } - } - else if (element.equals(XMLCatalogTreeViewer.PLUGIN_SPECIFIED_ENTRIES_OBJECT) || element.equals(XMLCatalogTreeViewer.USER_SPECIFIED_ENTRIES_OBJECT)) - { - return true; - } - return result; - } - } - - protected void createCatalogDetailsView(Composite parent) - { - Group detailsGroup = new Group(parent, SWT.NONE); - detailsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - detailsGroup.setLayout(new GridLayout()); - detailsGroup.setText(XMLCatalogMessages.UI_LABEL_DETAILS); - final XMLCatalogEntryDetailsView detailsView = new XMLCatalogEntryDetailsView(detailsGroup); - ISelectionChangedListener listener = new ISelectionChangedListener() - { - public void selectionChanged(SelectionChangedEvent event) - { - ISelection selection = event.getSelection(); - Object selectedObject = (selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null; - if (selectedObject instanceof ICatalogEntry) - { - ICatalogEntry entry = (ICatalogEntry) selectedObject; - detailsView.setCatalogElement(entry); - currentSelectionLocation = entry.getURI(); - currentSelectionNamespace = entry.getKey(); - } - else - { - detailsView.setCatalogElement((ICatalogEntry) null); - currentSelectionLocation = ""; - currentSelectionNamespace = ""; - } - } - }; - catalogEntriesView.getViewer().addSelectionChangedListener(listener); - } - - public String getCurrentSelectionLocation() - { - return currentSelectionLocation; - } - - public String getCurrentSelectionNamespace() - { - return currentSelectionNamespace; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SpecificationForExtensionsSchema.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SpecificationForExtensionsSchema.java deleted file mode 100644 index 8b4a9a5518..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/SpecificationForExtensionsSchema.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.StringTokenizer; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleRemoveExtensionNodeCommand; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.custom.NodeFilter; - -public class SpecificationForExtensionsSchema -{ - private String description; - private String displayName; - private String namespaceURI; - private String location; - private ILabelProvider labelProvider; - private boolean isDefaultSchema = false; - private ExtensibleAddExtensionCommand addCommand; - private ExtensibleRemoveExtensionNodeCommand removeCommand; - private NodeFilter nodeFilter; - private String classification; - - /** - * Either the workspace-relative path of the xsd file or the namespace - * of the xsd file (if it come from the Catalog) - */ - private String sourceHint; - private boolean fromCatalog; - - public SpecificationForExtensionsSchema() - { - super(); - } - - public SpecificationForExtensionsSchema(String desc) { - StringTokenizer tokenizer = new StringTokenizer(desc, "\t"); - - // we must be sure that each 'desc' contains info in correct format - // no error checking here - description = tokenizer.nextToken(); - displayName = tokenizer.nextToken(); - namespaceURI = tokenizer.nextToken(); - location = tokenizer.nextToken(); - isDefaultSchema = tokenizer.nextToken().equals("true"); - sourceHint = tokenizer.nextToken(); - fromCatalog = tokenizer.nextToken().equals("true"); - } - -/** - * @return Returns the description. - */ - public String getDescription() - { - return description; - } - - /** - * @param description - * The description to set. - */ - public void setDescription(String description) - { - this.description = description; - } - - /** - * @return Returns the displayName. - */ - public String getDisplayName() - { - return displayName; - } - - /** - * @param name - * The displayName to set. - */ - public void setDisplayName(String displayName) - { - this.displayName = displayName; - } - - /** - * @return Returns the namespaceURI. - */ - public String getNamespaceURI() - { - return namespaceURI; - } - - /** - * @param namespaceURI - * The namespaceURI to set. - */ - public void setNamespaceURI(String namespaceURI) - { - this.namespaceURI = namespaceURI; - } - - /** - * @return Returns the location of the xsd file. - */ - public String getLocation() - { - return location; - } - - /** - * @param location - * The location to be set - */ - public void setLocation(String location) - { - this.location = location; - } - - public ILabelProvider getLabelProvider() - { - return labelProvider; - } - - public void setLabelProvider(ILabelProvider labelProvider) - { - this.labelProvider = labelProvider; - } - - public ExtensibleAddExtensionCommand getExtensibleAddExtensionCommand() - { - return addCommand; - } - - public void setExtensibleAddExtensionCommand(ExtensibleAddExtensionCommand addCommand) - { - this.addCommand = addCommand; - } - - public ExtensibleRemoveExtensionNodeCommand getExtensibleRemoveExtensionNodeCommand() - { - return removeCommand; - } - - public void setExtensibleRemoveExtensionNodeCommand(ExtensibleRemoveExtensionNodeCommand removeCommand) - { - this.removeCommand = removeCommand; - } - - public boolean isDefautSchema(){ - return isDefaultSchema ; - } - - public void setDefautSchema(){ - isDefaultSchema = true; - } - - public void setSourceHint(String s){ - sourceHint = s; - } - - public String getSourceHint(){ - return sourceHint; - } - - public boolean isFromCatalog() { - return fromCatalog; - } - - public void setFromCatalog(boolean fromCatalog) { - this.fromCatalog = fromCatalog; - } - - /** - * There is no support for setting this via the extension point defined in the plugin.xml - * This allows extenders to provide a filter for a category that has been added - * dynamically (programmatically) - * @param nodeFilter - */ - public void setNodeFilter(NodeFilter nodeFilter) - { - this.nodeFilter = nodeFilter; - } - - /** - * Get the node filter - * @return NodeFilter - */ - public NodeFilter getNodeFilter() - { - return nodeFilter; - } - - /** - * There is no support for setting this via the extension point defined in the plugin.xml - * This allows extenders to group categories into groups or classificationss - * @param classification - */ - public void setClassification(String classification) - { - this.classification = classification; - } - - /** - * Get the classification - * @return String - */ - public String getClassification() - { - return classification; - } -} 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 deleted file mode 100644 index d0e4255561..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/XSDExtensionTreeContentProvider.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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.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(); - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false); - if (xsdAnnotation != null) - { - // Bug 137856 - Extension page of properties shouldn't display imported elements - // Added this if statement - if (xsdAnnotation.getSchema() == component.getSchema()) - { - 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 = appInfoElement.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); //$NON-NLS-1$ - } - else - { - // this handles the xmlns="blah" case - return "xmlns".equals(attribute.getNodeName()); //$NON-NLS-1$ - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DefaultListNodeEditorConfiguration.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DefaultListNodeEditorConfiguration.java deleted file mode 100644 index 584ad71494..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DefaultListNodeEditorConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.custom; - - -public class DefaultListNodeEditorConfiguration extends ListNodeEditorConfiguration -{ - private String[] values; - - public DefaultListNodeEditorConfiguration(String[] values) - { - this.values = values; - } - - public Object[] getValues(Object propertyObject) - { - return values; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DialogNodeEditorConfiguration.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DialogNodeEditorConfiguration.java deleted file mode 100644 index ead530daf5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/DialogNodeEditorConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.custom; - -import org.eclipse.swt.graphics.Image; - -public abstract class DialogNodeEditorConfiguration extends NodeEditorConfiguration -{ - public int getStyle() - { - return STYLE_DIALOG; - } - - public String getButonText() - { - return null; - } - - public Image getButtonImage() - { - return null; - } - - public abstract void invokeDialog(); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/ListNodeEditorConfiguration.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/ListNodeEditorConfiguration.java deleted file mode 100644 index fdfbce6822..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/ListNodeEditorConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.custom; - -import org.eclipse.jface.viewers.LabelProvider; - -public abstract class ListNodeEditorConfiguration extends NodeEditorConfiguration -{ - private LabelProvider labelProvider; - - public LabelProvider getLabelProvider() - { - return labelProvider; - } - - public int getStyle() - { - return STYLE_COMBO; - } - - public void setLabelProvider(LabelProvider labelProvider) - { - this.labelProvider = labelProvider; - } - - public abstract Object[] getValues(Object propertyObject); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeCustomizationRegistry.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeCustomizationRegistry.java deleted file mode 100644 index a71b2f1163..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeCustomizationRegistry.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.custom; - -import java.util.HashMap; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.viewers.ILabelProvider; - -public class NodeCustomizationRegistry -{ - private static final String NAMESPACE = "namespace"; //$NON-NLS-1$ - private static final String LABEL_PROVIDER_CLASS_ATTRIBUTE_NAME = "labelProviderClass"; - private static final String NODE_EDITOR_PROVIDER_CLASS_ATTRIBUTE_NAME = "nodeEditorProviderClass"; //$NON-NLS-1$ - private static final String FILTER_CLASS_ATTRIBUTE_NAME = "filterClass"; - - - protected String extensionId; - protected HashMap map; - - public NodeCustomizationRegistry(String propertyEditorExtensionId) - { - extensionId = "org.eclipse.wst.xsd.ui.extensibilityNodeCustomizations";//propertyEditorExtensionId; - } - - private class Descriptor - { - IConfigurationElement configurationElement; - NodeEditorProvider nodeEditorProvider; - NodeFilter nodeFilter; - boolean nodeEditorProviderFailedToLoad = false; - boolean labelProviderFailedToLoad = false; - boolean nodeFilterFailedToLoad = false; - - Descriptor(IConfigurationElement element) - { - this.configurationElement = element; - } - - NodeEditorProvider lookupOrCreateNodeEditorProvider() - { - if (nodeEditorProvider == null && !nodeEditorProviderFailedToLoad) - { - try - { - nodeEditorProvider = (NodeEditorProvider)configurationElement.createExecutableExtension(NODE_EDITOR_PROVIDER_CLASS_ATTRIBUTE_NAME); - } - catch (Exception e) - { - nodeEditorProviderFailedToLoad = true; - } - } - return nodeEditorProvider; - } - - ILabelProvider createLabelProvider() - { - if (!labelProviderFailedToLoad) - { - try - { - return (ILabelProvider)configurationElement.createExecutableExtension(LABEL_PROVIDER_CLASS_ATTRIBUTE_NAME); - } - catch (Exception e) - { - labelProviderFailedToLoad = true; - } - } - return null; - } - - public NodeFilter getNodeFilter() - { - if (!nodeEditorProviderFailedToLoad) - { - try - { - nodeFilter = (NodeFilter)configurationElement.createExecutableExtension(FILTER_CLASS_ATTRIBUTE_NAME); - } - catch (Exception e) - { - nodeEditorProviderFailedToLoad = true; - } - } - return nodeFilter; - } - } - - - private HashMap initMap() - { - HashMap theMap = new HashMap(); - IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.wst.xsd.ui.extensibilityNodeCustomizations"); - for (int i = 0; i < extensions.length; i++) - { - IConfigurationElement configurationElement = extensions[i]; - String namespace = configurationElement.getAttribute(NAMESPACE); - if (namespace != null) - { - theMap.put(namespace, new Descriptor(configurationElement)); - } - } - return theMap; - } - - private Descriptor getDescriptor(String namespace) - { - map = null; - if (namespace != null) - { - if (map == null) - { - map = initMap(); - } - return (Descriptor)map.get(namespace); - } - return null; - } - - public NodeEditorProvider getNodeEditorProvider(String namespace) - { - Descriptor descriptor = getDescriptor(namespace); - if (descriptor != null) - { - return descriptor.lookupOrCreateNodeEditorProvider(); - } - return null; - } - - public ILabelProvider getLabelProvider(String namespace) - { - Descriptor descriptor = getDescriptor(namespace); - if (descriptor != null) - { - return descriptor.createLabelProvider(); - } - return null; - } - - public NodeFilter getNodeFilter(String namespace) - { - Descriptor descriptor = getDescriptor(namespace); - if (descriptor != null) - { - return descriptor.getNodeFilter(); - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorConfiguration.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorConfiguration.java deleted file mode 100644 index 1506ad222f..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.custom; - -import org.w3c.dom.Node; - -public abstract class NodeEditorConfiguration -{ - public final static int STYLE_NONE = 0; - public final static int STYLE_TEXT = 1; - public final static int STYLE_COMBO = 2; - public final static int STYLE_DIALOG = 4; - - public abstract int getStyle(); - - private Node node; - private Node parentNode; - - public Node getNode() - { - return node; - } - public void setNode(Node node) - { - this.node = node; - } - public Node getParentNode() - { - return parentNode; - } - public void setParentNode(Node parentNode) - { - this.parentNode = parentNode; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorProvider.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorProvider.java deleted file mode 100644 index 07d1c63909..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeEditorProvider.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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.custom; - - -public abstract class NodeEditorProvider -{ - public abstract NodeEditorConfiguration getNodeEditorConfiguration(String parentName, String nodeName); - //public abstract NodeEditorConfiguration getNodeEditorConfiguration(Node node); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeFilter.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeFilter.java deleted file mode 100644 index 5cabbc7622..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/appinfo/custom/NodeFilter.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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.custom; - -import org.w3c.dom.Node; - -public class NodeFilter -{ - public boolean isApplicableContext(Node parentNode, int nodeType, String namespace, String name) - { - return true; - } -} |