Search in sources :

Example 36 with XSDAttributeDeclaration

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

the class MoveXSDAttributeAction method moveUnderXSDComplexTypeDefinition.

protected void moveUnderXSDComplexTypeDefinition(XSDComplexTypeDefinition complexType) {
    int originalIndex = 0;
    for (Iterator iterator = complexType.getAttributeContents().iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (attribute == selected) {
                complexType.getAttributeContents().remove(attribute.getContainer());
                break;
            }
        }
        originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    List attributeGroupContents = complexType.getAttributeContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (insertType == INSERT_AFTER) {
                if (attribute == previousRefComponent) {
                    complexType.getAttributeContents().add(index + 1, selected.getContainer());
                    addedBack = true;
                    break;
                }
            } else if (insertType == INSERT_BEFORE) {
                if (attribute == nextRefComponent) {
                    complexType.getAttributeContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            }
        }
        index++;
    }
    if (attributeGroupContents.size() == 0) {
        complexType.getAttributeContents().add(selected.getContainer());
        addedBack = true;
    }
    if (!addedBack) {
        complexType.getAttributeContents().add(originalIndex, selected.getContainer());
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent)

Example 37 with XSDAttributeDeclaration

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

the class MoveXSDAttributeAction method moveUnderXSDAttributeGroupDefinition.

protected void moveUnderXSDAttributeGroupDefinition(XSDAttributeGroupDefinition parentGroup) {
    int originalIndex = 0;
    for (Iterator iterator = parentGroup.getContents().iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (attribute == selected) {
                parentGroup.getContents().remove(attribute.getContainer());
                break;
            }
        }
        originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    if (insertType == INSERT_DIRECT) {
        XSDConcreteComponent container = selected.getContainer();
        if (container != null) {
            if (insertAtEnd)
                ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(container);
            else
                ((XSDAttributeGroupDefinition) parentComponent).getResolvedAttributeGroupDefinition().getContents().add(0, container);
            addedBack = true;
        }
        return;
    }
    List attributeGroupContents = parentGroup.getContents();
    for (Iterator iterator = attributeGroupContents.iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupContent attributeGroupContent = (XSDAttributeGroupContent) iterator.next();
        if (attributeGroupContent instanceof XSDAttributeUse) {
            XSDAttributeDeclaration attribute = ((XSDAttributeUse) attributeGroupContent).getContent();
            if (insertType == INSERT_BEFORE) {
                if (attribute == nextRefComponent) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
                if (selected == nextRefComponent && originalIndex == index) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            } else if (insertType == INSERT_AFTER) {
                if (attribute == previousRefComponent) {
                    parentGroup.getContents().add(index + 1, selected.getContainer());
                    addedBack = true;
                    break;
                }
                if (selected == previousRefComponent && originalIndex == index) {
                    parentGroup.getContents().add(index, selected.getContainer());
                    addedBack = true;
                    break;
                }
            }
        }
        index++;
    }
    if (attributeGroupContents.size() == 0) {
        parentGroup.getContents().add(selected.getContainer());
        addedBack = true;
    }
    if (!addedBack) {
        parentGroup.getContents().add(originalIndex, selected.getContainer());
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Iterator(java.util.Iterator) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent)

Example 38 with XSDAttributeDeclaration

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

the class XSDAdapterFactory method createAdapter.

public Adapter createAdapter(Notifier target) {
    XSDSwitch xsdSwitch = new XSDSwitch() {

        public Object caseXSDSchemaDirective(XSDSchemaDirective object) {
            return new XSDSchemaDirectiveAdapter();
        }

        public Object caseXSDWildcard(XSDWildcard object) {
            return new XSDWildcardAdapter();
        }

        public Object caseXSDAttributeGroupDefinition(XSDAttributeGroupDefinition object) {
            return new XSDAttributeGroupDefinitionAdapter();
        }

        public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object) {
            return new XSDModelGroupDefinitionAdapter();
        }

        public Object caseXSDAttributeDeclaration(XSDAttributeDeclaration object) {
            return new XSDAttributeDeclarationAdapter();
        }

        public Object caseXSDAttributeUse(XSDAttributeUse object) {
            return new XSDAttributeUseAdapter();
        }

        public Object caseXSDParticle(XSDParticle object) {
            return new XSDParticleAdapter();
        }

        public Object caseXSDElementDeclaration(XSDElementDeclaration object) {
            return new XSDElementDeclarationAdapter();
        }

        public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition object) {
            return new XSDSimpleTypeDefinitionAdapter();
        }

        public Object caseXSDComplexTypeDefinition(XSDComplexTypeDefinition object) {
            // 
            if (// $NON-NLS-1$
            "anyType".equals(object.getName())) {
                return new XSDAnyTypeDefinitionAdapter();
            } else {
                return new XSDComplexTypeDefinitionAdapter();
            }
        }

        public Object caseXSDModelGroup(XSDModelGroup object) {
            return new XSDModelGroupAdapter();
        }

        public Object caseXSDSchema(XSDSchema object) {
            return new XSDSchemaAdapter();
        }

        public Object caseXSDEnumerationFacet(XSDEnumerationFacet object) {
            return new XSDEnumerationFacetAdapter();
        }

        public Object caseXSDRedefine(XSDRedefine object) {
            return new XSDRedefineAdapter();
        }
    };
    Object o = xsdSwitch.doSwitch((EObject) target);
    Adapter result = null;
    if (o instanceof Adapter) {
        result = (Adapter) o;
    } else {
    // Thread.dumpStack();
    }
    return result;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Adapter(org.eclipse.emf.common.notify.Adapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDSwitch(org.eclipse.xsd.util.XSDSwitch) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 39 with XSDAttributeDeclaration

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

the class ExtensionsSection method getAddExtensionCommand.

protected AddExtensionCommand getAddExtensionCommand(Object o) {
    AddExtensionCommand addExtensionCommand = null;
    if (o instanceof XSDElementDeclaration) {
        XSDElementDeclaration element = (XSDElementDeclaration) o;
        ExtensibleAddExtensionCommand extensibleAddExtensionCommand = getExtensionsSchemasRegistry().getAddExtensionCommand(element.getTargetNamespace());
        if (extensibleAddExtensionCommand != null) {
            extensibleAddExtensionCommand.setInputs((XSDConcreteComponent) input, element);
            addExtensionCommand = extensibleAddExtensionCommand;
        } else {
            addExtensionCommand = new AddExtensionElementCommand(Messages._UI_ACTION_ADD_APPINFO_ELEMENT, (XSDConcreteComponent) input, element);
        }
    } else if (o instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attribute = (XSDAttributeDeclaration) o;
        addExtensionCommand = new AddExtensionAttributeCommand(Messages._UI_ACTION_ADD_APPINFO_ATTRIBUTE, (XSDConcreteComponent) input, attribute);
    }
    return addExtensionCommand;
}
Also used : AddExtensionElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionElementCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddExtensionAttributeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionAttributeCommand) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) ExtensibleAddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.ExtensibleAddExtensionCommand) AddExtensionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddExtensionCommand)

Example 40 with XSDAttributeDeclaration

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

the class XSDAttributeDeclarationSection method doHandleEvent.

protected void doHandleEvent(Event event) {
    if (event.type == SWT.Traverse) {
        if (event.detail == SWT.TRAVERSE_ARROW_NEXT || event.detail == SWT.TRAVERSE_ARROW_PREVIOUS) {
            isTraversing = true;
            return;
        }
    }
    super.doHandleEvent(event);
    if (event.widget == nameText) {
        if (!nameText.getEditable())
            return;
        String newValue = nameText.getText().trim();
        if (input instanceof XSDAttributeDeclaration) {
            XSDAttributeDeclaration namedComponent = ((XSDAttributeDeclaration) input).getResolvedAttributeDeclaration();
            if (!validateSection())
                return;
            Command command = null;
            // Make sure an actual name change has taken place
            String oldName = namedComponent.getName();
            if (!newValue.equals(oldName)) {
                command = new UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_ACTION_RENAME, namedComponent, newValue);
            }
            if (command != null && getCommandStack() != null) {
                getCommandStack().execute(command);
            }
            if (isAttributeReference) {
                XSDAttributeDeclaration attrRef = (XSDAttributeDeclaration) input;
                String qname = attrRef.getResolvedAttributeDeclaration().getQName();
                attrRef.getElement().setAttribute(XSDConstants.REF_ATTRIBUTE, qname);
            // TypesHelper helper = new TypesHelper(xsdSchema);
            // List items = new ArrayList();
            // items = helper.getGlobalElements();
            // items.add(0, "");
            // componentNameCombo.setItems((String [])items.toArray(new String[0]));
            // 
            // refreshRefCombo();
            }
        }
    } else if (event.widget == defaultOrFixedText) {
        XSDAttributeDeclaration xsdAttribute = (XSDAttributeDeclaration) input;
        String newValue = defaultOrFixedText.getText();
        Element element = xsdAttribute.getElement();
        if (element != null) {
            if (newValue.length() == 0) {
                PropertiesChangeCommand command = new PropertiesChangeCommand(element, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_LABEL_VALUE) {

                    protected void doExecuteSteps() {
                        element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                    }
                };
                getCommandStack().execute(command);
            } else {
                UpdateAttributeValueCommand command = null;
                if (fixedButton.getSelection()) {
                    command = new UpdateAttributeValueCommand(element, XSDConstants.FIXED_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_FIXED) {

                        protected void doPostProcessing() {
                            element.removeAttribute(XSDConstants.DEFAULT_ATTRIBUTE);
                        }
                    };
                } else {
                    command = new UpdateAttributeValueCommand(element, XSDConstants.DEFAULT_ATTRIBUTE, newValue, org.eclipse.wst.xsd.ui.internal.common.util.Messages._UI_DEFAULT) {

                        protected void doPostProcessing() {
                            element.removeAttribute(XSDConstants.FIXED_ATTRIBUTE);
                        }
                    };
                }
                command.setDeleteIfEmpty(true);
                getCommandStack().execute(command);
            }
        }
    }
}
Also used : UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) UpdateNameCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateNameCommand) BaseCommand(org.eclipse.wst.xsd.ui.internal.common.commands.BaseCommand) UpdateAttributeValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateAttributeValueCommand) Command(org.eclipse.gef.commands.Command) Element(org.w3c.dom.Element) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

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