Search in sources :

Example 36 with XSDAttributeGroupDefinition

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

the class AddXSDAnyAttributeAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    AddXSDAnyAttributeCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAnyAttributeCommand(Messages._UI_ACTION_ADD_ANY_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDAttributeGroupDefinition) {
        command = new AddXSDAnyAttributeCommand(Messages._UI_ACTION_ADD_ANY_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAnyAttributeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAnyAttributeCommand) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 37 with XSDAttributeGroupDefinition

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

the class AddXSDAttributeDeclarationAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        if (selection instanceof XSDAttributeDeclaration) {
            selection = ((XSDAttributeDeclaration) selection).getContainer();
        }
    }
    AddXSDAttributeDeclarationCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDAttributeUse) {
        XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDAttributeGroupDefinition group = null;
        for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                group = (XSDAttributeGroupDefinition) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = ct.getAttributeContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = group.eContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    } else if (selection instanceof XSDAttributeGroupDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 38 with XSDAttributeGroupDefinition

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

the class XSDAttributeGroupDefinitionSection method doWidgetSelected.

public void doWidgetSelected(SelectionEvent e) {
    if (e.widget == refCombo) {
        String newValue = refCombo.getText();
        if (input instanceof XSDNamedComponent) {
            XSDNamedComponent namedComponent = (XSDNamedComponent) input;
            Element element = namedComponent.getElement();
            if (namedComponent instanceof XSDAttributeGroupDefinition) {
                element.setAttribute(XSDConstants.REF_ATTRIBUTE, newValue);
                XSDDirectivesManager.removeUnusedXSDImports(namedComponent.getSchema());
            }
        }
    }
    super.doWidgetSelected(e);
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) Element(org.w3c.dom.Element) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 39 with XSDAttributeGroupDefinition

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

the class RedefineAttributeGroupCommand method doExecute.

protected void doExecute() {
    XSDAttributeGroupDefinition redefinedAttributeGroupDefinition = XSDFactory.eINSTANCE.createXSDAttributeGroupDefinition();
    redefinedAttributeGroupDefinition.setName(redefinableComponent.getName());
    addedXSDConcreteComponent = redefinedAttributeGroupDefinition;
}
Also used : XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 40 with XSDAttributeGroupDefinition

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

the class DeleteCommand method execute.

public void execute() {
    XSDVisitor visitor = new XSDVisitor() {

        public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
            if (element.getTypeDefinition() == target) {
                // $NON-NLS-1$
                XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
                element.setTypeDefinition(type);
            }
            super.visitElementDeclaration(element);
        }
    };
    XSDConcreteComponent parent = target.getContainer();
    XSDSchema schema = target.getSchema();
    try {
        beginRecording(parent.getElement());
        boolean doCleanup = false;
        if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
            doCleanup = true;
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                } else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
                    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
                    complexType.setContent(null);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDModelGroupDefinitionAdapter) {
                    ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                ((XSDRedefine) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeDeclaration) {
            doCleanup = true;
            if (parent instanceof XSDAttributeUse) {
                EObject obj = parent.eContainer();
                XSDComplexTypeDefinition complexType = null;
                while (obj != null) {
                    if (obj instanceof XSDComplexTypeDefinition) {
                        complexType = (XSDComplexTypeDefinition) obj;
                        break;
                    }
                    obj = obj.eContainer();
                }
                if (complexType != null) {
                    complexType.getAttributeContents().remove(parent);
                }
                if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
                    attrGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
            doCleanup = true;
            ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
        } else if (target instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
            enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
        } else if (target instanceof XSDWildcard) {
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDComplexTypeDefinition) {
                ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
            }
        } else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
            doCleanup = true;
            ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
        } else {
            if (parent instanceof XSDSchema) {
                doCleanup = true;
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                doCleanup = false;
                EList contents = ((XSDRedefine) parent).getContents();
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
                    ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                contents.remove(target);
            }
        }
        if (doCleanup)
            XSDDirectivesManager.removeUnusedXSDImports(schema);
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDVisitor(org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)42 Iterator (java.util.Iterator)20 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)17 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)16 ArrayList (java.util.ArrayList)15 List (java.util.List)15 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)15 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)13 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)13 XSDSchema (org.eclipse.xsd.XSDSchema)12 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)11 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)11 XSDParticle (org.eclipse.xsd.XSDParticle)11 EList (org.eclipse.emf.common.util.EList)10 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)9 Element (org.w3c.dom.Element)9 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)7