use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class SimpleTypeInputDialog method modifyText.
public void modifyText(ModifyEvent e) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
// $NON-NLS-1$
infoLabel.setText("");
String type = elemPanel.getText();
if (// $NON-NLS-1$
Pattern.compile("^\\s+\\w+\\s*").matcher(type).matches() || type.trim().replaceAll("\\s", "").length() != type.trim().length()) {
// $NON-NLS-1$//$NON-NLS-2$
infoLabel.setText(Messages.SimpleTypeInputDialog_infoLabelText);
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
type = type.trim();
if (!XSDUtil.isValidatedXSDName(type)) {
infoLabel.setText(Messages.InvalidName_Message);
getButton(IDialogConstants.OK_ID).setEnabled(false);
return;
}
for (XSDTypeDefinition simpType : xsdSchema.getTypeDefinitions()) {
String typeToCompare = simpType.getName();
// $NON-NLS-1$
int delimiter = type.indexOf(" : ");
if (delimiter != -1) {
type = type.substring(0, delimiter);
}
if (typeToCompare.equals(type)) {
if (caller instanceof XSDNewSimpleTypeDefinition) {
infoLabel.setText(Messages.SimpleTypeInputDialog_SameName);
getButton(IDialogConstants.OK_ID).setEnabled(false);
} else if ((caller instanceof XSDChangeToSimpleTypeAction || caller instanceof XSDChangeBaseTypeAction) && simpType instanceof XSDComplexTypeDefinition) {
infoLabel.setText(Messages.SimpleTypeInputDialog_SameName);
getButton(IDialogConstants.OK_ID).setEnabled(false);
}
return;
}
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class MatchRuleSelectionFilter method check.
public FilterResult check(Object obj) {
if (obj instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) obj;
int maxOccurs = particle.getMaxOccurs();
if (maxOccurs > 1 || maxOccurs == -1) {
return FilterResult.DISABLE;
}
XSDTerm term = particle.getTerm();
if (term instanceof XSDElementDeclaration) {
XSDElementDeclaration element = ((XSDElementDeclaration) term);
XSDTypeDefinition type = element.getType();
if (type instanceof XSDSimpleTypeDefinition) {
return FilterResult.ENABLE;
}
}
}
return FilterResult.DISABLE;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class DataModelMainPage method validateType.
private void validateType() throws IllegalAccessException {
HashMap<String, Boolean> typeCntMap = new HashMap<String, Boolean>();
EList<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions();
// $NON-NLS-1$
String tail = "";
for (XSDTypeDefinition type : types) {
if (type instanceof XSDComplexTypeDefinition) {
tail = Messages.ComplexText;
} else {
tail = Messages.SimpleText;
}
if (typeCntMap.get(type.getName() + tail + type.getTargetNamespace()) == Boolean.TRUE) {
}
typeCntMap.put(type.getName() + tail + type.getTargetNamespace(), Boolean.TRUE);
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class TreeExpandHelper method getExpandedTypeElements.
private Object[] getExpandedTypeElements(DataModelMainPage mainPage) {
TreeViewer typesViewer = mainPage.getTypesViewer();
SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) typesViewer.getContentProvider();
Object[] xsdDeclarations = getChildren(contentProvider.getXsdSchema(), contentProvider);
//
List<Object> result = new ArrayList<Object>();
//
Deque<ExpandInfoNode> nodeStack = new LinkedList<ExpandInfoNode>();
//
Deque<Object> elementStack = new LinkedList<Object>();
// record entities
Map<ExpandInfoNode, XSDTypeDefinition> expandedRoots = new HashMap<ExpandInfoNode, XSDTypeDefinition>();
for (Object obj : xsdDeclarations) {
XSDTypeDefinition type = (XSDTypeDefinition) obj;
String name = type.getName();
for (ExpandInfoNode node : expandedTypes) {
if (name.equals(node.name)) {
expandedRoots.put(node, type);
result.add(type);
// /
nodeStack.add(node);
// /
elementStack.add(type);
break;
}
}
}
while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
ExpandInfoNode node = nodeStack.pollFirst();
Object element = elementStack.pollFirst();
List<ExpandInfoNode> nodes = node.childs;
Object[] elementChildren = getChildren(element, contentProvider);
if (nodes != null && nodes.size() > 0 && elementChildren != null) {
Map<ExpandInfoNode, Object> nodeElementPairs = getNodeElementPairs(elementChildren, nodes);
for (ExpandInfoNode node2 : nodeElementPairs.keySet()) {
nodeStack.add(node2);
elementStack.add(nodeElementPairs.get(node2));
result.add(nodeElementPairs.get(node2));
}
}
}
return result.toArray();
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class XPathTreeContentProvider method getChildren.
@Override
public Object[] getChildren(Object parent) {
if (parent instanceof XSDSchema) {
EList xsdElementDeclarations = xsdSchema.getElementDeclarations();
return filterOutDuplicatedElems(xsdElementDeclarations);
}
if (parent instanceof XSDAttributeGroupDefinition) {
XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) parent;
if (// a ref
attributeGroupDefinition.getContents().size() == 0)
attributeGroupDefinition = attributeGroupDefinition.getResolvedAttributeGroupDefinition();
return attributeGroupDefinition.getContents().toArray(new Object[attributeGroupDefinition.getContents().size()]);
}
if (parent instanceof XSDParticle) {
// a particle inside a choice or sequence or whatever
XSDParticle xsdParticle = (XSDParticle) parent;
return getXSDParticleChildren(xsdParticle);
}
if (parent instanceof XSDModelGroup) {
XSDModelGroup modelGroup = ((XSDModelGroup) parent);
EList list = modelGroup.getContents();
return list.toArray(new Object[list.size()]);
}
if (parent instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
ArrayList list = new ArrayList();
// add Base Type if not a pre-defined type
if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
list.add(std.getBaseTypeDefinition());
list.addAll(std.getFacetContents());
return list.toArray(new Object[list.size()]);
}
if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
// FIXME: How do we indicate it is a LIST?
return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
}
if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
return std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]);
// return new Object[]{std.getBaseTypeDefinition()};
}
if (parent instanceof XSDElementDeclaration) {
// abstract elements do not have children
if (((XSDElementDeclaration) parent).isAbstract())
return new Object[0];
ArrayList<Object> list = new ArrayList<Object>();
// handle extensions and restrictions directly
XSDTypeDefinition typeDefinition = ((XSDElementDeclaration) parent).getTypeDefinition();
if (typeDefinition instanceof XSDComplexTypeDefinition) {
list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition));
} else {
list.add(((XSDElementDeclaration) parent).getTypeDefinition());
}
// }
return list.toArray(new Object[list.size()]);
}
if (parent instanceof XSDIdentityConstraintDefinition) {
ArrayList list = new ArrayList();
return list.toArray(new Object[list.size()]);
}
if (parent instanceof Element) {
// appinfos
return new Object[0];
}
return new Object[0];
}
Aggregations