Search in sources :

Example 46 with XSDSimpleTypeDefinition

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

the class XSDSimpleTypeSection method handleWidgetSelection.

private void handleWidgetSelection(SelectionEvent e) {
    if (e.widget == typesCombo) {
        IEditorPart editor = getActiveEditor();
        if (editor == null)
            return;
        ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
        String selection = typesCombo.getText();
        ComponentSpecification newValue;
        IComponentDialog dialog = null;
        if (selection.equals(Messages._UI_COMBO_BROWSE)) {
            dialog = manager.getBrowseDialog();
            ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
        } else if (selection.equals(Messages._UI_COMBO_NEW)) {
            dialog = manager.getNewDialog();
            ((NewTypeDialog) dialog).allowComplexType(false);
        }
        if (dialog != null) {
            if (dialog.createAndOpen() == Window.OK) {
                newValue = dialog.getSelectedComponent();
                manager.modifyComponentReference(input, newValue);
            }
        } else // use the value from selected quickPick item
        {
            newValue = getComponentSpecFromQuickPickForValue(selection, manager);
            if (newValue != null)
                manager.modifyComponentReference(input, newValue);
        }
    } else if (e.widget == varietyCombo) {
        if (input != null) {
            if (input instanceof XSDSimpleTypeDefinition) {
                XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
                Element parent = st.getElement();
                String variety = varietyCombo.getText();
                if (variety.equals(XSDVariety.ATOMIC_LITERAL.getName())) {
                    // $NON-NLS-1$
                    typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_BASE_TYPE_WITH_COLON"));
                    st.setVariety(XSDVariety.ATOMIC_LITERAL);
                    // $NON-NLS-1$
                    addCreateElementActionIfNotExist(XSDConstants.RESTRICTION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_RESTRICTION"), parent, null);
                } else if (variety.equals(XSDVariety.UNION_LITERAL.getName())) {
                    // $NON-NLS-1$
                    typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_MEMBERTYPES"));
                    st.setVariety(XSDVariety.UNION_LITERAL);
                    // $NON-NLS-1$
                    addCreateElementActionIfNotExist(XSDConstants.UNION_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_UNION"), parent, null);
                } else if (variety.equals(XSDVariety.LIST_LITERAL.getName())) {
                    // $NON-NLS-1$
                    typesLabel.setText(XSDEditorPlugin.getXSDString("_UI_LABEL_ITEM_TYPE"));
                    st.setVariety(XSDVariety.LIST_LITERAL);
                    // $NON-NLS-1$
                    addCreateElementActionIfNotExist(XSDConstants.LIST_ELEMENT_TAG, XSDEditorPlugin.getXSDString("_UI_ACTION_ADD_LIST"), parent, null);
                }
            }
        }
    }
}
Also used : IComponentDialog(org.eclipse.wst.xsd.ui.internal.adt.edit.IComponentDialog) XSDComplexTypeBaseTypeEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDComplexTypeBaseTypeEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 47 with XSDSimpleTypeDefinition

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

the class XSDSimpleTypeSection method addCreateElementActionIfNotExist.

// issue (cs) this method seems to be utilizing 'old' classes, can we reimplement?
// (e.g. ChangeElementAction, XSDDOMHelper, etc)
protected boolean addCreateElementActionIfNotExist(String elementTag, String label, Element parent, Node relativeNode) {
    XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input;
    List attributes = new ArrayList();
    String reuseType = null;
    // parent); //$NON-NLS-1$
    if (elementTag.equals(XSDConstants.RESTRICTION_ELEMENT_TAG)) {
        Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
        if (listNode != null) {
            if (listNode.hasAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE))
                reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(listNode);
        }
        Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
        if (unionNode != null) {
            if (unionNode.hasAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE)) {
                String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
                StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
                reuseType = stringTokenizer.nextToken();
            }
            XSDDOMHelper.removeNodeAndWhitespace(unionNode);
        }
        if (reuseType == null) {
            reuseType = getBuiltInStringQName();
        }
        attributes.add(new DOMAttribute(XSDConstants.BASE_ATTRIBUTE, reuseType));
        st.setItemTypeDefinition(null);
    } else if (elementTag.equals(XSDConstants.LIST_ELEMENT_TAG)) {
        Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
        if (restrictionNode != null) {
            reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
        }
        Element unionNode = getFirstChildNodeIfExists(parent, XSDConstants.UNION_ELEMENT_TAG, false);
        if (unionNode != null) {
            String memberAttr = unionNode.getAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE);
            if (memberAttr != null) {
                StringTokenizer stringTokenizer = new StringTokenizer(memberAttr);
                reuseType = stringTokenizer.nextToken();
            }
            XSDDOMHelper.removeNodeAndWhitespace(unionNode);
        }
        attributes.add(new DOMAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE, reuseType));
    } else if (elementTag.equals(XSDConstants.UNION_ELEMENT_TAG)) {
        Element listNode = getFirstChildNodeIfExists(parent, XSDConstants.LIST_ELEMENT_TAG, false);
        if (listNode != null) {
            reuseType = listNode.getAttribute(XSDConstants.ITEMTYPE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(listNode);
        }
        Element restrictionNode = getFirstChildNodeIfExists(parent, XSDConstants.RESTRICTION_ELEMENT_TAG, false);
        if (restrictionNode != null) {
            reuseType = restrictionNode.getAttribute(XSDConstants.BASE_ATTRIBUTE);
            XSDDOMHelper.removeNodeAndWhitespace(restrictionNode);
        }
        attributes.add(new DOMAttribute(XSDConstants.MEMBERTYPES_ATTRIBUTE, reuseType));
        st.setItemTypeDefinition(null);
    }
    if (getFirstChildNodeIfExists(parent, elementTag, false) == null) {
        Action action = addCreateElementAction(elementTag, label, attributes, parent, relativeNode);
        action.run();
    }
    st.setElement(parent);
    st.updateElement();
    // endRecording(parent);
    return true;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) CreateElementAction(org.eclipse.wst.xsd.ui.internal.actions.CreateElementAction) Action(org.eclipse.jface.action.Action) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) DOMAttribute(org.eclipse.wst.xsd.ui.internal.actions.DOMAttribute) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 48 with XSDSimpleTypeDefinition

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

