Search in sources :

Example 1 with XSDConcreteComponent

use of org.eclipse.xsd.XSDConcreteComponent 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)

Example 2 with XSDConcreteComponent

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

the class Util method getParent.

public static Object getParent(Object son) {
    if (!((son instanceof XSDElementDeclaration) || (son instanceof XSDParticle))) {
        return null;
    }
    XSDElementDeclaration elem = null;
    if (son instanceof XSDParticle) {
        elem = (XSDElementDeclaration) ((XSDParticle) son).getContent();
    } else if (son instanceof XSDElementDeclaration) {
        elem = (XSDElementDeclaration) son;
    }
    if (elem == null || elem.getSchema() == null) {
        return null;
    }
    EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
    for (XSDSchemaContent top : parentList) {
        if (!(top instanceof XSDElementDeclaration) && !(top instanceof XSDComplexTypeDefinition)) {
            continue;
        }
        if (top instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) top;
            if (decl == son) {
                return decl;
            }
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
                if (type.getContent() instanceof XSDParticle) {
                    XSDParticle particle = (XSDParticle) type.getContent();
                    if (particle.getTerm() instanceof XSDModelGroup) {
                        XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                        EList<XSDParticle> elist = group.getContents();
                        for (XSDParticle pt : elist) {
                            if (pt.getContent() instanceof XSDElementDeclaration) {
                                if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                    return decl;
                                }
                            }
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        } else {
            XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) top;
            if (type.getContent() instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle) type.getContent();
                if (particle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                    EList<XSDParticle> elist = group.getContents();
                    for (XSDParticle pt : elist) {
                        if (pt.getContent() instanceof XSDElementDeclaration) {
                            if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                return top;
                            }
                        }
                        if (pt.getContent() instanceof XSDElementDeclaration) {
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet)

Example 3 with XSDConcreteComponent

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

the class XSDDeleteConceptWrapAction method refreshAction.

private void refreshAction() {
    if (delObjs.isEmpty()) {
        return;
    }
    XSDConcreteComponent comp = delObjs.get(0);
    if (checkInSameClassType(delObjs.toArray(), comp.getClass())) {
        String actionTxt = clsAction.get(comp.getClass()).getText();
        if (delObjs.size() > 1) {
            if (actionTxt.endsWith("y")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                actionTxt = actionTxt.substring(0, actionTxt.length() - 1) + "ies";
            } else {
                // $NON-NLS-1$
                actionTxt = actionTxt + "s";
            }
        }
        setText(actionTxt);
    } else {
        setText(Messages.XSDDeleteXX_DeleteObjects);
    }
    setToolTipText(Messages.XSDDeleteXX_DeleteEntities);
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent)

Example 4 with XSDConcreteComponent

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

the class TypesLabelProvider method getImage.

@Override
public Image getImage(Object obj) {
    if (obj instanceof XSDElementDeclaration) {
        // top declaration
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        // check if concept or "just" element
        boolean isConcept = false;
        EList l = decl.getIdentityConstraintDefinitions();
        for (Iterator iter = l.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                isConcept = true;
                break;
            }
        }
        // display approprite image
        if (isConcept) {
            return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
        } else {
            return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
        /*
                 * if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
                 * PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
                 * return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
                 */
        }
    }
    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDTerm xsdTerm = xsdParticle.getTerm();
        if (xsdTerm instanceof XSDElementDeclaration) {
            // get Type of Parent Group
            // if (Util.getKeyInfo(xsdTerm) != null && Util.getKeyInfo(xsdTerm).size() > 0) {
            // return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
            // }
            XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
            if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
                return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
            }
            if (xsdConcreteComponent instanceof XSDModelGroup) {
                return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
            }
        /*
                 * if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
                 * XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
                 * return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
                 */
        } else if (xsdTerm instanceof XSDModelGroup) {
            int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
            switch(type) {
                case XSDCompositor.ALL:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                case XSDCompositor.CHOICE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                case XSDCompositor.SEQUENCE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
            }
        } else if (xsdTerm instanceof XSDWildcard) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/wildcard.gif");
        } else {
            log.info(Messages.TypesLabelProvider_16 + xsdTerm.getClass().getName());
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDSimpleTypeDefinition) {
        return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
    }
    if (obj instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
        XSDComplexTypeContent ctc = ctd.getContent();
        if (ctc instanceof XSDParticle) {
            if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
                int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
                switch(type) {
                    case XSDCompositor.ALL:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                    case XSDCompositor.CHOICE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                    case XSDCompositor.SEQUENCE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
                }
            }
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDModelGroup) {
        int type = ((XSDModelGroup) obj).getCompositor().getValue();
        switch(type) {
            case XSDCompositor.ALL:
                return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
            case XSDCompositor.CHOICE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
            case XSDCompositor.SEQUENCE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
        }
    }
    if (obj instanceof XSDFacet) {
        return ImageCache.getCreatedImage(EImage.FACET.getPath());
    }
    if (obj instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
        if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
            return ImageCache.getCreatedImage(EImage.KEYS.getPath());
        }
        return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
    }
    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/field.gif");
        }
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/selector.gif");
    }
    if (obj instanceof XSDAttributeGroupDefinition) {
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/attribute_group.gif");
    }
    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse att = (XSDAttributeUse) obj;
        if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
        }
        if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute.gif");
        }
    }
    if (obj instanceof XSDAnnotation) {
        return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
    }
    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {
                // $NON-NLS-1$
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            } else 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 ImageCache.getCreatedImage(EImage.LABEL.getPath());
                    } else if (source.equals("X_ForeignKey")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
                    } else if (source.equals("X_ForeignKeyInfo")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity_Override")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_SourceSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
                    } else if (source.equals("X_TargetSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
                    } else if (source.startsWith("X_Description_")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    } else if (source.equals("X_Write")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Hide")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_Create")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_LogicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_AutoExpand")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
                    } else {
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    }
                } else {
                    return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                }
            } else {
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // $NON-NLS-1$
    return ImageCache.getCreatedImage("icons/tree_object.gif");
// return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDFacet(org.eclipse.xsd.XSDFacet) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 5 with XSDConcreteComponent

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

the class UtilMockTest method testFindOutSpecialSonElement.

@Test
public void testFindOutSpecialSonElement() {
    // $NON-NLS-1$
    String method_findspecial = "findOutSpecialSonElement";
    // $NON-NLS-1$
    String method_findall = "findOutAllSonElements";
    Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String[] names = { "ele1", "ele2", "ele3", "ele4" };
    PowerMockito.mockStatic(Util.class);
    try {
        PowerMockito.when(Util.class, method_findspecial, any(XSDElementDeclaration.class), any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
        XSDFactory factory = XSDFactory.eINSTANCE;
        XSDElementDeclaration parent = factory.createXSDElementDeclaration();
        XSDElementDeclaration xsdElementDeclaration1 = factory.createXSDElementDeclaration();
        xsdElementDeclaration1.setName(names[0]);
        XSDElementDeclaration xsdElementDeclaration2 = factory.createXSDElementDeclaration();
        xsdElementDeclaration2.setName(names[1]);
        List<XSDElementDeclaration> particleElementList1 = new ArrayList<XSDElementDeclaration>();
        particleElementList1.add(xsdElementDeclaration1);
        particleElementList1.add(xsdElementDeclaration2);
        // 
        PowerMockito.when(Util.class, method_findall, any(XSDElementDeclaration.class), any(XSDComplexTypeDefinition.class)).thenReturn(particleElementList1);
        Object result = Whitebox.invokeMethod(Util.class, method_findspecial, parent, xsdElementDeclaration1, complexTypes);
        assertSame(parent, result);
        // 
        XSDElementDeclaration xsdEleDeclaration1 = factory.createXSDElementDeclaration();
        xsdEleDeclaration1.setName(names[2]);
        XSDElementDeclaration xsdEleDeclaration2 = factory.createXSDElementDeclaration();
        xsdEleDeclaration2.setName(names[3]);
        List<XSDElementDeclaration> particleElementList2 = new ArrayList<XSDElementDeclaration>();
        particleElementList2.add(xsdEleDeclaration1);
        particleElementList2.add(xsdEleDeclaration2);
        PowerMockito.when(Util.class, method_findall, any(XSDElementDeclaration.class), any(XSDComplexTypeDefinition.class)).thenReturn(particleElementList1, particleElementList2);
        result = Whitebox.invokeMethod(Util.class, method_findspecial, parent, xsdEleDeclaration1, complexTypes);
        assertSame(xsdElementDeclaration1, result);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)88 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)30 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)18 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)17 Adapter (org.eclipse.emf.common.notify.Adapter)15 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDParticle (org.eclipse.xsd.XSDParticle)13 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)11 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)11 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)11 List (java.util.List)10 Element (org.w3c.dom.Element)10 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)9 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)9