use of org.eclipse.xsd.XSDParticle 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.XSDParticle in project webtools.sourceediting by eclipse.
the class XSDVisitor method visitModelGroup.
public void visitModelGroup(XSDModelGroup modelGroup) {
if (modelGroup.getContents() != null) {
for (Iterator iterator = modelGroup.getContents().iterator(); iterator.hasNext(); ) {
XSDParticle particle = (XSDParticle) iterator.next();
visitParticle(particle);
}
}
}
use of org.eclipse.xsd.XSDParticle 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.XSDParticle in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method execute.
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();
}
}
use of org.eclipse.xsd.XSDParticle in project webtools.sourceediting by eclipse.
the class MultiplicitySection method updateMinAttribute.
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 (// $NON-NLS-1$ //$NON-NLS-2$
newValue.equals("unbounded") || newValue.equals("*")) {
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) {
}
}
}
Aggregations