use of org.eclipse.xsd.XSDModelGroup 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;
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class XSDModelGroupSection method doWidgetSelected.
public void doWidgetSelected(SelectionEvent e) {
XSDModelGroup particle = (XSDModelGroup) input;
if (e.widget == modelGroupCombo) {
XSDCompositor newValue = XSDCompositor.get(modelGroupCombo.getText());
UpdateContentModelCommand command = new UpdateContentModelCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_CHANGE_CONTENT_MODEL, particle, newValue);
getCommandStack().execute(command);
}
super.doWidgetSelected(e);
}
use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils method getInputXSDAnnotation.
public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
XSDAnnotation xsdAnnotation = null;
XSDFactory factory = XSDFactory.eINSTANCE;
if (input instanceof XSDAttributeDeclaration) {
XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDElementDeclaration) {
XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDNotationDeclaration) {
XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDXPathDefinition) {
XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroup) {
XSDModelGroup xsdComp = (XSDModelGroup) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDWildcard) {
XSDWildcard xsdComp = (XSDWildcard) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDSchema) {
XSDSchema xsdComp = (XSDSchema) input;
List list = xsdComp.getAnnotations();
if (list.size() > 0) {
xsdAnnotation = (XSDAnnotation) list.get(0);
} else {
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
if (xsdComp.getContents() != null) {
xsdComp.getContents().add(0, xsdAnnotation);
}
}
}
return xsdAnnotation;
} else if (input instanceof XSDFacet) {
XSDFacet xsdComp = (XSDFacet) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDTypeDefinition) {
XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDInclude) {
XSDInclude xsdComp = (XSDInclude) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDImport) {
XSDImport xsdComp = (XSDImport) input;
xsdAnnotation = xsdComp.getAnnotation();
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
xsdComp.setAnnotation(xsdAnnotation);
}
} else if (input instanceof XSDRedefine) {
XSDRedefine xsdComp = (XSDRedefine) input;
List contents = xsdComp.getContents();
for (int i = 0; i < contents.size(); i++) {
Object content = contents.get(i);
if (content instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) content;
break;
}
}
if (createIfNotExist && xsdAnnotation == null) {
xsdAnnotation = factory.createXSDAnnotation();
contents.add(0, xsdAnnotation);
}
return xsdAnnotation;
} else if (input instanceof XSDAnnotation) {
xsdAnnotation = (XSDAnnotation) input;
}
if (createIfNotExist) {
formatAnnotation(xsdAnnotation);
}
return xsdAnnotation;
}
use of org.eclipse.xsd.XSDModelGroup 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.XSDModelGroup in project webtools.sourceediting by eclipse.
the class ModelGroupEditPart method getModelChildren.
protected List getModelChildren() {
// XSDModelGroupAdapter modelGroupAdapter = (XSDModelGroupAdapter)getModel();
// ArrayList ch = new ArrayList();
// ITreeElement [] tree = modelGroupAdapter.getChildren();
// int length = tree.length;
// for (int i = 0; i < length; i++)
// {
// ch.add(tree[i]);
// }
List list = new ArrayList();
XSDModelGroup xsdModelGroup = getXSDModelGroup();
for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
XSDParticle next = (XSDParticle) i.next();
if (next.getContent() instanceof XSDElementDeclaration) {
XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) next.getContent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(elementDeclaration);
list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
}
if (next.getContent() instanceof XSDModelGroupDefinition) {
XSDModelGroupDefinition def = (XSDModelGroupDefinition) next.getContent();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(def);
list.add(adapter);
} else if (next.getTerm() instanceof XSDModelGroup) {
XSDModelGroup modelGroup = (XSDModelGroup) next.getTerm();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(modelGroup);
list.add(adapter);
} else if (next.getTerm() instanceof XSDWildcard) {
XSDWildcard wildCard = (XSDWildcard) next.getTerm();
Adapter adapter = XSDAdapterFactory.getInstance().adapt(wildCard);
list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
}
}
if (list.size() == 0)
list.add(new TargetConnectionSpaceFiller(null));
return list;
// return ch;
}
Aggregations