use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGlobalCommand method run.
public void run() {
XSDConcreteComponent model = getModelObject();
XSDConcreteComponent parent = model.getContainer();
XSDTypeDefinition globalTypeDef = null;
if (model instanceof XSDComplexTypeDefinition) {
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDComplexTypeDefinition) model.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
}
} else if (model instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) model;
if (parent instanceof XSDElementDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
formatChild(globalTypeDef.getElement());
} else if (parent instanceof XSDAttributeDeclaration) {
// clone typedef with it's content and set it global
globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
globalTypeDef.setName(fNewName);
parent.getSchema().getContents().add(globalTypeDef);
((XSDAttributeDeclaration) parent).setTypeDefinition((XSDSimpleTypeDefinition) globalTypeDef);
}
}
formatChild(globalTypeDef.getElement());
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypsGlobalEnablementTester method canEnable.
protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
if (selectedObject == null) {
return false;
}
XSDSchema selectedComponentSchema = null;
boolean enable = false;
selectedComponentSchema = selectedObject.getSchema();
if (selectedComponentSchema != null && selectedComponentSchema == schema) {
enable = true;
}
if (enable && selectedObject instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
}
} else if (enable && selectedObject instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) selectedObject;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
return true;
} else if (parent instanceof XSDAttributeDeclaration) {
return true;
}
}
return false;
}
use of org.eclipse.xsd.XSDConcreteComponent in project webtools.sourceediting by eclipse.
the class MakeAnonymousTypeGobalHandler method doExecute.
public Object doExecute(ISelection selection, XSDSchema schema) {
if (selection != null) {
Object selectedObject = ((StructuredSelection) selection).getFirstElement();
if (selectedObject instanceof XSDBaseAdapter) {
selectedObject = ((XSDBaseAdapter) selectedObject).getTarget();
}
XSDConcreteComponent concreteComp = null;
if (selectedObject instanceof Node) {
Node node = (Node) selectedObject;
concreteComp = schema.getCorrespondingComponent(node);
} else if (selectedObject instanceof XSDConcreteComponent) {
concreteComp = ((XSDConcreteComponent) selectedObject);
}
if (concreteComp != null) {
if (concreteComp instanceof XSDComplexTypeDefinition) {
isComplexType = true;
XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) concreteComp;
XSDConcreteComponent parent = typeDef.getContainer();
if (parent instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
run(selection, schema, typeDef);
} else if (concreteComp instanceof XSDSimpleTypeDefinition) {
isComplexType = false;
XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition) concreteComp;
XSDConcreteComponent parentComp = simpleTypeDef.getContainer();
if (parentComp instanceof XSDElementDeclaration) {
parentName = ((XSDElementDeclaration) parent).getName();
} else if (parent instanceof XSDAttributeDeclaration) {
parentName = ((XSDAttributeDeclaration) parent).getName();
}
run(selection, schema, simpleTypeDef);
}
}
}
}
return null;
}
use of org.eclipse.xsd.XSDConcreteComponent in project tmdm-studio-se by Talend.
the class ElementInfoConfigComposite method getAllReferences.
private String[] getAllReferences() {
ArrayList<String> elementDeclarations = new ArrayList<String>();
// $NON-NLS-1$
elementDeclarations.add("");
if (curXSDParticle == null) {
return elementDeclarations.toArray(new String[0]);
}
if (curXSDParticle.getSchema() == null) {
return new String[0];
}
XSDConcreteComponent entity = getParentElement(curXSDParticle);
for (XSDElementDeclaration eachXSDEleDeclaration : curXSDParticle.getSchema().getElementDeclarations()) {
if (eachXSDEleDeclaration.getTargetNamespace() != null && eachXSDEleDeclaration.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
continue;
}
if (!eachXSDEleDeclaration.equals(entity)) {
elementDeclarations.add(eachXSDEleDeclaration.getQName() + (// $NON-NLS-1$
eachXSDEleDeclaration.getTargetNamespace() != null ? // $NON-NLS-1$
" : " + eachXSDEleDeclaration.getTargetNamespace() : // $NON-NLS-1$
""));
}
}
return elementDeclarations.toArray(new String[0]);
}
use of org.eclipse.xsd.XSDConcreteComponent in project tmdm-studio-se by Talend.
the class ElementInfoConfigComposite method getParentElement.
private XSDConcreteComponent getParentElement(XSDParticle xSDParticle) {
XSDConcreteComponent rootContainer = xSDParticle.getRootContainer();
XSDConcreteComponent container = xSDParticle.getContainer();
while (!container.getContainer().equals(rootContainer)) {
container = container.getContainer();
}
return container;
}
Aggregations