use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class XSDVisitorForFields method visitComplexTypeDefinition.
public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) {
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());
// if (attrUse.getAttributeDeclaration() != attrUse.getContent())
// {
// visitAttributeDeclaration(attrUse.getContent());
// }
// else
// {
// thingsWeNeedToListenTo.add(attrUse.getAttributeDeclaration());
// concreteComponentList.add(attrUse.getAttributeDeclaration());
// }
} else if (attrGroupContent instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) attrGroupContent;
thingsWeNeedToListenTo.add(attrGroup);
if (attrGroup.isAttributeGroupDefinitionReference()) {
attrGroup = attrGroup.getResolvedAttributeGroupDefinition();
visitAttributeGroupDefinition(attrGroup);
}
}
}
}
if (type.getAttributeWildcard() != null) {
thingsWeNeedToListenTo.add(type.getAttributeWildcard());
concreteComponentList.add(type.getAttributeWildcard());
}
super.visitComplexTypeDefinition(type);
}
use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class AddXSDAttributeDeclarationCommand method execute.
public void execute() {
XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
try {
if (parent == null) {
beginRecording(xsdComplexTypeDefinition.getElement());
if (!isReference) {
// $NON-NLS-1$
attribute.setName(getNewName(nameToAdd == null ? "NewAttribute" : nameToAdd));
// $NON-NLS-1$
attribute.setTypeDefinition(xsdComplexTypeDefinition.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
} 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) {
// $NON-NLS-1$
attribute.setTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
List list = new ArrayList();
Iterator i = ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getAttributeUses().iterator();
while (i.hasNext()) {
XSDAttributeUse use = (XSDAttributeUse) i.next();
list.add(use.getAttributeDeclaration());
}
// $NON-NLS-1$
attribute.setName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", list));
} 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;
}
use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitAttributeGroupDefinition.
public void visitAttributeGroupDefinition(XSDAttributeGroupDefinition attributeGroup) {
if (attributeGroup.getAttributeUses() != null) {
for (Iterator iter = attributeGroup.getAttributeUses().iterator(); iter.hasNext(); ) {
XSDAttributeUse attrUse = (XSDAttributeUse) iter.next();
visitAttributeDeclaration(attrUse.getContent());
}
}
}
use of org.eclipse.xsd.XSDAttributeUse 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);
}
}
}
}
use of org.eclipse.xsd.XSDAttributeUse in project webtools.sourceediting by eclipse.
the class CreateElementAction method run.
/*
* @see IAction#run()
*/
public void run() {
beginRecording(getDescription());
final Element child = createAndAddNewChildElement();
endRecording();
if (selectionProvider != null) {
final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
// selectionProvider.setSelection(new StructuredSelection(comp));
Runnable runnable = new Runnable() {
public void run() {
if (comp instanceof XSDAttributeDeclaration) {
if (((XSDAttributeDeclaration) comp).getContainer() instanceof XSDAttributeUse) {
if (comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition) {
selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
} else if (comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
if (XSDDOMHelper.inputEquals(child, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true)) {
selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
} else {
selectionProvider.setSelection(new StructuredSelection(comp));
}
if (comp instanceof XSDNamedComponent) {
if (sourceContext instanceof AbstractEditPartViewer) {
// AbstractEditPartViewer viewer = (AbstractEditPartViewer)sourceContext;
// Object obj = viewer.getSelectedEditParts().get(0);
// if (obj instanceof GraphicalEditPart)
// {
// if (obj instanceof ElementDeclarationEditPart)
// {
// XSDElementDeclaration elem = ((ElementDeclarationEditPart)obj).getXSDElementDeclaration();
// if (!elem.isElementDeclarationReference())
// {
// ((ElementDeclarationEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof ModelGroupDefinitionEditPart)
// {
// XSDModelGroupDefinition group = ((ModelGroupDefinitionEditPart)obj).getXSDModelGroupDefinition();
// if (!group.isModelGroupDefinitionReference())
// {
// ((ModelGroupDefinitionEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof ComplexTypeDefinitionEditPart)
// {
// XSDComplexTypeDefinition ct = ((ComplexTypeDefinitionEditPart)obj).getXSDComplexTypeDefinition();
// if (ct.getName() != null)
// {
// ((ComplexTypeDefinitionEditPart)obj).doEditName();
// }
// }
// else if (obj instanceof TopLevelComponentEditPart)
// {
// ((TopLevelComponentEditPart)obj).doEditName();
// }
// }
}
}
}
};
Display.getDefault().timerExec(50, runnable);
}
}
Aggregations