Search in sources :

Example 26 with XSDNamedComponent

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

Aggregations

XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)26 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)8 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)6 XSDSchema (org.eclipse.xsd.XSDSchema)6 Element (org.w3c.dom.Element)6 ArrayList (java.util.ArrayList)4 Command (org.eclipse.gef.commands.Command)4 UpdateNameCommand (org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand)4 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)4 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)4 Iterator (java.util.Iterator)3 IFile (org.eclipse.core.resources.IFile)3 QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)3 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)3 Point (org.eclipse.draw2d.geometry.Point)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)2 XSDSearchQuery (org.eclipse.wst.xsd.ui.internal.search.XSDSearchQuery)2 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)2 TreeObject (com.amalto.workbench.models.TreeObject)1