use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDAddComplexTypeElementAction method createParticle.
private XSDParticle createParticle() {
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDElementDeclaration resultElementDeclaration = factory.createXSDElementDeclaration();
resultElementDeclaration.setName(elementName);
resultElementDeclaration.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), defaultTypeName));
XSDParticle resultParticle = factory.createXSDParticle();
resultParticle.setContent(resultElementDeclaration);
resultParticle.setMinOccurs(this.minOccurs);
XSDModelGroup group = modelGroup;
if (maxOccurs > -1) {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
} else {
resultParticle.setMaxOccurs(this.maxOccurs);
group.getContents().add(group.getContents().size(), resultParticle);
group.updateElement();
if (resultParticle.getElement().getAttributeNode("maxOccurs") != null) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");
} else {
// $NON-NLS-1$//$NON-NLS-2$
resultParticle.getElement().setAttribute("maxOccurs", "unbounded");
}
}
Util.changeElementTypeToSequence(resultElementDeclaration, maxOccurs);
if (dialogR.isInherit()) {
XSDTerm totm = resultParticle.getTerm();
XSDElementDeclaration concept = null;
Object parent = Util.getParent(resultParticle);
if (parent instanceof XSDElementDeclaration) {
concept = (XSDElementDeclaration) parent;
} else {
concept = (XSDElementDeclaration) resultParticle.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);
}
}
}
return resultParticle;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDAnnotationLookupFieldsAction 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);
// (XSDComponent) selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ExceptionInfo, xSDCom.getClass().getName()));
}
dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getLookupFields().values()), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDAnnotationLookupFieldsAction_SetLookupFields, Messages.XSDAnnotationLookupFieldsAction_LookupFields, page, AnnotationOrderedListsDialog.AnnotationLookupField_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_Lookup_Field");
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.XSDAnnotationLookupFieldsAction_ErrorMsg, 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 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;
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method addAnnotationForXSDElementDeclaration.
public void addAnnotationForXSDElementDeclaration(XSDElementDeclaration fromElem, XSDElementDeclaration toElem) {
if (fromElem.getAnnotation() != null) {
// toElem.setAnnotation(cloneXSDAnnotation(toElem.getAnnotation(),fromElem.getAnnotation()));
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(toElem);
addAnnotion(struc, fromElem.getAnnotation());
}
if (fromElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) fromElem.getTypeDefinition()).getContent();
// in this situation,if not copy the complex type, the type change to simple type
if (this.typeList.containsKey(toElem.getTypeDefinition().getName())) {
this.copyTypeSet.add(this.typeList.get(toElem.getTypeDefinition().getName()));
}
if (toElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
XSDComplexTypeContent tocomplexType = ((XSDComplexTypeDefinition) toElem.getTypeDefinition()).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) {
// ((XSDElementDeclaration)
// totm).setAnnotation(cloneXSDAnnotation(((XSDElementDeclaration)
// totm).getAnnotation(),fromannotation));
XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
if (((XSDElementDeclaration) totm).getType() != null) {
addAnnotion(struc, fromannotation);
} else {
MessageDialog.openInformation(page.getSite().getShell(), Messages.Warning, Messages.bind(Messages.XSDPasteConceptAction_Information, fromElem.getName()));
return;
}
}
if (((XSDElementDeclaration) totm).getType() != null && this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
}
addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
}
}
}
}
}
} else {
String simpleType = fromElem.getTypeDefinition().getName();
if (this.typeList.containsKey(simpleType)) {
this.copyTypeSet.add(fromElem.getTypeDefinition());
}
}
}
use of com.amalto.workbench.utils.XSDAnnotationsStructure in project tmdm-studio-se by Talend.
the class XSDSetAnnotaionDisplayFormatAction 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.XSDSetAnnoXX_ExceptionInfo + selection.getFirstElement().getClass().getName());
}
dlg = new AnnotationLanguageLabelsDialog(struc.getDisplayFormat(), new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
dlg.close();
}
}, page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle2);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
LinkedHashMap<String, String> fomats = dlg.getDescriptionsMap();
struc.setDisplayFormat(fomats);
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnoXX_ErrorMsg2, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations