use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method handleWidgetSelection.
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())) {
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON"));
st.setVariety(XSDVariety.ATOMIC_LITERAL);
// $NON-NLS-1$
addCreateElementActionIfNotExist(XSDConstants.RESTRICTION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_RESTRICTION"), parent, null);
} else if (variety.equals(XSDVariety.UNION_LITERAL.getName())) {
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES"));
st.setVariety(XSDVariety.UNION_LITERAL);
// $NON-NLS-1$
addCreateElementActionIfNotExist(XSDConstants.UNION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_UNION"), parent, null);
} else if (variety.equals(XSDVariety.LIST_LITERAL.getName())) {
// $NON-NLS-1$
typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_ITEM_TYPE"));
st.setVariety(XSDVariety.LIST_LITERAL);
// $NON-NLS-1$
addCreateElementActionIfNotExist(XSDConstants.LIST_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_LIST"), parent, null);
}
}
}
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method addCreateElementActionIfNotExist.
// 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;
// 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;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method getOwner.
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;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGlobalAction method canEnable.
private boolean canEnable(XSDConcreteComponent xsdComponent) {
if (xsdComponent instanceof XSDComplexTypeDefinition) {
fSelectedComponent = (XSDComplexTypeDefinition) xsdComponent;
isComplexType = true;
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
fParentName = ((XSDElementDeclaration) parent).getName();
return true;
}
} else if (xsdComponent instanceof XSDSimpleTypeDefinition) {
fSelectedComponent = (XSDSimpleTypeDefinition) xsdComponent;
isComplexType = false;
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
fParentName = ((XSDElementDeclaration) parent).getName();
return true;
} else if (parent instanceof XSDAttributeDeclaration) {
fParentName = ((XSDAttributeDeclaration) parent).getName();
return true;
}
}
return false;
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitComplexTypeDefinition.
public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) {
XSDComplexTypeContent complexContent = type.getContent();
if (complexContent != null) {
if (complexContent instanceof XSDSimpleTypeDefinition) {
visitSimpleTypeDefinition((XSDSimpleTypeDefinition) complexContent);
} else if (complexContent instanceof XSDParticle) {
visitParticle((XSDParticle) complexContent);
}
}
if (type.getAttributeContents() != null) {
for (Iterator iter = type.getAttributeContents().iterator(); iter.hasNext(); ) {
XSDAttributeGroupContent attrGroupContent = (XSDAttributeGroupContent) iter.next();
if (attrGroupContent instanceof XSDAttributeUse) {
XSDAttributeUse attrUse = (XSDAttributeUse) attrGroupContent;
visitAttributeDeclaration(attrUse.getContent());
} else if (attrGroupContent instanceof XSDAttributeGroupDefinition) {
visitAttributeGroupDefinition((XSDAttributeGroupDefinition) attrGroupContent);
}
}
}
}
Aggregations