use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDSetAnnotationForeignKeyAction method doAction.
@Override
public IStatus doAction() {
try {
IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
XSDComponent xSDCom = null;
if (selection.getFirstElement() instanceof Element) {
TreePath tPath = ((TreeSelection) selection).getPaths()[0];
for (int i = 0; i < tPath.getSegmentCount(); i++) {
if (tPath.getSegment(i) instanceof XSDAnnotation) {
xSDCom = (XSDAnnotation) (tPath.getSegment(i));
}
}
} else {
xSDCom = (XSDComponent) selection.getFirstElement();
}
XSDAnnotationsStructure struc = null;
if (xSDCom != null) {
struc = new XSDAnnotationsStructure(xSDCom);
}
if (struc == null || struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.UnableEditType, xSDCom.getClass().getName()));
}
sxid = getNewSimpleXpathInputDlg(struc.getForeignKey());
sxid.setLock(true);
sxid.setPKXpaths(XSDUtil.getAllPKXpaths(schema));
String fksep = struc.getForeignKeyNotSep();
if (fksep != null) {
sxid.setFkSep(Boolean.valueOf(fksep));
}
sxid.setBlockOnOpen(true);
int ret = sxid.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
String fk = "".equals(sxid.getXpath()) ? null : sxid.getXpath().replaceAll("'|\"", "");
// keep the foreignkey in memory to improve performance
if (Util.getForeignKeys() != null && fk != null) {
if (struc.getForeignKey() != null) {
Util.getForeignKeys().remove(Util.getConceptFromPath(struc.getForeignKey()));
}
Util.getForeignKeys().add(Util.getConceptFromPath(fk));
}
struc.setForeignKey(fk);
Boolean sep = sxid.getSepFk();
struc.setForeignKeyNotSep(sep);
updateAnnotationStructure(struc);
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDNewParticleFromParticleAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
selParticle = (XSDParticle) selection.getFirstElement();
if (!(selParticle.getContainer() instanceof XSDModelGroup))
return Status.CANCEL_STATUS;
;
XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
// get position of the selected particle in the container
int index = 0;
int i = 0;
for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
XSDParticle p = (XSDParticle) iter.next();
if (p.equals(selParticle)) {
index = i;
break;
}
i++;
}
EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
List<String> elementDeclarations = new ArrayList<String>();
for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext(); ) {
XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
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, null, null, elementDeclarations, 0, 1, true, false);
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return Status.CANCEL_STATUS;
}
XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent();
if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) {
return Status.CANCEL_STATUS;
}
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration decl = factory.createXSDElementDeclaration();
decl.setName(this.elementName);
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);
if (maxOccurs > -1) {
particle.setMaxOccurs(this.maxOccurs);
} else {
particle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), particle);
group.updateElement();
if (// $NON-NLS-1$
particle.getElement().getAttributeNode("maxOccurs") != null)
// $NON-NLS-1$//$NON-NLS-2$
particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
else {
// $NON-NLS-1$//$NON-NLS-2$
particle.getElement().setAttribute("maxOccurs", "unbounded");
}
}
if (maxOccurs > -1) {
group.getContents().add(group.getContents().size(), particle);
group.updateElement();
}
if (dialog.isInherit()) {
XSDTerm totm = particle.getTerm();
XSDElementDeclaration concept = null;
if (Util.getParent(selParticle) instanceof XSDElementDeclaration)
concept = (XSDElementDeclaration) Util.getParent(selParticle);
else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
if (selParticle instanceof XSDParticle)
concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent();
else if (selParticle instanceof XSDElementDeclaration)
concept = (XSDElementDeclaration) selParticle;
}
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;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class DisplayFormatCommitHandler method doSubmit.
@Override
protected boolean doSubmit() throws CommitException {
XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
LinkedHashMap<String, String> langCode2Value = new LinkedHashMap<String, String>();
for (Entry<String, LanguageInfo> eachLangCode2LangInfo : getCommitedObj().getLangCode2LangInfo().entrySet()) langCode2Value.put(eachLangCode2LangInfo.getKey(), eachLangCode2LangInfo.getValue().getLabel());
return xsdAnnoStruct.setDisplayFormat(langCode2Value);
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class ElementForeighKeyCommitHandler method doSubmit.
@Override
protected boolean doSubmit() throws CommitException {
XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
String[] values = getCommitedObj().getValues();
if (Util.getForeignKeys() != null && values != null) {
if (xsdAnnoStruct.getForeignKey() != null)
Util.getForeignKeys().remove(Util.getConceptFromPath(xsdAnnoStruct.getForeignKey()));
Util.getForeignKeys().add(Util.getConceptFromPath(values[0]));
}
if (values.length > 1) {
xsdAnnoStruct.setForeignKeyNotSep(Boolean.valueOf(values[1]));
}
boolean setForeignKey = xsdAnnoStruct.setForeignKey(values[0]);
doUpdateFKAnnotationStructure(xsdAnnoStruct);
return setForeignKey;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class ElementForeignKeyInfosCommitHandler method doSubmit.
@Override
protected boolean doSubmit() throws CommitException {
XSDAnnotationsStructure xsdAnnoStruct = getXSDAnnotationStruct();
try {
xsdAnnoStruct.setForeignKeyInfos(Arrays.asList(getCommitedObj().getInfos()));
xsdAnnoStruct.setFormatForeignKeyInfo(getCommitedObj().getFormatFkInfo());
doUpdateFKAnnotationStructure(xsdAnnoStruct);
} catch (Exception e) {
throw new CommitException(e.getMessage(), e);
}
return true;
}
Aggregations