Search in sources :

Example 46 with XSDConcreteComponent

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

the class MakeAnonymousTypeGlobalCommand method run.

public void run() {
    XSDConcreteComponent model = getModelObject();
    XSDConcreteComponent parent = model.getContainer();
    XSDTypeDefinition globalTypeDef = null;
    if (model instanceof XSDComplexTypeDefinition) {
        if (parent instanceof XSDElementDeclaration) {
            // clone typedef with it's content and set it global
            globalTypeDef = (XSDComplexTypeDefinition) model.cloneConcreteComponent(true, false);
            globalTypeDef.setName(fNewName);
            parent.getSchema().getContents().add(globalTypeDef);
            ((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
        }
    } else if (model instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) model;
        if (parent instanceof XSDElementDeclaration) {
            // clone typedef with it's content and set it global
            globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
            globalTypeDef.setName(fNewName);
            parent.getSchema().getContents().add(globalTypeDef);
            ((XSDElementDeclaration) parent).setTypeDefinition(globalTypeDef);
            formatChild(globalTypeDef.getElement());
        } else if (parent instanceof XSDAttributeDeclaration) {
            // clone typedef with it's content and set it global
            globalTypeDef = (XSDSimpleTypeDefinition) typeDef.cloneConcreteComponent(true, false);
            globalTypeDef.setName(fNewName);
            parent.getSchema().getContents().add(globalTypeDef);
            ((XSDAttributeDeclaration) parent).setTypeDefinition((XSDSimpleTypeDefinition) globalTypeDef);
        }
    }
    formatChild(globalTypeDef.getElement());
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 47 with XSDConcreteComponent

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

the class MakeAnonymousTypsGlobalEnablementTester method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
    if (selectedObject == null) {
        return false;
    }
    XSDSchema selectedComponentSchema = null;
    boolean enable = false;
    selectedComponentSchema = selectedObject.getSchema();
    if (selectedComponentSchema != null && selectedComponentSchema == schema) {
        enable = true;
    }
    if (enable && selectedObject instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) selectedObject;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            return true;
        }
    } else if (enable && selectedObject instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) selectedObject;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            return true;
        } else if (parent instanceof XSDAttributeDeclaration) {
            return true;
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 48 with XSDConcreteComponent

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

the class MakeAnonymousTypeGobalHandler method doExecute.

public Object doExecute(ISelection selection, XSDSchema schema) {
    if (selection != null) {
        Object selectedObject = ((StructuredSelection) selection).getFirstElement();
        if (selectedObject instanceof XSDBaseAdapter) {
            selectedObject = ((XSDBaseAdapter) selectedObject).getTarget();
        }
        XSDConcreteComponent concreteComp = null;
        if (selectedObject instanceof Node) {
            Node node = (Node) selectedObject;
            concreteComp = schema.getCorrespondingComponent(node);
        } else if (selectedObject instanceof XSDConcreteComponent) {
            concreteComp = ((XSDConcreteComponent) selectedObject);
        }
        if (concreteComp != null) {
            if (concreteComp instanceof XSDComplexTypeDefinition) {
                isComplexType = true;
                XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) concreteComp;
                XSDConcreteComponent parent = typeDef.getContainer();
                if (parent instanceof XSDElementDeclaration) {
                    parentName = ((XSDElementDeclaration) parent).getName();
                    run(selection, schema, typeDef);
                } else if (concreteComp instanceof XSDSimpleTypeDefinition) {
                    isComplexType = false;
                    XSDSimpleTypeDefinition simpleTypeDef = (XSDSimpleTypeDefinition) concreteComp;
                    XSDConcreteComponent parentComp = simpleTypeDef.getContainer();
                    if (parentComp instanceof XSDElementDeclaration) {
                        parentName = ((XSDElementDeclaration) parent).getName();
                    } else if (parent instanceof XSDAttributeDeclaration) {
                        parentName = ((XSDAttributeDeclaration) parent).getName();
                    }
                    run(selection, schema, simpleTypeDef);
                }
            }
        }
    }
    return null;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Node(org.w3c.dom.Node) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 49 with XSDConcreteComponent

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

the class ElementInfoConfigComposite method getAllReferences.

private String[] getAllReferences() {
    ArrayList<String> elementDeclarations = new ArrayList<String>();
    // $NON-NLS-1$
    elementDeclarations.add("");
    if (curXSDParticle == null) {
        return elementDeclarations.toArray(new String[0]);
    }
    if (curXSDParticle.getSchema() == null) {
        return new String[0];
    }
    XSDConcreteComponent entity = getParentElement(curXSDParticle);
    for (XSDElementDeclaration eachXSDEleDeclaration : curXSDParticle.getSchema().getElementDeclarations()) {
        if (eachXSDEleDeclaration.getTargetNamespace() != null && eachXSDEleDeclaration.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
            continue;
        }
        if (!eachXSDEleDeclaration.equals(entity)) {
            elementDeclarations.add(eachXSDEleDeclaration.getQName() + (// $NON-NLS-1$
            eachXSDEleDeclaration.getTargetNamespace() != null ? // $NON-NLS-1$
            " : " + eachXSDEleDeclaration.getTargetNamespace() : // $NON-NLS-1$
            ""));
        }
    }
    return elementDeclarations.toArray(new String[0]);
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList)

Example 50 with XSDConcreteComponent

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

the class ElementInfoConfigComposite method getParentElement.

private XSDConcreteComponent getParentElement(XSDParticle xSDParticle) {
    XSDConcreteComponent rootContainer = xSDParticle.getRootContainer();
    XSDConcreteComponent container = xSDParticle.getContainer();
    while (!container.getContainer().equals(rootContainer)) {
        container = container.getContainer();
    }
    return container;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent)

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