use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method getModelGroup.
// PORT
public XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {
XSDParticle particle = null;
XSDComplexTypeContent xsdComplexTypeContent = cType.getContent();
if (xsdComplexTypeContent instanceof XSDParticle) {
particle = (XSDParticle) xsdComplexTypeContent;
}
if (particle == null) {
return null;
}
Object particleContent = particle.getContent();
XSDModelGroup group = null;
if (particleContent instanceof XSDModelGroupDefinition) {
group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup();
} else if (particleContent instanceof XSDModelGroup) {
group = (XSDModelGroup) particleContent;
}
if (group == null) {
return null;
}
return group;
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupDefinitionCommand method createModelGroup.
protected XSDModelGroup createModelGroup() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDParticle particle = factory.createXSDParticle();
XSDModelGroup modelGroup = factory.createXSDModelGroup();
modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
particle.setContent(modelGroup);
return modelGroup;
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupDefinitionCommand method execute.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.commands.Command#execute()
*/
public void execute() {
if (parent instanceof XSDSchema) {
ensureSchemaElement((XSDSchema) parent);
}
try {
beginRecording(parent.getElement());
if (!isReference) {
XSDModelGroupDefinition def = createXSDModelGroupDefinition();
addedXSDConcreteComponent = def;
} else {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition();
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(def);
List list = parent.getSchema().getModelGroupDefinitions();
int length = list.size();
if (length > 1) {
for (int i = 0; i < length; i++) {
XSDModelGroupDefinition gr = (XSDModelGroupDefinition) list.get(i);
if (gr.getModelGroup() != parent) {
def.setResolvedModelGroupDefinition(gr);
}
}
} else if (length <= 1) {
XSDModelGroupDefinition newGroupDef = createXSDModelGroupDefinition();
def.setResolvedModelGroupDefinition(newGroupDef);
}
if (parent instanceof XSDModelGroup) {
((XSDModelGroup) parent).getContents().add(particle);
}
formatChild(def.getElement());
addedXSDConcreteComponent = def;
}
} finally {
endRecording();
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDElementAction method run.
public void run() {
Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
if (selection instanceof XSDBaseAdapter) {
selection = ((XSDBaseAdapter) selection).getTarget();
}
AddXSDElementCommand command = null;
if (selection instanceof XSDComplexTypeDefinition) {
command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroupDefinition) {
command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDSchema) {
command = new AddXSDElementCommand(getText(), (XSDSchema) selection);
getCommandStack().execute(command);
} else if (selection instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) selection;
XSDConcreteComponent component = modelGroup.getContainer();
XSDComplexTypeDefinition ct = null;
while (component != null) {
if (component instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) component;
break;
}
component = component.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct);
} else {
command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection);
}
command.setReference(isReference);
getCommandStack().execute(command);
} else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) {
XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection;
XSDConcreteComponent parent = null;
XSDComplexTypeDefinition ct = null;
XSDModelGroupDefinition group = null;
XSDModelGroupImpl ctGroup = null;
for (parent = xsdConcreteComponent.getContainer(); parent != null; ) {
if (parent instanceof XSDComplexTypeDefinition) {
ct = (XSDComplexTypeDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupDefinition) {
group = (XSDModelGroupDefinition) parent;
break;
} else if (parent instanceof XSDModelGroupImpl) {
ctGroup = (XSDModelGroupImpl) parent;
break;
}
parent = parent.getContainer();
}
if (ct != null) {
command = new AddXSDElementCommand(getText(), ct);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (ctGroup != null) {
XSDElementDeclaration sel = (XSDElementDeclaration) selection;
int index = ctGroup.getContents().indexOf(sel.eContainer());
command = new AddXSDElementCommand(getText(), ctGroup, getId(), index);
command.setReference(isReference);
getCommandStack().execute(command);
} else if (group != null) {
command = new AddXSDElementCommand(getText(), group);
command.setReference(isReference);
getCommandStack().execute(command);
}
}
if (command != null) {
addedComponent = command.getAddedComponent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
selectAddedComponent(adapter);
}
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class AddXSDModelGroupCommand method createModelGroup.
protected XSDModelGroup createModelGroup() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDParticle particle = factory.createXSDParticle();
XSDModelGroup modelGroup = factory.createXSDModelGroup();
modelGroup.setCompositor(xsdCompositor);
particle.setContent(modelGroup);
addedXSDConcreteComponent = modelGroup;
return modelGroup;
}
Aggregations