diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst')
142 files changed, 0 insertions, 24781 deletions
diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyAttributeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyAttributeAction.java deleted file mode 100644 index 07785fc680..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyAttributeAction.java +++ /dev/null @@ -1,90 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDAnyAttributeCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDComplexTypeDefinition; - -public class AddXSDAnyAttributeAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.AddXSDAnyAttributeAction"; //$NON-NLS-1$ - protected XSDComplexTypeDefinition xsdComplexTypeDefinition; - - public AddXSDAnyAttributeAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_ANY_ATTRIBUTE); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - AddXSDAnyAttributeCommand command = null; - if (selection instanceof XSDComplexTypeDefinition) - { - command = new AddXSDAnyAttributeCommand(Messages._UI_ACTION_ADD_ANY_ATTRIBUTE, (XSDComplexTypeDefinition) selection); - getCommandStack().execute(command); - } - else if (selection instanceof XSDAttributeGroupDefinition) - { - command = new AddXSDAnyAttributeCommand(Messages._UI_ACTION_ADD_ANY_ATTRIBUTE, (XSDAttributeGroupDefinition)selection); - getCommandStack().execute(command); - } - - if (command != null) - { - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } - - - protected boolean calculateEnabled() - { - boolean rc = super.calculateEnabled(); - if (rc) - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - if (selection instanceof XSDComplexTypeDefinition) - { - return ((XSDComplexTypeDefinition)selection).getAttributeWildcardContent() == null; - } - else if (selection instanceof XSDAttributeGroupDefinition) - { - return ((XSDAttributeGroupDefinition)selection).getAttributeWildcardContent() == null; - } - - } - return rc; - } - - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java deleted file mode 100644 index d50a53bb53..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAnyElementAction.java +++ /dev/null @@ -1,80 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDAnyElementCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDComplexTypeContent; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDParticleContent; - -public class AddXSDAnyElementAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.AddXSDAnyElementAction"; //$NON-NLS-1$ - - public AddXSDAnyElementAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_ANY_ELEMENT); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - XSDModelGroup modelGroup = getModelGroup(selection); - - AddXSDAnyElementCommand command = new AddXSDAnyElementCommand(getText(), modelGroup); - if (selection instanceof XSDComplexTypeDefinition) - { - command.setComplexType((XSDComplexTypeDefinition)selection); - } - command.setDoCreateModelGroupForComplexType(modelGroup == null); - getCommandStack().execute(command); - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - - private XSDModelGroup getModelGroup(Object selection) - { - if (selection instanceof XSDModelGroup) - { - return (XSDModelGroup) selection; - } - else if (selection instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeContent content = ((XSDComplexTypeDefinition)selection).getContent(); - if (content instanceof XSDParticle) - { - XSDParticleContent particleContent = ((XSDParticle)content).getContent(); - if (particleContent instanceof XSDModelGroup) - { - return (XSDModelGroup)particleContent; - } - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeDeclarationAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeDeclarationAction.java deleted file mode 100644 index 7c113fe61d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeDeclarationAction.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDAttributeDeclarationCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDAttributeDeclarationAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction.AddXSDAttributeAction"; //$NON-NLS-1$ - public static String BEFORE_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction.BEFORE_SELECTED_ID"; //$NON-NLS-1$ - public static String AFTER_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction.AFTER_SELECTED_ID"; //$NON-NLS-1$ - public static String REF_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeReferenceAction"; //$NON-NLS-1$ - boolean isReference = false; - - public AddXSDAttributeDeclarationAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_ATTRIBUTE); - setId(ID); - isReference = false; - } - - public AddXSDAttributeDeclarationAction(IWorkbenchPart part, String id, String label, boolean isReference) - { - super(part); - setText(label); - setId(id); - this.isReference = isReference; - doDirectEdit = !isReference; - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - if (selection instanceof XSDAttributeDeclaration) - { - selection = ((XSDAttributeDeclaration) selection).getContainer(); - } - } - AddXSDAttributeDeclarationCommand command = null; - if (selection instanceof XSDComplexTypeDefinition) - { - command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (selection instanceof XSDAttributeUse) - { - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection; - XSDConcreteComponent parent = null; - XSDComplexTypeDefinition ct = null; - XSDAttributeGroupDefinition group = null; - for (parent = xsdAttributeUse.getContainer(); parent != null;) - { - if (parent instanceof XSDComplexTypeDefinition) - { - ct = (XSDComplexTypeDefinition) parent; - break; - } - else if (parent instanceof XSDAttributeGroupDefinition) - { - group = (XSDAttributeGroupDefinition)parent; - break; - } - parent = parent.getContainer(); - } - if (ct != null) - { - XSDAttributeUse sel = (XSDAttributeUse) selection; - int index = ct.getAttributeContents().indexOf(sel); - command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (group != null) - { - XSDAttributeUse sel = (XSDAttributeUse) selection; - int index = group.eContents().indexOf(sel); - command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index); - command.setReference(isReference); - getCommandStack().execute(command); - } - } - else if (selection instanceof XSDAttributeGroupDefinition) - { - command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition)selection); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (selection instanceof XSDSchema) - { - command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema)selection); - getCommandStack().execute(command); - } - - if (command != null) - { - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeGroupDefinitionAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeGroupDefinitionAction.java deleted file mode 100644 index f30a3e78de..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDAttributeGroupDefinitionAction.java +++ /dev/null @@ -1,78 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDAttributeGroupDefinitionCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDAttributeGroupDefinitionAction extends XSDBaseAction -{ - public static String ID = "AddXSDAttributeGroupDefinitionAction"; //$NON-NLS-1$ - public static String REF_ID = "AddXSDAttributeGroupDefinitionRefAction"; //$NON-NLS-1$ - - public AddXSDAttributeGroupDefinitionAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP); - setId(ID); - } - - public AddXSDAttributeGroupDefinitionAction(IWorkbenchPart part, String id) - { - super(part); - if (id.equals(REF_ID)) - { - setText(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_REF); - } - else - { - setText(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_DEFINITION); - } - setId(id); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - AddXSDAttributeGroupDefinitionCommand command = null; - if (selection instanceof XSDComplexTypeDefinition) - { - command = new AddXSDAttributeGroupDefinitionCommand(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_REF, (XSDComplexTypeDefinition) selection); - getCommandStack().execute(command); - } - else if (selection instanceof XSDSchema) - { - command = new AddXSDAttributeGroupDefinitionCommand(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_DEFINITION, (XSDSchema) selection); - getCommandStack().execute(command); - } - - if (command != null) - { - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDComplexTypeDefinitionAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDComplexTypeDefinitionAction.java deleted file mode 100644 index c55f4eff43..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDComplexTypeDefinitionAction.java +++ /dev/null @@ -1,52 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDComplexTypeDefinitionCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDComplexTypeDefinitionAction extends XSDBaseAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.internal.editor.AddXSDComplexTypeDefinitionAction"; //$NON-NLS-1$ - - public AddXSDComplexTypeDefinitionAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_COMPLEX_TYPE); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - if (selection instanceof XSDSchema) - { - AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, (XSDSchema) selection); - getCommandStack().execute(command); - - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDElementAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDElementAction.java deleted file mode 100644 index 68bd64a737..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDElementAction.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDElementCommand; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.impl.XSDModelGroupImpl; - -//revisit this and see if we can reuse AddFieldAction?? - -public class AddXSDElementAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction"; //$NON-NLS-1$ - public static String BEFORE_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction.BEFORE_SELECTED_ID"; //$NON-NLS-1$ - public static String AFTER_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction.AFTER_SELECTED_ID"; //$NON-NLS-1$ - public static String REF_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementReferenceAction"; //$NON-NLS-1$ - boolean isReference; - - public AddXSDElementAction(IWorkbenchPart part, String id, String label, boolean isReference) - { - super(part); - setText(label); - setId(id); - this.isReference = isReference; - doDirectEdit = !isReference; - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - AddXSDElementCommand command = null; - if (selection instanceof XSDComplexTypeDefinition) - { - command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (selection instanceof XSDModelGroupDefinition) - { - command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (selection instanceof XSDSchema) - { - command = new AddXSDElementCommand(getText(), (XSDSchema) selection); - getCommandStack().execute(command); - } - else if (selection instanceof XSDModelGroup) - { - XSDModelGroup modelGroup = (XSDModelGroup) selection; - XSDConcreteComponent component = modelGroup.getContainer(); - XSDComplexTypeDefinition ct = null; - while (component != null) - { - if (component instanceof XSDComplexTypeDefinition) - { - ct = (XSDComplexTypeDefinition) component; - break; - } - component = component.getContainer(); - } - - if (ct != null) - { - command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct); - } - else - { - command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection); - } - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) - { - XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection; - XSDConcreteComponent parent = null; - XSDComplexTypeDefinition ct = null; - XSDModelGroupDefinition group = null; - XSDModelGroupImpl ctGroup = null; - - for (parent = xsdConcreteComponent.getContainer(); parent != null; ) - { - if (parent instanceof XSDComplexTypeDefinition) - { - ct = (XSDComplexTypeDefinition)parent; - break; - } - else if (parent instanceof XSDModelGroupDefinition) - { - group = (XSDModelGroupDefinition)parent; - break; - } - else if (parent instanceof XSDModelGroupImpl) - { - ctGroup = (XSDModelGroupImpl) parent; - break; - } - parent = parent.getContainer(); - } - if (ct != null) - { - command = new AddXSDElementCommand(getText(), ct); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (ctGroup != null) - { - XSDElementDeclaration sel = (XSDElementDeclaration) selection; - int index = ctGroup.getContents().indexOf(sel.eContainer()); - command = new AddXSDElementCommand(getText(), ctGroup, getId(), index); - command.setReference(isReference); - getCommandStack().execute(command); - } - else if (group != null) - { - command = new AddXSDElementCommand(getText(), group); - command.setReference(isReference); - getCommandStack().execute(command); - } - } - - if (command != null) - { - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDEnumerationFacetAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDEnumerationFacetAction.java deleted file mode 100644 index fe4c11fb0d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDEnumerationFacetAction.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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.actions; - -import java.util.List; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.adapters.XSDComplexTypeDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; - -public class AddXSDEnumerationFacetAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.AddXSDEnumerationFacetAction"; //$NON-NLS-1$ - public static String BEFORE_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDEnumerationFacetAction.BEFORE_SELECTED_ID"; //$NON-NLS-1$ - public static String AFTER_SELECTED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDEnumerationFacetAction.AFTER_SELECTED_ID"; //$NON-NLS-1$ - - public AddXSDEnumerationFacetAction(IWorkbenchPart part, String id, String label) - { - super(part); - setText(label); - setId(id); - } - - public AddXSDEnumerationFacetAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_ENUMERATION); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - int index = -1; - AddEnumerationsCommand command = null; - XSDSimpleTypeDefinition st = null; - if (selection instanceof XSDSimpleTypeDefinition) - { - st = (XSDSimpleTypeDefinition)selection; - command = new AddEnumerationsCommand(getText(), st); - } - else if (selection instanceof XSDEnumerationFacet) - { - st = ((XSDEnumerationFacet)selection).getSimpleTypeDefinition(); - index = st.getFacetContents().indexOf(selection); - doDirectEdit = true; - command = new AddEnumerationsCommand(getText(), st, getId(), index); - } - else if (selection instanceof XSDComplexTypeDefinition) // Support for Complex Type's simple Content with enumerations - { - st = (XSDSimpleTypeDefinition) ((XSDComplexTypeDefinition)selection).getContent(); - command = new AddEnumerationsCommand(getText(), st); - } - else // null - { - return; - } - - List enumList = st.getEnumerationFacets(); - - String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList); //$NON-NLS-1$ - - command.setValue(newName); - getCommandStack().execute(command); - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } - - protected boolean calculateEnabled() { - - boolean parentResult = super.calculateEnabled(); - boolean endResult = true; - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - if (selection instanceof XSDComplexTypeDefinitionAdapter) - { - XSDComplexTypeDefinition definition = ((XSDComplexTypeDefinitionAdapter) selection).getXSDComplexTypeDefinition(); - XSDTypeDefinition baseType = definition.getBaseType(); - if (baseType instanceof XSDSimpleTypeDefinition) - endResult = false; - } - endResult = endResult & parentResult; - return endResult; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupAction.java deleted file mode 100644 index f4fb4648c6..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupAction.java +++ /dev/null @@ -1,97 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDModelGroupCommand; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; - -public class AddXSDModelGroupAction extends XSDBaseAction -{ - public static String SEQUENCE_ID = "AddXSDSequenceModelGroupAction"; //$NON-NLS-1$ - public static String CHOICE_ID = "AddXSDChoiceModelGroupAction"; //$NON-NLS-1$ - public static String ALL_ID = "AddXSDAllModelGroupAction"; //$NON-NLS-1$ - XSDCompositor xsdCompositor; - - public AddXSDModelGroupAction(IWorkbenchPart part, XSDCompositor compositor, String ID) - { - super(part); - setText(getLabel(compositor)); - setId(ID); - this.xsdCompositor = compositor; - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - if (selection instanceof XSDBaseAdapter) - { - XSDConcreteComponent xsdComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget(); - AddXSDModelGroupCommand command = null; - if (xsdComponent instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdComponent; - - command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdElementDeclaration, xsdCompositor); - getCommandStack().execute(command); - } - else if (xsdComponent instanceof XSDModelGroup) - { - XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdComponent; - - command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdModelGroup, xsdCompositor); - getCommandStack().execute(command); - } - else if (xsdComponent instanceof XSDComplexTypeDefinition - || xsdComponent instanceof XSDModelGroupDefinition) - { - command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdComponent, xsdCompositor); - getCommandStack().execute(command); - } - - if (command != null) - { - Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent()); - if (adapter != null) - provider.setSelection(new StructuredSelection(adapter)); - } - - } - } - - private String getLabel(XSDCompositor compositor) - { - String result = XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_SEQUENCE"); //$NON-NLS-1$ - if (compositor != null) - { - if (compositor == XSDCompositor.CHOICE_LITERAL) - { - result = XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_CHOICE"); //$NON-NLS-1$ - } - else if (compositor == XSDCompositor.ALL_LITERAL) - { - result = XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_ALL");//$NON-NLS-1$ - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupDefinitionAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupDefinitionAction.java deleted file mode 100644 index d49a367a58..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDModelGroupDefinitionAction.java +++ /dev/null @@ -1,62 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDModelGroupDefinitionCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDConcreteComponent; - -public class AddXSDModelGroupDefinitionAction extends XSDBaseAction -{ - public static final String MODELGROUPDEFINITION_ID = "AddXSDModelGroupDefinitionAction"; //$NON-NLS-1$ - public static final String MODELGROUPDEFINITIONREF_ID = "AddXSDModelGroupDefinitionRefAction"; //$NON-NLS-1$ - boolean isReference; - - public AddXSDModelGroupDefinitionAction(IWorkbenchPart part, boolean isReference) - { - super(part); - this.isReference = isReference; - if (isReference) - { - setText(Messages._UI_ACTION_ADD_GROUP_REF); - setId(MODELGROUPDEFINITION_ID); - } - else - { - setText(Messages._UI_ACTION_ADD_GROUP); - setId(MODELGROUPDEFINITIONREF_ID); - } - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - XSDConcreteComponent xsdConcreteComponent = null; - if (selection instanceof XSDBaseAdapter) - { - xsdConcreteComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget(); - } - if (xsdConcreteComponent != null) - { - AddXSDModelGroupDefinitionCommand command = new AddXSDModelGroupDefinitionCommand(getText(), xsdConcreteComponent, isReference); - getCommandStack().execute(command); - - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinableContentAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinableContentAction.java deleted file mode 100644 index 8b8c19c020..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinableContentAction.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.actions; - - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.core.search.scope.SearchScope; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSearchListDialog; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSearchListDialogConfiguration; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentDescriptionProvider; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentSearchListProvider; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddRedefinedComponentCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -public abstract class AddXSDRedefinableContentAction extends XSDBaseAction -{ - protected AddXSDRedefinableContentAction(IWorkbenchPart part, String ID, String text) - { - super(part); - setText(text); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection)getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter)selection).getTarget(); - } - - if (selection instanceof XSDRedefine) - { - ComponentSearchListDialogConfiguration configuration = new ComponentSearchListDialogConfiguration(); - configuration.setDescriptionProvider(new RedefineDescriptor()); - configuration.setSearchListProvider(new RedefineSearchListProvider((XSDRedefine)selection, this)); - ComponentSearchListDialog dialog = new ComponentSearchListDialog(Display.getDefault().getActiveShell(), Messages._UI_LABEL_REDEFINE_COMPONENT, configuration) - { - protected Control createDialogArea(Composite parent) - { - // Adjust the dialog's initial size. - - Composite mainComposite = (Composite)super.createDialogArea(parent); - GridData gridData = (GridData)mainComposite.getLayoutData(); - gridData.heightHint = 500; - gridData.widthHint = 350; - return mainComposite; - } - }; - dialog.create(); - dialog.setBlockOnOpen(true); - int result = dialog.open(); - - if (result == Window.OK) - { - ComponentSpecification selectedComponent = dialog.getSelectedComponent(); - buildRedefine((XSDRedefine)selection, selectedComponent); - } - } - } - - protected abstract AddRedefinedComponentCommand getCommand(XSDRedefine redefine, XSDRedefinableComponent redefinableComponent); - - protected abstract void buildComponentsList(XSDRedefine xsdRedefine, Set redefinedComponentsNames, IComponentList componentList); - - protected void buildRedefine(XSDRedefine redefine, ComponentSpecification selectedComponent) - { - XSDRedefinableComponent redefinableComponent = (XSDRedefinableComponent)selectedComponent.getObject(); - AddRedefinedComponentCommand command = getCommand(redefine, redefinableComponent); - getCommandStack().execute(command); - addedComponent = command.getAddedComponent(); - } - - class RedefineSearchListProvider implements IComponentSearchListProvider - { - XSDRedefine xsdRedefine; - AddXSDRedefinableContentAction action; - - public RedefineSearchListProvider(XSDRedefine xsdRedefine, AddXSDRedefinableContentAction action) - { - this.xsdRedefine = xsdRedefine; - this.action = action; - } - - // Should refactor this to have a separate subclass for each type of redefine. - public void populateComponentList(IComponentList list, SearchScope scope, IProgressMonitor pm) - { - List currentRedefines = xsdRedefine.getContents(); - Set redefinedComponentsNames = new HashSet(currentRedefines.size()); - Iterator redefinesIterator = currentRedefines.iterator(); - while (redefinesIterator.hasNext()) - { - XSDRedefinableComponent component = (XSDRedefinableComponent)redefinesIterator.next(); - String redefinedComponentName = component.getName(); - redefinedComponentsNames.add(redefinedComponentName); - } - action.buildComponentsList(xsdRedefine, redefinedComponentsNames, list); - } - } - - class RedefineDescriptor implements IComponentDescriptionProvider - { - public IFile getFile(Object component) - { - if (component instanceof XSDNamedComponent) - { - if (((XSDNamedComponent)component).getSchema() == null) - { - return null; - } - String location = ((XSDNamedComponent)component).getSchema().getSchemaLocation(); - String platformResource = "platform:/resource"; //$NON-NLS-1$ - if (location != null && location.startsWith(platformResource)) - { - Path path = new Path(location.substring(platformResource.length())); - return ResourcesPlugin.getWorkspace().getRoot().getFile(path); - } - } - return null; - } - - public Image getFileIcon(Object component) - { - return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif"); //$NON-NLS-1$ - } - - public ILabelProvider getLabelProvider() - { - return new XSDRedefineComponentsLabelProvider(); - } - - public String getName(Object component) - { - if (component instanceof XSDNamedComponent) - { - return ((XSDNamedComponent)component).getName(); - } - return ""; - } - - public String getQualifier(Object component) - { - if (component instanceof XSDNamedComponent) - { - return ((XSDNamedComponent)component).getTargetNamespace(); - } - return ""; - } - - public boolean isApplicable(Object component) - { - return true; - } - - } - - protected abstract Image getRedefinedComponentImage(); - - class XSDRedefineComponentsLabelProvider implements ILabelProvider - { - - public Image getImage(Object element) - { - Image image = getRedefinedComponentImage(); - return image; - } - - public String getText(Object element) - { - if (element instanceof XSDNamedComponent) - { - return ((XSDNamedComponent)element).getName(); - } - return ""; - } - - public void addListener(ILabelProviderListener listener) - { - } - - public void dispose() - { - } - - public boolean isLabelProperty(Object element, String property) - { - return false; - } - - public void removeListener(ILabelProviderListener listener) - { - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedAttributeGroupAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedAttributeGroupAction.java deleted file mode 100644 index 5f5b0e4365..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedAttributeGroupAction.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.actions; - - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddRedefinedComponentCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.RedefineAttributeGroupCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -public class AddXSDRedefinedAttributeGroupAction extends AddXSDRedefinableContentAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.actions.RedefineAttributeGroup"; //$NON-NLS-1$ - - public AddXSDRedefinedAttributeGroupAction(IWorkbenchPart part) - { - super(part, ID, Messages._UI_ACTION_REDEFINE_ATTRIBUTE_GROUP); - } - - protected AddRedefinedComponentCommand getCommand(XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - AddRedefinedComponentCommand command = new RedefineAttributeGroupCommand( - Messages._UI_ACTION_REDEFINE_ATTRIBUTE_GROUP, - redefine, - redefinableComponent); - return command; - } - - protected void buildComponentsList(XSDRedefine xsdRedefine, Set redefinedComponentsNames, IComponentList componentList) - { - List attributeGroups = xsdRedefine.getIncorporatedSchema().getAttributeGroupDefinitions(); - Iterator iterator = attributeGroups.iterator(); - while (iterator.hasNext()) - { - XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition)iterator.next(); - String attributeGroupDefinitionName = attributeGroupDefinition.getName(); - if (!redefinedComponentsNames.contains(attributeGroupDefinitionName)) - { - componentList.add(attributeGroupDefinition); - } - } - } - - protected Image getRedefinedComponentImage() - { - return XSDEditorPlugin.getXSDImage(Messages._UI_IMAGE_ATTRIBUTE_GROUP); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedComplexTypeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedComplexTypeAction.java deleted file mode 100644 index 901d5a6c6c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedComplexTypeAction.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.actions; - - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddRedefinedComponentCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.RedefineComplexTypeCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDTypeDefinition; - - -public class AddXSDRedefinedComplexTypeAction extends AddXSDRedefinableContentAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.actions.RedefineComplexType"; //$NON-NLS-1$ - - public AddXSDRedefinedComplexTypeAction(IWorkbenchPart part) - { - super(part, ID, Messages._UI_ACTION_REDEFINE_COMPLEX_TYPE); - } - - protected AddRedefinedComponentCommand getCommand(XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - AddRedefinedComponentCommand command = new RedefineComplexTypeCommand( - Messages._UI_ACTION_REDEFINE_COMPLEX_TYPE, - redefine, - redefinableComponent); - return command; - } - - protected void buildComponentsList(XSDRedefine xsdRedefine, Set redefinedComponentsNames, IComponentList componentList) - { - List typeDefinitions = xsdRedefine.getIncorporatedSchema().getTypeDefinitions(); - Iterator iterator = typeDefinitions.iterator(); - while (iterator.hasNext()) - { - XSDTypeDefinition typeDefinition = (XSDTypeDefinition)iterator.next(); - String typeDefinitionName = typeDefinition.getName(); - if (typeDefinition instanceof XSDComplexTypeDefinition && !redefinedComponentsNames.contains(typeDefinitionName)) - { - componentList.add(typeDefinition); - } - } - } - - protected Image getRedefinedComponentImage() - { - return XSDEditorPlugin.getXSDImage(Messages._UI_IMAGE_COMPLEX_TYPE); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedModelGroupAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedModelGroupAction.java deleted file mode 100644 index d3839a92dd..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedModelGroupAction.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.actions; - - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddRedefinedComponentCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.RedefineModelGroupCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -public class AddXSDRedefinedModelGroupAction extends AddXSDRedefinableContentAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.actions.RedefineModelGroup"; //$NON-NLS-1$ - - public AddXSDRedefinedModelGroupAction(IWorkbenchPart part) - { - super(part, ID, Messages._UI_ACTION_REDEFINE_MODEL_GROUP); - } - - protected AddRedefinedComponentCommand getCommand(XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - AddRedefinedComponentCommand command = new RedefineModelGroupCommand( - Messages._UI_ACTION_REDEFINE_MODEL_GROUP, - redefine, - redefinableComponent); - return command; - } - - protected void buildComponentsList(XSDRedefine xsdRedefine, Set redefinedComponentsNames, IComponentList componentList) - { - List modelGroupList = xsdRedefine.getIncorporatedSchema().getModelGroupDefinitions(); - Iterator iterator = modelGroupList.iterator(); - while (iterator.hasNext()) - { - XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition)iterator.next(); - String modelGroupDefinitionName = modelGroupDefinition.getName(); - if (!redefinedComponentsNames.contains(modelGroupDefinitionName)) - { - componentList.add(modelGroupDefinition); - } - } - } - - protected Image getRedefinedComponentImage() - { - return XSDEditorPlugin.getXSDImage(Messages._UI_IMAGE_MODEL_GROUP); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedSimpleTypeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedSimpleTypeAction.java deleted file mode 100644 index dd86050645..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDRedefinedSimpleTypeAction.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.actions; - - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.IComponentList; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddRedefinedComponentCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.RedefineSimpleTypeCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; - - -public class AddXSDRedefinedSimpleTypeAction extends AddXSDRedefinableContentAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.actions.RedefineSimpleType"; //$NON-NLS-1$ - - public AddXSDRedefinedSimpleTypeAction(IWorkbenchPart part) - { - super(part, ID, Messages._UI_ACTION_REDEFINE_SIMPLE_TYPE); - } - - public AddRedefinedComponentCommand getCommand(XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - AddRedefinedComponentCommand command = new RedefineSimpleTypeCommand( - Messages._UI_ACTION_REDEFINE_SIMPLE_TYPE, - redefine, - redefinableComponent); - return command; - } - - protected void buildComponentsList(XSDRedefine xsdRedefine, Set redefinedComponentsNames, IComponentList componentList) - { - List typeDefinitions = xsdRedefine.getIncorporatedSchema().getTypeDefinitions(); - Iterator iterator = typeDefinitions.iterator(); - while (iterator.hasNext()) - { - XSDTypeDefinition typeDefinition = (XSDTypeDefinition)iterator.next(); - String typeDefinitionName = typeDefinition.getName(); - if (typeDefinition instanceof XSDSimpleTypeDefinition && !redefinedComponentsNames.contains(typeDefinitionName)) - { - componentList.add(typeDefinition); - } - } - - } - - protected Image getRedefinedComponentImage() - { - return XSDEditorPlugin.getXSDImage(Messages._UI_IMAGE_SIMPLE_TYPE); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSchemaDirectiveAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSchemaDirectiveAction.java deleted file mode 100644 index 0324f1c91c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSchemaDirectiveAction.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.adapters.XSDSchemaDirectiveAdapter; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDImportCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDIncludeCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDRedefineCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesSchemaLocationUpdater; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDSchemaDirectiveAction extends XSDBaseAction -{ - public static String INCLUDE_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDIncludeAction"; //$NON-NLS-1$ - public static String IMPORT_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDImportAction"; //$NON-NLS-1$ - public static String REDEFINE_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDRedefineAction"; //$NON-NLS-1$ - String label; - - public AddXSDSchemaDirectiveAction(IWorkbenchPart part, String ID, String label) - { - super(part); - setText(label); - setId(ID); - this.label = label; - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - BaseCommand command = null; - if (selection instanceof XSDSchema) - { - if (INCLUDE_ID.equals(getId())) - { - command = new AddXSDIncludeCommand(label, (XSDSchema) selection); - } - else if (IMPORT_ID.equals(getId())) - { - command = new AddXSDImportCommand(label, (XSDSchema) selection); - } - else if (REDEFINE_ID.equals(getId())) - { - command = new AddXSDRedefineCommand(label, (XSDSchema) selection); - } - getCommandStack().execute(command); - } - - if (command != null) - { - Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent()); - if (adapter != null) - { - provider.setSelection(new StructuredSelection(adapter)); - // Automatically open the schema location dialog if the preference is enabled - if(XSDEditorPlugin.getDefault().getAutomaticallyOpenSchemaLocationDialogSetting()) - { - XSDSchemaDirectiveAdapter xsdSchemaDirectiveAdapter = null; - if(adapter instanceof XSDSchemaDirectiveAdapter) - { - xsdSchemaDirectiveAdapter = (XSDSchemaDirectiveAdapter)adapter; - } - XSDDirectivesSchemaLocationUpdater.updateSchemaLocation((XSDSchema) selection, xsdSchemaDirectiveAdapter.getTarget(), - (command instanceof AddXSDIncludeCommand || command instanceof AddXSDRedefineCommand)); - } - // The graphical view may deselect, so select again - provider.setSelection(new StructuredSelection(adapter)); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSimpleTypeDefinitionAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSimpleTypeDefinitionAction.java deleted file mode 100644 index bc7cd73e62..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/AddXSDSimpleTypeDefinitionAction.java +++ /dev/null @@ -1,53 +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.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.AddXSDSimpleTypeDefinitionCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDSimpleTypeDefinitionAction extends XSDBaseAction -{ - public static final String ID = "org.eclipse.wst.xsd.ui.internal.editor.AddXSDSimpleTypeDefinitionAction"; //$NON-NLS-1$ - - public AddXSDSimpleTypeDefinitionAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_ADD_SIMPLE_TYPE); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - if (selection instanceof XSDSchema) - { - AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, (XSDSchema) selection); - getCommandStack().execute(command); - - addedComponent = command.getAddedComponent(); - Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent); - selectAddedComponent(adapter); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/DeleteXSDConcreteComponentAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/DeleteXSDConcreteComponentAction.java deleted file mode 100644 index abfe49d036..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/DeleteXSDConcreteComponentAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.actions; - -import java.util.Iterator; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -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.common.commands.DeleteCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -/** - * @deprecated Use org.eclipse.wst.xsd.ui.internal.adt.actions.DeleteAction - * - */ -public class DeleteXSDConcreteComponentAction extends XSDBaseAction -{ - public static final String DELETE_XSD_COMPONENT_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.DeleteXSDConcreteComponentAction"; //$NON-NLS-1$ - - public DeleteXSDConcreteComponentAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_DELETE); - setId(DELETE_XSD_COMPONENT_ID); - setImageDescriptor(XSDEditorPlugin.getImageDescriptor("icons/delete_obj.gif") ); //$NON-NLS-1$ - } - - public void run() - { - for (Iterator i = ((IStructuredSelection) getSelection()).iterator(); i.hasNext();) - { - Object selection = i.next(); - boolean doReselect = false; - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - - if (selection instanceof XSDConcreteComponent) - { - XSDConcreteComponent xsdComponent = (XSDConcreteComponent) selection; - XSDSchema model = xsdComponent.getSchema(); - - doReselect = xsdComponent.eContainer() instanceof XSDSchema; - - DeleteCommand command = new DeleteCommand(getText(), xsdComponent); - getCommandStack().execute(command); - - if (model != null && doReselect) - { - Adapter adapter = XSDAdapterFactory.getInstance().adapt(model); - if (adapter != null) - provider.setSelection(new StructuredSelection(adapter)); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/OpenInNewEditor.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/OpenInNewEditor.java deleted file mode 100644 index 1efade029c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/OpenInNewEditor.java +++ /dev/null @@ -1,546 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.actions; - -import java.net.URI; - -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.filesystem.IFileStore; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.FileStoreEditorInput; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDSchemaDirectiveAdapter; -import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction; -import org.eclipse.wst.xsd.ui.internal.adt.editor.ADTFileStoreEditorInput; -import org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.editor.XSDFileEditorInput; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSchemaDirective; -import org.eclipse.xsd.impl.XSDImportImpl; - -public class OpenInNewEditor extends BaseSelectionAction -{ - public static final String ID = "OpenInNewEditor"; //$NON-NLS-1$ - - public OpenInNewEditor(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_OPEN_IN_NEW_EDITOR); //$NON-NLS-1$ - setId(ID); - } - - protected boolean calculateEnabled() - { - return true; - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - IWorkbenchPage page = null; - IEditorInput editorInput = null; - if (workbenchWindow != null) - { - page = workbenchWindow.getActivePage(); - IEditorPart activeEditor = page.getActiveEditor(); - if (activeEditor != null) - { - editorInput = activeEditor.getEditorInput(); - } - - } - - if (selection instanceof XSDBaseAdapter) - { - XSDBaseAdapter xsdAdapter = (XSDBaseAdapter) selection; - XSDConcreteComponent fComponent = (XSDConcreteComponent) xsdAdapter.getTarget(); - XSDSchema schema = fComponent.getSchema(); - - boolean isReference = false; - if (fComponent instanceof XSDFeature) - { - isReference = ((XSDFeature)fComponent).isFeatureReference(); - fComponent = ((XSDFeature)fComponent).getResolvedFeature(); - } - - String schemaLocation = null; - IPath schemaPath = null; - IFile schemaFile = null; - - // Special case any imports/includes - if (selection instanceof XSDSchemaDirectiveAdapter) - { - XSDSchemaDirective dir = (XSDSchemaDirective)((XSDSchemaDirectiveAdapter)selection).getTarget(); - // force load of imported schema - if (dir instanceof XSDImportImpl) - { - ((XSDImportImpl)dir).importSchema(); - } - if (dir.getResolvedSchema() != null) - { - schemaLocation = URIHelper.removePlatformResourceProtocol(dir.getResolvedSchema().getSchemaLocation()); - schemaPath = new Path(schemaLocation); - schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath); - schema = dir.getResolvedSchema(); - fComponent = dir.getResolvedSchema(); - } - } // Handle any other external components - else if (fComponent.getSchema() != null && fComponent.eContainer() instanceof XSDSchema || - fComponent.eContainer() instanceof XSDRedefine || isReference) - { - schemaLocation = URIHelper.removePlatformResourceProtocol(fComponent.getSchema().getSchemaLocation()); - schemaPath = new Path(schemaLocation); - schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath); - - try - { - XSDSchema xsdSchema = (XSDSchema)getWorkbenchPart().getAdapter(XSDSchema.class); - if (fComponent.getSchema() == xsdSchema) - { - IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - if (editorPart instanceof InternalXSDMultiPageEditor) - { - ((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent); - } - return; - } - } - catch (Exception e) - { - - } - } - - // If the schemaFile exists in the workspace - if (page != null && schemaFile != null && schemaFile.exists()) - { - try - { - // Get the current editor's schema - XSDSchema xsdSchema = (XSDSchema)getWorkbenchPart().getAdapter(XSDSchema.class); - IEditorPart editorPart = null; - // This first check is to ensure that the schema is actually - // different than the current one we are editing against in the editor, and that we - // are in the same resource file....hence multiple schemas in the same file. - if (xsdSchema != null && fComponent.getRootContainer().eResource() == xsdSchema.eResource() && xsdSchema != schema) - { - String editorName = null; - XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(schemaFile, fComponent.getSchema()); - // will use FileEditorInput's name if still null - // Try to use the same editor name as the current one - if (editorInput != null) - { - editorName = editorInput.getName(); - xsdFileEditorInput.setEditorName(editorName); - } - editorPart = getExistingEditorForInlineSchema(page, schemaFile, schema); - if (editorPart == null) - { - editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); - } - } - else - { - editorPart = page.openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.EDITOR_ID); - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - ((InternalXSDMultiPageEditor) editorPart).openOnGlobalReference(fComponent); - } - } - catch (Exception e) - { - } - } - else - { - // open the xsd externally - if (schemaLocation != null) - openExternalFiles(page, schemaLocation, fComponent); - } - } - } - - public static void openXSDEditor(IEditorInput editorInput, XSDConcreteComponent xsdComponent) - { - openXSDEditor(editorInput, xsdComponent.getSchema(), xsdComponent); - } - - public static void openXSDEditor(IEditorInput editorInput, XSDSchema schema, XSDConcreteComponent xsdComponent) - { - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - IWorkbenchPage page = null; - if (workbenchWindow != null) - { - page = workbenchWindow.getActivePage(); - } - - String resource = schema.getSchemaLocation(); - - if (editorInput instanceof FileEditorInput && resource != null && !resource.startsWith("http")) - { - String schemaLocation = URIHelper.removePlatformResourceProtocol(resource); - openWorkspaceFile(page, schemaLocation, xsdComponent); - } - else - { - openExternalFiles(page, resource, xsdComponent); - } - } - - public static void openInlineSchema(IEditorInput editorInput, XSDConcreteComponent xsdComponent, XSDSchema schema, String editorName) - { - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - IWorkbenchPage page = null; - if (workbenchWindow != null) - { - page = workbenchWindow.getActivePage(); - } - - boolean isWorkspaceFile = false; - - String schemaLocation = schema.getSchemaLocation(); - String workspaceFileLocation = URIHelper.removePlatformResourceProtocol(schemaLocation); - IPath workspaceFilePath = new Path(workspaceFileLocation); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(workspaceFilePath); - - if (page != null && file != null && file.exists()) - { - isWorkspaceFile = true; - } - - if (isWorkspaceFile) - { - try - { - IEditorPart editorPart = null; - XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(file, schema); - xsdFileEditorInput.setEditorName(editorName); - IEditorReference[] refs = page.getEditorReferences(); - int length = refs.length; - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof XSDFileEditorInput) - { - IFile aFile = ((XSDFileEditorInput) input).getFile(); - if (aFile.getFullPath().equals(file.getFullPath())) - { - if (((XSDFileEditorInput) input).getSchema() == schema) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - } - if (editorPart == null) - { - editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); //$NON-NLS-1$ - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(xsdComponent); - } - } - catch (PartInitException pie) - { - } - } - else - { - if (schemaLocation != null && !schemaLocation.startsWith("http")) - { - String fileLocation = null; - // This is to workaround the difference in URI resolution. On linux, the resolved location is - // platform:/resource/ On Windows, it's file:// - // - if (java.io.File.separatorChar == '/') - { - fileLocation = "/" + URIHelper.removePlatformResourceProtocol(schemaLocation); - } - else // Windows - { - fileLocation = URIHelper.removeProtocol(schemaLocation); - } - IPath schemaPath = new Path(fileLocation); - IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath); - if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) - { - try - { - ADTFileStoreEditorInput xsdFileStoreEditorInput = new ADTFileStoreEditorInput(fileStore, schema); - xsdFileStoreEditorInput.setEditorName(editorName); - - IEditorPart editorPart = null; - IEditorReference[] refs = page.getEditorReferences(); - int length = refs.length; - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof ADTFileStoreEditorInput) - { - URI uri = ((ADTFileStoreEditorInput) input).getURI(); - if (uri.equals(xsdFileStoreEditorInput.getURI()) && ((ADTFileStoreEditorInput) input).getSchema() == xsdFileStoreEditorInput.getSchema()) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - - if (page != null && editorPart == null) - { - editorPart = page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); //$NON-NLS-1$ - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(xsdComponent); - } - } - catch (PartInitException pie) - { - - } - } - } - else - { - try - { - IEditorPart editorPart = null; - IEditorReference[] refs = page.getEditorReferences(); - int length = refs.length; - // Need to find if an editor on that schema has already been opened - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof ADTReadOnlyFileEditorInput) - { - ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = (ADTReadOnlyFileEditorInput) input; - if (xsdFileStorageEditorInput.getUrlString().equals(schemaLocation) - && xsdFileStorageEditorInput.getEditorID().equals(XSDEditorPlugin.EDITOR_ID)) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - if (editorPart == null) - { - ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation); - xsdFileStorageEditorInput.setSchema(schema); - xsdFileStorageEditorInput.setEditorName(editorName); - xsdFileStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID); - editorPart = page.openEditor(xsdFileStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(xsdComponent); - } - } - catch (PartInitException pie) - { - } - - } - return; - } - } - - private IEditorPart getExistingEditorForInlineSchema(IWorkbenchPage page, IFile schemaFile, XSDSchema schema) - { - IEditorReference [] refs = page.getEditorReferences(); - int length = refs.length; - IEditorPart editorPart = null; - try - { - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof XSDFileEditorInput) - { - IFile aFile = ((XSDFileEditorInput)input).getFile(); - if (aFile.getFullPath().equals(schemaFile.getFullPath())) - { - if (((XSDFileEditorInput)input).getSchema() == schema) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - } - } - catch (PartInitException e) - { - } - return editorPart; - } - - public static void openWorkspaceFile(IWorkbenchPage page, String schemaLocation, XSDConcreteComponent xsdComponent) - { - IPath schemaPath = new Path(schemaLocation); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath); - if (page != null && file != null && file.exists()) - { - try - { - IEditorPart editorPart = IDE.openEditor(page, file, true); - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(xsdComponent); - } - } - catch (PartInitException pie) - { - - } - } - } - - public static void openExternalFiles(IWorkbenchPage page, String schemaLocation, XSDConcreteComponent fComponent) - { - if (schemaLocation == null) return; // Assert not null - - IPath schemaPath = new Path(schemaLocation); -// Initially tried to use schemaPath.getDevice() to determine if it is an http reference. However, on Linux, it is null. -// So as a result of bug 221421, we will just use the schemaLocation. - if (!schemaLocation.startsWith("http")) - { - schemaPath = new Path(URIHelper.removeProtocol(schemaLocation)); - } - IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath); - URI schemaURI = URI.create(schemaLocation); - if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) - { - try - { - IEditorPart editorPart = null; - IEditorReference[] refs = page.getEditorReferences(); - int length = refs.length; - // Need to find if an editor on that schema has already been opened - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof FileStoreEditorInput) - { - URI uri = ((FileStoreEditorInput) input).getURI(); - if (uri.equals(schemaURI)) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - if (editorPart == null) - { - editorPart = IDE.openEditorOnFileStore(page, fileStore); - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(fComponent); - } - } - catch (PartInitException pie) - { - } - } - else - { - try - { - if (schemaLocation.startsWith("http")) - { - try - { - IEditorPart editorPart = null; - IEditorReference[] refs = page.getEditorReferences(); - int length = refs.length; - // Need to find if an editor on that schema has already been opened - for (int i = 0; i < length; i++) - { - IEditorInput input = refs[i].getEditorInput(); - if (input instanceof ADTReadOnlyFileEditorInput) - { - ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input; - if (readOnlyEditorInput.getUrlString().equals(schemaLocation) && - XSDEditorPlugin.EDITOR_ID.equals(readOnlyEditorInput.getEditorID())) - { - editorPart = refs[i].getEditor(true); - page.activate(refs[i].getPart(true)); - break; - } - } - } - if (editorPart == null) - { - ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation); - readOnlyStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID); - editorPart = page.openEditor(readOnlyStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); //$NON-NLS-1$ - } - if (editorPart instanceof InternalXSDMultiPageEditor) - { - InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart; - xsdEditor.openOnGlobalReference(fComponent); - } - } - catch (PartInitException pie) - { - } - - } - else - { - FileStoreEditorInput xsdFileStoreEditorInput = new FileStoreEditorInput(fileStore); - page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0); //$NON-NLS-1$ - } - - } - catch (PartInitException e) - { - - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetBaseTypeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetBaseTypeAction.java deleted file mode 100644 index dbc3a457a4..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetBaseTypeAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.actions; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -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.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager; -import org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - -public class SetBaseTypeAction extends XSDBaseAction -{ - public static String ID = "org.eclipse.wst.xsd.ui.internal.common.actions.setBaseType"; //$NON-NLS-1$ - - public SetBaseTypeAction(IWorkbenchPart part) - { - super(part); - setText(Messages._UI_ACTION_SET_BASE_TYPE + "..."); //$NON-NLS-1$ - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - - boolean complexType = selection instanceof XSDComplexTypeDefinition; - boolean simpleType = selection instanceof XSDSimpleTypeDefinition; - - if (complexType || simpleType) - { - - if (getWorkbenchPart() instanceof IEditorPart) - { - IEditorPart editor = (IEditorPart)getWorkbenchPart(); - - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class); - ComponentSpecification newValue; - IComponentDialog dialog = null; - dialog = manager.getBrowseDialog(); - if (dialog != null) - { - if(simpleType) - { - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); - } - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - manager.modifyComponentReference(selection, newValue); - } - } - } - } - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetMultiplicityAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetMultiplicityAction.java deleted file mode 100644 index a33996a005..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetMultiplicityAction.java +++ /dev/null @@ -1,88 +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.actions; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.common.commands.SetMultiplicityCommand; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; - -public class SetMultiplicityAction extends XSDBaseAction -{ - public static String REQUIRED_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.SetMultiplicity.REQUIRED_ID"; //$NON-NLS-1$ - public static String ZERO_OR_ONE_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.SetMultiplicity.ZERO_OR_ONE_ID"; //$NON-NLS-1$ - public static String ZERO_OR_MORE_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.SetMultiplicity.ZERO_OR_MORE_ID"; //$NON-NLS-1$ - public static String ONE_OR_MORE_ID = "org.eclipse.wst.xsd.ui.internal.common.actions.SetMultiplicity.ONE_OR_MORE_ID"; //$NON-NLS-1$ - - SetMultiplicityCommand command; - - public SetMultiplicityAction(IWorkbenchPart part, String label, String ID) - { - super(part); - setText(label); - setId(ID); - command = new SetMultiplicityCommand(label); - } - - public void setMaxOccurs(int i) - { - command.setMaxOccurs(i); - } - - public void setMinOccurs(int i) - { - command.setMinOccurs(i); - } - - protected boolean calculateEnabled() - { - boolean state = super.calculateEnabled(); - if (state) - { - XSDConcreteComponent xsdConcreteComponent = getXSDInput(); - if (xsdConcreteComponent instanceof XSDElementDeclaration) - { - return !((XSDElementDeclaration)xsdConcreteComponent).isGlobal(); - } - else if (xsdConcreteComponent instanceof XSDModelGroup) - { - return !(((XSDModelGroup)xsdConcreteComponent).eContainer() instanceof XSDModelGroupDefinition); - } - } - return state; - } - - private XSDConcreteComponent getXSDInput() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - XSDConcreteComponent xsdConcreteComponent = null; - if (selection instanceof XSDBaseAdapter) - { - xsdConcreteComponent = (XSDConcreteComponent)((XSDBaseAdapter) selection).getTarget(); - } - return xsdConcreteComponent; - } - - public void run() - { - XSDConcreteComponent xsdConcreteComponent = getXSDInput(); - if (xsdConcreteComponent != null) - { - command.setXSDConcreteComponent(xsdConcreteComponent); - getCommandStack().execute(command); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetTypeAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetTypeAction.java deleted file mode 100644 index 2083e4f420..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/SetTypeAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.actions; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.common.commands.SetTypeCommand; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -import org.eclipse.xsd.XSDConcreteComponent; - -public class SetTypeAction extends XSDBaseAction -{ - public static final String SET_NEW_TYPE_ID = "SetTypeAction_AddType"; //$NON-NLS-1$ - public static final String SELECT_EXISTING_TYPE_ID = "SetTypeAction_ExistingType"; //$NON-NLS-1$ - - SetTypeCommand command; - - public SetTypeAction(String label, String ID, IWorkbenchPart part) - { - super(part); - setText(label); - setId(ID); - } - - public void run() - { - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - - if (selection instanceof XSDBaseAdapter) - { - Object target = ((XSDBaseAdapter) selection).getTarget(); - - if (target instanceof XSDConcreteComponent) - { - command = new SetTypeCommand(Messages._UI_ACTION_SET_TYPE, getId(), (XSDConcreteComponent) target); - command.setAdapter((XSDBaseAdapter) selection); - getCommandStack().execute(command); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/XSDBaseAction.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/XSDBaseAction.java deleted file mode 100644 index 472d9605c0..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/actions/XSDBaseAction.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.actions; - -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.views.contentoutline.ContentOutline; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction; -import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseFieldEditPart; -import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.IAutoDirectEdit; -import org.eclipse.wst.xsd.ui.internal.design.editparts.TopLevelComponentEditPart; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public class XSDBaseAction extends BaseSelectionAction -{ - XSDConcreteComponent addedComponent; - - public XSDBaseAction(IWorkbenchPart part) - { - super(part); - } - - protected boolean calculateEnabled() - { - if (getWorkbenchPart() instanceof IEditorPart) - { - IEditorPart owningEditor = (IEditorPart)getWorkbenchPart(); - - Object selection = ((IStructuredSelection) getSelection()).getFirstElement(); - if (selection instanceof XSDBaseAdapter) - { - selection = ((XSDBaseAdapter) selection).getTarget(); - } - XSDSchema xsdSchema = null; - if (selection instanceof XSDConcreteComponent) - { - xsdSchema = ((XSDConcreteComponent)selection).getSchema(); - } - - if (xsdSchema != null && xsdSchema == owningEditor.getAdapter(XSDSchema.class)) - { - return true; - } - } - return false; - } - - protected void doEdit(Object obj, IWorkbenchPart part) - { - if (obj instanceof TopLevelComponentEditPart) - { - TopLevelComponentEditPart editPart = (TopLevelComponentEditPart)obj; - if (addedComponent == ((XSDBaseAdapter)editPart.getModel()).getTarget()) - { - editPart.setScroll(true); - editPart.addFeedback(); - editPart.doEditName(!(part instanceof ContentOutline)); - } - } - else if (obj instanceof BaseFieldEditPart) - { - BaseFieldEditPart editPart = (BaseFieldEditPart)obj; - editPart.doEditName(!(part instanceof ContentOutline)); - } - else if (obj instanceof IAutoDirectEdit) - { - ((IAutoDirectEdit)obj).doEditName(!(part instanceof ContentOutline)); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddDocumentationCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddDocumentationCommand.java deleted file mode 100644 index 4462eccf0a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddDocumentationCommand.java +++ /dev/null @@ -1,131 +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.commands; - -import java.util.List; - -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class AddDocumentationCommand extends BaseCommand -{ - XSDAnnotation xsdAnnotation; - XSDConcreteComponent input; - String newValue, oldValue; - boolean documentationExists; - Element documentationElement; - - public AddDocumentationCommand(String label, XSDAnnotation xsdAnnotation, XSDConcreteComponent input, String newValue, String oldValue) - { - super(label); - this.xsdAnnotation = xsdAnnotation; - this.input = input; - this.newValue = newValue; - this.oldValue = oldValue; - } - - public void execute() - { - if (input instanceof XSDSchema) - { - ensureSchemaElement((XSDSchema)input); - } - - try - { - beginRecording(input.getElement()); - - xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(input, true); - Element element = xsdAnnotation.getElement(); - - List documentationList = xsdAnnotation.getUserInformation(); - documentationElement = null; - documentationExists = false; - if (documentationList.size() > 0) - { - documentationExists = true; - documentationElement = (Element) documentationList.get(0); - } - - if (documentationElement == null) - { - documentationElement = xsdAnnotation.createUserInformation(null); - element.appendChild(documentationElement); - formatChild(documentationElement); - // Defect in model....I create it but the model object doesn't appear - // to be updated - xsdAnnotation.updateElement(); - xsdAnnotation.setElement(element); - } - - if (documentationElement.hasChildNodes()) - { - if (documentationElement instanceof IDOMElement) - { - IDOMElement domElement = (IDOMElement) documentationElement; - - Node firstChild = documentationElement.getFirstChild(); - Node lastChild = documentationElement.getLastChild(); - int start = 0; - int end = 0; - - // IDOMModel model = domElement.getModel(); - // IDOMDocument doc = model.getDocument(); - IDOMNode first = null; - if (firstChild instanceof IDOMNode) - { - first = (IDOMNode) firstChild; - start = first.getStartOffset(); - } - if (lastChild instanceof IDOMNode) - { - IDOMNode last = (IDOMNode) lastChild; - end = last.getEndOffset(); - } - - if (domElement != null) - { - oldValue = domElement.getModel().getStructuredDocument().get(start, end - start); - domElement.getModel().getStructuredDocument().replaceText(documentationElement, start, end - start, newValue); - } - } - } - else - { - if (newValue.length() > 0) - { - oldValue = ""; //$NON-NLS-1$ - Node childNode = documentationElement.getOwnerDocument().createTextNode(newValue); - documentationElement.appendChild(childNode); - } - } - } - catch (Exception e) - { - - } - finally - { - endRecording(); - } - } - - public void undo() - { - super.undo(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddEnumerationsCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddEnumerationsCommand.java deleted file mode 100644 index 6cb8fa7892..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddEnumerationsCommand.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import java.util.List; - -import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDEnumerationFacetAction; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; - -public class AddEnumerationsCommand extends BaseCommand -{ - XSDSimpleTypeDefinition simpleType; - String value; - // The index of the currently selected item. If no item is selected, index will be less than 0 - private int index = -1; - // Determines where the element should be inserted based on the currently selected element. If no - // element is selected, use the default behaviour of appending the element to the end - private String addEnumerationLocation; - - public AddEnumerationsCommand(String label, XSDSimpleTypeDefinition simpleType) - { - super(label); - this.simpleType = simpleType; - } - - public AddEnumerationsCommand(String label, XSDSimpleTypeDefinition simpleType, String ID, int index) - { - super(label); - this.simpleType = simpleType; - this.index = index; - this.addEnumerationLocation = ID; - } - - public void setValue(String value) - { - this.value = value; - } - - public void execute() - { - try - { - beginRecording(simpleType.getElement()); - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDEnumerationFacet enumerationFacet = factory.createXSDEnumerationFacet(); - enumerationFacet.setLexicalValue(value); - - index = getInsertionIndex(); - List facets = simpleType.getFacetContents(); - if (index >=0 && index < facets.size()) - { - facets.add(index, enumerationFacet); - } - else - { - facets.add(enumerationFacet); - } - formatChild(simpleType.getElement()); - addedXSDConcreteComponent = enumerationFacet; - } - finally - { - endRecording(); - } - } - - protected int getInsertionIndex() - { - if (index < 0) - return -1; - - if (addEnumerationLocation.equals(AddXSDEnumerationFacetAction.BEFORE_SELECTED_ID)) - { - return index; - } - else if (addEnumerationLocation.equals(AddXSDEnumerationFacetAction.AFTER_SELECTED_ID)) - { - index++; - return index; - } - else - { - return -1; - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensibilityElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensibilityElementCommand.java deleted file mode 100644 index 6747f59c12..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensibilityElementCommand.java +++ /dev/null @@ -1,81 +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.commands; - -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class AddExtensibilityElementCommand extends BaseCommand -{ - Element input, elementToAdd; - SpecificationForExtensionsSchema extensionSchemaSpec; - - public AddExtensibilityElementCommand(String label, Element input, Element elementToAdd) - { - super(label); - this.input = input; - this.elementToAdd = elementToAdd; - } - - public void execute() - { - super.execute(); - try - { - beginRecording(input); - addElement(); - } - finally - { - endRecording(); - } - } - - public void undo() - { - super.undo(); - // TODO - } - - public void setSchemaProperties(SpecificationForExtensionsSchema appInfoSchemaSpec) - { - this.extensionSchemaSpec = appInfoSchemaSpec; - } - - private void addElement() - { - if (input != null) - { - Document doc = input.getOwnerDocument(); - String name = elementToAdd.getAttribute("name"); //$NON-NLS-1$ - try - { - Element rootElement = doc.createElementNS(extensionSchemaSpec.getNamespaceURI(), name); - String prefix = input.getPrefix(); - rootElement.setPrefix(prefix); - String xmlns = (prefix == null || prefix.equals("")) ? "xmlns" : "xmlns:" + prefix; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Attr nsURIAttribute = doc.createAttribute(xmlns); - nsURIAttribute.setValue(extensionSchemaSpec.getNamespaceURI()); - rootElement.setAttributeNode(nsURIAttribute); - input.appendChild(rootElement); - - } - catch (Exception e) - { - - } - - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java deleted file mode 100644 index 8ee0c5253e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionAttributeCommand.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMNamespaceInfoManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.w3c.dom.Element; - -public class AddExtensionAttributeCommand extends AddExtensionCommand -{ - private static DOMNamespaceInfoManager manager = new DOMNamespaceInfoManager(); - private XSDAttributeDeclaration attribute; - private boolean appInfoAttributeAdded = false; - private String attributeQName; - private String namespacePrefix; - - public AddExtensionAttributeCommand(String label, XSDConcreteComponent component, - XSDAttributeDeclaration attribute) - { - super(label); - this.component = component; - this.attribute = attribute; - } - - public void execute() - { - try - { - beginRecording(component.getElement()); - super.execute(); - namespacePrefix = handleNamespacePrefices(); - - attributeQName = namespacePrefix + ":" + attribute.getName(); //$NON-NLS-1$ - - if (!(component.getElement().hasAttribute(attributeQName))) - { - appInfoAttributeAdded = true; - component.getElement().setAttribute(attributeQName, ""); //$NON-NLS-1$ - } - } - finally - { - endRecording(); - } - } - - public void undo() - { - super.undo(); - if (appInfoAttributeAdded){ - component.getElement().removeAttribute(attributeQName); - } - } - - /** Create a namespace prefix if needed, other wise retrieve - * a predefined namespace prefix - * @return */ - private String handleNamespacePrefices() - { - Element schemaElement = component.getSchema().getElement(); - String prefix = null; - - // If target namespace of the attribute already exists - List namespacePrefices = manager.getNamespaceInfoList(schemaElement); - for (int i = 0; i < namespacePrefices.size(); i++){ - NamespaceInfo info = (NamespaceInfo) namespacePrefices.get(i); - if ( info.uri.equals(attribute.getTargetNamespace())) { - prefix = info.prefix; - } - } - - // Create unquie namespace prefix - if ( prefix == null){ - prefix = createUniquePrefix(component); - } - - NamespaceInfo info = new NamespaceInfo(attribute.getTargetNamespace(), prefix, ""); //$NON-NLS-1$ - List infoList = new ArrayList(1); - infoList.add(info); - manager.addNamespaceInfo(schemaElement, infoList, false); - return prefix; - } - - protected String createUniquePrefix(XSDConcreteComponent component) - { - String prefix = "p"; //$NON-NLS-1$ - Map prefMapper = component.getSchema().getQNamePrefixToNamespaceMap(); - if ( prefMapper.get(prefix) != null){ - int i = 1; - while ( prefMapper.get(prefix + i) != null) - i++; - prefix += i; - } - return prefix; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java deleted file mode 100644 index 5672104048..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionCommand.java +++ /dev/null @@ -1,48 +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.commands; - -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public class AddExtensionCommand extends BaseCommand -{ - protected SpecificationForExtensionsSchema extensionsSchemaSpec; - protected XSDConcreteComponent component; - - protected AddExtensionCommand(String label) - { - super(label); - } - - public void setSchemaProperties(SpecificationForExtensionsSchema appInfoSchemaSpec) - { - this.extensionsSchemaSpec = appInfoSchemaSpec; - } - - public Object getNewObject() - { - return null; - } - - public void execute() - { - if (component instanceof XSDSchema) - { - ensureSchemaElement((XSDSchema)component); - } - - super.execute(); - } - - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java deleted file mode 100644 index 2446901182..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddExtensionElementCommand.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import java.util.List; -import java.util.Map; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.appinfo.SpecificationForExtensionsSchema; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class AddExtensionElementCommand extends AddExtensionCommand -{ - XSDElementDeclaration element; - Element appInfo; - Element newElement; - - public AddExtensionElementCommand(String label, XSDConcreteComponent input, XSDElementDeclaration element) - { - super(label); - this.component = input; - this.element = element; - } - - public void execute() - { - try - { - beginRecording(component.getElement()); - super.execute(); - addAnnotationSet(component.getSchema(), extensionsSchemaSpec); - formatChild(component.getElement()); - } - finally - { - endRecording(); - } - } - - public void undo() - { - super.undo(); - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false); - xsdAnnotation.getElement().removeChild(appInfo); - List appInfos = xsdAnnotation.getApplicationInformation(); - appInfos.remove(appInfo); - xsdAnnotation.updateElement(); - - } - - public void setSchemaProperties(SpecificationForExtensionsSchema spec) - { - this.extensionsSchemaSpec = spec; - } - - public void addAnnotationSet(XSDSchema xsdSchema, SpecificationForExtensionsSchema spec) - { - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, true); - addAnnotationSet(spec, xsdAnnotation); - } - - private void addAnnotationSet(SpecificationForExtensionsSchema spec, XSDAnnotation xsdAnnotation) - { - XSDSchema schema= xsdAnnotation.getSchema(); - Element schemaElement = schema.getElement(); - - if (xsdAnnotation.getApplicationInformation().size() == 0) - { - appInfo = xsdAnnotation.createApplicationInformation(null); - xsdAnnotation.getElement().appendChild(appInfo); - List appInfos = xsdAnnotation.getApplicationInformation(); - appInfos.add(appInfo); - } - else - { - // use the first appInfo - appInfo = (Element)xsdAnnotation.getApplicationInformation().get(0); - } - - String prefix = addNamespaceDeclarationIfRequired(schemaElement, "p", spec.getNamespaceURI()); - - if (appInfo != null) - { - Document doc = appInfo.getOwnerDocument(); - - newElement = doc.createElementNS(spec.getNamespaceURI(), element.getName()); - newElement.setPrefix(prefix); - appInfo.appendChild(newElement); - - xsdAnnotation.updateElement(); - } - } - - public Object getNewObject() - { - return newElement; - } - - /** - * @deprecated - */ - protected String createUniquePrefix(XSDConcreteComponent component) - { - String prefix = "p"; //$NON-NLS-1$ - Map prefMapper = component.getSchema().getQNamePrefixToNamespaceMap(); - if ( prefMapper.get(prefix) != null){ - int i = 1; - while ( prefMapper.get(prefix + i) != null) - i++; - prefix += i; - } - return prefix; - } - - // TODO... common this up with wsdl.ui - private String addNamespaceDeclarationIfRequired(Element schemaElement, String prefixHint, String namespace) - { - String prefix = null; - NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument()); - namespaceTable.addElement(schemaElement); - prefix = namespaceTable.getPrefixForURI(namespace); - if (prefix == null) - { - String basePrefix = prefixHint; - prefix = basePrefix; - String xmlnsColon = "xmlns:"; //$NON-NLS-1$ - String attributeName = xmlnsColon + prefix; - int count = 0; - while (schemaElement.hasAttribute(attributeName)) - { - count++; - prefix = basePrefix + count; - attributeName = xmlnsColon + prefix; - } - schemaElement.setAttribute(attributeName, namespace); - } - return prefix; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddRedefinedComponentCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddRedefinedComponentCommand.java deleted file mode 100644 index 05ecede51d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddRedefinedComponentCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 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.commands; - - -import org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; -import org.w3c.dom.Element; - - -/** - * Base class for commands that add redefined components to a schema redefine. - */ -public abstract class AddRedefinedComponentCommand extends BaseCommand -{ - protected XSDRedefine redefine; - - protected XSDRedefinableComponent redefinableComponent; - - public AddRedefinedComponentCommand(String label, XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - super(label); - this.redefine = redefine; - this.redefinableComponent = redefinableComponent; - } - - protected abstract void doExecute(); - - public void execute() - { - Element element = redefine.getElement(); - - try - { - beginRecording(element); - doExecute(); - Object adapter = redefinableComponent.eAdapters().get(0); - if (adapter instanceof XSDComplexTypeDefinitionAdapter) - { - ((XSDComplexTypeDefinitionAdapter)adapter).updateDeletedMap(redefinableComponent.getName()); - } - else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) - { - ((XSDSimpleTypeDefinitionAdapter)adapter).updateDeletedMap(redefinableComponent.getName()); - } - else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) - { - ((XSDAttributeGroupDefinitionAdapter)adapter).updateDeletedMap(redefinableComponent.getName()); - } - else if (adapter instanceof XSDModelGroupDefinitionAdapter) - { - ((XSDModelGroupDefinitionAdapter)adapter).updateDeletedMap(redefinableComponent.getName()); - } - redefine.getContents().add(addedXSDConcreteComponent); - formatChild(addedXSDConcreteComponent.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyAttributeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyAttributeCommand.java deleted file mode 100644 index 211cbc9d82..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyAttributeCommand.java +++ /dev/null @@ -1,64 +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.commands; - -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDWildcard; - -public class AddXSDAnyAttributeCommand extends BaseCommand -{ - XSDComplexTypeDefinition xsdComplexTypeDefinition; - XSDAttributeGroupDefinition xsdAttributeGroupDefinition; - XSDConcreteComponent input; - - public AddXSDAnyAttributeCommand(String label, XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - super(label); - this.xsdComplexTypeDefinition = xsdComplexTypeDefinition; - this.input = xsdComplexTypeDefinition; - } - - public AddXSDAnyAttributeCommand(String label, XSDAttributeGroupDefinition xsdAttributeGroupDefinition) - { - super(label); - this.xsdAttributeGroupDefinition = xsdAttributeGroupDefinition; - this.input = xsdAttributeGroupDefinition; - } - - public void execute() - { - try - { - beginRecording(input.getElement()); - - XSDWildcard anyAttribute = XSDFactory.eINSTANCE.createXSDWildcard(); - if (xsdComplexTypeDefinition != null) - { - xsdComplexTypeDefinition.setAttributeWildcardContent(anyAttribute); - formatChild(xsdComplexTypeDefinition.getElement()); - } - else if (xsdAttributeGroupDefinition != null) - { - xsdAttributeGroupDefinition.setAttributeWildcardContent(anyAttribute); - formatChild(xsdAttributeGroupDefinition.getElement()); - } - addedXSDConcreteComponent = anyAttribute; - } - finally - { - endRecording(); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java deleted file mode 100644 index 1b88a5809c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAnyElementCommand.java +++ /dev/null @@ -1,80 +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.commands; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDWildcard; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; - -public class AddXSDAnyElementCommand extends BaseCommand -{ - XSDModelGroup parent; - XSDComplexTypeDefinition complexType; - boolean doCreateModelGroupForComplexType = false; - - public AddXSDAnyElementCommand(String label, XSDModelGroup parent) - { - super(label); - this.parent = parent; - } - - public void setComplexType(XSDComplexTypeDefinition complexType) - { - this.complexType = complexType; - } - - public void setDoCreateModelGroupForComplexType(boolean doCreate) - { - this.doCreateModelGroupForComplexType = doCreate; - } - - private void createModelGroup() - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDParticle particle = factory.createXSDParticle(); - parent = factory.createXSDModelGroup(); - parent.setCompositor(XSDCompositor.SEQUENCE_LITERAL); - particle.setContent(parent); - complexType.setContent(particle); - } - - public void execute() - { - try - { - if (doCreateModelGroupForComplexType) - { - Assert.isNotNull(complexType); - beginRecording(complexType.getElement()); - createModelGroup(); - } - else - { - beginRecording(parent.getElement()); - } - XSDWildcard wildCard = XSDFactory.eINSTANCE.createXSDWildcard(); - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(wildCard); - parent.getContents().add(particle); - addedXSDConcreteComponent = wildCard; - formatChild(parent.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java deleted file mode 100644 index 00df7e042e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeDeclarationCommand.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Text; - -public class AddXSDAttributeDeclarationCommand extends BaseCommand -{ - XSDComplexTypeDefinition xsdComplexTypeDefinition; - XSDModelGroup xsdModelGroup; - XSDConcreteComponent parent; - boolean isReference; - private String nameToAdd; - // The index of the currently selected item. If no item is selected, index will be less than 0 - private int index = -1; - // Determines where the attribute should be inserted based on the currently selected attribute. If no - // attribute is selected, use the default behaviour of appending the attribute to the end - private String addAttributeLocation; - - public AddXSDAttributeDeclarationCommand(String label, XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - super(label); - this.xsdComplexTypeDefinition = xsdComplexTypeDefinition; - } - - public AddXSDAttributeDeclarationCommand(String label, XSDConcreteComponent parent) - { - super(label); - this.parent = parent; - } - - public AddXSDAttributeDeclarationCommand(String label, XSDConcreteComponent parent, String addAttributeLocation, int index) - { - super(label); - if (parent instanceof XSDComplexTypeDefinition) - { - this.xsdComplexTypeDefinition = (XSDComplexTypeDefinition) parent; - } - else - { - this.parent = parent; - } - this.addAttributeLocation = addAttributeLocation; - this.index = index; - } - - protected int getInsertionIndex() - { - if (index < 0) - return -1; - - if (addAttributeLocation.equals(org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction.BEFORE_SELECTED_ID)) - { - return index; - } - else if (addAttributeLocation.equals(org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction.AFTER_SELECTED_ID)) - { - index++; - return index; - } - else - { - return -1; - } - } - - public void execute() - { - XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration(); - try - { - if (parent == null) - { - beginRecording(xsdComplexTypeDefinition.getElement()); - if (!isReference) - { - attribute.setName(getNewName(nameToAdd == null ? "NewAttribute" : nameToAdd)); //$NON-NLS-1$ - attribute.setTypeDefinition(xsdComplexTypeDefinition.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string")); //$NON-NLS-1$ - } - else - { - attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(xsdComplexTypeDefinition.getSchema())); - } - XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse(); - attributeUse.setAttributeDeclaration(attribute); - attributeUse.setContent(attribute); - - if (xsdComplexTypeDefinition.getAttributeContents() != null) - { - index = getInsertionIndex(); - if (index >= 0 && index < xsdComplexTypeDefinition.getAttributeContents().size()) - { - xsdComplexTypeDefinition.getAttributeContents().add(index, attributeUse); - } - else - { - xsdComplexTypeDefinition.getAttributeContents().add(attributeUse); - } - formatChild(xsdComplexTypeDefinition.getElement()); - } - } - else - { - beginRecording(parent.getElement()); - if (parent instanceof XSDSchema) - { - XSDSchema xsdSchema = (XSDSchema) parent; - attribute = createGlobalXSDAttributeDeclaration(xsdSchema); - } - else if (parent instanceof XSDAttributeGroupDefinition) - { - if (!isReference) - { - attribute.setTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string")); //$NON-NLS-1$ - - List list = new ArrayList(); - Iterator i = ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getAttributeUses().iterator(); - while (i.hasNext()) - { - XSDAttributeUse use = (XSDAttributeUse) i.next(); - list.add(use.getAttributeDeclaration()); - } - attribute.setName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", list)); //$NON-NLS-1$ - } - else - { - attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(parent.getSchema())); - } - - XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse(); - attributeUse.setAttributeDeclaration(attribute); - attributeUse.setContent(attribute); - - index = getInsertionIndex(); - if (index >= 0 && index < (((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().size())) - { - ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(index, attributeUse); - } - else - { - ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(attributeUse); - } - formatChild(parent.getElement()); - } - } - } - finally - { - endRecording(); - } - addedXSDConcreteComponent = attribute; - } - - ArrayList names; - - public void setNameToAdd(String name) - { - nameToAdd = name; - } - - protected String getNewName(String description) - { - ArrayList usedAttributeNames = new ArrayList(); - usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes(xsdComplexTypeDefinition)); - usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes(xsdComplexTypeDefinition)); - return XSDCommonUIUtils.createUniqueElementName(description, usedAttributeNames); //$NON-NLS-1$ - } - - public void setReference(boolean isReference) - { - this.isReference = isReference; - } - - protected XSDAttributeDeclaration createGlobalXSDAttributeDeclaration(XSDSchema xsdSchema) - { - ensureSchemaElement(xsdSchema); - XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration(); - attribute.setTypeDefinition(xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("string")); //$NON-NLS-1$ - attribute.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewAttribute" : nameToAdd, xsdSchema.getAttributeDeclarations())); //$NON-NLS-1$ - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(attribute); - return attribute; - } - - protected XSDAttributeDeclaration setGlobalAttributeReference(XSDSchema xsdSchema) - { - List list = xsdSchema.getAttributeDeclarations(); - XSDAttributeDeclaration referencedAttribute = null; - boolean isUserDefined = false; - for (Iterator i = list.iterator(); i.hasNext(); ) - { - Object obj = i.next(); - if (obj instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration attr = (XSDAttributeDeclaration) obj; - if (!XSDConstants.SCHEMA_INSTANCE_URI_2001.equals(attr.getTargetNamespace())) - { - referencedAttribute = attr; - isUserDefined = true; - break; - } - } - } - if (!isUserDefined) - { - referencedAttribute = createGlobalXSDAttributeDeclaration(xsdSchema); - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(referencedAttribute); - } - - return referencedAttribute; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeGroupDefinitionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeGroupDefinitionCommand.java deleted file mode 100644 index 2ee575e73a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDAttributeGroupDefinitionCommand.java +++ /dev/null @@ -1,159 +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.commands; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDTypeDefinition; -import org.w3c.dom.Text; - -public class AddXSDAttributeGroupDefinitionCommand extends BaseCommand -{ - XSDComplexTypeDefinition xsdComplexTypeDefinition; - XSDSchema xsdSchema; - - public AddXSDAttributeGroupDefinitionCommand(String label, XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - super(label); - this.xsdComplexTypeDefinition = xsdComplexTypeDefinition; - } - - public AddXSDAttributeGroupDefinitionCommand(String label, XSDSchema xsdSchema) - { - super(label); - this.xsdSchema = xsdSchema; - } - - public void execute() - { - XSDAttributeGroupDefinition attributeGroup = XSDFactory.eINSTANCE.createXSDAttributeGroupDefinition(); - try - { - if (xsdSchema == null) - { - beginRecording(xsdComplexTypeDefinition.getElement()); - attributeGroup.setName(getNewName("AttributeGroup")); //$NON-NLS-1$ - - List list = xsdComplexTypeDefinition.getSchema().getAttributeGroupDefinitions(); - if (list.size() > 0) - { - attributeGroup.setResolvedAttributeGroupDefinition((XSDAttributeGroupDefinition) list.get(0)); - } - else - { - attributeGroup.setName(null); - XSDAttributeGroupDefinition attributeGroup2 = XSDFactory.eINSTANCE.createXSDAttributeGroupDefinition(); - attributeGroup2.setName(XSDCommonUIUtils.createUniqueElementName("NewAttributeGroup", xsdComplexTypeDefinition.getSchema().getAttributeGroupDefinitions())); //$NON-NLS-1$ - xsdComplexTypeDefinition.getSchema().getContents().add(attributeGroup2); - attributeGroup.setResolvedAttributeGroupDefinition(attributeGroup2); - } - - if (xsdComplexTypeDefinition.getAttributeContents() != null) - { - xsdComplexTypeDefinition.getAttributeContents().add(attributeGroup); - } - addedXSDConcreteComponent = attributeGroup; - } - else - { - ensureSchemaElement(xsdSchema); - // put this after, since we don't have a DOM node yet - beginRecording(xsdSchema.getElement()); - attributeGroup.setName(XSDCommonUIUtils.createUniqueElementName("NewAttributeGroup", xsdSchema.getAttributeGroupDefinitions())); //$NON-NLS-1$ - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(attributeGroup); - addedXSDConcreteComponent = attributeGroup; - } - } - finally - { - endRecording(); - } - } - - ArrayList names; - - protected String getNewName(String description) - { - String candidateName = "New" + description; //$NON-NLS-1$ - XSDConcreteComponent parent = xsdComplexTypeDefinition; - names = new ArrayList(); - int i = 1; - if (parent instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent; - walkUpInheritance(ct); - - boolean ready = false; - while (!ready) - { - ready = true; - for (Iterator iter = names.iterator(); iter.hasNext();) - { - String attrName = (String) iter.next(); - if (candidateName.equals(attrName)) - { - ready = false; - candidateName = "New" + description + String.valueOf(i); //$NON-NLS-1$ - i++; - } - } - } - } - return candidateName; - } - - private void walkUpInheritance(XSDComplexTypeDefinition ct) - { - updateNames(ct); - XSDTypeDefinition typeDef = ct.getBaseTypeDefinition(); - if (ct != ct.getRootType()) - { - if (typeDef instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition ct2 = (XSDComplexTypeDefinition) typeDef; - walkUpInheritance(ct2); - } - } - } - - private void updateNames(XSDComplexTypeDefinition ct) - { - Iterator iter = ct.getAttributeContents().iterator(); - while (iter.hasNext()) - { - Object obj = iter.next(); - if (obj instanceof XSDAttributeUse) - { - XSDAttributeUse use = (XSDAttributeUse) obj; - XSDAttributeDeclaration attr = use.getAttributeDeclaration(); - String attrName = attr.getName(); - if (attrName != null) - { - names.add(attrName); - } - } - } - - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDComplexTypeDefinitionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDComplexTypeDefinitionCommand.java deleted file mode 100644 index fa636cc11e..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDComplexTypeDefinitionCommand.java +++ /dev/null @@ -1,122 +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.commands; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; -import org.w3c.dom.Text; - -public final class AddXSDComplexTypeDefinitionCommand extends BaseCommand -{ - protected XSDConcreteComponent parent; - protected XSDComplexTypeDefinition createdComplexType; - private String nameToAdd; - - public AddXSDComplexTypeDefinitionCommand(String label, XSDConcreteComponent parent) - { - super(label); - this.parent = parent; - } - - public void setNameToAdd(String nameToAdd) - { - this.nameToAdd = nameToAdd; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.gef.commands.Command#execute() - */ - public void execute() - { - try - { - beginRecording(parent.getElement()); - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition(); - addedXSDConcreteComponent = complexType; - String newName = getNewName(nameToAdd == null ? "NewComplexType" : nameToAdd, parent.getSchema()); //$NON-NLS-1$ - complexType.setName(newName); - if (parent instanceof XSDSchema) - { - try - { - XSDSchema xsdSchema = (XSDSchema) parent; - ensureSchemaElement(xsdSchema); - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(complexType); - } - catch (Exception e) - { - - } - } - else if (parent instanceof XSDElementDeclaration) - { - ((XSDElementDeclaration) parent).setAnonymousTypeDefinition(complexType); - formatChild(parent.getElement()); - } - createdComplexType = complexType; - } - finally - { - endRecording(); - } - } - - protected String getNewName(String description, XSDSchema schema) - { - String candidateName = description; //$NON-NLS-1$ - int i = 1; - - List list = schema.getTypeDefinitions(); - List listOfNames = new ArrayList(); - for (Iterator iter = list.iterator(); iter.hasNext();) - { - XSDTypeDefinition typeDef = (XSDTypeDefinition) iter.next(); - String name = typeDef.getName(); - if (name == null) - name = ""; //$NON-NLS-1$ - if (typeDef.getTargetNamespace() == schema.getTargetNamespace()) - listOfNames.add(name); - } - - boolean flag = true; - while (flag) - { - if (!listOfNames.contains(candidateName)) - { - flag = false; - break; - } - candidateName = description + String.valueOf(i); //$NON-NLS-1$ - i++; - } - - return candidateName; - } - - public XSDComplexTypeDefinition getCreatedComplexType() - { - return createdComplexType; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDElementCommand.java deleted file mode 100644 index a1bdff69e0..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDElementCommand.java +++ /dev/null @@ -1,388 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDComplexTypeContent; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; -import org.w3c.dom.Text; - -public class AddXSDElementCommand extends BaseCommand -{ - XSDComplexTypeDefinition xsdComplexTypeDefinition; - XSDModelGroupDefinition xsdModelGroupDefinition; - XSDModelGroup xsdModelGroup; - XSDSchema xsdSchema; - boolean isReference; - private String nameToAdd; - // The index of the currently selected item. If no item is selected, index will be less than 0 - private int index = -1; - // Determines where the element should be inserted based on the currently selected element. If no - // element is selected, use the default behaviour of appending the element to the end - private String addElementLocation; - - public AddXSDElementCommand() - { - super(); - } - - public AddXSDElementCommand(String label, XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - super(label); - this.xsdComplexTypeDefinition = xsdComplexTypeDefinition; - xsdModelGroup = getModelGroup(xsdComplexTypeDefinition); - } - - public AddXSDElementCommand(String label, XSDModelGroupDefinition xsdModelGroupDefinition) - { - super(label); - this.xsdModelGroupDefinition = xsdModelGroupDefinition; - xsdModelGroup = getModelGroup(xsdModelGroupDefinition); - } - - public AddXSDElementCommand(String label, XSDModelGroup xsdModelGroup, XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - super(label); - this.xsdModelGroup = xsdModelGroup; - this.xsdComplexTypeDefinition = xsdComplexTypeDefinition; - } - - public AddXSDElementCommand(String label, XSDModelGroup xsdModelGroup) - { - super(label); - this.xsdModelGroup = xsdModelGroup; - } - - public AddXSDElementCommand(String label, XSDModelGroup xsdModelGroup, String ID, int index) - { - super(label); - this.xsdModelGroup = xsdModelGroup; - this.index = index; - this.addElementLocation = ID; - } - - public AddXSDElementCommand(String label, XSDSchema xsdSchema) - { - super(label); - this.xsdSchema = xsdSchema; - } - - public void setReference(boolean isReference) - { - this.isReference = isReference; - } - - public void setNameToAdd(String name) - { - nameToAdd = name; - } - - public void setAddElementLocation(String LocationType) - { - addElementLocation = LocationType; - } - - protected int getInsertionIndex() - { - if (index < 0) - return -1; - - if (addElementLocation.equals(org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction.BEFORE_SELECTED_ID)) - { - return index; - } - else if (addElementLocation.equals(org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction.AFTER_SELECTED_ID)) - { - index++; - return index; - } - else - { - return -1; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.gef.commands.Command#execute() - */ - public void execute() - { - try - { - if (xsdSchema != null) - { - beginRecording(xsdSchema.getElement()); - XSDElementDeclaration element = createGlobalXSDElementDeclaration(); - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(element); - addedXSDConcreteComponent = element; - } - else if (xsdModelGroupDefinition != null) - { - beginRecording(xsdModelGroupDefinition.getElement()); - if (xsdModelGroup == null) - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDParticle particle = factory.createXSDParticle(); - xsdModelGroup = factory.createXSDModelGroup(); - xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); - particle.setContent(xsdModelGroup); - xsdModelGroupDefinition.setModelGroup(xsdModelGroup); - } - xsdSchema = xsdModelGroupDefinition.getSchema(); - if (!isReference) - { - xsdModelGroup.getContents().add(createXSDElementDeclarationForModelGroupDefinitions()); - } - else - { - xsdModelGroup.getContents().add(createXSDElementReference()); - } - formatChild(xsdModelGroupDefinition.getElement()); - } - else if (xsdModelGroup != null && (xsdComplexTypeDefinition == null || xsdModelGroupDefinition == null) ) - { - xsdSchema = xsdModelGroup.getSchema(); - beginRecording(xsdSchema.getElement()); - if (!isReference) - { - index = getInsertionIndex(); - if(index >= 0 && index < xsdModelGroup.getContents().size()) - { - xsdModelGroup.getContents().add(index,createXSDElementDeclaration()); - } - else - { - xsdModelGroup.getContents().add(createXSDElementDeclaration()); - } - } - else - { - xsdModelGroup.getContents().add(createXSDElementReference()); - } - formatChild(xsdModelGroup.getElement()); - } - else - { - xsdSchema = xsdComplexTypeDefinition.getSchema(); - beginRecording(xsdSchema.getElement()); - if (xsdModelGroup == null) - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDParticle particle = factory.createXSDParticle(); - xsdModelGroup = factory.createXSDModelGroup(); - xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); - particle.setContent(xsdModelGroup); - xsdComplexTypeDefinition.setContent(particle); - } - if (!isReference) - { - xsdModelGroup.getContents().add(createXSDElementDeclarationForComplexType()); - } - else - { - xsdModelGroup.getContents().add(createXSDElementReference()); - } - formatChild(xsdComplexTypeDefinition.getElement()); - } - } - finally - { - endRecording(); - } - } - - protected XSDParticle createXSDElementDeclaration() - { - XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"); //$NON-NLS-1$ - - XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration(); - - XSDConcreteComponent comp = xsdModelGroup.getContainer(); - ArrayList usedAttributeNames = new ArrayList(); - XSDCommonUIUtils.resetVisitedGroupsStack(); - usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup)); - while (comp != null) - { - if (comp instanceof XSDModelGroupDefinition) - { - usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition)comp)); - break; - } - else if (comp instanceof XSDComplexTypeDefinition) - { - usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition)comp)); - usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition)comp)); - break; - } - comp = comp.getContainer(); - } - element.setName(XSDCommonUIUtils.createUniqueElementName( - nameToAdd == null ? "NewElement" : nameToAdd , usedAttributeNames)); //$NON-NLS-1$ - element.setTypeDefinition(type); - - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(element); - addedXSDConcreteComponent = element; - return particle; - } - - protected XSDParticle createXSDElementReference() - { - List list = xsdModelGroup.getSchema().getElementDeclarations(); - XSDElementDeclaration referencedElement = null; - if (list.size() > 0) - { - referencedElement = (XSDElementDeclaration)list.get(0); - } - else - { - referencedElement = createGlobalXSDElementDeclaration(); - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(referencedElement); - } - - XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration(); - - element.setResolvedElementDeclaration(referencedElement); - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(element); - addedXSDConcreteComponent = element; - return particle; - } - - protected XSDParticle createXSDElementDeclarationForComplexType() - { - XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"); //$NON-NLS-1$ - - XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration(); - - ArrayList usedAttributeNames = new ArrayList(); - usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes(xsdComplexTypeDefinition)); - usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes(xsdComplexTypeDefinition)); - element.setName(XSDCommonUIUtils.createUniqueElementName( - nameToAdd == null ? "NewElement" : nameToAdd , usedAttributeNames)); //$NON-NLS-1$ - element.setTypeDefinition(type); - - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(element); - addedXSDConcreteComponent = element; - return particle; - } - - protected XSDParticle createXSDElementDeclarationForModelGroupDefinitions() - { - XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"); //$NON-NLS-1$ - - XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration(); - - ArrayList usedAttributeNames = new ArrayList(); - usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes(xsdModelGroupDefinition)); - element.setName(XSDCommonUIUtils.createUniqueElementName( - nameToAdd == null ? "NewElement" : nameToAdd , usedAttributeNames)); //$NON-NLS-1$ - element.setTypeDefinition(type); - - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(element); - addedXSDConcreteComponent = element; - return particle; - } - - protected XSDElementDeclaration createGlobalXSDElementDeclaration() - { - ensureSchemaElement(xsdSchema); - XSDSimpleTypeDefinition type = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("string"); //$NON-NLS-1$ - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDElementDeclaration element = factory.createXSDElementDeclaration(); - - element.setName(XSDCommonUIUtils.createUniqueElementName( - nameToAdd == null ? "NewElement" : nameToAdd , xsdSchema.getElementDeclarations())); //$NON-NLS-1$ - element.setTypeDefinition(type); - - return element; - } - - public XSDModelGroup getModelGroup(XSDModelGroupDefinition modelGroupDef) - { - return modelGroupDef.getModelGroup(); - } - - //PORT - public XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) - { - XSDParticle particle = null; - - XSDComplexTypeContent xsdComplexTypeContent = cType.getContent(); - if (xsdComplexTypeContent instanceof XSDParticle) - { - particle = (XSDParticle)xsdComplexTypeContent; - } - - if (particle == null) - { - return null; - } - - Object particleContent = particle.getContent(); - XSDModelGroup group = null; - - if (particleContent instanceof XSDModelGroupDefinition) - { - group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup(); - } - else if (particleContent instanceof XSDModelGroup) - { - group = (XSDModelGroup) particleContent; - } - - if (group == null) - { - return null; - } - -// if (group.getContents().isEmpty() || group.eResource() != cType.eResource()) -// { -// if (cType.getBaseType() != null) -// { -// XSDComplexTypeContent content = cType.getContent(); -// if (content instanceof XSDParticle) -// { -// group = (XSDModelGroup) ((XSDParticle) content).getContent(); -// } -// } -// } - - return group; - } - - public XSDConcreteComponent getAddedComponent() - { - return super.getAddedComponent(); - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDImportCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDImportCommand.java deleted file mode 100644 index e91f872f2a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDImportCommand.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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDImport; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDImportCommand extends AddXSDSchemaDirectiveCommand -{ - public AddXSDImportCommand(String label, XSDSchema schema) - { - super(label); - this.xsdSchema = schema; - } - - public void execute() - { - try - { - super.execute(); - // Add this after if we don't have a DOM Node yet - beginRecording(xsdSchema.getElement()); - XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport(); - xsdSchema.getContents().add(findNextPositionToInsert(), xsdImport); - addedXSDConcreteComponent = xsdImport; - formatChild(xsdSchema.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDIncludeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDIncludeCommand.java deleted file mode 100644 index e69b309467..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDIncludeCommand.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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDIncludeCommand extends AddXSDSchemaDirectiveCommand -{ - public AddXSDIncludeCommand(String label, XSDSchema schema) - { - super(label); - this.xsdSchema = schema; - } - - public void execute() - { - try - { - super.execute(); - // Add this after if we don't have a DOM Node yet - beginRecording(xsdSchema.getElement()); - XSDInclude xsdInclude = XSDFactory.eINSTANCE.createXSDInclude(); - xsdInclude.setSchemaLocation(""); //$NON-NLS-1$ - xsdSchema.getContents().add(findNextPositionToInsert(), xsdInclude); - addedXSDConcreteComponent = xsdInclude; - formatChild(xsdSchema.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupCommand.java deleted file mode 100644 index 5d14b27017..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupCommand.java +++ /dev/null @@ -1,167 +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.commands; - -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; - -public class AddXSDModelGroupCommand extends BaseCommand -{ - XSDConcreteComponent parent; - XSDCompositor xsdCompositor; - XSDModelGroup newModelGroup; - - public AddXSDModelGroupCommand(String label, XSDConcreteComponent parent, XSDCompositor xsdCompositor) - { - super(label); - this.parent = parent; - this.xsdCompositor = xsdCompositor; - } - - public void execute() - { - try - { - beginRecording(parent.getElement()); - XSDConcreteComponent owner = getOwner(); - if (owner != null) - { - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - newModelGroup = createModelGroup(); - particle.setContent(newModelGroup); - - XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) owner; - ctd.setContent(particle); - } - formatChild(parent.getElement()); - } - finally - { - endRecording(); - } - } - - public void undo() - { - super.undo(); - - if (parent instanceof XSDModelGroup) - { - XSDModelGroup model = (XSDModelGroup) parent; - model.getContents().remove(newModelGroup.getContainer()); - } - } - - private XSDConcreteComponent getOwner() - { - XSDConcreteComponent owner = null; - if (parent instanceof XSDElementDeclaration) - { - XSDElementDeclaration ed = (XSDElementDeclaration)parent; - if (ed.getTypeDefinition() != null) - { - if (ed.getAnonymousTypeDefinition() == null) - { - ed.setTypeDefinition(null); - XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - ed.setAnonymousTypeDefinition(td); - owner = ed.getTypeDefinition(); - } - else - { - XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - ed.setAnonymousTypeDefinition(td); - owner = td; - } - } - else if (ed.getAnonymousTypeDefinition() == null) - { - XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - ed.setAnonymousTypeDefinition(td); - owner = td; - } - else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) - { - owner = ed.getAnonymousTypeDefinition(); - } - else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) - { - XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - ed.setAnonymousTypeDefinition(td); - owner = td; - } - } - else if (parent instanceof XSDModelGroup) - { - newModelGroup = createModelGroup(); - ((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer()); - } - else if (parent instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition)parent; - owner = parent; - if (ct.getContent() instanceof XSDParticle) - { - XSDParticle particle = (XSDParticle)ct.getContent(); - if (particle.getContent() instanceof XSDModelGroup) - { - owner = null; - newModelGroup = createModelGroup(); - XSDModelGroup newParent = (XSDModelGroup)particle.getContent(); - newParent.getContents().add(newModelGroup.getContainer()); - } - - } - } - else if (parent instanceof XSDModelGroupDefinition) - { - XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition)parent; - owner = null; - newModelGroup = createModelGroup(); - if (modelGroupDefinition.getModelGroup() != null) - { - XSDModelGroup newParent = modelGroupDefinition.getModelGroup(); - newParent.getContents().add(newModelGroup.getContainer()); - } - else - { - modelGroupDefinition.setModelGroup(newModelGroup); - } - } - return owner; - } - - - protected boolean adopt(XSDConcreteComponent model) - { - return false; - } - - protected XSDModelGroup createModelGroup() - { - - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDParticle particle = factory.createXSDParticle(); - XSDModelGroup modelGroup = factory.createXSDModelGroup(); - modelGroup.setCompositor(xsdCompositor); - particle.setContent(modelGroup); - addedXSDConcreteComponent = modelGroup; - return modelGroup; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupDefinitionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupDefinitionCommand.java deleted file mode 100644 index 7e782d8294..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDModelGroupDefinitionCommand.java +++ /dev/null @@ -1,124 +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.commands; - -import java.util.List; - -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; -import org.w3c.dom.Text; - -public class AddXSDModelGroupDefinitionCommand extends BaseCommand -{ - XSDConcreteComponent parent; - boolean isReference; - - public AddXSDModelGroupDefinitionCommand(String label, XSDConcreteComponent parent, boolean isReference) - { - super(label); - this.parent = parent; - this.isReference = isReference; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.gef.commands.Command#execute() - */ - public void execute() - { - if (parent instanceof XSDSchema) - { - ensureSchemaElement((XSDSchema)parent); - } - try - { - beginRecording(parent.getElement()); - if (!isReference) - { - XSDModelGroupDefinition def = createXSDModelGroupDefinition(); - addedXSDConcreteComponent = def; - } - else - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition(); - XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle(); - particle.setContent(def); - List list = parent.getSchema().getModelGroupDefinitions(); - int length = list.size(); - if (length > 1) - { - for (int i = 0; i < length; i++) - { - XSDModelGroupDefinition gr = (XSDModelGroupDefinition) list.get(i); - if (gr.getModelGroup() != parent) - { - def.setResolvedModelGroupDefinition(gr); - } - } - } - else if (length <= 1) - { - XSDModelGroupDefinition newGroupDef = createXSDModelGroupDefinition(); - def.setResolvedModelGroupDefinition(newGroupDef); - } - - if (parent instanceof XSDModelGroup) - { - ((XSDModelGroup) parent).getContents().add(particle); - } - formatChild(def.getElement()); - addedXSDConcreteComponent = def; - } - } - finally - { - endRecording(); - } - } - - protected XSDModelGroupDefinition createXSDModelGroupDefinition() - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition(); - List list = parent.getSchema().getModelGroupDefinitions(); - String newName = XSDCommonUIUtils.createUniqueElementName("NewGroupDefinition", list); //$NON-NLS-1$ - def.setName(newName); - - XSDModelGroup modelGroup = createModelGroup(); - def.setModelGroup(modelGroup); - Text textNode = parent.getSchema().getDocument().createTextNode("\n"); //$NON-NLS-1$ - parent.getSchema().getElement().appendChild(textNode); - parent.getSchema().getContents().add(def); - formatChild(def.getElement()); - return def; - } - - protected XSDModelGroup createModelGroup() - { - XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); - XSDParticle particle = factory.createXSDParticle(); - XSDModelGroup modelGroup = factory.createXSDModelGroup(); - modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); - particle.setContent(modelGroup); - - return modelGroup; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDRedefineCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDRedefineCommand.java deleted file mode 100644 index e2fd36721a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDRedefineCommand.java +++ /dev/null @@ -1,44 +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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; - -public class AddXSDRedefineCommand extends AddXSDSchemaDirectiveCommand -{ - public AddXSDRedefineCommand(String label, XSDSchema schema) - { - super(label); - this.xsdSchema = schema; - } - - public void execute() - { - super.execute(); - try - { - // Add this after if we don't have a DOM Node yet - beginRecording(xsdSchema.getElement()); - XSDRedefine xsdRedefine = XSDFactory.eINSTANCE.createXSDRedefine(); - xsdRedefine.setSchemaLocation(""); //$NON-NLS-1$ - xsdSchema.getContents().add(findNextPositionToInsert(), xsdRedefine); - addedXSDConcreteComponent = xsdRedefine; - formatChild(xsdSchema.getElement()); - } - finally - { - endRecording(); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSchemaDirectiveCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSchemaDirectiveCommand.java deleted file mode 100644 index a4f9008868..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSchemaDirectiveCommand.java +++ /dev/null @@ -1,60 +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.commands; - -import java.util.Iterator; - -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSchemaDirective; - -public abstract class AddXSDSchemaDirectiveCommand extends BaseCommand -{ - protected XSDSchema xsdSchema; - - public AddXSDSchemaDirectiveCommand(String label) - { - super(label); - } - - public void undo() - { - super.undo(); - } - - protected boolean adopt(XSDConcreteComponent model) - { - return false; - } - - protected int findNextPositionToInsert() - { - int index = 0; - for (Iterator i = xsdSchema.getContents().iterator(); i.hasNext(); ) - { - Object o = i.next(); - if (o instanceof XSDSchemaDirective) - { - index ++; - } - else - { - break; - } - } - return index; - } - - public void execute() - { - ensureSchemaElement(xsdSchema); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSimpleTypeDefinitionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSimpleTypeDefinitionCommand.java deleted file mode 100644 index 8cabbef36d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/AddXSDSimpleTypeDefinitionCommand.java +++ /dev/null @@ -1,91 +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.commands; - -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Text; - -public final class AddXSDSimpleTypeDefinitionCommand extends BaseCommand -{ - XSDConcreteComponent parent; - XSDSimpleTypeDefinition createdSimpleType; - private String nameToAdd; - - public AddXSDSimpleTypeDefinitionCommand(String label, XSDConcreteComponent parent) - { - super(label); - this.parent = parent; - } - - public void setNameToAdd(String nameToAdd) - { - this.nameToAdd = nameToAdd; - } - - public void execute() - { - if (parent instanceof XSDSchema) - { - ensureSchemaElement((XSDSchema)parent); - } - - try - { - beginRecording(parent.getElement()); - XSDSimpleTypeDefinition typeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - typeDef.setBaseTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string")); //$NON-NLS-1$ - - if (parent instanceof XSDSchema) - { - typeDef.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewSimpleType" : nameToAdd, ((XSDSchema) parent).getTypeDefinitions())); //$NON-NLS-1$ - createdSimpleType = typeDef; - try - { - XSDSchema xsdSchema = (XSDSchema) parent; - Text textNode = xsdSchema.getDocument().createTextNode("\n"); //$NON-NLS-1$ - xsdSchema.getElement().appendChild(textNode); - xsdSchema.getContents().add(typeDef); - } - catch (Exception e) - { - - } - } - else if (parent instanceof XSDElementDeclaration) - { - ((XSDElementDeclaration) parent).setAnonymousTypeDefinition(typeDef); - } - else if (parent instanceof XSDAttributeDeclaration) - { - ((XSDAttributeDeclaration) parent).setAnonymousTypeDefinition(typeDef); - } - formatChild(createdSimpleType.getElement()); - - addedXSDConcreteComponent = createdSimpleType; - } - finally - { - endRecording(); - } - } - - public XSDSimpleTypeDefinition getCreatedSimpleType() - { - return createdSimpleType; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/BaseCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/BaseCommand.java deleted file mode 100644 index dbbca4ccf6..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/BaseCommand.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.commands; - -import java.util.Map; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.emf.common.util.URI; -import org.eclipse.gef.commands.Command; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - -public class BaseCommand extends Command -{ - private static final String XML = "xml"; //$NON-NLS-1$ - - XSDConcreteComponent addedXSDConcreteComponent; - - public BaseCommand() - { - super(); - } - - public BaseCommand(String label) - { - // Commands inherit their name from the associated action. - // This label shows up in the undo menu and it would look ugly with the mnemonic in it. - // Ideally, we'd have separate strings. - - super(label.replaceFirst("&", "")); - } - - public XSDConcreteComponent getAddedComponent() - { - return addedXSDConcreteComponent; - } - - IDOMNode domNode; - protected void beginRecording(Object element) { - if (element instanceof IDOMNode) - { - domNode = (IDOMNode) element; - domNode.getModel().beginRecording(this, getUndoDescription()); - } - } - - protected void endRecording() - { - if (domNode != null) - domNode.getModel().endRecording(this); - } - - protected String getUndoDescription() { - return getLabel(); - } - - protected void formatChild(Element child) - { - if (child instanceof IDOMNode) - { - IDOMModel model = ((IDOMNode)child).getModel(); - try - { - // tell the model that we are about to make a big model change - model.aboutToChangeModel(); - - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(child); - } - finally - { - // tell the model that we are done with the big model change - model.changedModel(); - } - } - } - - protected static void ensureSchemaElement(XSDSchema schema) - { - Document document = schema.getDocument(); - - Element schemaElement = document.getDocumentElement(); - - if (schemaElement == null) - { - String targetNamespace = getDefaultNamespace(schema); - schema.setTargetNamespace(targetNamespace); - Map qNamePrefixToNamespaceMap = schema.getQNamePrefixToNamespaceMap(); - qNamePrefixToNamespaceMap.put("tns", targetNamespace); - if (XSDEditorPlugin.getDefault().isQualifyXMLSchemaLanguage()) - { - String prefix = XSDEditorPlugin.getDefault().getXMLSchemaPrefix(); - schema.setSchemaForSchemaQNamePrefix(prefix); - qNamePrefixToNamespaceMap.put(prefix, XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); - } - else - { - qNamePrefixToNamespaceMap.put(null, XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); - } - - schema.updateElement(); - ensureXMLDirective(document); - } - } - - private static void ensureXMLDirective(Document document) - { - if (hasXMLDirective(document)) - { - return; - } - - Node firstChild = document.getFirstChild(); - ProcessingInstruction xmlDeclaration = getXMLDeclaration(document); - document.insertBefore(xmlDeclaration, firstChild); - Text textNode = document.createTextNode(System.getProperty("line.separator")); - document.insertBefore(textNode, firstChild); - } - - private static boolean hasXMLDirective(Document document) - { - Node firstChild = document.getFirstChild(); - - if (firstChild == null) - { - return false; - } - - if (firstChild.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE) - { - return false; - } - - ProcessingInstruction processingInstruction = (ProcessingInstruction)firstChild; - - if (!XML.equals(processingInstruction.getTarget())) - { - return false; - } - - return true; - } - - private static ProcessingInstruction getXMLDeclaration(Document document) - { - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - if (charSet == null || charSet.trim().equals("")) - { - charSet = "UTF-8"; - } - ProcessingInstruction xmlDeclaration = document.createProcessingInstruction(XML, "version=\"1.0\" encoding=\"" + charSet + "\""); - return xmlDeclaration; - } - - private static String getDefaultNamespace(XSDSchema schema) - { - String namespace = XSDEditorPlugin.getDefault().getXMLSchemaTargetNamespace(); - - if (!namespace.endsWith("/")) - { - namespace = namespace.concat("/"); - } - - namespace += getFileName(schema) + "/"; - - return namespace; - - } - - private static String getFileName(XSDSchema schema) - { - URI schemaURI = schema.eResource().getURI(); - IPath filePath = new Path(schemaURI.toString()); - return filePath.removeFileExtension().lastSegment().toString(); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ChangeToLocalSimpleTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ChangeToLocalSimpleTypeCommand.java deleted file mode 100644 index bf10d8b590..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ChangeToLocalSimpleTypeCommand.java +++ /dev/null @@ -1,80 +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.commands; - -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - -public class ChangeToLocalSimpleTypeCommand extends BaseCommand -{ - XSDFeature parent; - XSDSimpleTypeDefinition anonymousSimpleType; - XSDSimpleTypeDefinition currentType; - - public ChangeToLocalSimpleTypeCommand(String label, XSDFeature parent) - { - super(label); - this.parent = parent; - -// if (parent instanceof XSDElementDeclaration) -// { -// XSDElementDeclaration element = (XSDElementDeclaration) parent; -// XSDTypeDefinition aType = element.getResolvedElementDeclaration().getTypeDefinition(); -// -// if (aType instanceof XSDSimpleTypeDefinition) -// { -// currentType = (XSDSimpleTypeDefinition) aType; -// } -// } - } - - public void execute() - { -// anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); -// anonymousSimpleType.setBaseTypeDefinition(currentType); - try - { - beginRecording(parent.getElement()); - - if (parent instanceof XSDElementDeclaration) - { - ((XSDElementDeclaration) parent).setAnonymousTypeDefinition(anonymousSimpleType); - } - else if (parent instanceof XSDAttributeDeclaration) - { - ((XSDAttributeDeclaration) parent).setAnonymousTypeDefinition(anonymousSimpleType); - } - formatChild(parent.getElement()); - } - finally - { - endRecording(); - } - } - - public void setAnonymousSimpleType(XSDSimpleTypeDefinition anonymousSimpleType) - { - this.anonymousSimpleType = anonymousSimpleType; - } - - public XSDSimpleTypeDefinition getAnonymousType() - { - if (anonymousSimpleType == null) - { - anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - anonymousSimpleType.setBaseTypeDefinition(currentType); - } - return anonymousSimpleType; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/DeleteCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/DeleteCommand.java deleted file mode 100644 index 09cc838b8a..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/DeleteCommand.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.commands; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesManager; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDWildcard; -import org.eclipse.xsd.util.XSDConstants; - -public class DeleteCommand extends BaseCommand -{ - XSDConcreteComponent target; - - public DeleteCommand(String label, XSDConcreteComponent target) - { - super(label); - this.target = target; - } - - public DeleteCommand(XSDConcreteComponent target) - { - super(Messages._UI_ACTION_DELETE); - this.target = target; - } - - public void execute() - { - XSDVisitor visitor = new XSDVisitor() - { - public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) - { - if (element.getTypeDefinition() == target) - { - XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"); //$NON-NLS-1$ - element.setTypeDefinition(type); - } - super.visitElementDeclaration(element); - } - }; - - XSDConcreteComponent parent = target.getContainer(); - XSDSchema schema = target.getSchema(); - - try - { - beginRecording(parent.getElement()); - boolean doCleanup = false; - if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) - { - doCleanup = true; - if (parent instanceof XSDParticle) - { - if (parent.getContainer() instanceof XSDModelGroup) - { - XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer(); - - modelGroup.getContents().remove(parent); - } - else if (parent.getContainer() instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer(); - complexType.setContent(null); - } - } - else if (parent instanceof XSDSchema) - { - visitor.visitSchema(target.getSchema()); - ((XSDSchema) parent).getContents().remove(target); - } - else if (parent instanceof XSDRedefine) - { - Object adapter = target.eAdapters().get(0); - if (adapter instanceof XSDModelGroupDefinitionAdapter) - { - ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true); - ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true); - } - ((XSDRedefine) parent).getContents().remove(target); - } - } - else if (target instanceof XSDAttributeDeclaration) - { - doCleanup = true; - if (parent instanceof XSDAttributeUse) - { - EObject obj = parent.eContainer(); - XSDComplexTypeDefinition complexType = null; - while (obj != null) - { - if (obj instanceof XSDComplexTypeDefinition) - { - complexType = (XSDComplexTypeDefinition) obj; - break; - } - obj = obj.eContainer(); - } - if (complexType != null) - { - complexType.getAttributeContents().remove(parent); - } - - if (parent.getContainer() instanceof XSDAttributeGroupDefinition) - { - XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer(); - - attrGroup.getContents().remove(parent); - } - } - else if (parent instanceof XSDSchema) - { - visitor.visitSchema(target.getSchema()); - ((XSDSchema) parent).getContents().remove(target); - } - } - else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) - { - doCleanup = true; - ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target); - } - else if (target instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target; - enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet); - } - else if (target instanceof XSDWildcard) - { - if (parent instanceof XSDParticle) - { - if (parent.getContainer() instanceof XSDModelGroup) - { - XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer(); - modelGroup.getContents().remove(parent); - } - } - else if (parent instanceof XSDComplexTypeDefinition) - { - ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null); - } - else if (parent instanceof XSDAttributeGroupDefinition) - { - ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null); - } - } - else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) - { - doCleanup = true; - ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string")); - } - else - { - if (parent instanceof XSDSchema) - { - doCleanup = true; - visitor.visitSchema(target.getSchema()); - ((XSDSchema) parent).getContents().remove(target); - } - else if(parent instanceof XSDRedefine) - { - doCleanup = false; - EList contents = ((XSDRedefine)parent).getContents(); - Object adapter = target.eAdapters().get(0); - if (adapter instanceof XSDComplexTypeDefinitionAdapter) - { - - ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true); - ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true); - } - else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) - { - - ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true); - ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true); - } - else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) - { - - ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true); - ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true); - } - contents.remove(target); - } - } - - if (doCleanup) - XSDDirectivesManager.removeUnusedXSDImports(schema); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java deleted file mode 100644 index 6ce4c73635..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleAddExtensionCommand.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.commands; - -import java.util.List; - -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDCommonUIUtils; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class ExtensibleAddExtensionCommand extends AddExtensionCommand -{ - protected XSDElementDeclaration element; - protected Element appInfo; - protected Element newElement; - - public ExtensibleAddExtensionCommand(String label) - { - super(label); - } - - public XSDElementDeclaration getXSDElementDeclarationElement() - { - return element; - } - - public Element getNewElement() - { - return newElement; - } - - public Element getAppInfo() - { - return appInfo; - } - - public XSDSchema getXSDSchema() - { - return component.getSchema(); - } - - public void setInputs(XSDConcreteComponent input, XSDElementDeclaration element) - { - this.component = input; - this.element = element; - } - - public XSDAnnotation getXSDAnnotation() - { - if (component != null) - { - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, false); - return xsdAnnotation; - } - return null; - } - - public void execute() - { - try - { - beginRecording(component.getElement()); - super.execute(); - doPreprocessing(); - addExtensionNode(); - doCustomizedActions(); - - formatChild(component.getElement()); - } - finally - { - endRecording(); - } - } - - protected void doPreprocessing() - { - - } - - protected void addExtensionNode() - { - XSDAnnotation xsdAnnotation = XSDCommonUIUtils.getInputXSDAnnotation(component, true); - XSDSchema schema= xsdAnnotation.getSchema(); - Element schemaElement = schema.getElement(); - - if (xsdAnnotation.getApplicationInformation().size() == 0) - { - appInfo = xsdAnnotation.createApplicationInformation(null); - xsdAnnotation.getElement().appendChild(appInfo); - List appInfos = xsdAnnotation.getApplicationInformation(); - appInfos.add(appInfo); - } - else - { - // use the first appInfo - appInfo = (Element)xsdAnnotation.getApplicationInformation().get(0); - } - - if (appInfo != null) - { - Document doc = appInfo.getOwnerDocument(); - String prefix = addToNamespaceTable(schemaElement); - newElement = doc.createElementNS(extensionsSchemaSpec.getNamespaceURI(), element.getName()); - newElement.setPrefix(prefix); - appInfo.appendChild(newElement); - - xsdAnnotation.updateElement(); - } - } - - protected String addToNamespaceTable(Element schemaElement) - { - String prefix = addNamespaceDeclarationIfRequired(schemaElement, "p", extensionsSchemaSpec.getNamespaceURI()); - return prefix; - } - - - protected void doCustomizedActions() - { - - } - - public void undo() - { - super.undo(); - } - - public Object getNewObject() - { - return newElement; - } - - // TODO... common this up with wsdl.ui - protected String addNamespaceDeclarationIfRequired(Element schemaElement, String prefixHint, String namespace) - { - String prefix = null; - NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument()); - namespaceTable.addElement(schemaElement); - prefix = namespaceTable.getPrefixForURI(namespace); - if (prefix == null) - { - String basePrefix = prefixHint; - prefix = basePrefix; - String xmlnsColon = "xmlns:"; //$NON-NLS-1$ - String attributeName = xmlnsColon + prefix; - int count = 0; - while (schemaElement.hasAttribute(attributeName)) - { - count++; - prefix = basePrefix + count; - attributeName = xmlnsColon + prefix; - } - schemaElement.setAttribute(attributeName, namespace); - } - return prefix; - } - - protected void addSchemaAttribute(Element schemaElement, String namespace, String attributeName, String attributeValue) - { - String prefix = null; - NamespaceTable namespaceTable = new NamespaceTable(schemaElement.getOwnerDocument()); - namespaceTable.addElement(schemaElement); - prefix = namespaceTable.getPrefixForURI(namespace); - try - { - if (prefix != null) - { - if (schemaElement.getAttributeNode(prefix + ":" + attributeName) == null) - schemaElement.setAttribute(prefix + ":" + attributeName, attributeValue); - } - else - { - if (schemaElement.getAttributeNode(attributeName) == null) - schemaElement.setAttribute(attributeName, attributeValue); - } - } - catch (Exception e) - { - - } - } - - protected void addSourceAttributeToAppInfo(String namespace) - { - if (appInfo.getAttributeNode(XSDConstants.SOURCE_ATTRIBUTE) == null) - appInfo.setAttribute(XSDConstants.SOURCE_ATTRIBUTE, namespace); - } - - /** - * - * @param element - * @param attributeName - * @param attributeValue - */ - protected void addAttribute(Element element, String attributeName, String attributeValue) - { - element.setAttribute(attributeName, attributeValue); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleRemoveExtensionNodeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleRemoveExtensionNodeCommand.java deleted file mode 100644 index cb5ff38f82..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/ExtensibleRemoveExtensionNodeCommand.java +++ /dev/null @@ -1,94 +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.commands; - -import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -public class ExtensibleRemoveExtensionNodeCommand extends BaseCommand -{ - protected Node node; - protected XSDConcreteComponent input; - - public ExtensibleRemoveExtensionNodeCommand(String label) - { - super(label); - } - - public void setNode(Node node) - { - this.node = node; - } - - public XSDConcreteComponent getInput() - { - return input; - } - - public void setInput(XSDConcreteComponent input) - { - this.input = input; - } - - public void execute() - { - super.execute(); - try - { - beginRecording(node); - - doPreprocessing(); - - if (node.getNodeType() == Node.ATTRIBUTE_NODE) - { - Attr attr = (Attr) node; - attr.getOwnerElement().removeAttributeNode(attr); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) - { - Node parent = node.getParentNode(); - if (parent != null) - { - XSDDOMHelper.removeNodeAndWhitespace(node); - - if (XSDDOMHelper.hasOnlyWhitespace(parent)) - { - if (XSDConstants.APPINFO_ELEMENT_TAG.equals(parent.getLocalName())) - { - XSDDOMHelper.removeNodeAndWhitespace(parent); - } - } - } - } - - doCustomizedActions(); - - } - finally - { - endRecording(); - } - } - - protected void doPreprocessing() - { - - } - - protected void doCustomizedActions() - { - - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineAttributeGroupCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineAttributeGroupCommand.java deleted file mode 100644 index 3d473b4e8d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineAttributeGroupCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.commands; - - -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -/** - * Creates a redefined attribute group based on the input attribute group and adds it to the parent redefine. - */ -public class RedefineAttributeGroupCommand extends AddRedefinedComponentCommand -{ - public RedefineAttributeGroupCommand(String label, XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - super(label, redefine, redefinableComponent); - } - - protected void doExecute() - { - XSDAttributeGroupDefinition redefinedAttributeGroupDefinition = XSDFactory.eINSTANCE.createXSDAttributeGroupDefinition(); - redefinedAttributeGroupDefinition.setName(redefinableComponent.getName()); - addedXSDConcreteComponent = redefinedAttributeGroupDefinition; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineComplexTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineComplexTypeCommand.java deleted file mode 100644 index 34dad50c1f..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineComplexTypeCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.commands; - - -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -/** - * Creates a redefined complex type based on the input complex type and adds it to the parent redefine. - */ -public class RedefineComplexTypeCommand extends AddRedefinedComponentCommand -{ - public RedefineComplexTypeCommand(String label, XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - super(label, redefine, redefinableComponent); - } - - protected void doExecute() - { - XSDComplexTypeDefinition redefinedComplexTypeDefinition = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - redefinedComplexTypeDefinition.setName(redefinableComponent.getName()); - redefinedComplexTypeDefinition.setContent(XSDFactory.eINSTANCE.createXSDComplexTypeDefinition().getContent()); - redefinedComplexTypeDefinition.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); - redefinedComplexTypeDefinition.setBaseTypeDefinition((XSDComplexTypeDefinition)redefinableComponent); - addedXSDConcreteComponent = redefinedComplexTypeDefinition; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineModelGroupCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineModelGroupCommand.java deleted file mode 100644 index 7366eebefc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineModelGroupCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.commands; - - -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; - - -/** - * Creates a redefined model group based on the input model group and adds it to the parent redefine. - */ -public class RedefineModelGroupCommand extends AddRedefinedComponentCommand -{ - - public RedefineModelGroupCommand(String label, XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - super(label, redefine, redefinableComponent); - } - - protected void doExecute() - { - XSDModelGroupDefinition modelGroup = (XSDModelGroupDefinition) redefinableComponent; - XSDModelGroupDefinition redefinedModelGroupDefinition = (XSDModelGroupDefinition)modelGroup.cloneConcreteComponent(true, false); - addedXSDConcreteComponent = redefinedModelGroupDefinition; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineSimpleTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineSimpleTypeCommand.java deleted file mode 100644 index 00765ae3d1..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RedefineSimpleTypeCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.commands; - - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDRedefinableComponent; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - - -/** - * Creates a redefined simple type based on the input simple type and adds it to the parent redefine. - */ -public class RedefineSimpleTypeCommand extends AddRedefinedComponentCommand -{ - public RedefineSimpleTypeCommand(String label, XSDRedefine redefine, XSDRedefinableComponent redefinableComponent) - { - super(label, redefine, redefinableComponent); - } - - protected void doExecute() - { - XSDSimpleTypeDefinition redefinedSimpleTypeDefinition = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - redefinedSimpleTypeDefinition.setName(redefinableComponent.getName()); - redefinedSimpleTypeDefinition.setBaseTypeDefinition((XSDSimpleTypeDefinition)redefinableComponent); - addedXSDConcreteComponent = redefinedSimpleTypeDefinition; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.java deleted file mode 100644 index a173a43def..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionAttributerCommand.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.commands; - -import org.eclipse.gef.commands.Command; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; - -/** - * @deprecated - */ -public class RemoveExtensionAttributerCommand extends Command -{ - Element hostElement; - Attr attr; - - public RemoveExtensionAttributerCommand(String label, Element hostElement, Attr attr) - { - super(label); - this.hostElement = hostElement; - this.attr = attr; - } - - public void execute() - { - super.execute(); - hostElement.removeAttributeNode(attr); - } - - public void undo() - { - super.undo(); - //TODO implement me - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java deleted file mode 100644 index d33c756093..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionElementCommand.java +++ /dev/null @@ -1,46 +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.commands; - -import org.eclipse.gef.commands.Command; -import org.eclipse.xsd.XSDAnnotation; -import org.w3c.dom.Node; - -/** - * @deprecated - */ -public class RemoveExtensionElementCommand extends Command -{ - XSDAnnotation xsdAnnotation; - Node appInfo; - - public RemoveExtensionElementCommand(String label, XSDAnnotation xsdAnnotation, Node appInfo) - { - super(label); - this.xsdAnnotation = xsdAnnotation; - this.appInfo = appInfo; - } - - public void execute() - { - super.execute(); - xsdAnnotation.getApplicationInformation().remove(appInfo); - xsdAnnotation.getElement().removeChild(appInfo); - xsdAnnotation.updateElement(); - } - - public void undo() - { - super.undo(); - xsdAnnotation.getApplicationInformation().add(appInfo); - xsdAnnotation.getElement().appendChild(appInfo); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java deleted file mode 100644 index e41166b976..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/RemoveExtensionNodeCommand.java +++ /dev/null @@ -1,61 +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.commands; - -import org.eclipse.wst.xsd.ui.internal.util.XSDDOMHelper; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -public class RemoveExtensionNodeCommand extends BaseCommand -{ - Node node; - - public RemoveExtensionNodeCommand(String label, Node node) - { - super(label); - this.node = node; - } - - public void execute() - { - super.execute(); - try - { - beginRecording(node); - if (node.getNodeType() == Node.ATTRIBUTE_NODE) - { - Attr attr = (Attr) node; - attr.getOwnerElement().removeAttributeNode(attr); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) - { - Node parent = node.getParentNode(); - if (parent != null) - { - XSDDOMHelper.removeNodeAndWhitespace(node); - - if (XSDDOMHelper.hasOnlyWhitespace(parent)) - { - if (XSDConstants.APPINFO_ELEMENT_TAG.equals(parent.getLocalName())) - { - XSDDOMHelper.removeNodeAndWhitespace(parent); - } - } - } - } - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeAndManagerDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeAndManagerDirectivesCommand.java deleted file mode 100644 index 1ec47ce5a6..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeAndManagerDirectivesCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesManager; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDTypeDefinition; - -public class SetBaseTypeAndManagerDirectivesCommand extends UpdateTypeReferenceAndManageDirectivesCommand -{ - - public SetBaseTypeAndManagerDirectivesCommand(XSDConcreteComponent concreteComponent, String componentName, String componentNamespace, IFile file) - { - super(concreteComponent, componentName, componentNamespace, file); - } - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - XSDComponent td = computeComponent(); - if (td != null && td instanceof XSDTypeDefinition) - { - SetBaseTypeCommand command = new SetBaseTypeCommand(concreteComponent, (XSDTypeDefinition) td); - command.execute(); - XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema()); - } - } - catch (Exception e) - { - - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeCommand.java deleted file mode 100644 index 7b74ec92a2..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetBaseTypeCommand.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDComplexTypeContent; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDVariety; - -public class SetBaseTypeCommand extends BaseCommand -{ - XSDConcreteComponent concreteComponent; - XSDTypeDefinition baseType; - XSDBaseAdapter adapter; - - - public SetBaseTypeCommand(XSDConcreteComponent concreteComponent, XSDTypeDefinition baseType) - { - super(Messages._UI_ACTION_SET_BASE_TYPE); - this.concreteComponent = concreteComponent; - this.baseType = baseType; - } - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - if (concreteComponent instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) concreteComponent; - XSDComplexTypeContent contentType = (baseType instanceof XSDComplexTypeDefinition) ? ((XSDComplexTypeDefinition)baseType).getContentType() : null; - - // Complex type simple content - if (baseType instanceof XSDSimpleTypeDefinition || (contentType != null && contentType instanceof XSDSimpleTypeDefinition)) - { - if (!(complexType.getContent() instanceof XSDSimpleTypeDefinition)) - { - XSDSimpleTypeDefinition simpleContent = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); - complexType.setContent(simpleContent); - } - } - // Complex type complex content - else if(baseType instanceof XSDComplexTypeDefinition) - { - if(!(complexType.getContent() instanceof XSDComplexTypeDefinition)) - { - XSDComplexTypeDefinition complexContent = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition(); - complexType.setContent(complexContent.getContent()); - } - } - complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); - complexType.setBaseTypeDefinition(baseType); - // vb This call should not be needed. The XSD Infoset model should reconcile itself properly. - complexType.updateElement(true); - formatChild(complexType.getElement()); - } - else if (concreteComponent instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) concreteComponent; - if (baseType instanceof XSDSimpleTypeDefinition) - { - XSDVariety variety = simpleType.getVariety(); - if (variety.getValue() == XSDVariety.ATOMIC) - { - simpleType.setBaseTypeDefinition((XSDSimpleTypeDefinition) baseType); - } - else if (variety.getValue() == XSDVariety.UNION) - { - simpleType.getMemberTypeDefinitions().add(baseType); - } - else if (variety.getValue() == XSDVariety.LIST) - { - simpleType.setItemTypeDefinition((XSDSimpleTypeDefinition) baseType); - } - } - } - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetMultiplicityCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetMultiplicityCommand.java deleted file mode 100644 index 1679feca03..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetMultiplicityCommand.java +++ /dev/null @@ -1,70 +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.commands; - -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDParticleContent; - -public class SetMultiplicityCommand extends BaseCommand -{ - XSDConcreteComponent parent; - int maxOccurs, minOccurs; - - /** - * @param parent - */ - public SetMultiplicityCommand(String label) - { - super(label); - } - - public void setMaxOccurs(int i) - { - maxOccurs=i; - } - - public void setMinOccurs(int i) - { - minOccurs=i; - } - - public void setXSDConcreteComponent(XSDConcreteComponent parent) - { - this.parent = parent; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.xsd.ui.internal.commands.AbstractCommand#run() - */ - public void execute() - { - try - { - beginRecording(parent.getElement()); - if (parent instanceof XSDParticleContent) - { - XSDParticleContent xsdParticleContent = (XSDParticleContent) parent; - XSDParticle xsdParticle = (XSDParticle) xsdParticleContent.getContainer(); - if (maxOccurs < 0) - { - maxOccurs = XSDParticle.UNBOUNDED; - } - xsdParticle.setMaxOccurs(maxOccurs); - xsdParticle.setMinOccurs(minOccurs); - } - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetTypeCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetTypeCommand.java deleted file mode 100644 index da4cb49c22..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetTypeCommand.java +++ /dev/null @@ -1,116 +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.commands; - -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification; -import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter; -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.actions.SetTypeAction; -import org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; - -public class SetTypeCommand extends BaseCommand -{ - XSDConcreteComponent parent; - private boolean continueApply; - XSDBaseAdapter adapter; - String action; - - public SetTypeCommand(String label, String ID, XSDConcreteComponent parent) - { - super(label); - this.parent = parent; - this.action = ID; - } - - public void setAdapter(XSDBaseAdapter adapter) - { - this.adapter = adapter; - } - - public void execute() - { - try - { - beginRecording(parent.getElement()); - ComponentReferenceEditManager componentReferenceEditManager = getComponentReferenceEditManager(); - continueApply = true; - if (parent instanceof XSDElementDeclaration) - { - if (action.equals(SetTypeAction.SET_NEW_TYPE_ID)) - { - ComponentSpecification newValue = (ComponentSpecification) invokeDialog(componentReferenceEditManager.getNewDialog()); - if (continueApply) - componentReferenceEditManager.modifyComponentReference(adapter, newValue); - } - else - { - ComponentSpecification newValue = (ComponentSpecification) invokeDialog(componentReferenceEditManager.getBrowseDialog()); - if (continueApply) - componentReferenceEditManager.modifyComponentReference(adapter, newValue); - } - formatChild(parent.getElement()); - } - } - finally - { - endRecording(); - } - } - - private Object invokeDialog(IComponentDialog dialog) - { - Object newValue = null; - - if (dialog == null) - { - return null; - } - - if (dialog.createAndOpen() == Window.OK) - { - newValue = dialog.getSelectedComponent(); - } - else - { - continueApply = false; - } - - return newValue; - } - - protected ComponentReferenceEditManager getComponentReferenceEditManager() - { - ComponentReferenceEditManager result = null; - IEditorPart editor = getActiveEditor(); - if (editor != null) - { - result = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - } - return result; - } - - private IEditorPart getActiveEditor() - { - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); - IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor(); - return editorPart; - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetXSDFacetValueCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetXSDFacetValueCommand.java deleted file mode 100644 index 45c6884bb7..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/SetXSDFacetValueCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; - -import org.eclipse.xsd.XSDFacet; - -public class SetXSDFacetValueCommand extends BaseCommand -{ - protected XSDFacet facet; - protected String value; - - public SetXSDFacetValueCommand(String label, XSDFacet facet) - { - super(label); - this.facet = facet; - } - - public SetXSDFacetValueCommand(String label, XSDFacet facet, String value) - { - super(label); - this.facet = facet; - this.value = value; - } - - public void setValue(String value) - { - this.value = value; - } - - public void execute() - { - try - { - beginRecording(facet.getElement()); - facet.setLexicalValue(value); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java deleted file mode 100644 index 7d38b4cb5c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceAndManagerDirectivesCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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.commands; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesManager; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; - -public class UpdateAttributeReferenceAndManagerDirectivesCommand extends UpdateComponentReferenceAndManageDirectivesCommand -{ - - public UpdateAttributeReferenceAndManagerDirectivesCommand(XSDConcreteComponent concreteComponent, String componentName, String componentNamespace, IFile file) - { - super(concreteComponent, componentName, componentNamespace, file); - } - - protected XSDComponent getDefinedComponent(XSDSchema schema, String componentName, String componentNamespace) - { - XSDAttributeDeclaration result = schema.resolveAttributeDeclaration(componentNamespace, componentName); - if (result.eContainer() == null) - { - result = null; - } - return result; - } - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - XSDComponent componentDef = computeComponent(); - if (componentDef != null) - { - UpdateAttributeReferenceCommand command = new UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, (XSDAttributeDeclaration) concreteComponent, - (XSDAttributeDeclaration) componentDef); - command.execute(); - XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema()); - } - } - catch (Exception e) - { - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java deleted file mode 100644 index 6af63752d3..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeReferenceCommand.java +++ /dev/null @@ -1,38 +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.commands; - -import org.eclipse.xsd.XSDAttributeDeclaration; - -public class UpdateAttributeReferenceCommand extends BaseCommand -{ - XSDAttributeDeclaration attribute, ref; - - public UpdateAttributeReferenceCommand(String label, XSDAttributeDeclaration attribute, XSDAttributeDeclaration ref) - { - super(label); - this.attribute = attribute; - this.ref = ref; - } - - public void execute() - { - try - { - beginRecording(attribute.getElement()); - attribute.setResolvedAttributeDeclaration(ref); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java deleted file mode 100644 index b76f241939..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateAttributeValueCommand.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.commands; - -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.w3c.dom.Element; - -/* - * This command is used from the extension view to edit extension elements - * and attributes which are implemented as DOM objects (not part of the EMF model) - * - * (trung) also used in XSDComplexTypeAdvancedSection to change attribute of - * specical attributes like block, restriction which is not part of EMF Model - */ -public class UpdateAttributeValueCommand extends BaseCommand -{ - protected Element element; - protected String attributeName; - protected String attributeValue; - - /** Whether the attribute should be deleted if value to - * be set is an empty String or null */ - protected boolean deleteIfValueEmpty = false; - - public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue, boolean deleteIfValueEmpty) - { - this.element = element; - this.attributeName = attributeName; - this.attributeValue = attributeValue; - this.deleteIfValueEmpty = deleteIfValueEmpty; - } - - public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue, String label) - { - this(element, attributeName, attributeValue, false); - - // The command label is shared with the actual UI label, which contains - // mnemonics and colon characters. Since we don't want these to show up in - // the undo menu we do a little bit of regular expression magic here to remove them. - - setLabel(NLS.bind(Messages._UI_ACTION_CHANGE, label.replaceAll("[&:]", ""))); - } - - public UpdateAttributeValueCommand(Element element, String attributeName, String attributeValue) - { - this(element, attributeName, attributeValue, false); - setLabel(NLS.bind(Messages._UI_ACTION_CHANGE, attributeName)); - } - - public void setDeleteIfEmpty(boolean v) - { - deleteIfValueEmpty = v; - } - - public void setAttributeName(String attributeName) - { - this.attributeName = attributeName; - } - - public void execute() - { - try - { - beginRecording(element); - if (deleteIfValueEmpty && - (attributeValue == null || attributeValue.equals("") ) ) - { - element.removeAttribute(attributeName); - } - else - { - element.setAttribute(attributeName, attributeValue); - } - - doPostProcessing(); - } - finally - { - endRecording(); - } - } - - protected void doPostProcessing() - { - - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComplexTypeDerivationBy.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComplexTypeDerivationBy.java deleted file mode 100644 index facae6a3d3..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComplexTypeDerivationBy.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; - -public class UpdateComplexTypeDerivationBy extends BaseCommand -{ - private XSDComplexTypeDefinition complexType; - private String derivation; - - public UpdateComplexTypeDerivationBy(XSDComplexTypeDefinition complexType, String derivation) - { - this.complexType = complexType; - this.derivation = derivation; - // TODO: use new Message bundle mechanism - setLabel(XSDEditorPlugin.getXSDString("_UI_DERIVEDBY_CHANGE")); - } - - public void execute() - { - super.execute(); - try - { - beginRecording(complexType.getElement()); - XSDTypeDefinition originalBaseType = complexType.getBaseType(); - if (derivation.equals(XSDConstants.EXTENSION_ELEMENT_TAG)) - { - complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); - } - else if (derivation.equals(XSDConstants.RESTRICTION_ELEMENT_TAG)) - { - complexType.setDerivationMethod(XSDDerivationMethod.RESTRICTION_LITERAL); - } - complexType.setBaseTypeDefinition(originalBaseType); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComponentReferenceAndManageDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComponentReferenceAndManageDirectivesCommand.java deleted file mode 100644 index 9a23f365bc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateComponentReferenceAndManageDirectivesCommand.java +++ /dev/null @@ -1,150 +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.commands; -import org.eclipse.core.resources.IFile; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDImport; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSchemaDirective; -import org.eclipse.xsd.util.XSDResourceImpl; -public abstract class UpdateComponentReferenceAndManageDirectivesCommand extends BaseCommand -{ - protected XSDConcreteComponent concreteComponent; - protected String componentName; - protected String componentNamespace; - protected IFile file; - - public UpdateComponentReferenceAndManageDirectivesCommand(XSDConcreteComponent concreteComponent, String componentName, String componentNamespace, IFile file) - { - this.concreteComponent = concreteComponent; - this.componentName = componentName; - this.componentNamespace = componentNamespace; - this.file = file; - } - - protected XSDComponent computeComponent() - { - XSDComponent result = null; - XSDSchema schema = concreteComponent.getSchema(); - XSDSchemaDirective directive = null; - - // lets see if the element is already visible to our schema - result = getDefinedComponent(schema, componentName, componentNamespace); - if (result == null) - { - // TODO (cs) we need to provide a separate command to do this part - // - // apparently the element is not yet visible, we need to add - // includes/imports to get to it - if (componentNamespace != null && componentNamespace.equals(schema.getTargetNamespace())) - { - // we need to add an include - // if the component's namespace is not null and matches the schema's - // target namespace - directive = XSDFactory.eINSTANCE.createXSDInclude(); - } - else if (componentNamespace == null) - { - // we need to add an include - // if the component's namespace is null, then we can just add it - // only if the current namespace is not null - directive = XSDFactory.eINSTANCE.createXSDInclude(); - - // we have to ensure the schema for schema prefix is NOT null - if (schema.getSchemaForSchemaQNamePrefix() == null) - { - String targetNS = schema.getTargetNamespace(); - if (targetNS == null) - targetNS = ""; - // this will just update the schema for schema prefix to be, say, xsd - UpdateNamespaceInformationCommand command = new UpdateNamespaceInformationCommand("", schema, "", targetNS); - command.execute(); - } - } - else - { - // we need to add an import - XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport(); - xsdImport.setNamespace(componentNamespace); - directive = xsdImport; - } - - String location = computeNiceLocation(schema.getSchemaLocation(), file); - directive.setSchemaLocation(location); - // TODO (cs) we should at the directive 'next' in the list of directives - // for now I'm just adding as the first thing in the schema :-( - // - schema.getContents().add(0, directive); - XSDSchema resolvedSchema = directive.getResolvedSchema(); - if (resolvedSchema == null) - { - String platformLocation = "platform:/resource" + file.getFullPath(); - Resource resource = concreteComponent.eResource().getResourceSet().createResource(URI.createURI(platformLocation)); - if (resource instanceof XSDResourceImpl) - { - try - { - resource.load(null); - XSDResourceImpl resourceImpl = (XSDResourceImpl) resource; - resolvedSchema = resourceImpl.getSchema(); - if (resolvedSchema != null) - { - directive.setResolvedSchema(resolvedSchema); - } - } - catch (Exception e) - { - } - } - } - if (resolvedSchema != null) - { - result = getDefinedComponent(resolvedSchema, componentName, componentNamespace); - } - else - { - // TODO (cs) consider setting some error state so that the client can - // provide a pop-dialog error - // we should also remove the import/include so save from cluttering - // the file with bogus directives - } - } - - return result; - } - - private final static String PLATFORM_RESOURCE_PREFIX = "platform:/resource"; - private String computeNiceLocation(String baseLocation, IFile file) - { - if (baseLocation.startsWith(PLATFORM_RESOURCE_PREFIX)) - { - URI baseURI = URI.createURI(baseLocation); - URI fileURI = URI.createPlatformResourceURI(file.getFullPath().toString()); - URI relative = fileURI.deresolve(baseURI, false, true, true); - return relative.toString(); - } - else - { - URI baseURI = URI.createURI(baseLocation); - URI fileURI = URI.createFileURI(file.getLocation().toOSString()); - URI relative = fileURI.deresolve(baseURI, false, true, true); - return relative.toString(); - } - } - - protected abstract XSDComponent getDefinedComponent(XSDSchema schema, String componentName, String componentNamespace); - - public abstract void execute(); -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateContentModelCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateContentModelCommand.java deleted file mode 100644 index 87a560efbb..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateContentModelCommand.java +++ /dev/null @@ -1,49 +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.commands; - -import org.eclipse.xsd.XSDCompositor; -import org.eclipse.xsd.XSDModelGroup; - -public class UpdateContentModelCommand extends BaseCommand -{ - XSDModelGroup xsdModelGroup; - XSDCompositor oldXSDCompositor, newXSDCompositor; - - - public UpdateContentModelCommand(String label, XSDModelGroup xsdModelGroup, XSDCompositor xsdCompositor) - { - super(label); - this.xsdModelGroup = xsdModelGroup; - this.newXSDCompositor = xsdCompositor; - this.oldXSDCompositor = xsdModelGroup.getCompositor(); - } - - - public void execute() - { - try - { - super.execute(); - beginRecording(xsdModelGroup.getElement()); - xsdModelGroup.setCompositor(newXSDCompositor); - } - finally - { - endRecording(); - } - } - - public void undo() - { - xsdModelGroup.setCompositor(oldXSDCompositor); - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceAndManageDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceAndManageDirectivesCommand.java deleted file mode 100644 index b8aeb47443..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceAndManageDirectivesCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesManager; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSchema; - -public class UpdateElementReferenceAndManageDirectivesCommand extends UpdateComponentReferenceAndManageDirectivesCommand -{ - public UpdateElementReferenceAndManageDirectivesCommand(XSDConcreteComponent concreteComponent, String componentName, String componentNamespace, IFile file) - { - super(concreteComponent, componentName, componentNamespace, file); - } - - protected XSDComponent getDefinedComponent(XSDSchema schema, String componentName, String componentNamespace) - { - XSDElementDeclaration result = schema.resolveElementDeclaration(componentNamespace, componentName); - if (result.eContainer() == null) - { - result = null; - } - return result; - } - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - XSDComponent elementDef = computeComponent(); - if (elementDef != null) - { - UpdateElementReferenceCommand command = new UpdateElementReferenceCommand(Messages._UI_ACTION_UPDATE_ELEMENT_REFERENCE, (XSDElementDeclaration) concreteComponent, - (XSDElementDeclaration) elementDef); - command.execute(); - XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema()); - } - } - catch (Exception e) - { - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceCommand.java deleted file mode 100644 index d4b52781f4..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateElementReferenceCommand.java +++ /dev/null @@ -1,39 +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.commands; - -import org.eclipse.xsd.XSDElementDeclaration; - -public class UpdateElementReferenceCommand extends BaseCommand -{ - XSDElementDeclaration element, ref; - - public UpdateElementReferenceCommand(String label, XSDElementDeclaration element, XSDElementDeclaration ref) - { - super(label); - this.element = element; - this.ref = ref; - } - - public void execute() - { - try - { - beginRecording(element.getElement()); - element.setResolvedElementDeclaration(ref); - } - finally - { - endRecording(); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMaxOccursCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMaxOccursCommand.java deleted file mode 100644 index d159eb17a9..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMaxOccursCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class UpdateMaxOccursCommand extends BaseCommand -{ - private int oldMaxOccurs; - private int newMaxOccurs; - private boolean removeMaxOccursAttribute; - - XSDParticle particle; - - public UpdateMaxOccursCommand(String label, XSDParticle particle, int MaxOccurs) - { - super(label); - this.newMaxOccurs = MaxOccurs; - this.particle = particle; - } - - public void execute() - { - try - { - Element element = particle.getElement(); - beginRecording(element); - removeMaxOccursAttribute = (!(element.hasAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE)))? true: false; - oldMaxOccurs = particle.getMaxOccurs(); - particle.setMaxOccurs(newMaxOccurs); - } - finally - { - endRecording(); - } - } - - public void redo() - { - execute(); - } - - public void undo() - { - if (removeMaxOccursAttribute) - { - particle.unsetMaxOccurs(); - } - else - { - particle.setMaxOccurs(oldMaxOccurs); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMinOccursCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMinOccursCommand.java deleted file mode 100644 index 5e317665a6..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateMinOccursCommand.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDAttributeUseCategory; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; - -public class UpdateMinOccursCommand extends BaseCommand -{ - private int oldMinOccurs; - private int newMinOccurs; - private boolean removeMinOccursAttribute; - - XSDComponent component; - - public UpdateMinOccursCommand(String label, XSDComponent component, int minOccurs) - { - super(label); - this.newMinOccurs = minOccurs; - this.component = component; - } - - public void execute() - { - Element element = component.getElement(); - try - { - beginRecording(element); - removeMinOccursAttribute = (!(element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE))) ? true : false; - - if (component instanceof XSDParticle) - { - oldMinOccurs = ((XSDParticle) component).getMinOccurs(); - ((XSDParticle) component).setMinOccurs(newMinOccurs); - } - else if (component instanceof XSDAttributeUse) - { - oldMinOccurs = (((XSDAttributeUse) component).getUse() == XSDAttributeUseCategory.REQUIRED_LITERAL ? 1 : 0); - if (newMinOccurs == 1) - ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.REQUIRED_LITERAL); - else - ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.OPTIONAL_LITERAL); - } - } - finally - { - endRecording(); - } - } - - public void undo() - { - if (component instanceof XSDParticle) - { - if (removeMinOccursAttribute) - { - ((XSDParticle) component).unsetMinOccurs(); - } - else - { - ((XSDParticle) component).setMinOccurs(oldMinOccurs); - } - } - else if (component instanceof XSDAttributeUse) - { - if (removeMinOccursAttribute) - { - ((XSDParticle) component).unsetMinOccurs(); - } - else - { - if (oldMinOccurs == 1) - ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.REQUIRED_LITERAL); - else - ((XSDAttributeUse) component).setUse(XSDAttributeUseCategory.OPTIONAL_LITERAL); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNameCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNameCommand.java deleted file mode 100644 index 730a7c2790..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNameCommand.java +++ /dev/null @@ -1,112 +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.commands; - -import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xsd.ui.internal.refactor.PerformUnsavedRefactoringOperation; -import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.XMLRefactoringComponent; -import org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameComponentProcessor; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; - -public class UpdateNameCommand extends BaseCommand -{ -// private String oldName; - private String newName; - private XSDNamedComponent component; - - public UpdateNameCommand(String label, XSDNamedComponent component, String newName) - { - super(label); - - if (component instanceof XSDComplexTypeDefinition && component.getName() == null && component.eContainer() instanceof XSDNamedComponent && ((XSDNamedComponent) component.eContainer()).getName() != null) - { - component = (XSDNamedComponent) component.eContainer(); - } - - this.component = component; - this.newName = newName; -// this.oldName = component.getName(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.gef.commands.Command#execute() - */ - public void execute() - { - try - { - beginRecording(component.getElement()); - renameComponent(newName); - } - finally - { - endRecording(); - } - } - - /** - * Performs a rename refactoring to rename the component and all the - * references to it within the current schema. - * - * @param newName the new component name. - */ - private void renameComponent(String newName) - { - // this is a 'globally' defined component (e.g. global element) - if (component.eContainer() instanceof XSDSchema) - { - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (workbenchWindow != null) - { - IWorkbenchPage page = workbenchWindow.getActivePage(); - if (page != null) - { - IEditorInput editorInput = page.getActiveEditor().getEditorInput(); - if (editorInput instanceof FileEditorInput) - { - RefactoringComponent refactoringComponent = new XMLRefactoringComponent( - component, - (IDOMElement)component.getElement(), - component.getName(), - component.getTargetNamespace()); - - RenameComponentProcessor processor = new RenameComponentProcessor(refactoringComponent, newName, true); - RenameRefactoring refactoring = new RenameRefactoring(processor); - PerformUnsavedRefactoringOperation operation = new PerformUnsavedRefactoringOperation(refactoring); - operation.run(null); - } - else - { - // We can't refactor rename external files - component.setName(newName); - } - } - } - } - else - { - // this is a 'locally' defined component (e.g. local element) - // no need to call refactoring since this component can't be referenced - component.setName(newName); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNamespaceInformationCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNamespaceInformationCommand.java deleted file mode 100644 index 35efdd6740..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNamespaceInformationCommand.java +++ /dev/null @@ -1,298 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.commands; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -import org.apache.xerces.util.XMLChar; -import org.eclipse.emf.ecore.EReference; -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.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class UpdateNamespaceInformationCommand extends BaseCommand -{ - protected XSDSchema xsdSchema; - protected String newPrefix, newTargetNamespace; - - public UpdateNamespaceInformationCommand(String label, XSDSchema xsdSchema, String newPrefix, String newTargetNamespace) - { - super(label); - this.xsdSchema = xsdSchema; - this.newPrefix = newPrefix; - this.newTargetNamespace = newTargetNamespace; - } - - public void execute() - { - ensureSchemaElement(xsdSchema); - - Element element = xsdSchema.getElement(); - try - { - //DocumentImpl doc = (DocumentImpl) element.getOwnerDocument(); - - String modelTargetNamespace = xsdSchema.getTargetNamespace(); - String oldNamespace = xsdSchema.getTargetNamespace(); - - TypesHelper helper = new TypesHelper(xsdSchema); - String oldPrefix = helper.getPrefix(element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE), false); - - if (modelTargetNamespace == null) - { - modelTargetNamespace = ""; //$NON-NLS-1$ - } - - String targetNamespace = newTargetNamespace.trim(); - String prefix = newPrefix.trim(); - - if (!validatePrefix(prefix) || !validateTargetNamespace(targetNamespace)) - { - return; - } - - if (prefix.length() > 0 && targetNamespace.length() == 0) - { - // can't have blank targetnamespace and yet specify a prefix - return; - } - - //doc.getModel().beginRecording(this, XSDEditorPlugin.getXSDString("_UI_TARGETNAMESPACE_CHANGE")); //$NON-NLS-1$ - beginRecording(element); - - String xsdForXSDPrefix = xsdSchema.getSchemaForSchemaQNamePrefix(); - Map map = xsdSchema.getQNamePrefixToNamespaceMap(); - - // Check if prefix is blank - // if it is, then make sure we have a prefix - // for schema for schema - if (prefix.length() == 0) - { - // if prefix for schema for schema is blank - // then set it to value specified in preference - // and update ALL nodes with this prefix - if (xsdForXSDPrefix == null || (xsdForXSDPrefix != null && xsdForXSDPrefix.trim().length() == 0)) - { - // get preference prefix - xsdForXSDPrefix = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); - // get a unique prefix by checking what's in the map - - xsdForXSDPrefix = getUniqueSchemaForSchemaPrefix(xsdForXSDPrefix, map); - element.setAttribute("xmlns:" + xsdForXSDPrefix, XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); //$NON-NLS-1$ - - updateAllNodes(element, xsdForXSDPrefix); - - // remove the old xmlns attribute for the schema for schema - if (element.hasAttribute("xmlns") && //$NON-NLS-1$ - element.getAttribute("xmlns").equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) //$NON-NLS-1$ - { - element.removeAttribute("xmlns"); //$NON-NLS-1$ - } - } - } - - if (targetNamespace.length() > 0 || (targetNamespace.length() == 0 && prefix.length() == 0)) - { - // clean up the old prefix for this schema - if (oldPrefix != null && oldPrefix.length() > 0) - { - element.removeAttribute("xmlns:" + oldPrefix); //$NON-NLS-1$ - // element.setAttribute("xmlns:" + prefix, targetNamespace); - // java.util.Map prefixToNameSpaceMap = - // xsdSchema.getQNamePrefixToNamespaceMap(); - // prefixToNameSpaceMap.remove(oldPrefix); - } - else - // if no prefix - { - if (element.hasAttribute("xmlns")) //$NON-NLS-1$ - { - if (!element.getAttribute("xmlns").equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) //$NON-NLS-1$ - { - element.removeAttribute("xmlns"); //$NON-NLS-1$ - } - } - } - } - - if (targetNamespace.length() > 0) - { - if (!modelTargetNamespace.equals(targetNamespace)) - { - element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, targetNamespace); - } - // now set the new xmlns:prefix attribute - if (prefix.length() > 0) - { - element.setAttribute("xmlns:" + prefix, targetNamespace); //$NON-NLS-1$ - } - else - { - element.setAttribute("xmlns", targetNamespace); //$NON-NLS-1$ - } - // set the targetNamespace attribute - } - else - // else targetNamespace is blank - { - if (prefix.length() == 0) - { - element.removeAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE); - } - } - - // do our own referential integrity - TargetNamespaceChangeHandler targetNamespaceChangeHandler = new TargetNamespaceChangeHandler(xsdSchema, oldNamespace, targetNamespace); - targetNamespaceChangeHandler.resolve(); - - updateElement(xsdSchema); - - //doc.getModel().endRecording(this); - } - finally - { - endRecording(); - } - } - - - // issue (cs) I don't have a clue why we need to call this method - // - private static void updateElement(XSDConcreteComponent concreteComp) - { - try - { - concreteComp.updateElement(); - } - catch (Exception e) - { - for (Iterator containments = concreteComp.eClass().getEAllReferences().iterator(); containments.hasNext(); ) - { - EReference eReference = (EReference)containments.next(); - if (eReference.isContainment()) - { - if (eReference.isMany()) - { - for (Iterator objects = ((Collection)concreteComp.eGet(eReference)).iterator(); objects.hasNext(); ) - { - XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent)objects.next(); - try - { - xsdConcreteComponent.updateElement(); - } - catch (Exception ex) {} - } - } - else - { - XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent)concreteComp.eGet(eReference); - if (xsdConcreteComponent != null) - { - try - { - xsdConcreteComponent.updateElement(); - } - catch (Exception ex) {} - } - } - } - } - } - } - private String getUniqueSchemaForSchemaPrefix(String xsdForXSDPrefix, Map map) - { - if (xsdForXSDPrefix == null || (xsdForXSDPrefix != null && xsdForXSDPrefix.trim().length() == 0)) - { - xsdForXSDPrefix = "xsd"; //$NON-NLS-1$ - } - // ensure prefix is unique - int prefixExtension = 1; - while (map.containsKey(xsdForXSDPrefix) && prefixExtension < 100) - { - xsdForXSDPrefix = xsdForXSDPrefix + String.valueOf(prefixExtension); - prefixExtension++; - } - return xsdForXSDPrefix; - } - - private void updateAllNodes(Element element, String prefix) - { - element.setPrefix(prefix); - NodeList list = element.getChildNodes(); - if (list != null) - { - for (int i = 0; i < list.getLength(); i++) - { - Node child = list.item(i); - if (child != null && child instanceof Element) - { - child.setPrefix(prefix); - if (child.hasChildNodes()) - { - updateAllNodes((Element) child, prefix); - } - } - } - } - } - - private boolean validateTargetNamespace(String ns) - { - // will allow blank namespace !! - if (ns.equals("")) //$NON-NLS-1$ - { - return true; - } - - String errorMessage = null; - try - { - URI testURI = new URI(ns); - testURI.isAbsolute(); - } - catch (URISyntaxException e) - { - errorMessage = XSDEditorPlugin.getXSDString("_WARN_INVALID_TARGET_NAMESPACE"); //$NON-NLS-1$ - } - - if (errorMessage == null || errorMessage.length() == 0) - { - return true; - } - return false; - } - - protected boolean validatePrefix(String prefix) - { - if (prefix != null && prefix.equals("")) return true; - return XMLChar.isValidNCName(prefix); - } - - public void redo() - { - execute(); - } - - public void undo() - { - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNumericBoundsFacetCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNumericBoundsFacetCommand.java deleted file mode 100644 index 0f5cea91e8..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateNumericBoundsFacetCommand.java +++ /dev/null @@ -1,168 +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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDMaxExclusiveFacet; -import org.eclipse.xsd.XSDMaxInclusiveFacet; -import org.eclipse.xsd.XSDMinExclusiveFacet; -import org.eclipse.xsd.XSDMinInclusiveFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - -public class UpdateNumericBoundsFacetCommand extends BaseCommand -{ - XSDSimpleTypeDefinition xsdSimpleType; - String max, min; - boolean includeMin, includeMax; - private boolean doUpdateMax = false, doUpdateMin = false; - XSDMinInclusiveFacet minInclusiveFacet; - XSDMinExclusiveFacet minExclusiveFacet; - XSDMaxInclusiveFacet maxInclusiveFacet; - XSDMaxExclusiveFacet maxExclusiveFacet; - - - public UpdateNumericBoundsFacetCommand(String label, XSDSimpleTypeDefinition xsdSimpleType, boolean includeMin, boolean includeMax) - { - super(label); - this.xsdSimpleType = xsdSimpleType; - this.includeMin = includeMin; - this.includeMax = includeMax; - - minInclusiveFacet = xsdSimpleType.getMinInclusiveFacet(); - minExclusiveFacet = xsdSimpleType.getMinExclusiveFacet(); - maxInclusiveFacet = xsdSimpleType.getMaxInclusiveFacet(); - maxExclusiveFacet = xsdSimpleType.getMaxExclusiveFacet(); - - } - - public void setMin(String min) - { - this.min = min; - doUpdateMin = true; - } - - public void setMax(String max) - { - this.max = max; - doUpdateMax = true; - } - - public void execute() - { - try - { - beginRecording(xsdSimpleType.getElement()); - - if (doUpdateMin) - { - if (includeMin) - { - if (minInclusiveFacet == null && min != null) - { - minInclusiveFacet = XSDFactory.eINSTANCE.createXSDMinInclusiveFacet(); - minInclusiveFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().add(minInclusiveFacet); - - if (minExclusiveFacet != null) - { - xsdSimpleType.getFacetContents().remove(minExclusiveFacet); - } - } - else if (minInclusiveFacet != null && min != null) - { - minInclusiveFacet.setLexicalValue(min); - } - else if (minInclusiveFacet != null && min == null) - { - xsdSimpleType.getFacetContents().remove(minInclusiveFacet); - } - } - else - // !includeMin - { - if (minExclusiveFacet == null && min != null) - { - minExclusiveFacet = XSDFactory.eINSTANCE.createXSDMinExclusiveFacet(); - minExclusiveFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().add(minExclusiveFacet); - - if (minInclusiveFacet != null) - { - xsdSimpleType.getFacetContents().remove(minInclusiveFacet); - } - } - else if (minExclusiveFacet != null && min != null) - { - minExclusiveFacet.setLexicalValue(min); - } - else if (minExclusiveFacet != null && min == null) - { - xsdSimpleType.getFacetContents().remove(minExclusiveFacet); - } - } - } - else if (doUpdateMax) - { - if (includeMax) - { - if (maxInclusiveFacet == null && max != null) - { - maxInclusiveFacet = XSDFactory.eINSTANCE.createXSDMaxInclusiveFacet(); - maxInclusiveFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().add(maxInclusiveFacet); - - if (maxExclusiveFacet != null) - { - xsdSimpleType.getFacetContents().remove(maxExclusiveFacet); - } - } - else if (maxInclusiveFacet != null && max != null) - { - maxInclusiveFacet.setLexicalValue(max); - } - else if (maxInclusiveFacet != null && max == null) - { - xsdSimpleType.getFacetContents().remove(maxInclusiveFacet); - } - } - else - // !includeMax - { - if (maxExclusiveFacet == null && max != null) - { - maxExclusiveFacet = XSDFactory.eINSTANCE.createXSDMaxExclusiveFacet(); - maxExclusiveFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().add(maxExclusiveFacet); - - if (maxInclusiveFacet != null) - { - xsdSimpleType.getFacetContents().remove(maxInclusiveFacet); - } - } - else if (maxExclusiveFacet != null && max != null) - { - maxExclusiveFacet.setLexicalValue(max); - } - else if (maxExclusiveFacet != null && max == null) - { - xsdSimpleType.getFacetContents().remove(maxExclusiveFacet); - } - } - } - - formatChild(xsdSimpleType.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateStringLengthFacetCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateStringLengthFacetCommand.java deleted file mode 100644 index b5e78e9280..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateStringLengthFacetCommand.java +++ /dev/null @@ -1,230 +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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDLengthFacet; -import org.eclipse.xsd.XSDMaxLengthFacet; -import org.eclipse.xsd.XSDMinLengthFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - -public class UpdateStringLengthFacetCommand extends BaseCommand -{ - XSDSimpleTypeDefinition xsdSimpleType; - String max, min; - private boolean doUpdateMax = false, doUpdateMin = false; - - public UpdateStringLengthFacetCommand(String label, XSDSimpleTypeDefinition xsdSimpleType) - { - super(label); - this.xsdSimpleType = xsdSimpleType; - } - - public void setMin(String min) - { - this.min = min; - doUpdateMin = true; - } - - public void setMax(String max) - { - this.max = max; - doUpdateMax = true; - } - - public void execute() - { - try - { - beginRecording(xsdSimpleType.getElement()); - XSDLengthFacet lengthFacet = xsdSimpleType.getEffectiveLengthFacet(); - XSDMinLengthFacet minLengthFacet = xsdSimpleType.getEffectiveMinLengthFacet(); - XSDMaxLengthFacet maxLengthFacet = xsdSimpleType.getEffectiveMaxLengthFacet(); - - 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 (doUpdateMax && !doUpdateMin) - { - if (maxLengthFacet != null) - { - if (max != null) - { - if (max.equals(currentMin)) - { - lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet(); - lengthFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().add(lengthFacet); - xsdSimpleType.getFacetContents().remove(maxLengthFacet); - xsdSimpleType.getFacetContents().remove(minLengthFacet); - } - else - { - if (lengthFacet != null) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - } - if (minLengthFacet == null && currentLength != null) - { - minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet(); - minLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(minLengthFacet); - } - maxLengthFacet.setLexicalValue(max); - } - } - else - { - xsdSimpleType.getFacetContents().remove(maxLengthFacet); - } - } - else - { - if (currentMin != null && currentMin.equals(max)) - { - if (lengthFacet == null) - { - lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet(); - xsdSimpleType.getFacetContents().add(lengthFacet); - } - lengthFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().remove(minLengthFacet); - } - else if (currentLength != null && !currentLength.equals(max)) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - - if (max != null) - { - maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet(); - maxLengthFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().add(maxLengthFacet); - } - - minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet(); - minLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(minLengthFacet); - } - else - { - if (lengthFacet != null) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - - minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet(); - minLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(minLengthFacet); - - } - maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet(); - maxLengthFacet.setLexicalValue(max); - xsdSimpleType.getFacetContents().add(maxLengthFacet); - } - } - } - else if (!doUpdateMax && doUpdateMin) - { - if (minLengthFacet != null) - { - if (min != null) - { - if (min.equals(currentMax)) - { - lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet(); - lengthFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().add(lengthFacet); - xsdSimpleType.getFacetContents().remove(maxLengthFacet); - xsdSimpleType.getFacetContents().remove(minLengthFacet); - } - else - { - if (lengthFacet != null) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - } - if (maxLengthFacet == null && currentLength != null) - { - maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet(); - maxLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(maxLengthFacet); - } - minLengthFacet.setLexicalValue(min); - } - } - else - { - xsdSimpleType.getFacetContents().remove(minLengthFacet); - } - } - else - { - if (currentMax != null && currentMax.equals(min)) - { - if (lengthFacet == null) - { - lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet(); - xsdSimpleType.getFacetContents().add(lengthFacet); - } - lengthFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().remove(maxLengthFacet); - } - else if (currentLength != null && !currentLength.equals(min)) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - - if (min != null) - { - minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet(); - minLengthFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().add(minLengthFacet); - } - - maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet(); - maxLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(maxLengthFacet); - } - else - { - minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet(); - minLengthFacet.setLexicalValue(min); - xsdSimpleType.getFacetContents().add(minLengthFacet); - - if (lengthFacet != null) - { - xsdSimpleType.getFacetContents().remove(lengthFacet); - - maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet(); - maxLengthFacet.setLexicalValue(currentLength); - xsdSimpleType.getFacetContents().add(maxLengthFacet); - } - } - } - } - formatChild(xsdSimpleType.getElement()); - } - finally - { - endRecording(); - } - } - -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTextValueCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTextValueCommand.java deleted file mode 100644 index 66636465db..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTextValueCommand.java +++ /dev/null @@ -1,61 +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.commands; - -import org.eclipse.wst.xml.ui.internal.tabletree.TreeContentHelper; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/* - * This command is used from the extension view to edit extension elements - * and which are implemented as DOM objects (not part of the EMF model) - */ -public class UpdateTextValueCommand extends BaseCommand -{ - Element element; - String value; - - public UpdateTextValueCommand(Element element, String value) - { - this.element = element; - this.value = value; - } - - - public void execute() - { - try - { - beginRecording(element); - Node textNode = null; - TreeContentHelper helper = new TreeContentHelper(); - for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) - { - if (node.getNodeType() == Node.TEXT_NODE && - !helper.isIgnorableText(node)) - { - textNode = node; - break; - } - } - if (textNode == null) - { - textNode = element.getOwnerDocument().createTextNode(""); - element.appendChild(textNode); - } - helper.setNodeValue(textNode, value); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceAndManageDirectivesCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceAndManageDirectivesCommand.java deleted file mode 100644 index 0ed77b38da..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceAndManageDirectivesCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.commands; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesManager; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDTypeDefinition; - -public class UpdateTypeReferenceAndManageDirectivesCommand extends UpdateComponentReferenceAndManageDirectivesCommand -{ - - public UpdateTypeReferenceAndManageDirectivesCommand(XSDConcreteComponent concreteComponent, - String componentName, String componentNamespace, IFile file) - { - super(concreteComponent, componentName, componentNamespace, file); - } - - - protected XSDComponent getDefinedComponent(XSDSchema schema, String componentName, String componentNamespace) - { - XSDTypeDefinition result = schema.resolveTypeDefinition(componentNamespace, componentName); - if (result.eContainer() == null) - { - result = null; - } - return result; - } - - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - XSDComponent td = computeComponent(); - if (td != null && td instanceof XSDTypeDefinition) - { - UpdateTypeReferenceCommand command = new UpdateTypeReferenceCommand(concreteComponent, (XSDTypeDefinition) td); - command.execute(); - XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema()); - } - } - catch (Exception e) - { - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceCommand.java deleted file mode 100644 index cda106c5bb..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateTypeReferenceCommand.java +++ /dev/null @@ -1,78 +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.commands; - -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; - -public class UpdateTypeReferenceCommand extends BaseCommand -{ - XSDConcreteComponent concreteComponent; - XSDTypeDefinition newType; - - public UpdateTypeReferenceCommand(XSDConcreteComponent concreteComponent, XSDTypeDefinition newType) - { - this.concreteComponent = concreteComponent; - this.newType = newType; - } - - public void execute() - { - try - { - beginRecording(concreteComponent.getElement()); - - if (concreteComponent instanceof XSDElementDeclaration) - { - setElementType((XSDElementDeclaration) concreteComponent); - } - else if (concreteComponent instanceof XSDAttributeUse) - { - setAttributeType((XSDAttributeUse) concreteComponent); - } - else if (concreteComponent instanceof XSDAttributeDeclaration) - { - setAttributeType((XSDAttributeDeclaration) concreteComponent); - } - } - finally - { - endRecording(); - } - } - - protected void setElementType(XSDElementDeclaration ed) - { - ed = ed.getResolvedElementDeclaration(); - if (ed != null) - { - ed.setTypeDefinition(newType); - } - } - - protected void setAttributeType(XSDAttributeUse attributeUse) - { - setAttributeType(attributeUse.getAttributeDeclaration()); - } - - protected void setAttributeType(XSDAttributeDeclaration ad) - { - ad = ad.getResolvedAttributeDeclaration(); - if (ad != null && newType instanceof XSDSimpleTypeDefinition) - { - ad.setTypeDefinition((XSDSimpleTypeDefinition)newType); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDPatternFacetCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDPatternFacetCommand.java deleted file mode 100644 index 3d1b6adc1d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDPatternFacetCommand.java +++ /dev/null @@ -1,76 +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.commands; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDPatternFacet; -import org.eclipse.xsd.XSDSimpleTypeDefinition; - -public class UpdateXSDPatternFacetCommand extends BaseCommand -{ - public static final int ADD = 0; - public static final int DELETE = 1; - public static final int UPDATE = 2; - - XSDSimpleTypeDefinition xsdSimpleTypeDefinition; - String value; - int actionType; - XSDPatternFacet patternToEdit; - - public UpdateXSDPatternFacetCommand(String label, XSDSimpleTypeDefinition xsdSimpleTypeDefinition, int actionType) - { - super(label); - this.xsdSimpleTypeDefinition = xsdSimpleTypeDefinition; - this.actionType = actionType; - - } - - public void setValue(String value) - { - this.value = value; - } - - public void setPatternToEdit(XSDPatternFacet patternToEdit) - { - this.patternToEdit = patternToEdit; - } - - public void execute() - { - try - { - beginRecording(xsdSimpleTypeDefinition.getElement()); - if (actionType == ADD) - { - XSDPatternFacet pattern = XSDFactory.eINSTANCE.createXSDPatternFacet(); - pattern.setLexicalValue(value); - xsdSimpleTypeDefinition.getFacetContents().add(pattern); - } - else if (actionType == DELETE) - { - Assert.isNotNull(patternToEdit); - if (xsdSimpleTypeDefinition.getFacetContents().contains(patternToEdit)) - xsdSimpleTypeDefinition.getFacetContents().remove(patternToEdit); - } - else if (actionType == UPDATE) - { - Assert.isNotNull(patternToEdit); - patternToEdit.setLexicalValue(value); - } - formatChild(xsdSimpleTypeDefinition.getElement()); - } - finally - { - endRecording(); - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDWhiteSpaceFacetCommand.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDWhiteSpaceFacetCommand.java deleted file mode 100644 index bd92c3fab8..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/commands/UpdateXSDWhiteSpaceFacetCommand.java +++ /dev/null @@ -1,60 +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.commands; - -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDWhiteSpace; -import org.eclipse.xsd.XSDWhiteSpaceFacet; - -public class UpdateXSDWhiteSpaceFacetCommand extends BaseCommand -{ - XSDSimpleTypeDefinition xsdSimpleTypeDefinition; - boolean doAddFacet; - - public UpdateXSDWhiteSpaceFacetCommand(String label, XSDSimpleTypeDefinition xsdSimpleType, boolean doAddFacet) - { - super(label); - this.xsdSimpleTypeDefinition = xsdSimpleType; - this.doAddFacet = doAddFacet; - } - - public void execute() - { - try - { - beginRecording(xsdSimpleTypeDefinition.getElement()); - XSDWhiteSpaceFacet whitespaceFacet = xsdSimpleTypeDefinition.getWhiteSpaceFacet(); - - if (doAddFacet) - { - if (whitespaceFacet == null) - { - whitespaceFacet = XSDFactory.eINSTANCE.createXSDWhiteSpaceFacet(); - xsdSimpleTypeDefinition.getFacetContents().add(whitespaceFacet); - } - whitespaceFacet.setLexicalValue(XSDWhiteSpace.COLLAPSE_LITERAL.getName()); - } - else - { - if (whitespaceFacet != null) - { - xsdSimpleTypeDefinition.getFacetContents().remove(whitespaceFacet); - } - } - formatChild(xsdSimpleTypeDefinition.getElement()); - } - finally - { - endRecording(); - } - } -} 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 321e5f8837..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/providers/XSDSectionLabelProvider.java +++ /dev/null @@ -1,172 +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.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.FileStoreEditorInput; -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(); - IEditorInput editorInput = editorPart.getEditorInput(); - boolean isReadOnly = false; - if (!(editorInput instanceof IFileEditorInput || editorInput instanceof FileStoreEditorInput)) - { - isReadOnly = true; - } - if (editorPart != null && xsdSchema != editorPart.getAdapter(XSDSchema.class) || isReadOnly) - { - 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 c0705c64ac..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractExtensionsSection.java +++ /dev/null @@ -1,615 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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(); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - extensionDetailsViewer.setCommandStack(getCommandStack()); - } - - 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_DELETE_BUTTON, 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 1d07b36818..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AbstractSection.java +++ /dev/null @@ -1,396 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IFileEditorInput; -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.ide.FileStoreEditorInput; -import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import org.eclipse.wst.xsd.ui.internal.editor.Messages; -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; - protected boolean isTraversing = false; - - 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; - } - - IEditorInput editorInput = owningEditor.getEditorInput(); - if (!(editorInput instanceof IFileEditorInput || editorInput instanceof FileStoreEditorInput)) - { - isReadOnly = true; - } - } - - public void refresh() - { - super.refresh(); - composite.setEnabled(!isReadOnly); - } - - 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; - } - } - } - } - } - - protected boolean shouldPerformComboSelection(int eventType, Object selectedItem) - { - // if traversing through combobox, don't automatically pop up - // the browse and new dialog boxes - boolean wasTraversing = isTraversing; - if (isTraversing) - isTraversing = false; - - // we only care about default selecting (hitting enter in combobox) - // for browse.. and new.. otherwise, selection event will be fired - if (eventType == SWT.DefaultSelection) - { - if (selectedItem instanceof String && ((Messages._UI_COMBO_BROWSE.equals(selectedItem) || Messages._UI_COMBO_NEW.equals(selectedItem)))) - return true; - return false; - } - - // if was traversing and got selection event, do nothing if it's - // browse.. or new.. - if (wasTraversing && selectedItem instanceof String) - { - if (Messages._UI_COMBO_BROWSE.equals(selectedItem) || Messages._UI_COMBO_NEW.equals(selectedItem)) - { - return false; - } - } - return true; - } -} 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 8de7f40285..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/AnnotationSection.java +++ /dev/null @@ -1,166 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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)); - } - } - else - { - simpleText.setText(""); - } - } - 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 e301ebbc41..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/CommonDirectivesSection.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.HashMap; - -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.IEditorInput; -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 = null; - IEditorInput editorInput = getActiveEditor().getEditorInput(); - if (editorInput instanceof IFileEditorInput) - { - currentIFile = ((IFileEditorInput)editorInput).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$ - final String normalizedURI = URI.encodeFragment(URIHelper.addImpliedFileProtocol(normalizedXSDFile), true).toString(); - XSDParser parser = new XSDParser(new HashMap()); - parser.parse(normalizedURI); - 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 e8e2adde5c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/EnumerationsSection.java +++ /dev/null @@ -1,392 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.common.util.XSDCommonUIUtils; -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(); - String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList); //$NON-NLS-1$ - - AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, (XSDSimpleTypeDefinition) input); - command.setValue(newName); - 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 556acfa0e8..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, 2009 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) - { - if (element.hasAttribute(XSDConstants.MINOCCURS_ATTRIBUTE) && refreshMinText) - { - String min = element.getAttribute(XSDConstants.MINOCCURS_ATTRIBUTE); - minCombo.setText(min); - } - if (element.hasAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE) && refreshMaxText) - { - String max = element.getAttribute(XSDConstants.MAXOCCURS_ATTRIBUTE); - 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 b9efd04c87..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/RefactoringSection.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 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.jface.viewers.StructuredSelection; -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.handlers.RenameHandler; -import org.eclipse.xsd.XSDSchema; - -public abstract class RefactoringSection extends AbstractSection implements IHyperlinkListener -{ - /** - * Clicking on it invokes the refactor->rename action. - */ - private ImageHyperlink renameHyperlink; - - protected boolean hideHyperLink; - - /** - * 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 = new StructuredSelection(input); - ISelectionMapper mapper = (ISelectionMapper) editor.getAdapter(ISelectionMapper.class); - selection = mapper != null ? mapper.mapSelection(selection) : selection; - RenameHandler renameHandler = new RenameHandler(); - renameHandler.execute(selection, schema); - } - - protected void showLink(boolean isVisible) - { - renameHyperlink.setVisible(isVisible); - } - - /** - * 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 e8798bb0c5..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SchemaLocationSection.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.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.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesSchemaLocationUpdater; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDRedefine; -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) - { - XSDDirectivesSchemaLocationUpdater.updateSchemaLocation(xsdSchema,input,true); - 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; - } -} 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 c13b65ddca..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/SpecificConstraintsWidget.java +++ /dev/null @@ -1,727 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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; - -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; - - /** - * @deprecated - * @param composite - * @param factory - * @param feature - * @param input - * @param facetSection - */ - public SpecificConstraintsWidget(Composite composite, TabbedPropertySheetWidgetFactory factory, XSDFeature feature, XSDSimpleTypeDefinition input, XSDFacetSection facetSection) - { - this(composite, factory, feature, input, facetSection, ENUMERATION); - } - - public SpecificConstraintsWidget(Composite composite, TabbedPropertySheetWidgetFactory factory, XSDFeature feature, XSDSimpleTypeDefinition input, XSDFacetSection facetSection, int kind) - { - this.factory = factory; - this.input = input; - this.composite = composite; - this.feature = feature; - this.facetSection = facetSection; - this.kind = kind; - - 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.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.addSelectionListener(this); - - setButtonStates(kind); - 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 int getConstraintKind() - { - return this.kind; - } - - protected void setButtonStates(int kind) - { - boolean add, addUsing, delete, edit; - - boolean listHasItems = false; - StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); - if (selection != null) - { - if (selection.toList().size() > 0) - { - listHasItems = true; - } - } - - if (kind == ENUMERATION) - { - add = true; - addUsing = true; - edit = false; - } - else if (kind == PATTERN) - { - add = false; - addUsing = true; - edit = listHasItems; - } - else - { - add = true; - addUsing = true; - edit = true; - } - delete = listHasItems; - - if (!addButton.isDisposed()) - { - addButton.setEnabled(add); - } - if (!addUsingDialogButton.isDisposed()) - { - addUsingDialogButton.setEnabled(addUsing); - } - if (!deleteButton.isDisposed()) - { - deleteButton.setEnabled(delete); - } - if (!editButton.isDisposed()) - { - editButton.setEnabled(edit); - } - } - - public void widgetSelected(SelectionEvent e) - { - XSDSimpleTypeDefinition st = input; - if (e.widget == addButton) - { - List enumList = st.getEnumerationFacets(); - String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList); //$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); - 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(); - } - } - 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(); - pattern.setLexicalValue(newPattern); - constraintsTableViewer.refresh(); - } - } - } - } - - setButtonStates(this.kind); - } - - public void widgetDefaultSelected(SelectionEvent e) - { - - } - - - public void setConstraintKind(int kind) - { - this.kind = kind; - setButtonStates(kind); - constraintsTableViewer.setInput(input); - constraintsTableViewer.refresh(); - } - - public void doModify(Object element, String property, Object value) - { - setButtonStates(this.kind); - 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 a17ab481c2..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAnyElementContentsSection.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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; - -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, Messages._UI_LABEL_ATTRIBUTES_NAMESPACE); - 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, Messages._UI_LABEL_ATTRIBUTES_PROCESSCONTENTS); - 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 1ab3e25504..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeDeclarationSection.java +++ /dev/null @@ -1,908 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.osgi.util.NLS; -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.BaseCommand; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -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 - // ------------------------------------------------------------------ - if (!hideHyperLink) - { - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isAttributeReference); - } - else - { - getWidgetFactory().createCLabel(composite, ""); - } - - - // ------------------------------------------------------------------ - // 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.addListener(SWT.Traverse, this); - componentNameCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ATTRIBUTE__NAME); - - // dummy - 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); - typeCombo.addListener(SWT.Traverse, 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); - if (manager != null) - { - ComponentSpecification[] items = manager.getQuickPicks(); - - typeCombo.removeAll(); - typeCombo.add(Messages._UI_COMBO_BROWSE); - typeCombo.add(Messages._UI_COMBO_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 !=null && componentSpecification!=null && 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 doWidgetDefaultSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - String selection = typeCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else if (e.widget == componentNameCombo) - { - String selection = componentNameCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - String selection = typeCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else if (e.widget == componentNameCombo) - { - String selection = componentNameCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - private void handleWidgetSelection(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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); - } - else if ( selection.equals(Messages._UI_COMBO_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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_COMBO_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) - { - final String newValue = usageCombo.getText(); - if (element != null) - { - PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_USAGE) - { - protected void doExecuteSteps() - { - if (newValue.length() == 0) - element.removeAttribute(XSDConstants.USE_ATTRIBUTE); - else - element.setAttribute(XSDConstants.USE_ATTRIBUTE, newValue); - } - }; - getCommandStack().execute(command); - } - } - else if (e.widget == formCombo) - { - final String newValue = formCombo.getText(); - if (element != null) - { - PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FORM) - { - protected void doExecuteSteps() - { - if (newValue.length() == 0) - element.removeAttribute(XSDConstants.FORM_ATTRIBUTE); - else - element.setAttribute(XSDConstants.FORM_ATTRIBUTE, newValue); - } - }; - getCommandStack().execute(command); - } - } - else if (e.widget == defaultButton) - { - boolean newValue = defaultButton.getSelection(); - if (element != null) - { - if (newValue) - { - if (element.hasAttribute(XSDConstants.FIXED_ATTRIBUTE)) - { - final String value = element.getAttribute(XSDConstants.FIXED_ATTRIBUTE); - - PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) - { - protected void doExecuteSteps() - { - element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE); - element.setAttribute(XSDConstants.DEFAULT_ATTRIBUTE, value); - } - }; - getCommandStack().execute(command); - } - } - } - } - else if (e.widget == fixedButton) - { - boolean newValue = fixedButton.getSelection(); - if (element != null) - { - if (newValue) - { - if (element.hasAttribute(XSDConstants.DEFAULT_ATTRIBUTE)) - { - final String value = element.getAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) - { - protected void doExecuteSteps() - { - element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - element.setAttribute(XSDConstants.FIXED_ATTRIBUTE, value); - } - }; - getCommandStack().execute(command); - } - } - } - } - } - super.doWidgetSelected(e); - } - - protected void doHandleEvent(Event event) - { - if (event.type == SWT.Traverse) { - if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) { - isTraversing = true; - return; - } - } - 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) - { - PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_VALUE) - { - protected void doExecuteSteps() - { - element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE); - element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - } - }; - getCommandStack().execute(command); - } - else - { - UpdateAttributeValueCommand command = null; - if (fixedButton.getSelection()) - { - command = new UpdateAttributeValueCommand(element, XSDConstants.FIXED_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) - { - protected void doPostProcessing() - { - element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE); - } - }; - } - else - { - command = new UpdateAttributeValueCommand(element, XSDConstants.DEFAULT_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) - { - protected void doPostProcessing() - { - element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE); - } - }; - } - command.setDeleteIfEmpty(true); - 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(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); - componentNameCombo.removeListener(SWT.Traverse, this); - } - if (nameText != null && !nameText.isDisposed()) - removeListeners(nameText); - if (typeCombo != null && !typeCombo.isDisposed()) - { - typeCombo.removeSelectionListener(this); - typeCombo.removeListener(SWT.Traverse, 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(); - hideHyperLink = !xsdAttribute.isGlobal() || isAttributeReference; - } - } - - 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; - } - } - - protected class PropertiesChangeCommand extends BaseCommand - { - protected Element element; - public PropertiesChangeCommand(Element element, String label) - { - super(NLS.bind(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_CHANGE, label)); - this.element = element; - } - - public void execute() - { - try - { - beginRecording(element); - doExecuteSteps(); - } - finally - { - endRecording(); - } - } - - protected void doExecuteSteps() - { - - } - } -} 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 8a409f0d03..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDAttributeGroupDefinitionSection.java +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.common.util.XSDDirectivesManager; -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 - // ------------------------------------------------------------------ - if (!hideHyperLink) - { - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isReference); - } - else - { - getWidgetFactory().createCLabel(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(); - hideHyperLink = isReference; - } - } - - 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); - XSDDirectivesManager.removeUnusedXSDImports(namedComponent.getSchema()); - } - } - } - 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 4c4f99d749..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeAdvancedSection.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.wst.xsd.ui.internal.common.util.Messages; -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; - - CLabel abstractLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_ABSTRACT); - 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; - - CLabel blockLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_BLOCK); - 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; - - CLabel finalLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_FINAL); - 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; - - CLabel mixedLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_MIXED); - 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, Messages._UI_LABEL_BLOCK); - 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, Messages._UI_LABEL_FINAL); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == abstractCombo) - { - String value = abstractCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(complexType.getElement(), XSDConstants.ABSTRACT_ATTRIBUTE, value, Messages._UI_LABEL_ABSTRACT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == mixedCombo) - { - String value = mixedCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(complexType.getElement(), XSDConstants.MIXED_ATTRIBUTE, value, Messages._UI_LABEL_MIXED); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } - - 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; - } - - if (complexType.getElement().hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) - { - String blockAttValue = complexType.getElement().getAttribute(XSDConstants.BLOCK_ATTRIBUTE); - blockCombo.setText(blockAttValue); - } - else - { - blockCombo.setText(EMPTY); - } - blockCombo.setEnabled(enabled); - - if (complexType.getElement().hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) - { - String finalAttValue = complexType.getElement().getAttribute(XSDConstants.FINAL_ATTRIBUTE); - 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 ce8fecb970..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDComplexTypeSection.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.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.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.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.wst.xsd.ui.internal.util.XSDDOMHelper; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDSchema; -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); - baseTypeCombo.addListener(SWT.Traverse, 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); - showLink(!hideHyperLink); - - 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(); - XSDDOMHelper domHelper = new XSDDOMHelper(); - if(domHelper.getDerivedByElementFromComplexType(complexType.getElement()) != null) { - if (derivationMethod == XSDDerivationMethod.EXTENSION) - { - derivedByCombo.setText(XSDConstants.EXTENSION_ELEMENT_TAG); - } - else if (derivationMethod == XSDDerivationMethod.RESTRICTION) - { - derivedByCombo.setText(XSDConstants.RESTRICTION_ELEMENT_TAG); - } - } - } - - } - finally - { - setListenerEnabled(true); - } - } - - public void doWidgetDefaultSelected(SelectionEvent e) - { - if (e.widget == baseTypeCombo) - { - String selection = baseTypeCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == baseTypeCombo) - { - String selection = baseTypeCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - private void handleWidgetSelection(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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_COMBO_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(); - if (baseTypeCombo != null && !baseTypeCombo.isDisposed()) - baseTypeCombo.removeListener(SWT.Traverse, this); - } - - public void doHandleEvent(Event event) - { - if (event.type == SWT.Traverse) { - if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) { - isTraversing = true; - return; - } - } - 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; - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - setListenerEnabled(false); - if (input instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input; - hideHyperLink = !(complexType.getContainer() instanceof XSDSchema); - - } - - setListenerEnabled(true); - } - - private void fillTypesCombo() - { - baseTypeCombo.removeAll(); - baseTypeCombo.add(Messages._UI_COMBO_BROWSE); - baseTypeCombo.add(Messages._UI_COMBO_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 56c6aa98ab..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationAdvancedSection.java +++ /dev/null @@ -1,453 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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 Carver - STAR - added nillable advanced tab option, bug 209356 - *******************************************************************************/ - -package org.eclipse.wst.xsd.ui.internal.common.properties.sections; - -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.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; - protected CCombo nillableCombo; - - 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 booleanValues[] = { EMPTY, TRUE, FALSE }; - - 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; - - CLabel abstractLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_ABSTRACT); - 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; - - CLabel blockLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_BLOCK); - 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; - - CLabel finalLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FINAL); - 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; - - CLabel subGroupLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP); - 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); - substGroupCombo.addListener(SWT.Traverse, this); - applyAllListeners(substGroupCombo); - - // ------------------------------------------------------------------ - // Nillable Label - // ------------------------------------------------------------------ - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - CLabel nillableLabel = getWidgetFactory().createCLabel(composite, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NILLABLE); - nillableLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // NillableCombo - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - nillableCombo = getWidgetFactory().createCCombo(composite); - nillableCombo.setLayoutData(data); - nillableCombo.setEditable(false); - - nillableCombo.setItems(booleanValues); - nillableCombo.addSelectionListener(this); - - } - - public void doHandleEvent(Event e) - { - if (e.widget == substGroupCombo) - { - if (e.type == SWT.Traverse) { - if (e.detail == SWT.TRAVERSE_ARROW_NEXT || e.detail == SWT.TRAVERSE_ARROW_PREVIOUS) - { - isTraversing = true; - return; - } - } - - 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, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_SUBSTITUTION_GROUP); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } - - public void doWidgetDefaultSelected(SelectionEvent e) - { - if (e.widget == substGroupCombo) - { - String selection = substGroupCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == substGroupCombo) - { - String selection = substGroupCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - private void handleWidgetSelection(SelectionEvent e) - { - if (e.widget == blockCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = blockCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.BLOCK_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_BLOCK); - 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, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_FINAL); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - else if (e.widget == abstractCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = abstractCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.ABSTRACT_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_ABSTRACT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - 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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_COMBO_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); - } - } - else if (e.widget == nillableCombo) - { - XSDElementDeclaration eleDec = (XSDElementDeclaration) input; - String value = nillableCombo.getText(); - - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(eleDec.getElement(), XSDConstants.NILLABLE_ATTRIBUTE, value, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_NILLABLE); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } - - 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); - nillableCombo.setEnabled(true); - } - else - { - abstractCombo.setEnabled(false); - finalCombo.setEnabled(false); - substGroupCombo.setEnabled(false); - - // Nillable when used in a local element declaration can't be set on - // on elements that use @ref. - nillableCombo.setEnabled(!eleDec.isElementDeclarationReference()); - } - - Element element = eleDec.getElement(); - - if (element.hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) - { - String blockAttValue = element.getAttribute(XSDConstants.BLOCK_ATTRIBUTE); - blockCombo.setText(blockAttValue); - } - else - { - blockCombo.setText(EMPTY); - } - // We should show the value of the attribute regardless if it is invalid - // ie. as the user starts typing 'true' in the source, the properties view - // should show the value dynamically - if (element.hasAttribute(XSDConstants.NILLABLE_ATTRIBUTE)) - { - String attrValue = element.getAttribute(XSDConstants.NILLABLE_ATTRIBUTE); - nillableCombo.setText(attrValue); - } - else - { - nillableCombo.setText(EMPTY); - } - - if (element.hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) - { - String finalAttValue = element.getAttribute(XSDConstants.FINAL_ATTRIBUTE); - finalCombo.setText(finalAttValue); - } - else - { - finalCombo.setText(EMPTY); - } - - if (element.hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) - { - abstractCombo.setText(element.getAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)); - } - 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); - if (manager != null) - { - ComponentSpecification[] items = manager.getQuickPicks(); - - substGroupCombo.removeAll(); - substGroupCombo.add(Messages._UI_COMBO_BROWSE); - substGroupCombo.add(Messages._UI_COMBO_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; - } - - public void dispose() - { - if (substGroupCombo != null && !substGroupCombo.isDisposed()) - { - substGroupCombo.removeListener(SWT.Traverse, this); - } - super.dispose(); - } - -} 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 41223f0c27..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDElementDeclarationSection.java +++ /dev/null @@ -1,647 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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 - // ------------------------------------------------------------------ - if (!hideHyperLink) - { - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isElementReference); - } - else - { - getWidgetFactory().createCLabel(composite, ""); - } - - // ------------------------------------------------------------------ - // 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.addListener(SWT.Traverse, this); - componentNameCombo.setLayoutData(data); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(componentNameCombo, - XSDEditorCSHelpIds.GENERAL_TAB__ELEMENT__REFERENCE); - - // dummy - 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); - typeCombo.addListener(SWT.Traverse, 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(); - - hideHyperLink = !xsdElementDeclaration.isGlobal() || isElementReference; - typeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getTypeDefinition(); - } - } - - private void fillTypesCombo() - { - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - if (manager != null) - { - ComponentSpecification[] items = manager.getQuickPicks(); - - typeCombo.removeAll(); - typeCombo.add(Messages._UI_COMBO_BROWSE); - typeCombo.add(Messages._UI_COMBO_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 doWidgetDefaultSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - String selection = typeCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else if (e.widget == componentNameCombo) - { - String selection = componentNameCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typeCombo) - { - String selection = typeCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else if (e.widget == componentNameCombo) - { - String selection = componentNameCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - private void handleWidgetSelection(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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(true); - } - else if ( selection.equals(Messages._UI_COMBO_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_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - } - else if ( selection.equals(Messages._UI_COMBO_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) - { - if (event.type == SWT.Traverse) { - if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) { - isTraversing = true; - return; - } - } - 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); - componentNameCombo.removeListener(SWT.Traverse, 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); - typeCombo.removeListener(SWT.Traverse, 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); - if (manager != null) - { - componentNameCombo.removeAll(); - componentNameCombo.add(Messages._UI_COMBO_BROWSE); - componentNameCombo.add(Messages._UI_COMBO_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/XSDEnumerationFacetSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDEnumerationFacetSection.java deleted file mode 100644 index ab1b0061fd..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDEnumerationFacetSection.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.jface.viewers.ISelection; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -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.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.SetXSDFacetValueCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorCSHelpIds; -import org.eclipse.xsd.XSDEnumerationFacet; - -public class XSDEnumerationFacetSection extends AbstractSection -{ - CCombo finalCombo; - Text valueText; - - public XSDEnumerationFacetSection() - { - 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); - - // ------------------------------------------------------------------ - // ValueLabel - // ------------------------------------------------------------------ - data = new GridData(); - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - CLabel valueLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_VALUE); - valueLabel.setLayoutData(data); - - // ------------------------------------------------------------------ - // ValueText - // ------------------------------------------------------------------ - data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - valueText = getWidgetFactory().createText(composite, ""); //$NON-NLS-1$ - valueText.setLayoutData(data); - applyAllListeners(valueText); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(valueText, - XSDEditorCSHelpIds.GENERAL_TAB__SIMPLE_TYPE__NAME); - - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - } - - public void refresh() - { - super.refresh(); - - setListenerEnabled(false); - - valueText.setText(""); //$NON-NLS-1$ - - if (input instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet xsdEnumeration = (XSDEnumerationFacet)input; - - if(xsdEnumeration != null) - { - valueText.setText(xsdEnumeration.getLexicalValue()); - } - } - setListenerEnabled(true); - } - - public void doHandleEvent(Event event) - { - if (event.widget == valueText) - { - if (!valueText.getEditable()) - return; - - String value = valueText.getText(); - - if (input instanceof XSDEnumerationFacet) - { - XSDEnumerationFacet xsdEnumeration = (XSDEnumerationFacet)input; - - Command command = null; - command = new SetXSDFacetValueCommand(Messages._UI_ACTION_CHANGE_ENUMERATION_VALUE, - xsdEnumeration, value); - - if (command != null && getCommandStack() != null) - { - getCommandStack().execute(command); - valueText.setText(value); - } - } - } - } -} 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 4f953acc3d..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDFacetSection.java +++ /dev/null @@ -1,1019 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.XSDVariety; -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; - boolean isSimpleTypeRestriction; - private XSDTypeDefinition typeDefinition; - private XSDSimpleTypeDefinition xsdSimpleTypeDefinition; - private XSDSimpleTypeDefinition currentPrimitiveType, previousPrimitiveType; - private XSDElementDeclaration xsdElementDeclaration; - private XSDAttributeDeclaration xsdAttributeDeclaration; - private XSDFeature xsdFeature; - boolean hasMaxMinFacets; - - SpecificConstraintsWidget constraintsWidget; - - private int constraintKind = SpecificConstraintsWidget.ENUMERATION; - - 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, constraintKind); - 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) - { - isSimpleTypeRestriction = xsdSimpleTypeDefinition.getVariety().getValue() == XSDVariety.ATOMIC; - - 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 - && constraintsWidget.getConstraintKind() == SpecificConstraintsWidget.ENUMERATION) - || xsdSimpleTypeDefinition.getPatternFacets().size() == 0) - { - usePatternsButton.setSelection(false); - useEnumerationsButton.setSelection(true); - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.ENUMERATION); - constraintsWidget.addButton.setEnabled(true); - } - else if ((xsdSimpleTypeDefinition.getPatternFacets().size() > 0 - && constraintsWidget.getConstraintKind() == SpecificConstraintsWidget.PATTERN) - || xsdSimpleTypeDefinition.getEnumerationFacets().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); - } - constraintKind = constraintsWidget.getConstraintKind(); - constraintsWidget.setInput(xsdSimpleTypeDefinition); - - setWidgetsEnabled(isSimpleTypeRestriction && !isReadOnly); - composite.setEnabled(isSimpleTypeRestriction && !isReadOnly); - - setListenerEnabled(true); - } - - private void setWidgetsEnabled(boolean isEnabled) - { - if (collapseWhitespaceButton != null && !collapseWhitespaceButton.isDisposed()) - collapseWhitespaceButton.setEnabled(isEnabled); - if (useEnumerationsButton != null && !useEnumerationsButton.isDisposed()) - useEnumerationsButton.setEnabled(isEnabled); - if (usePatternsButton != null && !usePatternsButton.isDisposed()) - usePatternsButton.setEnabled(isEnabled); - if (minimumInclusiveCheckbox != null && !minimumInclusiveCheckbox.isDisposed()) - minimumInclusiveCheckbox.setEnabled(isEnabled); - if (maximumInclusiveCheckbox != null && !maximumInclusiveCheckbox.isDisposed()) - maximumInclusiveCheckbox.setEnabled(isEnabled); - if (constraintsWidget != null && !constraintsWidget.getControl().isDisposed()) - { - if(constraintsWidget.getConstraintKind() == SpecificConstraintsWidget.PATTERN) - { - constraintsWidget.addButton.setEnabled(false); - } - else - { - constraintsWidget.addButton.setEnabled(isEnabled); - } - constraintsWidget.addUsingDialogButton.setEnabled(isEnabled); - } - } - - 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.getBaseType()) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) //$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.getBaseType()) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("float").equals(xsdSimpleTypeDefinition.getBaseType()) || //$NON-NLS-1$ - xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("decimal").equals(xsdSimpleTypeDefinition.getBaseType())) //$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); - constraintKind = constraintsWidget.getConstraintKind(); - } - } - else if (e.widget == usePatternsButton) - { - constraintsWidget.addButton.setEnabled(false); - if (isListenerEnabled()) - { - constraintsWidget.setConstraintKind(SpecificConstraintsWidget.PATTERN); - constraintKind = constraintsWidget.getConstraintKind(); - } - } - } - - 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 98263e197c..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDImportSection.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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.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.Event; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xsd.ui.internal.common.util.XSDDirectivesSchemaLocationUpdater; -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.xsd.XSDImport; -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); - - XSDDirectivesSchemaLocationUpdater.updateSchemaLocation(xsdSchema,input,false); - refresh(); - setListenerEnabled(true); - prefixText.addListener(SWT.Modify, this); - } - } - - 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 fec1b37ad1..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDModelGroupDefinitionSection.java +++ /dev/null @@ -1,360 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.common.util.XSDDirectivesManager; -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 - // ------------------------------------------------------------------ - if (!hideHyperLink) - { - createRenameHyperlink(composite); - setRenameHyperlinkEnabled(!isReference); - } - else - { - getWidgetFactory().createCLabel(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(); - hideHyperLink = isReference; - } - } - - 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); - XSDDirectivesManager.removeUnusedXSDImports(namedComponent.getSchema()); - } - } - } - 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/XSDSchemaAdvancedSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaAdvancedSection.java deleted file mode 100644 index 89029253ab..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaAdvancedSection.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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.dialogs.Dialog; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -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.XSDForm; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDSchemaAdvancedSection extends AbstractSection -{ - IWorkbenchPart part; - protected CLabel elementFormLabel, attributeFormLabel, blockDefaultLabel, finalDefaultLabel; - protected CCombo elementFormCombo, attributeFormCombo, blockDefaultCombo, finalDefaultCombo; - - protected static final String emptyOption = ""; //$NON-NLS-1$ - - protected static final String [] formQualification = { emptyOption, XSDForm.QUALIFIED_LITERAL.getLiteral(), - XSDForm.UNQUALIFIED_LITERAL.getLiteral() }; //$NON-NLS-1$ - - - protected static final String derivedByChoicesComboValues[] = { "", XSDConstants.RESTRICTION_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG }; - - protected static final String blockDefaultValues[] = { emptyOption, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG, - "substitution"}; - - protected static final String finalDefaultValues[] = { emptyOption, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.EXTENSION_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG, - XSDConstants.LIST_ELEMENT_TAG, XSDConstants.UNION_ELEMENT_TAG}; - - public XSDSchemaAdvancedSection() - { - 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); - - // Create elementFormDefault label and combo - elementFormLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(), - Messages._UI_LABEL_ELEMENTFORMDEFAULT); - elementFormCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this, - formQualification,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_ELEMENT_FORM_DEFAULT); - - // Create attributeFormDefault label and combo - attributeFormLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(), - Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT); - attributeFormCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this, - formQualification,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_ATTRIBUTE_FORM_DEFAULT); - - // Create blockDefault label and combo - blockDefaultLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(), - Messages._UI_LABEL_BLOCKDEFAULT); - blockDefaultCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this, - blockDefaultValues,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_BLOCK_DEFAULT); - - // Create finalDefault label and combo - finalDefaultLabel = XSDCommonUIUtils.getNewPropertiesLabel(composite,getWidgetFactory(), - Messages._UI_LABEL_FINALDEFAULT); - finalDefaultCombo = XSDCommonUIUtils.getNewPropertiesCombo(composite,getWidgetFactory(),this, - finalDefaultValues,XSDEditorCSHelpIds.ADVANCE_TAB__SCHEMA_FINAL_DEFAULT); - - Dialog.applyDialogFont(parent); - } - - /* - * @see org.eclipse.wst.common.ui.properties.internal.provisional.view.ITabbedPropertySection#refresh() - */ - public void refresh() - { - super.refresh(); - setListenerEnabled(false); - - if (xsdSchema != null) - { - if (elementFormCombo != null) - { - String text; - if (xsdSchema.getElement().hasAttribute(XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE)) - { - text = xsdSchema.getElementFormDefault().getName(); - } - else - { - text = emptyOption; - } - elementFormCombo.setText(text); - } - - if (attributeFormCombo != null) - { - String text; - if (xsdSchema.getElement().hasAttribute(XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE)) - { - text = xsdSchema.getAttributeFormDefault().getName(); - } - else - { - text = emptyOption; - } - attributeFormCombo.setText(text); - } - - if (blockDefaultCombo != null) - { - String text; - if (xsdSchema.getElement().hasAttribute(XSDConstants.BLOCKDEFAULT_ATTRIBUTE)) - { - text = xsdSchema.getElement().getAttribute(XSDConstants.BLOCKDEFAULT_ATTRIBUTE); - } - else - { - text = emptyOption; - } - blockDefaultCombo.setText(text); - } - - if (finalDefaultCombo != null) - { - String text; - if (xsdSchema.getElement().hasAttribute(XSDConstants.FINALDEFAULT_ATTRIBUTE)) - { - text = xsdSchema.getElement().getAttribute(XSDConstants.FINALDEFAULT_ATTRIBUTE); - } - else - { - text = emptyOption; - } - finalDefaultCombo.setText(text); - } - } - setListenerEnabled(true); - } - - public void doWidgetSelected(SelectionEvent e) - { - if (xsdSchema != null) - { - if (e.widget == elementFormCombo && elementFormCombo != null) - { - String valueElementForm = elementFormCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), - XSDConstants.ELEMENTFORMDEFAULT_ATTRIBUTE, valueElementForm, - Messages._UI_LABEL_ELEMENTFORMDEFAULT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - - if (e.widget == attributeFormCombo && attributeFormCombo != null) - { - String valueAttributeForm = attributeFormCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), - XSDConstants.ATTRIBUTEFORMDEFAULT_ATTRIBUTE, valueAttributeForm, - Messages._UI_LABEL_ATTRIBUTEFORMDEFAULT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - - if (e.widget == blockDefaultCombo && blockDefaultCombo != null) - { - String valueBlockDefault = blockDefaultCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), - XSDConstants.BLOCKDEFAULT_ATTRIBUTE, valueBlockDefault, Messages._UI_LABEL_BLOCKDEFAULT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - - if(e.widget == finalDefaultCombo && finalDefaultCombo != null) - { - String finalBlockDefault = finalDefaultCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(xsdSchema.getElement(), - XSDConstants.FINALDEFAULT_ATTRIBUTE, finalBlockDefault, Messages._UI_LABEL_FINALDEFAULT); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } - } -} 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 dab2646974..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSchemaSection.java +++ /dev/null @@ -1,319 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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.common.util.Messages; -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_ACTION_EDIT_NAMESPACES"), SWT.PUSH); //$NON-NLS-1$ - 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() - { - super.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 - - if (element.hasAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE)) - { - String tns = element.getAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE); - 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(Messages._UI_ACTION_NAMESPACE_INFORMATION_CHANGE, xsdSchema, newPrefix, newTargetNamespace); - getCommandStack().execute(command); - } - - 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/XSDSimpleTypeAdvancedSection.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeAdvancedSection.java deleted file mode 100644 index 0e2bb218bc..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeAdvancedSection.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 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.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.IWorkbenchPart; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand; -import org.eclipse.wst.xsd.ui.internal.common.util.Messages; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.util.XSDConstants; - -public class XSDSimpleTypeAdvancedSection extends AbstractSection -{ - private static final String EMPTY = ""; //$NON-NLS-1$ - private String finalValues[] = { EMPTY, "#" + XSDConstants.ALL_ELEMENT_TAG, //$NON-NLS-1$ - XSDConstants.LIST_ELEMENT_TAG, XSDConstants.RESTRICTION_ELEMENT_TAG, - XSDConstants.UNION_ELEMENT_TAG}; - - CCombo finalCombo; - - public XSDSimpleTypeAdvancedSection() - { - 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); - - // ------------------------------------------------------------------ - // FinalLabel - // ------------------------------------------------------------------ - data = new GridData(); - data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - - CLabel finalLabel = getWidgetFactory().createCLabel(composite, Messages._UI_LABEL_FINAL); - 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); - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - } - - public void refresh() - { - super.refresh(); - - setListenerEnabled(false); - - finalCombo.setText(""); //$NON-NLS-1$); - - if (input instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input; - - - if (simpleType.getElement().hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) - { - String finalAttValue = simpleType.getElement().getAttribute(XSDConstants.FINAL_ATTRIBUTE); - finalCombo.setText(finalAttValue); - } - else - { - finalCombo.setText(EMPTY); - } - } - setListenerEnabled(true); - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == finalCombo && input != null && input instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input; - String value = finalCombo.getText(); - UpdateAttributeValueCommand command = new UpdateAttributeValueCommand(simpleType.getElement(), XSDConstants.FINAL_ATTRIBUTE, value, Messages._UI_LABEL_FINAL); - command.setDeleteIfEmpty(true); - getCommandStack().execute(command); - } - } -} 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 e3275a3feb..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/properties/sections/XSDSimpleTypeSection.java +++ /dev/null @@ -1,655 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.editor.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.XSDSchema; -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); - typesCombo.addListener(SWT.Traverse, 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); - - } - - 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); - showLink(!hideHyperLink); - - 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); - nameText.setEditable(true); - } - else - { - nameText.setText("**anonymous**"); //$NON-NLS-1$); - nameText.setEditable(false); - } - - String variety = st.getVariety().getName(); - int intVariety = st.getVariety().getValue(); - XSDDOMHelper domHelper = new XSDDOMHelper(); - if(domHelper.getDerivedByElementFromSimpleType(st.getElement()) != null) { - if (variety != null) - { - varietyCombo.setText(variety); - if (intVariety == XSDVariety.ATOMIC) - { - baseTypeDefinition = st.getBaseTypeDefinition(); - String name = ""; //$NON-NLS-1$ - if (baseTypeDefinition != null) - { - name = baseTypeDefinition.getName(); - if (name == null) name = ""; - } - 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(); - if (name == null) name = ""; - } - 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 doWidgetDefaultSelected(SelectionEvent e) - { - if (e.widget == typesCombo) - { - String selection = typesCombo.getText(); - if (shouldPerformComboSelection(SWT.DefaultSelection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - public void doWidgetSelected(SelectionEvent e) - { - if (e.widget == typesCombo) - { - String selection = typesCombo.getText(); - if (shouldPerformComboSelection(SWT.Selection, selection)) - handleWidgetSelection(e); - } else - { - handleWidgetSelection(e); - } - } - - private void handleWidgetSelection(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(Messages._UI_COMBO_BROWSE)) - { - dialog = manager.getBrowseDialog(); - ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false); - } - else if ( selection.equals(Messages._UI_COMBO_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$ - } - } - } - } - } - - 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) - { - if (listNode.hasAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE)) - reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE); - XSDDOMHelper.removeNodeAndWhitespace(listNode); - } - - Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false); - if (unionNode != null) - { - - if (unionNode.hasAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE)) - { - String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE); - 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; - } - - // TODO: Common this up with element declaration - public void doHandleEvent(Event event) - { - if (event.type == SWT.Traverse) { - if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) { - isTraversing = true; - return; - } - } - 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(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; - } - - public void setInput(IWorkbenchPart part, ISelection selection) - { - super.setInput(part, selection); - setListenerEnabled(false); - if (input instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input; - hideHyperLink = !(simpleType.getContainer() instanceof XSDSchema); - - } - // Don't have to call relayout() here - setListenerEnabled(true); - } - - private void fillTypesCombo() - { - typesCombo.removeAll(); - - IEditorPart editor = getActiveEditor(); - ComponentReferenceEditManager manager = (ComponentReferenceEditManager)editor.getAdapter(XSDTypeReferenceEditManager.class); - if (manager != null) - { - ComponentSpecification[] items = manager.getQuickPicks(); - - typesCombo.add(Messages._UI_COMBO_BROWSE); - typesCombo.add(Messages._UI_COMBO_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; - } - - public void dispose() - { - if (typesCombo != null && !typesCombo.isDisposed()) - typesCombo.removeListener(SWT.Traverse, this); - super.dispose(); - } -} 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 5356877a48..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,370 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.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.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.Label; -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 static final String SELECT_FROM_WORKSPACE = Messages._UI_LABEL_WORKSPACE; - private static final String SELECT_FROM_CATALOG = Messages._UI_LABEL_CATALOG; - 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 Button searchCatalog; - protected Button searchWorkspace; - protected Composite sourcesComposite; - - 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; - } - - // redundant 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(2, 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); - - - - // 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; - - // Line 3, schema selection buttons - Button hidden = new Button(mainComposite, SWT.NONE); - hidden.setVisible(false); - - sourcesComposite = new Composite(mainComposite, SWT.NONE); - RowLayout sourcesLayout = new RowLayout(); - - sourcesComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - sourcesComposite.setLayout(sourcesLayout); - - searchWorkspace = new Button(sourcesComposite, SWT.NONE); - searchWorkspace.setText(SELECT_FROM_WORKSPACE); - - searchCatalog = new Button(sourcesComposite, SWT.NONE); - searchCatalog.setText(SELECT_FROM_CATALOG); - - searchWorkspace.addSelectionListener(new SelectionAdapter() - { - public void widgetSelected(SelectionEvent e) - { - final String XSD_FILE_EXTENSION = ".xsd"; //$NON-NLS-1$ - - 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); - } - } - } - } - } - - ); - - searchCatalog.addSelectionListener(new SelectionAdapter() - { - public void widgetSelected(SelectionEvent e) - { - 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); - } - } - } - }); - - - // TODO: Should be able to get the image from the XML plugin. Don't need - // to copy to XSDEditor icons folder like this. - - - // 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(); - } -} 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 8a62a5a0b8..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,336 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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 - * Jesse Valianes - Seneca College https://bugs.eclipse.org/bugs/show_bug.cgi?id=235381 - *******************************************************************************/ -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.gef.commands.CommandStack; -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; - CommandStack commandStack; - - 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 void setCommandStack(CommandStack commandStack) - { - this.commandStack = commandStack; - } - - 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) - { - if (commandStack != null) - commandStack.execute(command); - else - 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(); - refresh(); - } - 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 9b5daf0a65..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,207 +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 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 e4df63d1e5..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; - - 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; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java deleted file mode 100644 index e5180f09a8..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/Messages.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 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.util; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS -{ - static - { - NLS.initializeMessages("org.eclipse.wst.xsd.ui.internal.common.util.messages", Messages.class); //$NON-NLS-1$ - } - - public Messages() - { - super(); - } - - public static String _UI_ACTION_OPEN_IN_NEW_EDITOR; - public static String _UI_ACTION_ADD_ATTRIBUTE_GROUP; - public static String _UI_ACTION_ADD_ATTRIBUTE_GROUP_REF; - public static String _UI_ACTION_ADD_ATTRIBUTE_GROUP_DEFINITION; - public static String _UI_ACTION_ADD_GROUP_REF; - public static String _UI_ACTION_ADD_GROUP; - public static String _UI_ACTION_DELETE; - public static String _UI_ACTION_ADD_COMPLEX_TYPE; - public static String _UI_ACTION_ADD_ATTRIBUTE; - public static String _UI_ACTION_ADD_SIMPLE_TYPE; - public static String _UI_ACTION_UPDATE_ELEMENT_REFERENCE; - public static String _UI_LABEL_NO_ITEMS_SELECTED; - public static String _UI_ACTION_ADD; - public static String _UI_ACTION_ADD_WITH_DOTS; - public static String _UI_ACTION_EDIT_WITH_DOTS; - public static String _UI_ACTION_CHANGE_PATTERN; - public static String _UI_ACTION_ADD_ENUMERATION; - public static String _UI_ACTION_INSERT_ENUMERATION; - public static String _UI_ACTION_ADD_PATTERN; - public static String _UI_ACTION_ADD_ENUMERATIONS; - public static String _UI_ACTION_DELETE_CONSTRAINTS; - public static String _UI_ACTION_DELETE_PATTERN; - public static String _UI_ACTION_DELETE_ENUMERATION; - public static String _UI_ACTION_SET_ENUMERATION_VALUE; - public static String _UI_LABEL_PATTERN; - public static String _UI_ACTION_CHANGE_MAXIMUM_OCCURRENCE; - public static String _UI_ERROR_INVALID_VALUE_FOR_MAXIMUM_OCCURRENCE; - public static String _UI_ACTION_CHANGE_MINIMUM_OCCURRENCE; - public static String _UI_ACTION_ADD_APPINFO_ELEMENT; - public static String _UI_ACTION_ADD_APPINFO_ATTRIBUTE; - public static String _UI_ACTION_DELETE_APPINFO_ELEMENT; - public static String _UI_ACTION_DELETE_APPINFO_ATTRIBUTE; - public static String _UI_ACTION_CHANGE_CONTENT_MODEL; - public static String _UI_ACTION_RENAME; - public static String _UI_ACTION_CHANGE_ENUMERATION_VALUE; - public static String _UI_ERROR_INVALID_NAME; - public static String _UI_LABEL_NAME; - public static String _UI_LABEL_REFERENCE; - public static String _UI_ACTION_UPDATE_MAXIMUM_OCCURRENCE; - public static String _UI_ACTION_UPDATE_MINIMUM_OCCURRENCE; - public static String _UI_LABEL_READONLY; - public static String _UI_LABEL_INCLUSIVE; - public static String _UI_LABEL_COLLAPSE_WHITESPACE; - public static String _UI_LABEL_SPECIFIC_CONSTRAINT_VALUES; - public static String _UI_LABEL_RESTRICT_VALUES_BY; - public static String _UI_LABEL_ENUMERATIONS; - public static String _UI_LABEL_PATTERNS; - public static String _UI_LABEL_MINIMUM_LENGTH; - public static String _UI_LABEL_MAXIMUM_LENGTH; - public static String _UI_LABEL_CONSTRAINTS_ON_LENGTH_OF; - public static String _UI_LABEL_CONSTRAINTS_ON_VALUE_OF; - public static String _UI_LABEL_MINIMUM_VALUE; - public static String _UI_LABEL_MAXIMUM_VALUE; - public static String _UI_LABEL_CONTRAINTS_ON; - public static String _UI_LABEL_TYPE; - public static String _UI_LABEL_BLOCKDEFAULT; - public static String _UI_LABEL_FINALDEFAULT; - public static String _UI_ACTION_CONSTRAIN_LENGTH; - public static String _UI_ACTION_UPDATE_BOUNDS; - public static String _UI_ACTION_COLLAPSE_WHITESPACE; - public static String _UI_LABEL_BASE; - public static String _UI_ERROR_INVALID_FILE; - public static String _UI_LABEL_EXTENSIONS; - public static String _UI_ACTION_ADD_EXTENSION_COMPONENT; - public static String _UI_ACTION_DELETE_EXTENSION_COMPONENT; - public static String _UI_LABEL_UP; - public static String _UI_LABEL_DOWN; - public static String _UI_LABEL_EXTENSION_DETAILS; - public static String _UI_ACTION_ADD_DOCUMENTATION; - public static String _UI_ACTION_ADD_EXTENSION_COMPONENTS; - public static String _UI_LABEL_EXTENSION_CATEGORIES; - public static String _UI_LABEL_ADD_WITH_DOTS; - public static String _UI_LABEL_DELETE; - public static String _UI_LABEL_EDIT; - public static String _UI_LABEL_AVAILABLE_COMPONENTS_TO_ADD; - public static String _UI_LABEL_EDIT_CATEGORY; - public static String _UI_ERROR_INVALID_CATEGORY; - public static String _UI_ERROR_FILE_CANNOT_BE_PARSED; - public static String _UI_ERROR_VALIDATE_THE_FILE; - public static String _UI_LABEL_SCHEMA; - public static String _UI_LABEL_ADD_CATEGORY; - public static String _UI_ERROR_NAME_ALREADY_USED; - public static String _UI_ACTION_BROWSE_WORKSPACE; - public static String _UI_LABEL_SELECT_XSD_FILE; - public static String _UI_DESCRIPTION_CHOOSE_XSD_FILE; - public static String _UI_ACTION_BROWSE_CATALOG; - public static String _UI_ACTION_ADD_ANY_ELEMENT; - public static String _UI_ACTION_ADD_ANY_ATTRIBUTE; - public static String _UI_ACTION_SET_BASE_TYPE; - public static String _UI_TOOLTIP_RENAME_REFACTOR; - public static String _UI_VALUE_COLON; - public static String _UI_ID; - public static String _UI_REF; - public static String _UI_FIXED; - public static String _UI_DEFAULT; - public static String _UI_FORM; - public static String _UI_USAGE; - public static String _UI_ACTION_CHANGE; - public static String _UI_ACTION_CLOSE_SCHEMA_PREVIEW_POPUP; - public static String _UI_ACTION_NAMESPACE_INFORMATION_CHANGE; - public static String _UI_LABEL_ABSTRACT; - public static String _UI_LABEL_BLOCK; - public static String _UI_LABEL_FINAL; - public static String _UI_LABEL_SUBSTITUTION_GROUP; - public static String _UI_LABEL_MIXED; - public static String _UI_LABEL_VALUE; - public static String _UI_LABEL_FORM; - public static String _UI_LABEL_NILLABLE; - public static String _UI_LABEL_ELEMENTFORMDEFAULT; - public static String _UI_LABEL_ATTRIBUTEFORMDEFAULT; - public static String _UI_LABEL_WORKSPACE; - public static String _UI_LABEL_CATALOG; - public static String _UI_DELETE_BUTTON; -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDCommonUIUtils.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDCommonUIUtils.java deleted file mode 100644 index 9510888c09..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDCommonUIUtils.java +++ /dev/null @@ -1,622 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 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 - * Naoki Akiyama, Fujitsu - Bug 244901 - Cannot set xsd:annotation to - * xsd:redefine by Properties view. - *******************************************************************************/ -package org.eclipse.wst.xsd.ui.internal.common.util; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Stack; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.DecorationOverlayIcon; -import org.eclipse.jface.viewers.IDecoration; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; -import org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML; -import org.eclipse.wst.xsd.ui.internal.adt.design.ImageOverlayDescriptor; -import org.eclipse.wst.xsd.ui.internal.common.properties.sections.AbstractSection; -import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeGroupDefinition; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeContent; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDEnumerationFacet; -import org.eclipse.xsd.XSDFacet; -import org.eclipse.xsd.XSDFactory; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDIdentityConstraintDefinition; -import org.eclipse.xsd.XSDImport; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDNotationDeclaration; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDWildcard; -import org.eclipse.xsd.XSDXPathDefinition; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -public class XSDCommonUIUtils -{ - public XSDCommonUIUtils() - { - super(); - } - - public static Image getUpdatedImage(XSDConcreteComponent input, Image baseImage, boolean isReadOnly) - { - XSDAnnotation xsdAnnotation = getInputXSDAnnotation(input, false); - - if (xsdAnnotation != null) - { - if (xsdAnnotation.getApplicationInformation().size() > 0) - { - // Will use the class name appended by the read only state as the name of the image. - // There is a disabled and an enabled version of each baseImage, so we can't simply - // use the component name as the name of the image - String imageName = input.getClass().getName() + isReadOnly; - Image newImage = XSDEditorPlugin.getDefault().getImageRegistry().get(imageName); - if (newImage == null) - { - ImageOverlayDescriptor ovr = new ImageOverlayDescriptor(baseImage, isReadOnly); - newImage = ovr.getImage(); - XSDEditorPlugin.getDefault().getImageRegistry().put(imageName, newImage); - } - return newImage; - } - } - return baseImage; - } - - public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) - { - XSDAnnotation xsdAnnotation = null; - XSDFactory factory = XSDFactory.eINSTANCE; - if (input instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDAttributeGroupDefinition) - { - XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdComp = (XSDElementDeclaration) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDNotationDeclaration) - { - XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDXPathDefinition) - { - XSDXPathDefinition xsdComp = (XSDXPathDefinition) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDModelGroup) - { - XSDModelGroup xsdComp = (XSDModelGroup) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDModelGroupDefinition) - { - XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDIdentityConstraintDefinition) - { - XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDWildcard) - { - XSDWildcard xsdComp = (XSDWildcard) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDSchema) - { - XSDSchema xsdComp = (XSDSchema) input; - List list = xsdComp.getAnnotations(); - if (list.size() > 0) - { - xsdAnnotation = (XSDAnnotation) list.get(0); - } - else - { - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - if (xsdComp.getContents() != null) - { - xsdComp.getContents().add(0, xsdAnnotation); - } - } - } - return xsdAnnotation; - } - else if (input instanceof XSDFacet) - { - XSDFacet xsdComp = (XSDFacet) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDTypeDefinition) - { - XSDTypeDefinition xsdComp = (XSDTypeDefinition) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDInclude) - { - XSDInclude xsdComp = (XSDInclude) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDImport) - { - XSDImport xsdComp = (XSDImport) input; - xsdAnnotation = xsdComp.getAnnotation(); - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - xsdComp.setAnnotation(xsdAnnotation); - } - } - else if (input instanceof XSDRedefine) - { - XSDRedefine xsdComp = (XSDRedefine) input; - List contents = xsdComp.getContents(); - for (int i = 0; i < contents.size(); i++) - { - Object content = contents.get(i); - if (content instanceof XSDAnnotation) - { - xsdAnnotation = (XSDAnnotation) content; - break; - } - } - if (createIfNotExist && xsdAnnotation == null) - { - xsdAnnotation = factory.createXSDAnnotation(); - contents.add(0, xsdAnnotation); - } - return xsdAnnotation; - } - else if (input instanceof XSDAnnotation) - { - xsdAnnotation = (XSDAnnotation) input; - } - - if (createIfNotExist) - { - formatAnnotation(xsdAnnotation); - } - - return xsdAnnotation; - } - - private static void formatAnnotation(XSDAnnotation annotation) - { - Element element = annotation.getElement(); - formatChild(element); - } - - public static void formatChild(Node child) - { - if (child instanceof IDOMNode) - { - IDOMModel model = ((IDOMNode) child).getModel(); - try - { - // tell the model that we are about to make a big model change - model.aboutToChangeModel(); - - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(child); - } - finally - { - // tell the model that we are done with the big model change - model.changedModel(); - } - } - } - - public static String createUniqueElementName(String prefix, List elements) - { - ArrayList usedNames = new ArrayList(); - for (Iterator i = elements.iterator(); i.hasNext();) - { - usedNames.add(getDisplayName((XSDNamedComponent) i.next())); - } - - int i = 1; - String testName = prefix; - while (usedNames.contains(testName)) - { - testName = prefix + i++; - } - return testName; - } - - public static String createUniqueEnumerationValue(String prefix, List elements) - { - ArrayList usedNames = new ArrayList(); - for (Iterator i = elements.iterator(); i.hasNext();) - { - usedNames.add(((XSDEnumerationFacet) i.next()).getLexicalValue()); - } - - int i = 1; - String testName = prefix; - while (usedNames.contains(testName)) - { - testName = prefix + i++; - } - return testName; - } - - public static String getDisplayName(XSDNamedComponent component) - { - if (component instanceof XSDTypeDefinition) - return getDisplayNameFromXSDType((XSDTypeDefinition) component); - - if (component instanceof XSDFeature) - { - XSDFeature feature = (XSDFeature) component; - if (feature.getName() != null) - return feature.getName(); - else if (feature.getResolvedFeature() != null && feature.getResolvedFeature().getName() != null) - return feature.getResolvedFeature().getName(); - } - - return component.getName(); - - } - - public static String getDisplayNameFromXSDType(XSDTypeDefinition type) - { - return getDisplayNameFromXSDType(type, true); - } - - public static String getDisplayNameFromXSDType(XSDTypeDefinition type, boolean returnPrimitiveParents) - { - if (type == null) - return null; - - if (type.getName() == null || type.getName().length() == 0) - { - if (returnPrimitiveParents && isPrimitiveType(type)) - { - return getDisplayNameFromXSDType(type.getBaseType()); - } - - EObject container = type.eContainer(); - - while (container != null) - { - if (container instanceof XSDNamedComponent && ((XSDNamedComponent) container).getName() != null) - { - return ((XSDNamedComponent) container).getName(); - } - container = container.eContainer(); - } - return null; - } - else - return type.getName(); - } - - public static boolean isPrimitiveType(XSDTypeDefinition type) - { - if (type instanceof XSDComplexTypeDefinition) - return false; - - XSDTypeDefinition baseType = null; - if (type != null) - { - baseType = type.getBaseType(); - XSDTypeDefinition origType = baseType; // KC: although invalid, we need to - // prevent cycles and to avoid an - // infinite loop - while (baseType != null && !XSDConstants.isAnySimpleType(baseType) && !XSDConstants.isAnyType(baseType) && origType != baseType) - { - type = baseType; - baseType = type.getBaseType(); - } - baseType = type; - } - else - { - return false; - } - - return (XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(baseType.getTargetNamespace())); - } - - public static XSDSimpleTypeDefinition getAnonymousSimpleType(XSDFeature input, XSDSimpleTypeDefinition xsdSimpleTypeDefinition) - { - XSDSimpleTypeDefinition anonymousSimpleType = null; - XSDTypeDefinition localType = null; - - if (input instanceof XSDElementDeclaration) - { - localType = ((XSDElementDeclaration) input).getAnonymousTypeDefinition(); - } - else if (input instanceof XSDAttributeDeclaration) - { - localType = ((XSDAttributeDeclaration) input).getAnonymousTypeDefinition(); - } - - if (localType instanceof XSDSimpleTypeDefinition) - { - anonymousSimpleType = (XSDSimpleTypeDefinition) localType; - } - return anonymousSimpleType; - } - - // bug246036 - check for cyclic groups. We should refactor out this static class. - private static Stack visitedGroups = new Stack(); - - public static void resetVisitedGroupsStack() - { - visitedGroups.clear(); - } - - public static List getChildElements(XSDModelGroup group) - { - List children = new ArrayList(); - visitedGroups.push(group); - if (group == null) return children; - - for (Iterator i = group.getContents().iterator(); i.hasNext();) - { - XSDParticle next = (XSDParticle) i.next(); - if (next.getContent() instanceof XSDFeature) - { - if (children.contains(next.getContent())) break; - children.add(next.getContent()); - } - else if (next.getTerm() instanceof XSDModelGroup) - { - if (!visitedGroups.contains(group)) - children.addAll(getChildElements((XSDModelGroup) next.getTerm())); - } - } - visitedGroups.pop(); - return children; - } - - public static List getAllAttributes(XSDComplexTypeDefinition xsdComplexType) - { - List attributes = getChildElements(xsdComplexType); - attributes.addAll(getChildAttributes(xsdComplexType)); - - return attributes; - } - - public static List getAllAttributes(XSDModelGroupDefinition xsdModelGroupDefinition) - { - List attributes = getChildElements(xsdModelGroupDefinition); - - return attributes; - } - - public static List getInheritedAttributes(XSDComplexTypeDefinition ct) - { - List attrs = new ArrayList(); - XSDTypeDefinition parent = ct.getBaseTypeDefinition(); - if (parent != null && parent instanceof XSDComplexTypeDefinition && ct.isSetDerivationMethod()) - { - attrs.addAll(getAllAttributes((XSDComplexTypeDefinition) parent)); - if (! ct.isCircular()) attrs.addAll(getInheritedAttributes((XSDComplexTypeDefinition) parent)); - } - - return attrs; - } - - public static List getChildElements(XSDComplexTypeDefinition ct) - { - return getChildElements(getModelGroup(ct)); - } - - public static List getChildElements(XSDModelGroupDefinition xsdModelGroupDefinition) - { - return getChildElements(xsdModelGroupDefinition.getModelGroup()); - } - - public static XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) - { - XSDParticle particle = cType.getComplexType(); - - if (particle == null || particle.eContainer() != cType) - return null; - - Object particleContent = particle.getContent(); - XSDModelGroup group = null; - - if (particleContent instanceof XSDModelGroupDefinition) - group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup(); - else if (particleContent instanceof XSDModelGroup) - group = (XSDModelGroup) particleContent; - - if (group == null) - return null; - - if (group.getContents().isEmpty() || group.eResource() != cType.eResource()) - { - XSDComplexTypeContent content = cType.getContent(); - if (content instanceof XSDParticle) - group = (XSDModelGroup) ((XSDParticle) content).getContent(); - } - - return group; - } - - public static List getChildAttributes(XSDComplexTypeDefinition ct) - { - EList attrContents = ct.getAttributeContents(); - List attrs = new ArrayList(); - for (int i = 0; i < attrContents.size(); i++) - { - Object next = attrContents.get(i); - - if (next instanceof XSDAttributeUse) - { - attrs.add(((XSDAttributeUse) next).getContent().getResolvedAttributeDeclaration()); - } - else if (next instanceof XSDAttributeGroupDefinition) - { - //XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) next; - } - } - return attrs; - } - - public static Image getImageWithErrorOverlay(XSDConcreteComponent input, Image baseImage, boolean isReadOnly) - { - Image extensionImage = getUpdatedImage(input, baseImage, isReadOnly); - ImageDescriptor errorOverlay = XSDEditorPlugin.getImageDescriptor("icons/ovr16/error_ovr.gif"); //$NON-NLS-1$ - if (baseImage == extensionImage) - { - String imageName = input.getClass().getName() + "_error_" + isReadOnly; - Image newImage = XSDEditorPlugin.getDefault().getImageRegistry().get(imageName); - if (newImage == null) - { - DecorationOverlayIcon ovr = new DecorationOverlayIcon(baseImage, errorOverlay, IDecoration.TOP_LEFT); - newImage = ovr.createImage(); - XSDEditorPlugin.getDefault().getImageRegistry().put(imageName, newImage); - } - return newImage; - } - else - { - String imageName = input.getClass().getName() + "_extension_error_" + isReadOnly; - Image newImage = XSDEditorPlugin.getDefault().getImageRegistry().get(imageName); - if (newImage == null) - { - DecorationOverlayIcon ovr = new DecorationOverlayIcon(extensionImage, errorOverlay, IDecoration.TOP_LEFT); - newImage = ovr.createImage(); - XSDEditorPlugin.getDefault().getImageRegistry().put(imageName, newImage); - } - return newImage; - } - } - - public static CCombo getNewPropertiesCombo(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, - AbstractSection listener, String[] items, String helpID) - { - CCombo combo = widgetFactory.createCCombo(composite); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - combo.setEditable(false); - combo.setItems(items); - combo.addSelectionListener(listener); - PlatformUI.getWorkbench().getHelpSystem().setHelp(combo, helpID); - return combo; - } - - public static CLabel getNewPropertiesLabel(Composite composite, TabbedPropertySheetWidgetFactory widgetFactory, - String labelText) - { - // Create label - CLabel label; - label = widgetFactory.createCLabel(composite, labelText); - GridData data = new GridData(); - data.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; - data.grabExcessHorizontalSpace = false; - label.setLayoutData(data); - - return label; - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesManager.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesManager.java deleted file mode 100644 index 39a1d8b6c9..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesManager.java +++ /dev/null @@ -1,815 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.util; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature.Setting; -import org.eclipse.wst.sse.core.StructuredModelManager; -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.editor.XSDEditorPlugin; -import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; -import org.eclipse.xsd.XSDConcreteComponent; -import org.eclipse.xsd.XSDImport; -import org.eclipse.xsd.XSDInclude; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSchemaDirective; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.impl.XSDSchemaImpl; -import org.eclipse.xsd.util.XSDConstants; -import org.eclipse.xsd.util.XSDUtil; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * This class performs cleanup/removal of unused XSD imports and includes from XML Schemas - * and xmlns entries in the namespace table - */ -public class XSDDirectivesManager -{ - protected static final String XMLNS = "xmlns"; //$NON-NLS-1$ - // List of all the unused directives. These will be removed - protected List unusedDirectives = new ArrayList(); - // List of all the included XSDSchema's - protected List usedIncludeSchemas = new ArrayList(); - // List of all the XSDInclude's that are indirectly used - protected List usedIndirectIncludes = new ArrayList(); - // List of the XSDInclude's that are directly used - protected List usedDirectIncludes = new ArrayList(); - // Used to track the included schemas that were analyzed to avoid circular loop - protected List analyzedIncludeSchemas = new ArrayList(); - // List of all the imported used schemas - protected List usedSchemas = new ArrayList(); - // List of all the indirectly used includes - protected Map usedIndirectIncludesMap = new HashMap(); - // Keep track of all the unused prefixes - protected Set unusedPrefixes; - // Keep track of all the used prefixes - protected Set usedPrefixes; - // Map of each schema's unused prefixes - protected Map schemaToPrefixMap; - - public static void removeUnusedXSDImports(XSDSchema schema) - { - // Only do the removal if the preference is turned on - if (XSDEditorPlugin.getDefault().getRemoveImportSetting()) - { - XSDDirectivesManager mgr = new XSDDirectivesManager(); - mgr.performRemoval(schema); - mgr.cleanup(); - } - } - - /** - * Main method to do the cleanup - * @param schema - */ - public void performRemoval(XSDSchema schema) - { - // Compute unused imports and unused prefixes - computeUnusedImports(schema); - // Remove the imports - removeUnusedImports(); - // Remove the prefixes - removeUnusedPrefixes(); - } - - /** - * Clients can manually clean the lists - */ - public void cleanup() - { - clearMaps(); - } - - /** - * After performing the cleanup, return the list of unused XSD directives - * - * @return list of unused XSD directives - */ - public List getUnusedXSDDirectives() - { - return unusedDirectives; - } - - /** - * After performing the cleanup, return the map of each schemas unused prefixes - * - * @return map of each schemas unused prefixes - */ - public Map getSchemaToPrefixMap() - { - return schemaToPrefixMap; - } - - /** - * Returns the set of unused prefixes from the XML namespace table - * - * @return set of unused prefixes - */ - public Set getUnusedPrefixes() - { - return unusedPrefixes; - } - - /** - * Returns the set of used prefixes from the XML namespace table - * - * @return set of used prefixes - */ - public Set getUsedPrefixes() - { - return usedPrefixes; - } - - /** - * Perform any cleanup after computing and removing the unused imports. - */ - protected void clearMaps() - { - if (schemaToPrefixMap != null) - { - schemaToPrefixMap.clear(); - } - } - - /** - * Remove the list of all unused imports. Imports is used in the generic term here. - */ - protected void removeUnusedImports() - { - Iterator iter = unusedDirectives.iterator(); - while (iter.hasNext()) - { - XSDSchemaDirective xsdDirective = (XSDSchemaDirective) iter.next(); - removeXSDDirective(xsdDirective); - } - } - - /** - * Removes the directive from the model - * @param xsdImport - */ - protected void removeXSDDirective(XSDSchemaDirective xsdImport) - { - XSDSchema schema = xsdImport.getSchema(); - - Element element = xsdImport.getElement(); - - Document doc = element.getOwnerDocument(); - - if (doc instanceof IDOMNode) - ((IDOMNode)doc).getModel().aboutToChangeModel(); - - try - { - if (!removeTextNodesBetweenNextElement(element)) - { - removeTextNodeBetweenPreviousElement(element); - } - element.getParentNode().removeChild(element); - } - finally - { - if (doc instanceof IDOMNode) - { - ((IDOMNode)doc).getModel().changedModel(); - } - schema.update(true); - } - - } - - /** - * This computes the list of unused imports for a schema - * @param schema - */ - protected void computeUnusedImports(XSDSchema schema) - { - unusedDirectives = new ArrayList(); - usedSchemas = new ArrayList(); - usedPrefixes = new HashSet(); - schemaToPrefixMap = new HashMap(); - - try - { - // Step One. Find unused imports using cross referencer - Map xsdNamedComponentUsage = TopLevelComponentCrossReferencer.find(schema); - - doCrossReferencer(schema, usedSchemas, xsdNamedComponentUsage); - - // Step Two. Update the unusedImport list given the list of used schemas obtained from cross referencing - addToUnusedImports(schema, usedSchemas); - - // Step Three. Compute unused prefixes to be removed - computeUnusedPrefixes(schema); - } - catch (Exception e) - { - unusedDirectives.clear(); - schemaToPrefixMap.clear(); - } - } - - /** - * Computes the list of unused prefixes from the XML namespace table given a schema - * @param schema - */ - protected void computeUnusedPrefixes(XSDSchema schema) - { - Map prefixMap = schema.getQNamePrefixToNamespaceMap(); - Set definedPrefixes = prefixMap.keySet(); - Set actualSet = new HashSet(); - NamedNodeMap attributes = schema.getElement().getAttributes(); - Iterator iter = definedPrefixes.iterator(); - while (iter.hasNext()) - { - String pref = (String)iter.next(); - if (pref == null) - { - if (attributes.getNamedItem(XMLNS) != null) - actualSet.add(null); - } - else - { - if (attributes.getNamedItem(XMLNS + ":" + pref) != null) //$NON-NLS-1$ - actualSet.add(pref); - } - } - - unusedPrefixes = new HashSet(actualSet); - - usedPrefixes.add(schema.getSchemaForSchemaQNamePrefix()); - - Element element = schema.getElement(); - - NodeList childElements = element.getChildNodes(); - int length = childElements.getLength(); - for (int i = 0; i < length; i++) - { - Node node = childElements.item(i); - if (node instanceof Element) - { - traverseDOMElement((Element)node, schema); - } - } - - // compute the used prefixes - computeUsedXSDPrefixes(schema); - - // remove the used prefixes from the unused to get the list of unused prefixes - unusedPrefixes.removeAll(usedPrefixes); - - // perform additional process from extenders - doAdditionalProcessing(schema); - - schemaToPrefixMap.put(schema, unusedPrefixes); - } - - /** - * Remove unused prefixes from the XML namespace table - */ - protected void removeUnusedPrefixes() - { - Set schemaSet = schemaToPrefixMap.keySet(); - Iterator iter = schemaSet.iterator(); - while (iter.hasNext()) - { - XSDSchema schema = (XSDSchema)iter.next(); - Map prefixMap = schema.getQNamePrefixToNamespaceMap(); - Set prefixesToRemove = (Set)schemaToPrefixMap.get(schema); - Iterator iter2 = prefixesToRemove.iterator(); - while (iter2.hasNext()) - { - String string = (String)iter2.next(); - if (prefixMap.containsKey(string)) - prefixMap.remove(string); - } - } - } - - /** - * Extenders can customize - * @param schema - */ - protected void doAdditionalProcessing(XSDSchema schema) - { - // Do nothing for XSD - } - - /** - * - * @param schema - */ - private void computeUsedXSDPrefixes(XSDSchema schema) - { - Map prefixMap = schema.getQNamePrefixToNamespaceMap(); - Set definedPrefixes = prefixMap.keySet(); - - boolean foundEntryForTargetNamespace = false; - String targetNamespace = schema.getTargetNamespace(); - for (Iterator iter = usedPrefixes.iterator(); iter.hasNext(); ) - { - String key = (String) iter.next(); - String value = (String) prefixMap.get(key); - if (targetNamespace == null && value == null) - { - foundEntryForTargetNamespace = true; - break; - } - else if (targetNamespace != null && value != null) - { - if (targetNamespace.equals(value)) - { - foundEntryForTargetNamespace = true; - break; - } - } - } - - if (!foundEntryForTargetNamespace) - { - for (Iterator iter = definedPrefixes.iterator(); iter.hasNext();) - { - String key = (String) iter.next(); - String value = (String) prefixMap.get(key); - if (targetNamespace == null && value == null) - { - usedPrefixes.add(null); - break; - } - else if (targetNamespace != null && value != null) - { - if (targetNamespace.equals(value)) - { - usedPrefixes.add(key); - break; - } - } - } - } - } - - /** - * Find prefixes that are in the document. - * @param element - * @param schema - */ - private void traverseDOMElement(Element element, XSDSchema schema) - { - String prefix = element.getPrefix(); - usedPrefixes.add(prefix); - - NamedNodeMap attrs = element.getAttributes(); - int numOfAttrs = attrs.getLength(); - for (int i = 0; i < numOfAttrs; i++) - { - Node node = attrs.item(i); - String attrPrefix = node.getPrefix(); - if (attrPrefix != null) - { - usedPrefixes.add(attrPrefix); - } - - String attr = node.getLocalName(); - if (attr != null) - { - String value = node.getNodeValue(); - if (value == null) continue; - if (attr.equals(XSDConstants.REF_ATTRIBUTE) || - attr.equals(XSDConstants.REFER_ATTRIBUTE) || - attr.equals(XSDConstants.TYPE_ATTRIBUTE) || - attr.equals(XSDConstants.BASE_ATTRIBUTE) || - attr.equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE) || - attr.equals(XSDConstants.ITEMTYPE_ATTRIBUTE)) - { - try - { - usedPrefixes.add(extractPrefix(value)); - } - catch (IndexOutOfBoundsException e) - { - } - } - else if (attr.equals(XSDConstants.MEMBERTYPES_ATTRIBUTE)) - { - StringTokenizer tokenizer = new StringTokenizer(value); - while (tokenizer.hasMoreTokens()) - { - try - { - String token = tokenizer.nextToken(); - usedPrefixes.add(extractPrefix(token)); - } - catch (IndexOutOfBoundsException e) - { - } - } - } - } - } - - NodeList childElements = element.getChildNodes(); - int length = childElements.getLength(); - for (int i = 0; i < length; i++) - { - Node node = childElements.item(i); - if (node instanceof Element) - { - traverseDOMElement((Element)node, schema); - } - } - } - - /** - * Extract the prefix from the given string. For example, pref:attr returns pref. - * @param value - * @return the prefix - */ - protected String extractPrefix(String value) - { - int index = value.indexOf(':'); - if (index < 0) - return null; - else - return value.substring(0, index); - } - - /** - * This determines the list of referenced components and hence the used schemas from which - * we can determine what are the unused directives - * - * @param schema - * @param unusedImportList - * @param usedSchemas - */ - protected void doCrossReferencer(XSDSchema schema, List usedSchemas, Map xsdNamedComponentUsage) - { - // Calculate additional unused imports that may have the same - // namespace that did not get added in the initial pass - Iterator iterator = xsdNamedComponentUsage.keySet().iterator(); - // First determine the used schemas from the cross referencer - while (iterator.hasNext()) - { - XSDNamedComponent namedComponent = (XSDNamedComponent) iterator.next(); - XSDSchema namedComponentSchema = namedComponent.getSchema(); - // If the named component belongs to the same schema, then continue...we - // want to check the external references - if (namedComponentSchema == schema) - { - continue; - } - Collection collection = (Collection) xsdNamedComponentUsage.get(namedComponent); - Iterator iterator2 = collection.iterator(); - while (iterator2.hasNext()) - { - Setting setting = (Setting) iterator2.next(); - Object obj = setting.getEObject(); - if (isComponentUsed(obj, schema, namedComponentSchema)) - { - if (!usedSchemas.contains(namedComponentSchema)) - usedSchemas.add(namedComponentSchema); - } - } - } - } - - /** - * Determines if the object to be analyzed is referenced by the schema - * @param obj - * @param schema - * @param targetSchema - * @return true if the component is referenced by the schema, false if not referenced - */ - protected boolean isComponentUsed(Object obj, XSDSchema schema, XSDSchema targetSchema) - { - if (obj instanceof XSDConcreteComponent) - { - XSDConcreteComponent component = (XSDConcreteComponent) obj; - if (component == schema || component instanceof XSDSchema) - { - return false; - } - if (!usedIncludeSchemas.contains(targetSchema)) - usedIncludeSchemas.add(targetSchema); - return true; - } - return false; - } - - /** - * From a list of used schemas, update the unusedImports list for the given schema - * - * @param schema - * @param unusedImports - * @param usedSchemas - */ - protected void addToUnusedImports(XSDSchema schema, List usedSchemas) - { - // now that we have the list of usedSchemas, get the list of unused - // schemas by comparing this list to what is actually in the schema - Iterator iter = schema.getContents().iterator(); - while(iter.hasNext()) - { - Object o = iter.next(); - if (o instanceof XSDSchemaDirective) - { - XSDSchemaDirective directive = (XSDSchemaDirective) o; - boolean isUsed = false; - Iterator iter2 = usedSchemas.iterator(); - while (iter2.hasNext()) - { - XSDSchema usedSchema = (XSDSchema) iter2.next(); - if (directive instanceof XSDImport && directive.getResolvedSchema() == usedSchema) - { - isUsed = true; - break; - } - if (directive instanceof XSDInclude && ((XSDInclude)directive).getIncorporatedSchema() == usedSchema) - { - isUsed = true; - usedDirectIncludes.add(usedSchema); - break; - } - // blindly accept redefines as used - if (directive instanceof XSDRedefine) - { - isUsed = true; - break; - } - } - - // If it is an include, we need to check if it is used indirectly - if (directive instanceof XSDInclude && !isUsed) - { - XSDInclude inc = (XSDInclude)directive; - XSDSchema incSchema = inc.getIncorporatedSchema(); - if (incSchema != null) - { - XSDSchema usedSchema = getUsedIncludeSchema(incSchema, inc); - if (usedSchema != null) - { - usedIndirectIncludes.add(directive); - usedIndirectIncludesMap.put(directive, usedSchema); - isUsed = true; - } - else - { - isUsed = false; - } - } - } - - // If resolved directives are determined unused - // If resolved directives are not already in the unused list - // Also any redefines should be considered used - if (!isUsed && !unusedDirectives.contains(directive) && !(directive instanceof XSDRedefine)) - { - unusedDirectives.add(directive); - } - } - } - Iterator iter3 = usedIndirectIncludes.iterator(); - while (iter3.hasNext()) - { - Object o = iter3.next(); - if (o instanceof XSDInclude) - { - XSDInclude inc = (XSDInclude)o; - XSDSchema targetSchema = (XSDSchema)usedIndirectIncludesMap.get(inc); - if (usedIncludeSchemas.contains(targetSchema) && usedDirectIncludes.contains(targetSchema)) - { - unusedDirectives.add(inc); - } - else - { - usedDirectIncludes.add(targetSchema); - } - } - } - } - - /** - * Includes can be used indirectly. If the schema includes A which includes B, but the schema - * references something in B, then A is indirectly used, and hence A cannot be removed. - * - * @param schema - * @param xsdInclude - * @return the referenced schema if used, null if not used - */ - private XSDSchema getUsedIncludeSchema(XSDSchema schema, XSDInclude xsdInclude) - { - XSDSchema refSchema = null; - boolean isUsed = false; - Iterator iter = schema.getContents().iterator(); - while (iter.hasNext()) - { - Object o = iter.next(); - if (o instanceof XSDInclude) - { - XSDInclude inc = (XSDInclude)o; - XSDSchema incSchema = inc.getIncorporatedSchema(); - if (incSchema != null) - { - Iterator iter2 = usedIncludeSchemas.iterator(); - while (iter2.hasNext()) - { - XSDSchema xsdSch = (XSDSchema)iter2.next(); - if (incSchema == xsdSch) - { - isUsed = true; - refSchema = incSchema; - break; - } - } - - if (!isUsed) - { - if (!analyzedIncludeSchemas.contains(incSchema)) // To prevent infinite cycle - { - analyzedIncludeSchemas.add(incSchema); - refSchema = getUsedIncludeSchema(incSchema, inc); - } - } - if (isUsed || refSchema != null) - { - return refSchema; - } - } - } - else - { - break; - } - } - return refSchema; - } - - /** - * See cross reference for more details. - */ - protected static class TopLevelComponentCrossReferencer extends XSDUtil.XSDNamedComponentCrossReferencer - { - private static final long serialVersionUID = 1L; - - XSDSchema schemaForSchema = XSDUtil.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001); - XSDSchema schemaForXSI = XSDSchemaImpl.getSchemaInstance(XSDConstants.SCHEMA_INSTANCE_URI_2001); - - protected TopLevelComponentCrossReferencer(EObject arg0) - { - super(arg0); - } - - /** - * Returns a map of all XSDNamedComponent cross references in the content - * tree. - */ - public static Map find(EObject eObject) - { - TopLevelComponentCrossReferencer result = new TopLevelComponentCrossReferencer(eObject); - result.crossReference(); - result.done(); - return result; - } - - protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) - { - if (crossReferencedEObject instanceof XSDNamedComponent) - { - XSDNamedComponent namedComponent = (XSDNamedComponent) crossReferencedEObject; - - if (namedComponent.getContainer() == schemaForSchema || - namedComponent.getContainer() == schemaForXSI || - crossReferencedEObject.eContainer() == eObject || - namedComponent.getName() == null) - { - return false; - } - - if (namedComponent instanceof XSDTypeDefinition) - { - XSDTypeDefinition typeDefinition = (XSDTypeDefinition) namedComponent; - if (!(typeDefinition.getContainer() instanceof XSDSchema)) - { - return false; - } - if (typeDefinition.getName() == null) - { - return false; - } - } - return true; - } - return false; - } - } - - /** - * Helper method to remove Text nodes - * @param element - * @return - */ - protected boolean removeTextNodesBetweenNextElement(Element element) - { - List nodesToRemove = new ArrayList(); - for (Node node = element.getNextSibling(); node != null; node = node.getNextSibling()) - { - if (node.getNodeType() == Node.TEXT_NODE) - { - nodesToRemove.add(node); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) - { - for (Iterator j = nodesToRemove.iterator(); j.hasNext();) - { - Node nodeToRemove = (Node) j.next(); - nodeToRemove.getParentNode().removeChild(nodeToRemove); - } - return true; - } - } - return false; - } - - /** - * Helper method to remove Text nodes. - * @param element - * @return - */ - protected boolean removeTextNodeBetweenPreviousElement(Element element) - { - List nodesToRemove = new ArrayList(); - for (Node node = element.getPreviousSibling(); node != null; node = node.getPreviousSibling()) - { - if (node.getNodeType() == Node.TEXT_NODE) - { - nodesToRemove.add(node); - } - else if (node.getNodeType() == Node.ELEMENT_NODE) - { - for (Iterator j = nodesToRemove.iterator(); j.hasNext();) - { - Node nodeToRemove = (Node) j.next(); - nodeToRemove.getParentNode().removeChild(nodeToRemove); - } - return true; - } - } - return false; - } - - /** - * - * @param iFile - * @param checkPreference - if false, ignore checking the preference setting - * @throws CoreException - * @throws IOException - */ - - public static void removeUnusedXSDImports(IFile iFile, boolean checkPreference) throws CoreException, IOException - { - if (!checkPreference || XSDEditorPlugin.getDefault().getRemoveImportSetting()) - { - IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(iFile); - if (model != null) - { - Document document = model.getDocument(); - if (document != null) - { - XSDSchema schema = XSDModelAdapter.lookupOrCreateSchema(document); - XSDDirectivesManager mgr = new XSDDirectivesManager(); - mgr.performRemoval(schema); - mgr.cleanup(); - model.save(); - } - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesSchemaLocationUpdater.java b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesSchemaLocationUpdater.java deleted file mode 100644 index 1f8c19d636..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/XSDDirectivesSchemaLocationUpdater.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.util; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorInput; -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.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.XSDInclude; -import org.eclipse.xsd.XSDRedefine; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.impl.XSDImportImpl; -import org.w3c.dom.Element; - -public class XSDDirectivesSchemaLocationUpdater -{ - /** - * Modifies the schema location by opening the schema location dialog and - * processing the results. This method refactors the code in - * XSDImportSection$widgetSelected and SchemaLocationSection$widgetSelected - * and the processing in handleSchemaLocationChange() - */ - public static void updateSchemaLocation(XSDSchema xsdSchema, Object selection, boolean isInclude) - { - Shell shell = Display.getCurrent().getActiveShell(); - IFile currentIFile = null; - IEditorInput editorInput = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput(); - ViewerFilter filter; - - if (editorInput instanceof IFileEditorInput) - { - currentIFile = ((IFileEditorInput) editorInput).getFile(); - filter = new ResourceFilter(new String[] { ".xsd" }, //$NON-NLS-1$ - new IFile[] { currentIFile }, null); - } - else - { - filter = new ResourceFilter(new String[] { ".xsd" }, //$NON-NLS-1$ - null, null); - } - - XSDSelectIncludeFileWizard fileSelectWizard = new XSDSelectIncludeFileWizard(xsdSchema, isInclude, XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_SCHEMA"), //$NON-NLS-1$ - XSDEditorPlugin.getXSDString("_UI_FILEDIALOG_SELECT_XML_DESC"), //$NON-NLS-1$ - filter, new StructuredSelection(selection)); - - WizardDialog wizardDialog = new WizardDialog(shell, fileSelectWizard); - wizardDialog.create(); - wizardDialog.setBlockOnOpen(true); - int result = wizardDialog.open(); - - if (result == Window.OK) - { - IFile selectedIFile = fileSelectWizard.getResultFile(); - String schemaFileString; - if (selectedIFile != null && currentIFile != null) - { - schemaFileString = URIHelper.getRelativeURI(selectedIFile.getLocation(), currentIFile.getLocation()); - } - else if (selectedIFile != null && currentIFile == null) - { - schemaFileString = selectedIFile.getLocationURI().toString(); - } - else - { - schemaFileString = fileSelectWizard.getURL(); - } - - String attributeSchemaLocation = "schemaLocation"; //$NON-NLS-1$ - if (selection instanceof XSDImport) - { - XSDImport xsdImport = (XSDImport) selection; - xsdImport.getElement().setAttribute(attributeSchemaLocation, schemaFileString); //$NON-NLS-1$ - - String namespace = fileSelectWizard.getNamespace(); - if (namespace == null) - namespace = ""; //$NON-NLS-1$ - - XSDSchema externalSchema = fileSelectWizard.getExternalSchema(); - java.util.Map map = xsdSchema.getQNamePrefixToNamespaceMap(); - 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)); //$NON-NLS-1$ - prefixExtension++; - } - prefix = newPrefix.toString(); - } - - String attributeNamespace = "namespace"; //$NON-NLS-1$ - 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); //$NON-NLS-1$ - } - // prefixText.setText(prefix); - xsdImport.getElement().setAttribute(attributeNamespace, namespace); - } - - // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=155885 - // Need to import otherwise the external schema is never - // resolved. One problem is that the schema location is still null, - // so the set types dialog will show types that belong to that schema - // with a null schema location. This should load resource - // into the resource set - if (selection instanceof XSDImportImpl) // redundant - { - XSDImportImpl xsdImportImpl = (XSDImportImpl) selection; - xsdImportImpl.importSchema(); - } - - } - else if (selection instanceof XSDInclude) - { - XSDInclude xsdInclude = (XSDInclude) selection; - xsdInclude.getElement().setAttribute(attributeSchemaLocation, schemaFileString); - } - else if (selection instanceof XSDRedefine) - { - XSDRedefine xsdRedefine = (XSDRedefine) selection; - xsdRedefine.getElement().setAttribute(attributeSchemaLocation, schemaFileString); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties b/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties deleted file mode 100644 index a5bdc10340..0000000000 --- a/bundles/org.eclipse.wst.xsd.ui/src-common/org/eclipse/wst/xsd/ui/internal/common/util/messages.properties +++ /dev/null @@ -1,123 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2010 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 -############################################################################### -_UI_ACTION_OPEN_IN_NEW_EDITOR=&Open In New Editor -_UI_ACTION_DELETE_CONSTRAINTS=Delete Constraints -_UI_ACTION_DELETE_ENUMERATION=Delete Enumeration -_UI_ACTION_DELETE_APPINFO_ELEMENT=Delete AppInfo Element -_UI_ACTION_DELETE_APPINFO_ATTRIBUTE=Delete AppInfo Attribute -_UI_ACTION_DELETE_EXTENSION_COMPONENT=Delete Extension Component -_UI_ACTION_ADD_ATTRIBUTE_GROUP=Add Attribute &Group -_UI_ACTION_ADD_APPINFO_ELEMENT=Add AppInfo Element -_UI_ACTION_ADD_ATTRIBUTE=Add &Attribute -_UI_ACTION_ADD_GROUP_REF=Add &Group Ref -_UI_ACTION_ADD_ANY_ELEMENT=Add An&y -_UI_ACTION_ADD_ANY_ATTRIBUTE=Add A&ny Attribute -_UI_ACTION_ADD_WITH_DOTS=&Add... -_UI_ACTION_UPDATE_BOUNDS=Update bounds -_UI_ACTION_ADD_COMPLEX_TYPE=Add &Complex Type -_UI_ACTION_ADD_ENUMERATIONS=Add Enumerations -_UI_ACTION_ADD_DOCUMENTATION=Add Documentation -_UI_ACTION_CONSTRAIN_LENGTH=Constrain length -_UI_ACTION_BROWSE_WORKSPACE=Workspace -_UI_DELETE_BUTTON=&Delete -_UI_LABEL_NO_ITEMS_SELECTED=No items selected -_UI_LABEL_ELEMENTFORMDEFAULT=Prefix for &Elements: -_UI_LABEL_ATTRIBUTEFORMDEFAULT=Prefix for &Attributes: -_UI_LABEL_BLOCKDEFAULT=&Block default: -_UI_LABEL_EXTENSION_DETAILS=Extension Details -_UI_LABEL_EXTENSION_CATEGORIES=Extension &Categories: -_UI_LABEL_FINALDEFAULT=&Final default: -_UI_LABEL_COLLAPSE_WHITESPACE=Collapse &whitespace -_UI_LABEL_RESTRICT_VALUES_BY=&Restrict values by: -_UI_LABEL_MINIMUM_LENGTH=Mi&nimum length: -_UI_LABEL_MAXIMUM_LENGTH=Ma&ximum length: -_UI_LABEL_SELECT_XSD_FILE=Select XSD file -_UI_LABEL_CONSTRAINTS_ON_VALUE_OF=Constraints on value of -_UI_ACTION_ADD_SIMPLE_TYPE=Add &Simple Type -_UI_ACTION_EDIT_WITH_DOTS=&Edit... -_UI_ACTION_CHANGE_PATTERN=Change pattern -_UI_ACTION_ADD_ENUMERATION=Add &Enumeration -_UI_ACTION_INSERT_ENUMERATION=&Insert Enumeration -_UI_ACTION_CHANGE_ENUMERATION_VALUE=Change Enumeration value -_UI_ACTION_DELETE_PATTERN=Delete Pattern -_UI_ACTION_BROWSE_CATALOG=Catalog -_UI_ACTION_ADD_GROUP=Add &Group -_UI_ACTION_ADD_PATTERN=Add pattern -_UI_ACTION_SET_BASE_TYPE=Set &Base Type -_UI_ERROR_INVALID_NAME=Invalid name -_UI_ERROR_INVALID_FILE=Invalid file -_UI_ERROR_INVALID_CATEGORY=Invalid Category -_UI_ACTION_DELETE=&Delete -_UI_ACTION_ADD=A&dd -_UI_ACTION_RENAME=Rename -_UI_LABEL_PATTERN=Pattern -_UI_LABEL_PATTERNS=&Patterns -_UI_LABEL_NAME=&Name: -_UI_LABEL_TYPE=&Type: -_UI_LABEL_BASE=&Base: -_UI_LABEL_UP=Up -_UI_LABEL_DOWN=Down -_UI_LABEL_DELETE=&Delete -_UI_LABEL_SCHEMA=&Schema: -_UI_LABEL_EDIT=&Edit... -_UI_LABEL_REFERENCE=Reference: -_UI_LABEL_READONLY=ReadOnly -_UI_LABEL_INCLUSIVE=Inclusive -_UI_LABEL_ENUMERATIONS=&Enumerations -_UI_LABEL_EXTENSIONS=Extensions -_UI_LABEL_MINIMUM_VALUE=&Minimum value: -_UI_LABEL_MAXIMUM_VALUE=Ma&ximum value: -_UI_LABEL_CONTRAINTS_ON=Constraints on -_UI_LABEL_ADD_WITH_DOTS=&Add... -_UI_LABEL_ADD_CATEGORY=Add Category -_UI_LABEL_EDIT_CATEGORY=Edit Category -_UI_ACTION_ADD_ATTRIBUTE_GROUP_REF=Add Attribute &Group Ref -_UI_ACTION_ADD_EXTENSION_COMPONENT=Add Extension Component -_UI_ACTION_ADD_EXTENSION_COMPONENTS=Add Extension Components -_UI_LABEL_CONSTRAINTS_ON_LENGTH_OF=Constraints on length of -_UI_ACTION_ADD_APPINFO_ATTRIBUTE=Add AppInfo Attribute -_UI_ACTION_SET_ENUMERATION_VALUE=Set Enumeration Value -_UI_ACTION_UPDATE_ELEMENT_REFERENCE=Update Element Reference -_UI_ACTION_UPDATE_MAXIMUM_OCCURRENCE=Update Maximum Occurrence -_UI_ACTION_UPDATE_MINIMUM_OCCURRENCE=Update Minimum Occurrence -_UI_ACTION_CHANGE_MAXIMUM_OCCURRENCE=Maximum Occurrence Change -_UI_ACTION_CHANGE_MINIMUM_OCCURRENCE=Minimum Occurrence Change -_UI_LABEL_SPECIFIC_CONSTRAINT_VALUES=Specific constraint values -_UI_LABEL_AVAILABLE_COMPONENTS_TO_ADD=Available com&ponents to Add: -_UI_ACTION_CHANGE_CONTENT_MODEL=Change Content Model -_UI_ERROR_FILE_CANNOT_BE_PARSED=The xsd file of the selected category cannot be parsed. -_UI_DESCRIPTION_CHOOSE_XSD_FILE=Choose an XSD file containing schema for your extensible components -_UI_ERROR_VALIDATE_THE_FILE=Please validate the file. -_UI_ERROR_NAME_ALREADY_USED=The name is already being used. -_UI_ACTION_COLLAPSE_WHITESPACE=Collapse whitespace -_UI_ACTION_ADD_ATTRIBUTE_GROUP_DEFINITION=Add Attribute Group Definition -_UI_ERROR_INVALID_VALUE_FOR_MAXIMUM_OCCURRENCE=Invalid value for maximum occurrence -_UI_TOOLTIP_RENAME_REFACTOR=Click here to invoke the Rename refactoring. -_UI_VALUE_COLON=Value: -_UI_ID=ID: -_UI_REF=Reference: -_UI_FIXED=Fixed -_UI_DEFAULT=Default -_UI_FORM=Form qualification: -_UI_LABEL_CATALOG=&XML Catalog... -_UI_LABEL_WORKSPACE=&Workspace... -_UI_ACTION_CHANGE={0} Change -_UI_ACTION_CLOSE_SCHEMA_PREVIEW_POPUP=&Close -_UI_ACTION_NAMESPACE_INFORMATION_CHANGE=Namespace Information Change -_UI_LABEL_ABSTRACT=&Abstract: -_UI_LABEL_BLOCK=&Block: -_UI_LABEL_FINAL=&Final: -_UI_LABEL_SUBSTITUTION_GROUP=&Substitution Group: -_UI_LABEL_MIXED=&Mixed: -_UI_LABEL_VALUE=&Value -_UI_USAGE=Usage -_UI_LABEL_FORM=Form -_UI_LABEL_NILLABLE=&Nillable:
\ No newline at end of file |