use of org.eclipse.xsd.XSDIdentityConstraintDefinition in project tmdm-studio-se by Talend.
the class XpathSelectDialog method provideViwerContent.
// changeDomTree(
protected void provideViwerContent(XSDSchema xsdSchema, String filter) {
drillDownAdapter = new DrillDownAdapter(domViewer);
domViewer.setLabelProvider(new XSDTreeLabelProvider(selectionFilter));
XPathTreeContentProvider provider = new XPathTreeContentProvider(this.site, xsdSchema, parent, filter);
// filter the entity with the filter text but not the concept name.
// provider.setConceptName(this.conceptName);
domViewer.setContentProvider(provider);
domViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent e) {
StructuredSelection sel = (StructuredSelection) e.getSelection();
xpath = getXpath(sel);
xpathText.setText(xpath);
boolean enable = false;
if (selectionFilter == null) {
enable = xpath.length() > 0;
} else {
enable = xpath.length() > 0 && (selectionFilter.check(sel.getFirstElement()) == FilterResult.ENABLE);
}
getButton(IDialogConstants.OK_ID).setEnabled(enable);
}
});
domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
domViewer.setSorter(new ViewerSorter() {
@Override
public int category(Object element) {
// SimpleTypeDefinition
if (element instanceof XSDFacet) {
return 100;
}
// unique keys after element declarations and before other keys
if (element instanceof XSDIdentityConstraintDefinition) {
XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) element;
if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
return 300;
} else if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.KEY_LITERAL)) {
return 301;
} else {
return 302;
}
}
return 200;
}
@Override
public int compare(Viewer theViewer, Object e1, Object e2) {
int cat1 = category(e1);
int cat2 = category(e2);
return cat1 - cat2;
}
});
domViewer.setInput(site);
}
use of org.eclipse.xsd.XSDIdentityConstraintDefinition in project tmdm-studio-se by Talend.
the class Util method checkConcept.
public static boolean checkConcept(XSDElementDeclaration decl) {
boolean isConcept = false;
EList<XSDIdentityConstraintDefinition> list = decl.getIdentityConstraintDefinitions();
for (Iterator<XSDIdentityConstraintDefinition> iter = list.iterator(); iter.hasNext(); ) {
XSDIdentityConstraintDefinition icd = iter.next();
if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
isConcept = true;
break;
}
}
return isConcept;
}
use of org.eclipse.xsd.XSDIdentityConstraintDefinition in project tmdm-studio-se by Talend.
the class Util method getRealKeyInfos.
public static List<Object> getRealKeyInfos(XSDElementDeclaration currentEntity, XSDParticle son) {
if (currentEntity == null || son == null) {
return null;
}
if (!isDirectChild(currentEntity, son)) {
return null;
}
List<Object> list = new ArrayList<Object>();
XSDTerm term = son.getTerm();
if (term instanceof XSDElementDeclaration) {
String primaryKey = ((XSDElementDeclaration) term).getName();
EList<XSDIdentityConstraintDefinition> idtylist = currentEntity.getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition idty : idtylist) {
EList<XSDXPathDefinition> fields = idty.getFields();
for (XSDXPathDefinition path : fields) {
if ((path.getValue()).equals(primaryKey)) {
list.add(idty);
list.add(path);
break;
}
}
}
}
return list;
}
use of org.eclipse.xsd.XSDIdentityConstraintDefinition in project tmdm-studio-se by Talend.
the class XSDUtil method getKeyFields.
public static List<String> getKeyFields(XSDElementDeclaration concept) {
List<String> keyFields = new ArrayList<String>();
EList<XSDIdentityConstraintDefinition> identityConstraintDefinitions = concept.getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition icd : identityConstraintDefinitions) {
if (concept.getName().equals(icd.getName())) {
EList<XSDXPathDefinition> fields = icd.getFields();
for (XSDXPathDefinition xpathdef : fields) {
keyFields.add(xpathdef.getValue());
}
}
}
return keyFields;
}
use of org.eclipse.xsd.XSDIdentityConstraintDefinition in project tmdm-studio-se by Talend.
the class Util method getTopParent.
public static List<Object> getTopParent(Object son) {
if (!((son instanceof XSDElementDeclaration))) {
return null;
}
XSDElementDeclaration elem = null;
elem = (XSDElementDeclaration) son;
if (elem.getSchema() == null) {
return null;
}
EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
List<Object> list = new ArrayList<Object>();
for (XSDSchemaContent top : parentList) {
list.clear();
if (!(top instanceof XSDElementDeclaration)) {
continue;
}
XSDElementDeclaration decl = (XSDElementDeclaration) top;
if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
String primaryKey = getTopElement(decl, elem);
if (!"".equalsIgnoreCase(primaryKey)) {
// $NON-NLS-1$
EList<XSDIdentityConstraintDefinition> idtylist = decl.getIdentityConstraintDefinitions();
for (XSDIdentityConstraintDefinition idty : idtylist) {
EList<XSDXPathDefinition> fields = idty.getFields();
for (XSDXPathDefinition path : fields) {
if ((path.getValue()).equals(primaryKey)) {
list.add(idty);
list.add(path);
return list;
}
}
}
}
}
}
return null;
}
Aggregations