the class AddXSDModelGroupCommand method getOwner.

private XSDConcreteComponent getOwner() {
    XSDConcreteComponent owner = null;
    if (parent instanceof XSDElementDeclaration) {
        XSDElementDeclaration ed = (XSDElementDeclaration) parent;
        if (ed.getTypeDefinition() != null) {
            if (ed.getAnonymousTypeDefinition() == null) {
                ed.setTypeDefinition(null);
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = ed.getTypeDefinition();
            } else {
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = td;
            }
        } else if (ed.getAnonymousTypeDefinition() == null) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) {
            owner = ed.getAnonymousTypeDefinition();
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        }
    } else if (parent instanceof XSDModelGroup) {
        newModelGroup = createModelGroup();
        ((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer());
    } else if (parent instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
        owner = parent;
        if (ct.getContent() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) ct.getContent();
            if (particle.getContent() instanceof XSDModelGroup) {
                owner = null;
                newModelGroup = createModelGroup();
                XSDModelGroup newParent = (XSDModelGroup) particle.getContent();
                newParent.getContents().add(newModelGroup.getContainer());
            }
        }
    } else if (parent instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition) parent;
        owner = null;
        newModelGroup = createModelGroup();
        if (modelGroupDefinition.getModelGroup() != null) {
            XSDModelGroup newParent = modelGroupDefinition.getModelGroup();
            newParent.getContents().add(newModelGroup.getContainer());
        } else {
            modelGroupDefinition.setModelGroup(newModelGroup);
        }
    }
    return owner;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 49 with XSDSimpleTypeDefinition

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

the class MakeAnonymousTypeGlobalAction method canEnable.

private boolean canEnable(XSDConcreteComponent xsdComponent) {
    if (xsdComponent instanceof XSDComplexTypeDefinition) {
        fSelectedComponent = (XSDComplexTypeDefinition) xsdComponent;
        isComplexType = true;
        XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        }
    } else if (xsdComponent instanceof XSDSimpleTypeDefinition) {
        fSelectedComponent = (XSDSimpleTypeDefinition) xsdComponent;
        isComplexType = false;
        XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        } else if (parent instanceof XSDAttributeDeclaration) {
            fParentName = ((XSDAttributeDeclaration) parent).getName();
            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)

Example 50 with XSDSimpleTypeDefinition

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

the class XSDVisitor method visitComplexTypeDefinition.

public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) {
    XSDComplexTypeContent complexContent = type.getContent();
    if (complexContent != null) {
        if (complexContent instanceof XSDSimpleTypeDefinition) {
            visitSimpleTypeDefinition((XSDSimpleTypeDefinition) complexContent);
        } else if (complexContent instanceof XSDParticle) {
            visitParticle((XSDParticle) complexContent);
        }
    }
    if (type.getAttributeContents() != null) {
        for (Iterator iter = type.getAttributeContents().iterator(); iter.hasNext(); ) {
            XSDAttributeGroupContent attrGroupContent = (XSDAttributeGroupContent) iter.next();
            if (attrGroupContent instanceof XSDAttributeUse) {
                XSDAttributeUse attrUse = (XSDAttributeUse) attrGroupContent;
                visitAttributeDeclaration(attrUse.getContent());
            } else if (attrGroupContent instanceof XSDAttributeGroupDefinition) {
                visitAttributeGroupDefinition((XSDAttributeGroupDefinition) attrGroupContent);
            }
        }
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) XSDParticle(org.eclipse.xsd.XSDParticle) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11