Search in sources :

Example 1 with XSDElementDeclaration

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

the class AnnotationOrderedListsDialog method getConceptElements.

private List<String> getConceptElements() {
    DataModelMainPage page = parentPage;
    IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
    List<String> childNames = new ArrayList<String>();
    XSDElementDeclaration decl = null;
    if (selection.getFirstElement() instanceof XSDElementDeclaration) {
        decl = (XSDElementDeclaration) selection.getFirstElement();
    // childNames = Util.getChildElementNames(decl.getElement());
    } else if (selection.getFirstElement() instanceof Element) {
        TreePath tPath = ((TreeSelection) selection).getPaths()[0];
        XSDComponent xSDCom = null;
        for (int i = 0; i < tPath.getSegmentCount(); i++) {
            if (tPath.getSegment(i) instanceof XSDAnnotation) {
                xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                break;
            }
        }
        decl = (XSDElementDeclaration) xSDCom.getContainer();
    }
    try {
        childNames = Util.getChildElementNames(decl.getName(), decl);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return childNames;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 2 with XSDElementDeclaration

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

the class ComplexTypeInputDialogR method valid.

private boolean valid() {
    elementName = elementNameText.getText().trim();
    if (((elementName == null) || ("".equals(elementName)))) {
        // $NON-NLS-1$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return false;
    }
    if (elementName.replaceAll("\\s", "").length() != elementName.length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotContainEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return false;
    }
    if ("".equals(minOccursText.getText()) && "".equals(maxOccursText.getText())) {
        // $NON-NLS-1$//$NON-NLS-2$
        minOccurs = 1;
        maxOccurs = 1;
        return false;
    }
    try {
        minOccurs = Integer.parseInt(minOccursText.getText());
    } catch (Exception e1) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }
    if (minOccurs < 0) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }
    if ("".equals(maxOccursText.getText())) {
        // $NON-NLS-1$
        maxOccurs = -1;
    } else {
        try {
            maxOccurs = Integer.parseInt(maxOccursText.getText());
        } catch (Exception e2) {
            MessageDialog.openError(this.getShell(), Messages._Error, Messages._MaxOccBeNum);
            setReturnCode(-1);
            maxOccursText.setFocus();
            return false;
        }
        if ((maxOccurs < minOccurs) || (maxOccurs <= 0)) {
            maxOccurs = -1;
        }
    }
    // get position of the selected particle in the container
    for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
        XSDParticle p = iter.next();
        if (p.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
            if (thisDecl.getName().equals(elementName)) {
                MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._BusinessEle, elementName));
                return false;
            }
        }
    }
    // for
    String typeName = getTypeName();
    if (!"".equals(typeName)) {
        // $NON-NLS-1$
        EList<XSDTypeDefinition> list = xsdSchema.getTypeDefinitions();
        for (Iterator<XSDTypeDefinition> iter = list.iterator(); iter.hasNext(); ) {
            XSDTypeDefinition td = iter.next();
            if (td.getName().equals(typeName)) {
                if (td instanceof XSDSimpleTypeDefinition) {
                    MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._ThisType, typeName));
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 3 with XSDElementDeclaration

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

the class DOMViewDialog method collectKeyWords.

private void collectKeyWords(XSDElementDeclaration elementDeclaration, Set<String> keys) {
    String elementName = elementDeclaration.getName();
    keys.add(elementName);
    XSDTypeDefinition typeDefinition = elementDeclaration.getType();
    if (typeDefinition instanceof XSDComplexTypeDefinition) {
        XSDParticle particle = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
        XSDTerm term = particle.getTerm();
        if (term instanceof XSDModelGroup) {
            EList<XSDParticle> particles = ((XSDModelGroup) term).getContents();
            for (XSDParticle p : particles) {
                XSDTerm childTerm = p.getTerm();
                if (childTerm instanceof XSDElementDeclaration) {
                    collectKeyWords((XSDElementDeclaration) childTerm, keys);
                }
            }
        }
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 4 with XSDElementDeclaration

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

the class NewConceptOrElementDialog method modifyText.

public void modifyText(ModifyEvent e) {
    if (typeNameText.getText().trim().equals("")) {
        // $NON-NLS-1$
        infoLabel.setText(Messages.NewConceptOrElementDialog_ElementNamecannotbeEmpty);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    } else if (typeNameText.getText().replaceAll("\\s", "").length() != typeNameText.getText().length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        infoLabel.setText(Messages.NewConceptOrElementDialog_NameCannotContainEmpty);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    } else if (!XSDUtil.isValidatedXSDName(typeNameText.getText().trim())) {
        infoLabel.setText(Messages.InvalidName_Message);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    } else if (simpleTypeBtn.getSelection() && (elemPanel.getText().trim().equals("") || elemPanel.getText().replaceAll("\\s", "").length() != // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    elemPanel.getText().length())) {
        infoLabel.setText(Messages.NewConceptOrElementDialog_ComboValueCannotbeEmptyOrXX);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    } else if (// $NON-NLS-1$
    complexTypeBtn.getSelection() && !conceptPanel.getText().trim().equals("") && conceptPanel.getText().replaceAll("\\s", "").length() != conceptPanel.getText().length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        infoLabel.setText(Messages.NewConceptOrElementDialog_ComboValueCannotbeEmptyOrXX);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    } else {
        EList list = schema.getElementDeclarations();
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            XSDElementDeclaration decl = (XSDElementDeclaration) iter.next();
            if (decl.getName().equalsIgnoreCase(typeNameText.getText())) {
                infoLabel.setText(Messages.NewConceptOrElementDialog_ElementEntityAlreadyExists);
                getButton(IDialogConstants.OK_ID).setEnabled(false);
                return;
            }
        }
        if ((e != null && e.widget == conceptPanel.getTypeCombo()) || (e == null && conceptPanel.getTypeCombo().isEnabled())) {
            validateType(conceptPanel.getText(), false);
            return;
        } else if ((e != null && e.widget == elemPanel.getTypeCombo()) || (e == null && elemPanel.getTypeCombo().isEnabled())) {
            validateType(elemPanel.getText(), true);
            return;
        }
    }
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    // $NON-NLS-1$
    infoLabel.setText("");
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator)

Example 5 with XSDElementDeclaration

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

the class XpathSelectDialog method getXpath.

private String getXpath(StructuredSelection sel) {
    // $NON-NLS-1$
    String path = "";
    // $NON-NLS-1$
    String totalXpath = "";
    TreeItem item;
    TreeItem[] items = domViewer.getTree().getSelection();
    for (int i = 0; i < items.length; i++) {
        item = items[i];
        XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
        if (!(component instanceof XSDParticle) && !(component instanceof XSDElementDeclaration)) {
            continue;
        }
        do {
            component = (XSDConcreteComponent) item.getData();
            if (component instanceof XSDParticle) {
                if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration) {
                    // $NON-NLS-1$
                    path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
                }
            } else if (component instanceof XSDElementDeclaration) {
                // $NON-NLS-1$//$NON-NLS-2$
                path = (isAbsolutePath ? "/" : "") + ((XSDElementDeclaration) component).getName() + path;
            }
            item = item.getParentItem();
        } while (item != null);
        if (i == 0) {
            totalXpath = path;
        } else {
            // $NON-NLS-1$
            totalXpath += "&" + path;
        }
        // $NON-NLS-1$
        path = "";
    }
    // for(i=0
    if (context != null && conceptName != null) {
        if (totalXpath.equals(conceptName)) {
            // $NON-NLS-1$
            totalXpath = totalXpath.replaceAll(conceptName, "/");
        } else {
            // $NON-NLS-1$//$NON-NLS-2$
            totalXpath = totalXpath.replaceAll(conceptName + "/", "");
        }
        if (totalXpath.equals(context) || totalXpath.equals(context.replaceAll(conceptName + "/", ""))) {
            // $NON-NLS-1$//$NON-NLS-2$
            // $NON-NLS-1$
            totalXpath = ".";
        }
        if (// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        totalXpath.indexOf('/') == -1 && !totalXpath.equals(".") && !"/".equals(totalXpath) && !"/".equals(context) && !context.equals(conceptName)) {
            // $NON-NLS-1$
            totalXpath = "../" + totalXpath;
        }
    }
    return totalXpath;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) TreeItem(org.eclipse.swt.widgets.TreeItem) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21