Search in sources :

Example 11 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.

the class XSDEditXPathAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement();
        icd = (XSDIdentityConstraintDefinition) xpath.getContainer();
        // InputDialog id = new InputDialog(
        // page.getSite().getShell(),
        // "Edit XPath",
        // "Enter a new XPath for the "+((xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))?"field":"selector"),
        // xpath.getValue(),
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty";
        // return null;
        // };
        // }
        // );
        // List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer());
        List<String> childNames = new ArrayList<String>();
        // $NON-NLS-1$
        childNames.add(".");
        SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(), Messages.XSDEditXPathAction_DialogTitle, childNames, xpath.getValue());
        id.create();
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        String field = id.getField();
        if (field.length() == 0)
            return Status.CANCEL_STATUS;
        XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
        newXpath.setValue(field);
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            int index = icd.getFields().indexOf(xpath);
            newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
            icd.getFields().set(index, newXpath);
        } else {
            newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
            icd.setSelector(newXpath);
        }
        icd.updateElement();
        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(newXpath), true);
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditXPathAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : SelectFieldDialog(com.amalto.workbench.dialogs.SelectFieldDialog) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 12 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.

the class XSDNewConceptAction method widgetSelected.

/**
 * author: fliu .this fun is to support button click event invoked from the new expansion of Concept creation dialog
 */
public void widgetSelected(SelectionEvent e) {
    // $NON-NLS-1$
    NewConceptOrElementDialog dlg = (NewConceptOrElementDialog) ((Widget) e.getSource()).getData("dialog");
    if (dlg.getReturnCode() == Window.OK) {
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        decl = factory.createXSDElementDeclaration();
        decl.setName(dlg.getTypeName());
        // $NON-NLS-1$
        decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));
        XSDIdentityConstraintDefinition uniqueKey = factory.createXSDIdentityConstraintDefinition();
        uniqueKey.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
        uniqueKey.setName(dlg.getTypeName());
        XSDXPathDefinition selector = factory.createXSDXPathDefinition();
        selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
        // $NON-NLS-1$
        selector.setValue(".");
        uniqueKey.setSelector(selector);
        XSDXPathDefinition field = factory.createXSDXPathDefinition();
        field.setVariety(XSDXPathVariety.FIELD_LITERAL);
        // $NON-NLS-1$
        field.setValue(".");
        uniqueKey.getFields().add(field);
        decl.getIdentityConstraintDefinitions().add(uniqueKey);
        schema.getContents().add(decl);
        // schema.getElementDeclarations().add(decl);
        decl.updateElement();
        // page.markDirty();
        getOperationHistory();
        UndoAction changeAction = null;
        if (dlg.isComplexType()) {
            changeAction = new XSDChangeToComplexTypeAction(page, decl, dlg.getComplexType(), dlg.isChoice(), dlg.isAll(), dlg.isAbstract(), dlg.getSuperTypeName());
        } else {
            changeAction = new XSDChangeToSimpleTypeAction(page, decl, dlg.getElementType(), dlg.isBuildIn());
        }
        dlg.close();
        changeAction.setOmitTrack(true);
        IStatus status = changeAction.execute();
        if (status == Status.CANCEL_STATUS) {
            schema.getContents().remove(decl);
        }
        page.refresh();
    }
}
Also used : NewConceptOrElementDialog(com.amalto.workbench.dialogs.NewConceptOrElementDialog) IStatus(org.eclipse.core.runtime.IStatus) XSDFactory(org.eclipse.xsd.XSDFactory) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 13 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition 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;
}
Also used : CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDFactory(org.eclipse.xsd.XSDFactory) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) CommitValidationException(com.amalto.workbench.detailtabs.exception.CommitValidationException) CommitException(com.amalto.workbench.detailtabs.exception.CommitException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) HashSet(java.util.HashSet)

Example 14 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.

the class EntityCommitHandler method commitKeyUpdate_Selector.

private boolean commitKeyUpdate_Selector(KeyWrapper keyWrapper) {
    if (keyWrapper.getSourceKey().getSelector().getValue().equals(keyWrapper.getSelector())) {
        return false;
    }
    XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
    newXpath.setValue(keyWrapper.getSelector());
    newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
    keyWrapper.getSourceKey().setSelector(newXpath);
    keyWrapper.getSourceKey().updateElement();
    return true;
}
Also used : XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 15 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition in project tmdm-studio-se by Talend.

the class EntityCommitHandler method commitKeyAddition.

private boolean commitKeyAddition() {
    boolean hasChanges = false;
    for (KeyWrapper eachKeyWrapper : getCommitedObj().getKeys()) {
        if (!eachKeyWrapper.isUserCreated()) {
            continue;
        }
        hasChanges = true;
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDIdentityConstraintDefinition newKey = factory.createXSDIdentityConstraintDefinition();
        newKey.setName(eachKeyWrapper.getName());
        newKey.setIdentityConstraintCategory(eachKeyWrapper.getType());
        XSDXPathDefinition selector = factory.createXSDXPathDefinition();
        selector.setValue(eachKeyWrapper.getSelector());
        selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
        newKey.setSelector(selector);
        for (FieldWrapper newFields : eachKeyWrapper.getFields()) {
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setValue(newFields.getXPath());
            field.setVariety(XSDXPathVariety.FIELD_LITERAL);
            newKey.getFields().add(field);
        }
        getCommitedObj().getSourceEntity().getIdentityConstraintDefinitions().add(newKey);
        getCommitedObj().getSourceEntity().updateElement();
    }
    return hasChanges;
}
Also used : KeyWrapper(com.amalto.workbench.detailtabs.sections.model.entity.KeyWrapper) XSDFactory(org.eclipse.xsd.XSDFactory) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) FieldWrapper(com.amalto.workbench.detailtabs.sections.model.entity.FieldWrapper) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Aggregations

XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)37 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)32 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)16 ArrayList (java.util.ArrayList)15 XSDParticle (org.eclipse.xsd.XSDParticle)15 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)14 XSDFactory (org.eclipse.xsd.XSDFactory)12 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)10 Iterator (java.util.Iterator)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 Element (org.w3c.dom.Element)7 EList (org.eclipse.emf.common.util.EList)6 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)6 XSDSchema (org.eclipse.xsd.XSDSchema)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)5