use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class XSDTypeReferenceEditManager method modifyComponentReference.
public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
XSDConcreteComponent concreteComponent = null;
if (referencingObject instanceof Adapter) {
Adapter adpater = (Adapter) referencingObject;
if (adpater.getTarget() instanceof XSDConcreteComponent) {
concreteComponent = (XSDConcreteComponent) adpater.getTarget();
}
} else if (referencingObject instanceof XSDConcreteComponent) {
concreteComponent = (XSDConcreteComponent) referencingObject;
}
if (concreteComponent != null) {
if (component.isNew()) {
XSDTypeDefinition td = null;
if (// This means we set to anonymous type
component.getName() == null && concreteComponent instanceof XSDElementDeclaration) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) concreteComponent;
// with the proper undo descriptions
if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
elementDeclaration.setAnonymousTypeDefinition(complexType);
} else {
XSDSimpleTypeDefinition simpleType = factory.createXSDSimpleTypeDefinition();
simpleType.setBaseTypeDefinition(// $NON-NLS-1$
elementDeclaration.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
elementDeclaration.setAnonymousTypeDefinition(simpleType);
}
// TODO use external literal string
elementDeclaration.getElement().removeAttribute("type");
} else if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
td = command.getCreatedComplexType();
} else {
AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
command.setNameToAdd(component.getName());
command.execute();
td = command.getCreatedSimpleType();
}
if (td != null) {
Command command = new UpdateTypeReferenceCommand(concreteComponent, td);
command.setLabel(Messages._UI_ACTION_SET_TYPE);
command.execute();
}
XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
} else {
Command command = new UpdateTypeReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
command.setLabel(Messages._UI_ACTION_SET_TYPE);
command.execute();
}
}
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddEnumerationsCommand method execute.
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();
}
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddXSDComplexTypeDefinitionCommand method execute.
/*
* (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;
// $NON-NLS-1$
String newName = getNewName(nameToAdd == null ? "NewComplexType" : nameToAdd, parent.getSchema());
complexType.setName(newName);
if (parent instanceof XSDSchema) {
try {
XSDSchema xsdSchema = (XSDSchema) parent;
ensureSchemaElement(xsdSchema);
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
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();
}
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method execute.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.commands.Command#execute()
*/
public void execute() {
try {
if (xsdSchema != null) {
beginRecording(xsdSchema.getElement());
XSDElementDeclaration element = createGlobalXSDElementDeclaration();
// $NON-NLS-1$
Text textNode = xsdSchema.getDocument().createTextNode("\n");
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();
}
}
use of org.eclipse.xsd.XSDFactory in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupDefinitionCommand method createXSDModelGroupDefinition.
protected XSDModelGroupDefinition createXSDModelGroupDefinition() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition();
List list = parent.getSchema().getModelGroupDefinitions();
// $NON-NLS-1$
String newName = XSDCommonUIUtils.createUniqueElementName("NewGroupDefinition", list);
def.setName(newName);
XSDModelGroup modelGroup = createModelGroup();
def.setModelGroup(modelGroup);
// $NON-NLS-1$
Text textNode = parent.getSchema().getDocument().createTextNode("\n");
parent.getSchema().getElement().appendChild(textNode);
parent.getSchema().getContents().add(def);
formatChild(def.getElement());
return def;
}
Aggregations