Search in sources :

Example 6 with XSDMinLengthFacet

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

the class UpdateStringLengthFacetCommand method execute.

public void execute() {
    try {
        beginRecording(xsdSimpleType.getElement());
        XSDLengthFacet lengthFacet = xsdSimpleType.getEffectiveLengthFacet();
        XSDMinLengthFacet minLengthFacet = xsdSimpleType.getEffectiveMinLengthFacet();
        XSDMaxLengthFacet maxLengthFacet = xsdSimpleType.getEffectiveMaxLengthFacet();
        String currentLength = null, currentMin = null, currentMax = null;
        if (lengthFacet != null) {
            currentLength = lengthFacet.getLexicalValue();
        }
        if (minLengthFacet != null) {
            currentMin = minLengthFacet.getLexicalValue();
        }
        if (maxLengthFacet != null) {
            currentMax = maxLengthFacet.getLexicalValue();
        }
        if (doUpdateMax && !doUpdateMin) {
            if (maxLengthFacet != null) {
                if (max != null) {
                    if (max.equals(currentMin)) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        lengthFacet.setLexicalValue(max);
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                        xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                        xsdSimpleType.getFacetContents().remove(minLengthFacet);
                    } else {
                        if (lengthFacet != null) {
                            xsdSimpleType.getFacetContents().remove(lengthFacet);
                        }
                        if (minLengthFacet == null && currentLength != null) {
                            minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                            minLengthFacet.setLexicalValue(currentLength);
                            xsdSimpleType.getFacetContents().add(minLengthFacet);
                        }
                        maxLengthFacet.setLexicalValue(max);
                    }
                } else {
                    xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                }
            } else {
                if (currentMin != null && currentMin.equals(max)) {
                    if (lengthFacet == null) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                    }
                    lengthFacet.setLexicalValue(max);
                    xsdSimpleType.getFacetContents().remove(minLengthFacet);
                } else if (currentLength != null && !currentLength.equals(max)) {
                    xsdSimpleType.getFacetContents().remove(lengthFacet);
                    if (max != null) {
                        maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                        maxLengthFacet.setLexicalValue(max);
                        xsdSimpleType.getFacetContents().add(maxLengthFacet);
                    }
                    minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                    minLengthFacet.setLexicalValue(currentLength);
                    xsdSimpleType.getFacetContents().add(minLengthFacet);
                } else {
                    if (lengthFacet != null) {
                        xsdSimpleType.getFacetContents().remove(lengthFacet);
                        minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                        minLengthFacet.setLexicalValue(currentLength);
                        xsdSimpleType.getFacetContents().add(minLengthFacet);
                    }
                    maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                    maxLengthFacet.setLexicalValue(max);
                    xsdSimpleType.getFacetContents().add(maxLengthFacet);
                }
            }
        } else if (!doUpdateMax && doUpdateMin) {
            if (minLengthFacet != null) {
                if (min != null) {
                    if (min.equals(currentMax)) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        lengthFacet.setLexicalValue(min);
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                        xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                        xsdSimpleType.getFacetContents().remove(minLengthFacet);
                    } else {
                        if (lengthFacet != null) {
                            xsdSimpleType.getFacetContents().remove(lengthFacet);
                        }
                        if (maxLengthFacet == null && currentLength != null) {
                            maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                            maxLengthFacet.setLexicalValue(currentLength);
                            xsdSimpleType.getFacetContents().add(maxLengthFacet);
                        }
                        minLengthFacet.setLexicalValue(min);
                    }
                } else {
                    xsdSimpleType.getFacetContents().remove(minLengthFacet);
                }
            } else {
                if (currentMax != null && currentMax.equals(min)) {
                    if (lengthFacet == null) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                    }
                    lengthFacet.setLexicalValue(min);
                    xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                } else if (currentLength != null && !currentLength.equals(min)) {
                    xsdSimpleType.getFacetContents().remove(lengthFacet);
                    if (min != null) {
                        minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                        minLengthFacet.setLexicalValue(min);
                        xsdSimpleType.getFacetContents().add(minLengthFacet);
                    }
                    maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                    maxLengthFacet.setLexicalValue(currentLength);
                    xsdSimpleType.getFacetContents().add(maxLengthFacet);
                } else {
                    minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                    minLengthFacet.setLexicalValue(min);
                    xsdSimpleType.getFacetContents().add(minLengthFacet);
                    if (lengthFacet != null) {
                        xsdSimpleType.getFacetContents().remove(lengthFacet);
                        maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                        maxLengthFacet.setLexicalValue(currentLength);
                        xsdSimpleType.getFacetContents().add(maxLengthFacet);
                    }
                }
            }
        }
        formatChild(xsdSimpleType.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet)

Example 7 with XSDMinLengthFacet

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

the class XSDEditFacetAction method editMinLength.

// EditLength
private void editMinLength() {
    XSDMinLengthFacet currentValue = std.getMinLengthFacet();
    // $NON-NLS-1$
    String stringValue = "0";
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle4, Messages.XSDEditFacetAction_DialogTitle4Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
    IInputValidator() {

        public String isValid(String newText) {
            int val;
            try {
                val = Integer.parseInt(newText);
            } catch (Exception e) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            if (val < 0) {
                return Messages.XSDEditFacetAction_ValueMustBeXX;
            }
            return null;
        }
    });
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
    if (intValue > 0) {
        XSDMinLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinLengthFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + intValue);
        std.getFacetContents().add(f);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

XSDMinLengthFacet (org.eclipse.xsd.XSDMinLengthFacet)7 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)6 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)6 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)4 XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)4 XSDMinExclusiveFacet (org.eclipse.xsd.XSDMinExclusiveFacet)4 XSDMinInclusiveFacet (org.eclipse.xsd.XSDMinInclusiveFacet)4 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)3 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 XSDTotalDigitsFacet (org.eclipse.xsd.XSDTotalDigitsFacet)3 ArrayList (java.util.ArrayList)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)2 XSDParticle (org.eclipse.xsd.XSDParticle)2 XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)2 XSDWhiteSpaceFacet (org.eclipse.xsd.XSDWhiteSpaceFacet)2 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1