use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class ElementWrapperCommitHandler method doSubmit.
@Override
protected boolean doSubmit() throws CommitException {
try {
String originalName = getCommitedObj().getSourceName();
XSDElementDeclaration decl = getCommitedObj().getSourceXSDContent();
XSDElementDeclaration ref = null;
if (decl.isElementDeclarationReference()) {
ref = decl.getResolvedElementDeclaration();
}
XSDAnnotationsStructure struct = new XSDAnnotationsStructure(getCommitedObj().getSourceElement());
// remove first
// struct.setAutoExpand(null);
struct.setAutoExpand(String.valueOf(getCommitedObj().isAutoExpand()));
// update validation rule
Set<String> paths = new HashSet<String>();
DataModelMainPage page = getPage();
Util.collectElementPaths((IStructuredContentProvider) page.getElementsViewer().getContentProvider(), page.getSite(), getCommitedObj().getSourceElement(), paths, null);
XSDElementDeclaration newRef = Util.findReference(getCommitedObj().getNewReference(), getCommitedObj().getSchema());
XSDIdentityConstraintDefinition identify = null;
XSDXPathDefinition keyPath = null;
List<Object> keyInfo = Util.getKeyInfo(getCommitedObj().getSourceXSDContent());
if (keyInfo != null && keyInfo.size() > 0) {
identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
keyPath = (XSDXPathDefinition) keyInfo.get(1);
identify.getFields().remove(keyPath);
}
getCommitedObj().getSourceXSDContent().setName(// $NON-NLS-1$
"".equals(getCommitedObj().getNewName()) ? null : getCommitedObj().getNewName());
if (keyPath != null) {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDXPathDefinition field = factory.createXSDXPathDefinition();
field.setVariety(keyPath.getVariety());
field.setValue(getCommitedObj().getNewName());
identify.getFields().add(field);
}
if (newRef != null) {
decl.setResolvedElementDeclaration(newRef);
decl.setTypeDefinition(null);
Element elem = decl.getElement();
if (elem.getAttributes().getNamedItem("type") != null) {
// $NON-NLS-1$
elem.getAttributes().removeNamedItem("type");
}
decl.updateElement();
} else if (ref != null) {
XSDElementDeclaration sourceXSDContent = getCommitedObj().getSourceXSDContent();
sourceXSDContent.setTypeDefinition(getCommitedObj().getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, // $NON-NLS-1$
"string"));
sourceXSDContent.setResolvedElementDeclaration(sourceXSDContent);
// XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
// XSDElementDeclaration newD = (XSDElementDeclaration) factory.createXSDElementDeclaration();
// newD.setName(getCommitedObj().getNewName());
// newD.updateElement();
// XSDSimpleTypeDefinition stringType = getCommitedObj().getSchema().getSchemaForSchema()
// .resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string");
//
// newD.setTypeDefinition(stringType);
// if (getCommitedObj().getSourceElement().getContainer() instanceof XSDModelGroup) {
// XSDModelGroup group = ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer());
// ((XSDModelGroup) getCommitedObj().getSourceElement().getContainer()).getContents().remove(
// getCommitedObj().getSourceElement());
// getCommitedObj().setSourceElement(factory.createXSDParticle());
// getCommitedObj().getSourceElement().setContent(newD);
// group.getContents().add(getCommitedObj().getSourceElement());
// }
}
int newMaxOcur = getCommitedObj().getNewMaxOcur();
if (Util.changeElementTypeToSequence(decl, newMaxOcur) == Status.CANCEL_STATUS) {
return false;
}
int newMinOcur = getCommitedObj().getNewMinOcur();
getCommitedObj().getSourceElement().setMinOccurs(newMinOcur);
if (newMaxOcur == -1 || (newMaxOcur == 0 & newMinOcur == 0)) {
if (!"unbounded".equals(getCommitedObj().getSourceElement().getElement().getAttribute("maxOccurs"))) {
// $NON-NLS-1$//$NON-NLS-2$
getCommitedObj().getSourceElement().getElement().setAttribute("maxOccurs", "unbounded");
}
} else {
getCommitedObj().getSourceElement().setMaxOccurs(newMaxOcur);
}
getCommitedObj().getSourceElement().updateElement();
updateReference(originalName);
if (elementExAdapter != null) {
elementExAdapter.renameElement(getCommitedObj().getSchema(), paths, getCommitedObj().getNewName());
}
if (mapinfoExAdapter != null) {
mapinfoExAdapter.renameElementMapinfo(paths, decl.getName());
}
} catch (Exception e) {
throw new CommitException(e.getMessage(), e);
}
return true;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class ElementFKInfosSection method initUIContents.
@Override
protected void initUIContents(XSDComponent editedObj) {
super.initUIContents(editedObj);
fkInfos.clear();
XSDAnnotationsStructure annoStruct = new XSDAnnotationsStructure(curXSDComponent);
for (String eachFKInfo : annoStruct.getForeignKeyInfos().values()) {
fkInfos.add(eachFKInfo);
}
//
formatFKinfo = annoStruct.getFormatForeignKeyInfo();
holder.setDefaultDataModel(getDataModelName());
holder.setDefaultEntity(getEntityName());
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class EntityPKInfosSection method initUIContents.
@Override
protected void initUIContents(XSDComponent editedObj) {
super.initUIContents(editedObj);
list.clear();
holder.setDefaultDataModel(getDataModelName());
holder.setDefaultEntity(getEntityName());
XSDAnnotationsStructure annoStruct = new XSDAnnotationsStructure(curXSDComponent);
for (String eachLookUpFields : annoStruct.getPrimaryKeyInfos().values()) list.add(eachLookUpFields);
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDSetAnnotationPrimaryKeyInfoAction method doAction.
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 = new XSDAnnotationsStructure(xSDCom);
struc.setXSDSchema(schema);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo1, xSDCom.getClass().getName()));
}
dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getPrimaryKeyInfos().values()), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, // $NON-NLS-1$
page.getSite().getShell(), // $NON-NLS-1$
Messages.XSDSetAnnotationXX_DialogTitle, // $NON-NLS-1$
"xPaths", // $NON-NLS-1$
page, AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType, null);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
struc.setAccessRole(dlg.getXPaths(), false, (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), // $NON-NLS-1$
"X_PrimaryKeyInfo");
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.XSDSetAnnotationXX_Msg, 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 XSDSetAnnotationSourceSystemAction method doAction.
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 = new XSDAnnotationsStructure(xSDCom);
// XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.ExceptionInfo, xSDCom.getClass().getName()));
}
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle1, Messages.XSDSetAnnoXX_DialogTip, struc.getSourceSystem(), new IInputValidator() {
public String isValid(String newText) {
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
// $NON-NLS-1$
struc.setSourceSystem("".equals(id.getValue()) ? null : id.getValue());
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.XSDSetAnnoXX_ErrorMsg1, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations