Search in sources :

Example 66 with XSDComplexTypeDefinition

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

the class SetBaseTypeAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        boolean complexType = selection instanceof XSDComplexTypeDefinition;
        boolean simpleType = selection instanceof XSDSimpleTypeDefinition;
        if (complexType || simpleType) {
            if (getWorkbenchPart() instanceof IEditorPart) {
                IEditorPart editor = (IEditorPart) getWorkbenchPart();
                ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDComplexTypeBaseTypeEditManager.class);
                ComponentSpecification newValue;
                IComponentDialog dialog = null;
                dialog = manager.getBrowseDialog();
                if (dialog != null) {
                    if (simpleType) {
                        ((XSDSearchListDialogDelegate) dialog).showComplexTypes(false);
                    }
                    if (dialog.createAndOpen() == Window.OK) {
                        newValue = dialog.getSelectedComponent();
                        manager.modifyComponentReference(selection, newValue);
                    }
                }
            }
        }
    }
}
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) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSearchListDialogDelegate(org.eclipse.wst.xsd.ui.internal.editor.search.XSDSearchListDialogDelegate)

Example 67 with XSDComplexTypeDefinition

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

the class XSDImpl method findTypesDerivedFrom.

/**
 * Adapted from public static List findTypesDerivedFrom(XSDSchema schema,
 * String namespace, String localName) in class XSDSchemaQueryTools found in
 * org.eclipse.xsd plugin.
 *
 * Find typeDefinitions that derive from a given type.
 *
 * @param type
 *          the type derived from
 * @return List of any XSDTypeDefinitions found
 */
public static List findTypesDerivedFrom(XSDTypeDefinition type) {
    ArrayList typesDerivedFrom = new ArrayList();
    if (type != null) {
        XSDSchema schema = type.getSchema();
        String localName = type.getName();
        if ((null != schema) && (null != localName)) {
            String namespace = schema.getTargetNamespace();
            // A handy convenience method quickly gets all
            // typeDefinitions within our schema; note that
            // whether or not this returns types in included,
            // imported, or redefined schemas is subject to change
            List typedefs = schema.getTypeDefinitions();
            for (Iterator iter = typedefs.iterator(); iter.hasNext(); ) {
                XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
                if (typedef instanceof XSDComplexTypeDefinition) {
                    // of them match the requested one
                    if (isTypeDerivedFrom(typedef, namespace, localName)) {
                        // We found it, return the original one and continue
                        typesDerivedFrom.add(typedef);
                        continue;
                    }
                }
            }
        }
    }
    return typesDerivedFrom;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 68 with XSDComplexTypeDefinition

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

the class XSDComplexTypeAdvancedSection method refresh.

public void refresh() {
    super.refresh();
    setListenerEnabled(false);
    try {
        if (input instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) input;
            boolean enabled = true;
            if (complexType.getContainer() instanceof XSDSchema) {
                enabled = !isReadOnly;
            } else {
                enabled = false;
            }
            if (complexType.getElement().hasAttribute(XSDConstants.BLOCK_ATTRIBUTE)) {
                String blockAttValue = complexType.getElement().getAttribute(XSDConstants.BLOCK_ATTRIBUTE);
                blockCombo.setText(blockAttValue);
            } else {
                blockCombo.setText(EMPTY);
            }
            blockCombo.setEnabled(enabled);
            if (complexType.getElement().hasAttribute(XSDConstants.FINAL_ATTRIBUTE)) {
                String finalAttValue = complexType.getElement().getAttribute(XSDConstants.FINAL_ATTRIBUTE);
                finalCombo.setText(finalAttValue);
            } else {
                finalCombo.setText(EMPTY);
            }
            finalCombo.setEnabled(enabled);
            if (complexType.getElement().hasAttribute(XSDConstants.ABSTRACT_ATTRIBUTE)) {
                boolean absAttValue = complexType.isAbstract();
                if (absAttValue)
                    abstractCombo.setText(TRUE);
                else
                    abstractCombo.setText(FALSE);
            } else {
                abstractCombo.setText(EMPTY);
            }
            abstractCombo.setEnabled(enabled);
            if (complexType.getElement().hasAttribute(XSDConstants.MIXED_ATTRIBUTE)) {
                boolean mixedValue = complexType.isMixed();
                if (mixedValue)
                    mixedCombo.setText(TRUE);
                else
                    mixedCombo.setText(FALSE);
            } else {
                mixedCombo.setText(EMPTY);
            }
        }
    } catch (Exception e) {
    }
    setListenerEnabled(true);
}
Also used : XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 69 with XSDComplexTypeDefinition

use of org.eclipse.xsd.XSDComplexTypeDefinition 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 70 with XSDComplexTypeDefinition

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

the class AddXSDModelGroupCommand method execute.

public void execute() {
    try {
        beginRecording(parent.getElement());
        XSDConcreteComponent owner = getOwner();
        if (owner != null) {
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            newModelGroup = createModelGroup();
            particle.setContent(newModelGroup);
            XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) owner;
            ctd.setContent(particle);
        }
        formatChild(parent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)162 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)76 XSDParticle (org.eclipse.xsd.XSDParticle)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)66 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)53 ArrayList (java.util.ArrayList)43 XSDSchema (org.eclipse.xsd.XSDSchema)37 Test (org.junit.Test)37 EList (org.eclipse.emf.common.util.EList)25 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)25 XSDFactory (org.eclipse.xsd.XSDFactory)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)21 XSDTerm (org.eclipse.xsd.XSDTerm)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)20 Iterator (java.util.Iterator)19 List (java.util.List)19 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)16