use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDUtil method iterateParticle.
private static void iterateParticle(XSDParticle particle, IXPathSelectionFilter filter, Set<String> paths, String prefix) {
XSDTerm term = particle.getTerm();
if (term instanceof XSDModelGroup) {
EList<XSDParticle> contents = ((XSDModelGroup) term).getContents();
for (XSDParticle p : contents) {
XSDTerm t = p.getTerm();
if (t instanceof XSDElementDeclaration) {
XSDElementDeclaration element = ((XSDElementDeclaration) t);
FilterResult r = filter.check(p);
if (r == FilterResult.ENABLE) {
String path = prefix + element.getName();
paths.add(path);
} else {
XSDTypeDefinition type = element.getType();
if (type instanceof XSDComplexTypeDefinition) {
String nextPrefix = prefix + element.getName() + DIVIDE;
XSDParticle cp = type.getComplexType();
iterateParticle(cp, filter, paths, nextPrefix);
}
}
}
}
}
}
use of org.eclipse.xsd.XSDTerm 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 org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class XSDChangeToComplexTypeAction method updateCompositorType.
private boolean updateCompositorType(XSDTypeDefinition superType, XSDModelGroup currentGroup) {
XSDParticle superTypeParticle = superType.getComplexType();
XSDTerm term = superTypeParticle.getTerm();
if (term instanceof XSDModelGroup) {
XSDModelGroup group = (XSDModelGroup) term;
if (group.getCompositor() == XSDCompositor.ALL_LITERAL || currentGroup.getCompositor() == XSDCompositor.ALL_LITERAL) {
if (MessageDialog.openConfirm(null, Messages._ChangeToSequenceType, Messages._ComplexTypeToSequence)) {
group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
superTypeParticle.updateElement();
currentGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
currentGroup.updateElement();
return true;
}
return false;
}
}
return true;
}
use of org.eclipse.xsd.XSDTerm in project tmdm-studio-se by Talend.
the class DataModelMainPage method fillContextMenu.
protected void fillContextMenu(IMenuManager manager, boolean isType) {
IStructuredSelection selection;
if (!isType) {
selection = ((IStructuredSelection) viewer.getSelection());
} else {
selection = ((IStructuredSelection) typesViewer.getSelection());
}
Object[] selectedObjs = selection.toArray();
Object obj = selection.getFirstElement();
if (!isType) {
manager.add(newConceptAction);
} else {
manager.add(newComplexTypeAction);
manager.add(newSimpleTypeAction);
// add by ymli; fix the bug:0012228. Made the multiple types can be deleted.
XSDDeleteTypeDefinition deleteTypeDefinition1;
if (selectedObjs.length > 1) {
deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, true);
} else {
deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, false);
}
if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs)) {
manager.add(deleteTypeDefinition1);
}
deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
manager.add(deleteConceptWrapAction.outPutDeleteActions());
if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs)) {
manager.add(newBrowseItemAction);
}
}
if (exAdapter != null && obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
exAdapter.fillContextMenu(manager);
}
}
manager.add(new Separator());
if (!isType && ((selection == null) || (selection.getFirstElement() == null))) {
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 0) {
manager.add(new Separator(ADDITIONMENUID));
// add by ymli, fix bug 0009770
// $NON-NLS-1$
String title = "";
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
title = Messages.PasteEntityText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
title = Messages.PasteEntitiesText;
}
XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
if (pasteConceptAction.checkInPasteType()) {
manager.add(new Separator());
manager.add(pasteConceptAction);
}
}
return;
}
// Element Declaration
if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
// check if concept or "just" element
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
boolean isConcept = Util.checkConcept(decl);
if (!Util.IsAImporedElement(decl, xsdSchema)) {
if (isConcept) {
manager.add(editConceptAction);
manager.add(deleteConceptAction);
manager.add(newBrowseItemAction);
} else {
manager.add(editElementAction);
manager.add(deleteElementAction);
}
// add by ymli. fix bug 0009770 add the copy of concepts
copyConceptAction.setText(Messages.CopyEntityText);
if (Util.checkInCopy(selectedObjs)) {
manager.add(new Separator());
manager.add(copyConceptAction);
}
/*
* boolean isMulti = false; if(WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size()>1)
* isMulti = true;
*/
// $NON-NLS-1$
String title = "";
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
title = Messages.PasteEntitiesText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
title = Messages.PasteEntityText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1) {
title = Messages.PasteElementsText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1) {
title = Messages.PasteElement;
}
XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
if (pasteConceptAction.checkInPasteType()) {
manager.add(pasteConceptAction);
}
manager.add(new Separator());
manager.add(newElementAction);
manager.add(new Separator());
manager.add(changeToComplexTypeAction);
manager.add(changeToSimpleTypeAction);
// add by fliu, see bugID:0009157
if (((XSDElementDeclaration) obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
manager.add(setFacetMsgAction);
manager.add(setAnnotationDisplayFomatAction);
}
manager.add(new Separator());
manager.add(newIdentityConstraintAction);
} else {
if (isConcept) {
manager.add(newBrowseItemAction);
}
manager.add(newElementAction);
}
// Annotations
if (!Util.IsAImporedElement(decl, xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(), xsdSchema)) {
setAnnotationActions2(obj, manager);
}
}
// add by rhou.fix bug 0012073: Enable to create element from sub element group
if (obj instanceof XSDModelGroup) {
manager.add(new Separator());
manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
manager.add(new Separator());
manager.add(changeSubElementGroupAction);
manager.add(new Separator());
manager.add(setAnnotationLabelAction);
addPasteElementAction(manager);
}
if (obj instanceof XSDAttributeUse && selectedObjs.length == 1) {
manager.add(deleteAttributeAction);
}
if (obj instanceof XSDAttributeDeclaration && selectedObjs.length == 1) {
manager.add(deleteAttributeAction);
}
if (obj instanceof XSDParticle && selectedObjs.length == 1) {
XSDTerm term = ((XSDParticle) obj).getTerm();
if (!(term instanceof XSDWildcard)) {
if (term instanceof XSDElementDeclaration) {
manager.add(editParticleAction);
if (!Util.IsAImporedElement(term, xsdSchema) || term.getContainer() instanceof XSDSchema) {
manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
if (term instanceof XSDModelGroup) {
manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
manager.add(newGroupFromTypeAction);
}
manager.add(deleteParticleAction);
// edit by ymli. fix the bug:0011523
copyConceptAction.setText(Messages.CopyElementText);
manager.add(copyConceptAction);
if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
addPasteElementAction(manager);
}
manager.add(new Separator());
manager.add(changeToComplexTypeAction);
manager.add(changeToSimpleTypeAction);
// add by fliu, see bugID:0009157
manager.add(new Separator());
// Annotations
XSDTypeDefinition type = ((XSDElementDeclaration) term).getTypeDefinition();
setAnnotationActions(obj, manager);
if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
manager.add(setFacetMsgAction);
manager.add(setAnnotationDisplayFomatAction);
}
// Xpath
manager.add(new Separator());
manager.add(getXPathAction);
}
}
}
}
if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition) obj).getTargetNamespace() == null) {
if (!isType && !Util.IsAImporedElement((XSDParticle) obj, xsdSchema)) {
manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
manager.add(newGroupFromTypeAction);
}
if (!Util.IsAImporedElement((XSDComplexTypeDefinition) obj, xsdSchema)) {
// add by rhou.fix bug 0012073: Enable to create element from sub element group
manager.add(new Separator());
manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
manager.add(new Separator());
manager.add(editComplexTypeAction);
}
manager.add(setAnnotationLabelAction);
addPasteElementAction(manager);
}
if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition) obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition) obj, xsdSchema)) {
manager.add(deleteIdentityConstraintAction);
manager.add(new Separator());
manager.add(newXPathAction);
}
if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition) obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDXPathDefinition) obj, xsdSchema)) {
manager.add(editXPathAction);
manager.add(newXPathAction);
XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
manager.add(deleteXPathAction);
}
}
// for the anonymous simpleType
if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition) obj, xsdSchema) || ((XSDSimpleTypeDefinition) obj).getName() == null)) {
XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) obj;
manager.add(changeBaseTypeAction);
manager.add(new Separator());
if (typedef.getBaseTypeDefinition() != null) {
EList list = typedef.getBaseTypeDefinition().getValidFacets();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
String element = (String) iter.next();
manager.add(new XSDEditFacetAction(this, element));
}
}
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
manager.add(newBrowseItemAction);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
if (!isType) {
manager.add(deleteConceptWrapAction.outPutDeleteActions());
}
// $NON-NLS-1$
String title = "";
if (Util.checkInCopyTypeElement(selectedObjs)) {
title = Messages.CopyEntitiesText;
} else if (Util.checkInCOpyTypeParticle(selectedObjs)) {
title = Messages.CopyElements;
}
copyConceptAction.setText(title);
if (Util.checkInCopy(selectedObjs)) {
manager.add(copyConceptAction);
}
// add by ymli; fix bug:0016645
if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
}
}
if (exAdapter != null) {
exAdapter.fillContextMenu(manager, selectedObjs);
}
// available models
java.util.List<IAvailableModel> availablemodels = AvailableModelUtil.getAvailableModels(isLocalInput());
for (int i = 0; i < availablemodels.size(); i++) {
IAvailableModel model = availablemodels.get(i);
model.fillContextMenu(obj, manager, this, dataModelName);
if (i == 1) {
manager.add(new Separator());
}
}
//
manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager);
// Other plug-ins can contribute there actions here
manager.add(new Separator(ADDITIONMENUID));
deleteConceptWrapAction.clearExtraClassToDel();
}
use of org.eclipse.xsd.XSDTerm 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