use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class DataModelMainPage method setLabelForElement.
private void setLabelForElement(XSDElementDeclaration xSDEle, boolean isAdd) {
if (xSDEle.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDAnnotationsStructure struc = null;
String labelValue = null;
List childrenList = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) xSDEle.getTypeDefinition());
for (int j = 0; j < childrenList.size(); j++) {
List<XSDParticle> particles = new ArrayList<XSDParticle>();
if (childrenList.get(j) instanceof XSDModelGroup) {
particles = ((XSDModelGroup) childrenList.get(j)).getParticles();
}
for (int k = 0; k < particles.size(); k++) {
XSDParticle xSDCom = particles.get(k);
struc = new XSDAnnotationsStructure(xSDCom);
if (xSDCom.getContent() instanceof XSDElementDeclaration) {
labelValue = ((XSDElementDeclaration) xSDCom.getContent()).getName();
setLabel(struc, labelValue, isAdd);
setLabelForElement((XSDElementDeclaration) xSDCom.getContent(), isAdd);
}
}
}
}
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class DataModelMainPage method addLabelForTheItem.
private void addLabelForTheItem(TreeItem[] items, boolean isAdd) {
XSDComponent xSDCom = null;
for (TreeItem item : items) {
XSDAnnotationsStructure struc = null;
String labelValue = null;
if (item.getData() instanceof XSDElementDeclaration) {
xSDCom = (XSDElementDeclaration) item.getData();
struc = new XSDAnnotationsStructure(xSDCom);
labelValue = ((XSDElementDeclaration) xSDCom).getName();
setLabel(struc, labelValue, isAdd);
setLabelForElement((XSDElementDeclaration) xSDCom, isAdd);
}
}
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method addAnnotationForComplexType.
public void addAnnotationForComplexType(XSDComplexTypeDefinition fromType, XSDComplexTypeDefinition toType) {
XSDComplexTypeContent tocomplexType = toType.getContent();
XSDComplexTypeContent fromcomplexType = fromType.getContent();
if (fromcomplexType instanceof XSDParticle) {
XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
EList<XSDParticle> fromlist = frommodelGroup.getContents();
EList<XSDParticle> tolist = tomodelGroup.getContents();
Iterator<XSDParticle> toIt = tolist.iterator();
for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
XSDParticle toel = toIt.next();
XSDTerm totm = toel.getTerm();
XSDTerm fromtm = fromel.getTerm();
if (fromtm instanceof XSDElementDeclaration) {
XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
if (fromannotation != null) {
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
addAnnotion(struc, fromannotation);
if (this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
}
addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
}
}
}
}
}
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method copyElements.
// edit by ymli; fix the bug:0011523: pasty partcles to the element
public void copyElements() {
ArrayList<XSDParticle> particles = WorkbenchClipboard.getWorkbenchClipboard().getParticles();
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDComplexTypeContent content = null;
XSDElementDeclaration element = null;
if (selection.getFirstElement() instanceof XSDElementDeclaration) {
element = (XSDElementDeclaration) selection.getFirstElement();
content = ((XSDComplexTypeDefinition) element.getTypeDefinition()).getContent();
} else if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
content = ((XSDComplexTypeDefinition) selection.getFirstElement()).getContent();
} else if (selection.getFirstElement() instanceof XSDModelGroup) {
XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) ((XSDModelGroup) selection.getFirstElement()).getContainer().getContainer();
content = complexType.getContent();
} else {
if (selection.getFirstElement() instanceof XSDParticle) {
XSDParticle particle = (XSDParticle) selection.getFirstElement();
XSDElementDeclaration declar = (XSDElementDeclaration) particle.getTerm();
if (declar.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeDefinition typeDefinition = (XSDComplexTypeDefinition) declar.getTypeDefinition();
content = typeDefinition.getContent();
}
}
}
if (content instanceof XSDParticle) {
XSDParticle partile = (XSDParticle) content;
if (partile.getTerm() instanceof XSDModelGroup) {
XSDModelGroup toGroup = ((XSDModelGroup) partile.getTerm());
for (XSDParticle particle : particles) {
// if the is particle with the same name, donot copy it.
if (isExist(toGroup, particle)) {
boolean ifOverwrite = MessageDialog.openConfirm(this.page.getSite().getShell(), Messages.XSDPasteConceptAction_Confirm, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg3, ((XSDElementDeclaration) particle.getTerm()).getName()));
if (ifOverwrite) {
reomveElement(toGroup, particle);
} else {
continue;
}
}
XSDParticle newParticle = (XSDParticle) particle.cloneConcreteComponent(true, false);
if (newParticle.getContent() instanceof XSDElementDeclaration && Util.changeElementTypeToSequence(element, newParticle.getMaxOccurs()) == Status.CANCEL_STATUS) {
break;
}
toGroup.getContents().add(newParticle);
toGroup.updateElement();
if (newParticle.getContent() instanceof XSDElementDeclaration) {
if (((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
addAnnotationForComplexType((XSDComplexTypeDefinition) ((XSDElementDeclaration) particle.getContent()).getTypeDefinition(), (XSDComplexTypeDefinition) ((XSDElementDeclaration) newParticle.getContent()).getTypeDefinition());
}
XSDAnnotationsStructure struc1 = new XSDAnnotationsStructure(newParticle.getTerm());
addAnnotion(struc1, ((XSDElementDeclaration) particle.getTerm()).getAnnotation());
Util.changeElementTypeToSequence((XSDElementDeclaration) newParticle.getContent(), newParticle.getMaxOccurs());
}
}
}
}
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDSetAnnotationDescriptionsAction 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);
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
}
AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem);
dlg.setBlockOnOpen(true);
dlg.open();
if (dlg.getReturnCode() == Window.OK) {
// remove existing annotations with labels
struc.removeAllDescriptions();
// add the new ones
LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
Set<String> isoCodes = descriptions.keySet();
for (Iterator iter = isoCodes.iterator(); iter.hasNext(); ) {
String isoCode = (String) iter.next();
struc.setDescription(isoCode, descriptions.get(isoCode));
}
} else {
return Status.CANCEL_STATUS;
}
if (struc.hasChanged()) {
page.markDirty();
page.refresh();
page.getTreeViewer().expandToLevel(xSDCom, 2);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations