use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class TreeExpandHelper method getExpandedEntityElements.
// ///
private Object[] getExpandedEntityElements(DataModelMainPage mainPage) {
TreeViewer elementsViewer = mainPage.getElementsViewer();
SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) elementsViewer.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, XSDElementDeclaration> expandedRoots = new HashMap<ExpandInfoNode, XSDElementDeclaration>();
for (Object obj : xsdDeclarations) {
if (obj instanceof XSDElementDeclaration) {
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
String name = decl.getName();
for (ExpandInfoNode node : expandedElements) {
if (name.equals(node.name)) {
expandedRoots.put(node, decl);
result.add(decl);
// /
nodeStack.add(node);
// /
elementStack.add(decl);
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.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class UserVariableDialog method getUserFields.
private List<String> getUserFields() {
try {
if (schema != null) {
XSDSchema xsd = Util.createXsdSchema(schema, null);
List<String> results = new ArrayList<String>();
EList<XSDElementDeclaration> elementDeclarations = xsd.getElementDeclarations();
for (XSDElementDeclaration decl : elementDeclarations) {
if (decl.getName().equals(USER)) {
// $NON-NLS-1$
Map<String, XSDParticle> childElements = Util.getChildElements("", decl, true, new HashSet<Object>());
for (String element : childElements.keySet()) {
// $NON-NLS-1$
String prefix = "//";
if (element.startsWith(prefix)) {
element = element.substring(prefix.length());
}
results.add(element);
}
}
}
return results;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class ElementInfoConfigComposite method refreshPK.
private void refreshPK() {
if (curXSDParticle != null) {
this.section.getTreeObject();
XSDElementDeclaration decl = (XSDElementDeclaration) curXSDParticle.getContent();
List<Object> keyInfo = Util.getKeyInfo(decl);
boolean isPK = keyInfo != null && keyInfo.size() > 0;
comboReference.setEnabled(!isPK);
spinMin.setEnabled(!isPK);
spinMax.setEnabled(!isPK);
}
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class XSDNewParticleFromParticleAction method widgetSelected.
public void widgetSelected(SelectionEvent e) {
if (dialog.getReturnCode() == -1)
// there was a validation error
return;
elementName = dialog.getElementName();
refName = dialog.getRefName();
minOccurs = dialog.getMinOccurs();
maxOccurs = dialog.getMaxOccurs();
// check that this element does not already exist
XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
// get position of the selected particle in the container
for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
XSDParticle p = (XSDParticle) iter.next();
if (p.getTerm() instanceof XSDElementDeclaration) {
XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
if (thisDecl.getName().equals(elementName)) {
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._TheBusinessElement, elementName));
return;
}
}
}
// for
dialog.close();
}
use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.
the class XSDNewParticleFromTypeAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
ctd = (XSDComplexTypeDefinition) selection.getFirstElement();
if (!(ctd.getContent() instanceof XSDParticle)) {
return Status.CANCEL_STATUS;
}
if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) {
return Status.CANCEL_STATUS;
}
;
group = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm();
} else if (selection.getFirstElement() instanceof XSDParticle) {
group = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm();
} else if (selection.getFirstElement() instanceof XSDModelGroup) {
group = (XSDModelGroup) selection.getFirstElement();
} else {
log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(), selection.getFirstElement().toString()));
return Status.CANCEL_STATUS;
}
EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
List<String> elementDeclarations = new LinkedList<String>();
for (XSDElementDeclaration xsdElementDeclaration : eDecls) {
XSDElementDeclaration d = xsdElementDeclaration;
if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
continue;
}
// $NON-NLS-1$//$NON-NLS-2$
elementDeclarations.add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));
}
// $NON-NLS-1$
elementDeclarations.add("");
dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, "", "", elementDeclarations, 0, 1, true, // $NON-NLS-1$//$NON-NLS-2$;
false);
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return Status.CANCEL_STATUS;
}
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration decl = factory.createXSDElementDeclaration();
decl.setName(this.elementName);
// simpleTypeName));
if (!refName.equals("")) {
// $NON-NLS-1$
XSDElementDeclaration ref = Util.findReference(refName, schema);
if (ref != null) {
decl.setResolvedElementDeclaration(ref);
}
} else {
decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
}
XSDParticle particle = factory.createXSDParticle();
particle.setContent(decl);
particle.setMinOccurs(this.minOccurs);
particle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), particle);
group.updateElement();
if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) {
return Status.CANCEL_STATUS;
}
if (dialog.isInherit()) {
XSDTerm totm = particle.getTerm();
XSDElementDeclaration concept = null;
Object obj = Util.getParent(particle);
if (obj instanceof XSDElementDeclaration) {
concept = (XSDElementDeclaration) obj;
} else {
concept = (XSDElementDeclaration) particle.getContent();
}
XSDAnnotation fromannotation = null;
if (concept != null) {
fromannotation = concept.getAnnotation();
}
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
if (((XSDElementDeclaration) totm).getType() != null) {
addAnnotion(struc, fromannotation);
}
}
}
page.refresh();
page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
page.markDirty();
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations