Search in sources :

Example 1 with XSDPatternFacet

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

the class XSDChangeBaseTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) selection.getFirstElement();
        // Cannot change the simple type definition of built in type
        // if (schema.getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) return
        // Status.CANCEL_STATUS;
        // build list of custom types and built in types
        ArrayList customTypes = new ArrayList();
        for (Object element : schema.getTypeDefinitions()) {
            XSDTypeDefinition type = (XSDTypeDefinition) element;
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List builtInTypes = XSDUtil.getBuiltInTypes();
        // can't change builtin's base type
        if (builtInTypes.contains(typedef.getName())) {
            return Status.CANCEL_STATUS;
        }
        dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema, Messages.XSDChangeBaseTypeAction_DialogTitle, customTypes, builtInTypes, typedef.getBaseTypeDefinition().getName());
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // backup current Base Type
        XSDTypeDefinition current = typedef.getBaseTypeDefinition();
        // set new one
        if (builtIn) {
            typedef.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if simple type definition already exists
            XSDSimpleTypeDefinition std = schema.resolveSimpleTypeDefinition(typeName);
            if (!schema.getTypeDefinitions().contains(std)) {
                // $NON-NLS-1$
                std.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));
                schema.getContents().add(std);
            }
            typedef.setBaseTypeDefinition(std);
        }
        // remove current facets
        typedef.getFacetContents().removeAll(typedef.getFacetContents());
        typedef.updateElement();
        if (builtIn) {
            EList<XSDConstrainingFacet> constrainFacts = typedef.getBaseTypeDefinition().getFacetContents();
            for (XSDConstrainingFacet fact : constrainFacts) {
                if (fact instanceof XSDPatternFacet) {
                    XSDPatternFacet newFact = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                    newFact.setLexicalValue(((XSDPatternFacet) fact).getLexicalValue());
                    typedef.getFacetContents().add(newFact);
                }
            }
            typedef.updateElement();
        }
        // remove current if no more in use
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeBaseTypeAction_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SimpleTypeInputDialog(com.amalto.workbench.dialogs.SimpleTypeInputDialog) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 2 with XSDPatternFacet

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

the class XSDChangeToSimpleTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        XSDElementDeclaration decl = null;
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        // declNew is the new created one not the selected one in tree vew
        if (declNew != null) {
            decl = declNew;
        } else if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            isConcept = true;
            decl = (XSDElementDeclaration) selection.getFirstElement();
        } else {
            isConcept = false;
            if (selection.getFirstElement() != null) {
                decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm();
            }
        }
        // build list of custom types and built in types
        List<String> customTypes = new ArrayList<String>();
        for (XSDTypeDefinition type : schema.getTypeDefinitions()) {
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List<String> builtInTypes = XSDUtil.getBuiltInTypes();
        if (showDlg) {
            String name = decl.getTypeDefinition().getName();
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                name = null;
                boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning, Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning);
                if (!confirm) {
                    return Status.CANCEL_STATUS;
                }
            }
            dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema, Messages.XSDChangeToXX_DialogTitle, customTypes, builtInTypes, name);
            dialog.setBlockOnOpen(true);
            int ret = dialog.open();
            if (ret == Window.CANCEL) {
                return Status.CANCEL_STATUS;
            }
        }
        // remove all unique keys and make new one
        if (isConcept) {
            // remove exisitng unique key(s)
            ArrayList keys = new ArrayList();
            EList list = decl.getIdentityConstraintDefinitions();
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    keys.add(icd);
                }
            }
            decl.getIdentityConstraintDefinitions().removeAll(keys);
            // add new unique Key
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDIdentityConstraintDefinition uniqueKey = factory.createXSDIdentityConstraintDefinition();
            uniqueKey.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
            uniqueKey.setName(decl.getName());
            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);
        }
        // Save current type definition
        XSDTypeDefinition current = decl.getTypeDefinition();
        // set new one
        if (builtIn) {
            decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if concept already exists
            if (typeName != null && typeName.length() > 0) {
                XSDSimpleTypeDefinition std = null;
                // $NON-NLS-1$
                String ns = "";
                if (typeName.lastIndexOf(" : ") != -1) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    ns = typeName.substring(typeName.lastIndexOf(" : ") + 3);
                    // $NON-NLS-1$
                    typeName = typeName.substring(0, typeName.lastIndexOf(" : "));
                }
                for (XSDTypeDefinition typeDef : schema.getTypeDefinitions()) {
                    if (typeDef instanceof XSDSimpleTypeDefinition) {
                        if (typeDef.getName().equals(typeName)) {
                            std = (XSDSimpleTypeDefinition) typeDef;
                            break;
                        }
                    }
                }
                if (std == null) {
                    std = schema.resolveSimpleTypeDefinition(typeName);
                    std.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
                    "string"));
                    if (typeName.equals(EUUIDCustomType.MULTI_LINGUAL.getName())) {
                        XSDPatternFacet f = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                        // $NON-NLS-1$
                        f.setLexicalValue("(\\[\\w+\\:[^\\[\\]]*\\]){0,}");
                        std.getFacetContents().add(f);
                    }
                    schema.getContents().add(std);
                }
                decl.setTypeDefinition(std);
            } else {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                simpleType = factory.createXSDSimpleTypeDefinition();
                simpleType.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), // $NON-NLS-1$
                "string"));
                decl.setAnonymousTypeDefinition(simpleType);
            }
        }
        decl.updateElement();
        // remove current if no more in use
        // if (current != null) {
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }
        // }
        declNew = null;
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeToXX_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDFactory(org.eclipse.xsd.XSDFactory) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) SimpleTypeInputDialog(com.amalto.workbench.dialogs.SimpleTypeInputDialog) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 3 with XSDPatternFacet

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

the class DataModelMainPage method getElementType.

private int getElementType(Object decl) {
    if (Util.getParent(decl) == decl) {
        if (Util.checkConcept((XSDElementDeclaration) decl)) {
            return 0;
        }
        return 1;
    }
    if (decl instanceof XSDComplexTypeDefinition) {
        return 2;
    }
    if (decl instanceof XSDIdentityConstraintDefinition) {
        return 3;
    }
    if (decl instanceof XSDXPathDefinition) {
        return 4;
    }
    if (decl instanceof XSDSimpleTypeDefinition) {
        return 5;
    }
    if (decl instanceof XSDAnnotation) {
        return 6;
    }
    if (decl instanceof XSDParticle) {
        return 7;
    }
    if (decl instanceof XSDModelGroup) {
        return 8;
    }
    if (decl instanceof XSDWhiteSpaceFacet) {
        return 201;
    }
    if (decl instanceof XSDLengthFacet) {
        return 202;
    }
    if (decl instanceof XSDMinLengthFacet) {
        return 203;
    }
    if (decl instanceof XSDMaxLengthFacet) {
        return 204;
    }
    if (decl instanceof XSDTotalDigitsFacet) {
        return 205;
    }
    if (decl instanceof XSDFractionDigitsFacet) {
        return 206;
    }
    if (decl instanceof XSDMaxInclusiveFacet) {
        return 207;
    }
    if (decl instanceof XSDMaxExclusiveFacet) {
        return 208;
    }
    if (decl instanceof XSDMinInclusiveFacet) {
        return 209;
    }
    if (decl instanceof XSDMinExclusiveFacet) {
        return 210;
    }
    if (decl instanceof XSDPatternFacet) {
        return 211;
    }
    if (decl instanceof XSDEnumerationFacet) {
        return 212;
    }
    if (decl instanceof Element) {
        Element e = (Element) decl;
        if (e.getLocalName().equals("appinfo")) {
        // $NON-NLS-1$
        }
        // $NON-NLS-1$
        String source = e.getAttribute("source");
        if (source != null) {
            if (source.startsWith("X_Label_")) {
                // $NON-NLS-1$
                return 101;
            } else if (source.equals("X_ForeignKey")) {
                // $NON-NLS-1$
                return 102;
            } else if (source.equals("X_ForeignKeyInfo")) {
                // $NON-NLS-1$
                return 103;
            } else if (source.equals("X_SourceSystem")) {
                // $NON-NLS-1$
                return 104;
            } else if (source.equals("X_TargetSystem")) {
                // $NON-NLS-1$
                return 105;
            } else if (source.startsWith("X_Description_")) {
                // $NON-NLS-1$
                return 106;
            } else if (source.equals("X_Write")) {
                // $NON-NLS-1$
                return 107;
            } else if (source.equals("X_Hide")) {
                // $NON-NLS-1$
                return 108;
            } else if (source.equals("X_Schematron")) {
                // $NON-NLS-1$
                return 109;
            } else if (source.startsWith("X_Facet_")) {
                // $NON-NLS-1$
                return 110;
            } else if (source.startsWith("X_Workflow")) {
                // $NON-NLS-1$
                return 111;
            } else if (source.startsWith("X_ForeignKey_Filter")) {
                // $NON-NLS-1$
                return 112;
            } else if (source.startsWith("X_Display_Format_")) {
                // $NON-NLS-1$
                return 113;
            } else if (source.equals("X_Lookup_Field")) {
                // $NON-NLS-1$
                return 114;
            } else if (source.equals("X_PrimaryKeyInfo")) {
                // $NON-NLS-1$
                return 115;
            } else if (source.equals("X_Visible_Rule")) {
                // $NON-NLS-1$
                return 116;
            } else if (source.equals("X_Default_Value_Rule")) {
                // $NON-NLS-1$
                return 117;
            } else if (source.equals("X_Deny_Create")) {
                // $NON-NLS-1$
                return 118;
            } else if (source.equals("X_Deny_PhysicalDelete")) {
                // $NON-NLS-1$
                return 119;
            } else if (source.equals("X_Deny_LogicalDelete")) {
                // $NON-NLS-1$
                return 120;
            } else if (source.equals("X_FKIntegrity")) {
                // $NON-NLS-1$
                return 121;
            } else if (source.equals("X_FKIntegrity_Override")) {
                // $NON-NLS-1$
                return 122;
            } else if (source.equals("X_ForeignKeyInfoFormat")) {
                // $NON-NLS-1$
                return 123;
            }
        }
    }
    return -1;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWhiteSpaceFacet(org.eclipse.xsd.XSDWhiteSpaceFacet) Element(org.w3c.dom.Element) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 4 with XSDPatternFacet

use of org.eclipse.xsd.XSDPatternFacet in project webtools.sourceediting by eclipse.

the class UpdateXSDPatternFacetCommand method execute.

public void execute() {
    try {
        beginRecording(xsdSimpleTypeDefinition.getElement());
        if (actionType == ADD) {
            XSDPatternFacet pattern = XSDFactory.eINSTANCE.createXSDPatternFacet();
            pattern.setLexicalValue(value);
            xsdSimpleTypeDefinition.getFacetContents().add(pattern);
        } else if (actionType == DELETE) {
            Assert.isNotNull(patternToEdit);
            if (xsdSimpleTypeDefinition.getFacetContents().contains(patternToEdit))
                xsdSimpleTypeDefinition.getFacetContents().remove(patternToEdit);
        } else if (actionType == UPDATE) {
            Assert.isNotNull(patternToEdit);
            patternToEdit.setLexicalValue(value);
        }
        formatChild(xsdSimpleTypeDefinition.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet)

Example 5 with XSDPatternFacet

use of org.eclipse.xsd.XSDPatternFacet in project webtools.sourceediting by eclipse.

the class SpecificConstraintsWidget method doGetValue.

public Object doGetValue(Object element, String property) {
    if (element instanceof XSDPatternFacet) {
        XSDPatternFacet patternFacet = (XSDPatternFacet) element;
        String value = patternFacet.getLexicalValue();
        if (value == null)
            // $NON-NLS-1$
            value = "";
        return value;
    } else if (element instanceof XSDEnumerationFacet) {
        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) element;
        String value = enumFacet.getLexicalValue();
        if (value == null)
            // $NON-NLS-1$
            value = "";
        return value;
    }
    // $NON-NLS-1$
    return "";
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet)

Aggregations

XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)9 ArrayList (java.util.ArrayList)5 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)5 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)4 Iterator (java.util.Iterator)3 List (java.util.List)3 SimpleTypeInputDialog (com.amalto.workbench.dialogs.SimpleTypeInputDialog)2 EList (org.eclipse.emf.common.util.EList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDConstrainingFacet (org.eclipse.xsd.XSDConstrainingFacet)2 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)2 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)2 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)2 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)2 XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)2 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)2 XSDMinExclusiveFacet (org.eclipse.xsd.XSDMinExclusiveFacet)2 XSDMinInclusiveFacet (org.eclipse.xsd.XSDMinInclusiveFacet)2 XSDMinLengthFacet (org.eclipse.xsd.XSDMinLengthFacet)2