Search in sources :

Example 46 with XSDAttributeDeclaration

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

the class XSDCommonUIUtils method getAnonymousSimpleType.

public static XSDSimpleTypeDefinition getAnonymousSimpleType(XSDFeature input, XSDSimpleTypeDefinition xsdSimpleTypeDefinition) {
    XSDSimpleTypeDefinition anonymousSimpleType = null;
    XSDTypeDefinition localType = null;
    if (input instanceof XSDElementDeclaration) {
        localType = ((XSDElementDeclaration) input).getAnonymousTypeDefinition();
    } else if (input instanceof XSDAttributeDeclaration) {
        localType = ((XSDAttributeDeclaration) input).getAnonymousTypeDefinition();
    }
    if (localType instanceof XSDSimpleTypeDefinition) {
        anonymousSimpleType = (XSDSimpleTypeDefinition) localType;
    }
    return anonymousSimpleType;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 47 with XSDAttributeDeclaration

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

the class RenameComponentAction method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject) {
    selectedComponent = null;
    if (selectedObject instanceof XSDNamedComponent) {
        selectedComponent = (XSDNamedComponent) selectedObject;
        // if it's element reference, then this action is not appropriate
        if (selectedComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
            if (element.isElementDeclarationReference()) {
                selectedComponent = null;
            }
        }
        if (selectedComponent instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
            XSDConcreteComponent parent = type.getContainer();
            if (parent instanceof XSDElementDeclaration) {
                XSDElementDeclaration element = (XSDElementDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            } else if (parent instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    selectedComponent = null;
                }
            }
        }
    }
    return canRun();
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 48 with XSDAttributeDeclaration

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

the class RenameEnablementTester method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
    if (selectedObject == null) {
        return false;
    }
    XSDNamedComponent selectedComponent = null;
    boolean enable = false;
    XSDSchema selectedComponentSchema = null;
    selectedComponentSchema = selectedObject.getSchema();
    if (selectedComponentSchema != null && selectedComponentSchema == schema) {
        enable = true;
    }
    if (enable && selectedObject instanceof XSDNamedComponent) {
        selectedComponent = (XSDNamedComponent) selectedObject;
        if (selectedComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
            if (element.isElementDeclarationReference()) {
                return false;
            }
            if (!element.isGlobal()) {
                return false;
            }
        }
        if (selectedComponent instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
            XSDConcreteComponent parent = type.getContainer();
            if (parent instanceof XSDElementDeclaration) {
                XSDElementDeclaration element = (XSDElementDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    return false;
                }
            } else if (parent instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    return false;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 49 with XSDAttributeDeclaration

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

the class XSDDeleteAttributeAction method doAction.

@Override
protected IStatus doAction() {
    try {
        XSDAttributeUse attriUse = attributeUse;
        XSDAttributeDeclaration attriDec = attributeDeclaration;
        if (attriUse == null || attriDec == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
            if (firstElement instanceof XSDAttributeUse) {
                attriUse = (XSDAttributeUse) firstElement;
            } else if (firstElement instanceof XSDAttributeDeclaration) {
                attriDec = (XSDAttributeDeclaration) firstElement;
            }
        }
        if (attriUse != null) {
            if (attriUse.getContainer() == null) {
                return Status.CANCEL_STATUS;
            }
            XSDConcreteComponent container = attriUse.getContainer();
            if (container instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition cType = (XSDComplexTypeDefinition) container;
                cType.getAttributeUses().remove(attriUse);
                cType.getAttributeContents().remove(attriUse);
                cType.updateElement();
            }
        } else if (attriDec != null) {
            if (attriDec.getContainer() == null) {
                return Status.CANCEL_STATUS;
            }
            XSDConcreteComponent container = attriDec.getContainer();
            if (container instanceof XSDSchema) {
                XSDSchema xsdschema = (XSDSchema) container;
                xsdschema.getContents().remove(attriDec);
            }
        }
        schema.update();
        attributeUse = null;
        attributeDeclaration = null;
        page.refresh();
        page.markDirtyWithoutCommit();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)49 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)27 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)18 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)17 Iterator (java.util.Iterator)16 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)16 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)15 XSDSchema (org.eclipse.xsd.XSDSchema)15 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 List (java.util.List)10 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)9 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 XSDParticle (org.eclipse.xsd.XSDParticle)7 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)6 XSDWildcard (org.eclipse.xsd.XSDWildcard)6 EList (org.eclipse.emf.common.util.EList)5