use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDAttributeUseAdapter method getTextForAttributeUse.
public String getTextForAttributeUse(XSDAttributeUse attributeUse, boolean showType) {
XSDAttributeDeclaration ad = attributeUse.getAttributeDeclaration();
StringBuffer result = new StringBuffer();
result.append(getTextForAttribute(ad, showType));
/*
if (xsdAttributeUse.isSetConstraint())
{
if (result.length() != 0)
{
result.append(" ");
}
result.append('<');
result.append(xsdAttributeUse.getConstraint());
result.append("=\"");
result.append(xsdAttributeUse.getLexicalValue());
result.append("\">");
}
*/
return result.toString();
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDBaseAttributeAdapter method getName.
public String getName() {
XSDAttributeDeclaration resolvedAttributeDeclaration = getResolvedXSDAttributeDeclaration();
String name = resolvedAttributeDeclaration.getName();
// $NON-NLS-1$
return (name == null) ? "" : name;
}
use of org.eclipse.xsd.XSDAttributeDeclaration 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.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class AddXSDAttributeDeclarationCommand method setGlobalAttributeReference.
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);
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
xsdSchema.getElement().appendChild(textNode);
xsdSchema.getContents().add(referencedAttribute);
}
return referencedAttribute;
}
use of org.eclipse.xsd.XSDAttributeDeclaration in project webtools.sourceediting by eclipse.
the class XSDFacetSection method updateInput.
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;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
} 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;
// $NON-NLS-1$ //$NON-NLS-2$
titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
}
}
Aggregations