Search in sources :

Example 1 with XSDModelGroupDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter in project webtools.sourceediting by eclipse.

the class ModelGroupDefinitionReferenceEditPart method refreshVisuals.

protected void refreshVisuals() {
    super.refreshVisuals();
    XSDModelGroupDefinitionAdapter adapter = (XSDModelGroupDefinitionAdapter) getModel();
    figure.getIconFigure().image = adapter.getImage();
    GenericGroupFigure groupFigure = (GenericGroupFigure) getFigure();
    String nodeName = "";
    // TODO: commmon this up with ModelGroupEditPart, XSDParticleAdapter's code
    // -2 means the user didn't specify (so the default is 1)
    int minOccurs = adapter.getMinOccurs();
    int maxOccurs = adapter.getMaxOccurs();
    // $NON-NLS-1$
    String occurenceDescription = "";
    if (minOccurs == -3 && maxOccurs == -3) {
        occurenceDescription = nodeName;
        groupFigure.setText(null);
    } else if (minOccurs == 0 && (maxOccurs == -2 || maxOccurs == 1)) {
        // $NON-NLS-1$
        occurenceDescription = nodeName + " [0..1]";
        groupFigure.setText("0..1");
    } else if ((minOccurs == 1 && maxOccurs == 1) || (minOccurs == -2 && maxOccurs == 1) || (minOccurs == 1 && maxOccurs == -2)) {
        // $NON-NLS-1$
        occurenceDescription = nodeName + " [1..1]";
        groupFigure.setText("1..1");
    } else if (minOccurs == -2 && maxOccurs == -2) {
        occurenceDescription = nodeName;
        groupFigure.setText(null);
    } else {
        if (maxOccurs == -2)
            maxOccurs = 1;
        // $NON-NLS-1$ //$NON-NLS-2$
        String maxSymbol = maxOccurs == -1 ? "*" : "" + maxOccurs;
        // $NON-NLS-1$ //$NON-NLS-2$
        String minSymbol = minOccurs == -2 ? "1" : "" + minOccurs;
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        occurenceDescription = nodeName + " [" + minSymbol + ".." + maxSymbol + "]";
        groupFigure.setText(minSymbol + ".." + maxSymbol);
    }
    groupFigure.getIconFigure().setToolTipText(occurenceDescription);
    groupFigure.getIconFigure().repaint();
}
Also used : GenericGroupFigure(org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter)

Example 2 with XSDModelGroupDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter in project webtools.sourceediting by eclipse.

the class AddRedefinedComponentCommand method execute.

public void execute() {
    Element element = redefine.getElement();
    try {
        beginRecording(element);
        doExecute();
        Object adapter = redefinableComponent.eAdapters().get(0);
        if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
            ((XSDComplexTypeDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
            ((XSDSimpleTypeDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
            ((XSDAttributeGroupDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDModelGroupDefinitionAdapter) {
            ((XSDModelGroupDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        }
        redefine.getContents().add(addedXSDConcreteComponent);
        formatChild(addedXSDConcreteComponent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) Element(org.w3c.dom.Element) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter)

Example 3 with XSDModelGroupDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter in project webtools.sourceediting by eclipse.

the class XSDGroupsForAnnotationEditPart method getModelChildren.

protected List getModelChildren() {
    List xsdModelGroupList = new ArrayList();
    List adapterList = new ArrayList();
    IStructure structure = ((Annotation) getModel()).getOwner();
    if (structure instanceof IComplexType) {
        complexType = (IComplexType) structure;
        if (complexType instanceof XSDComplexTypeDefinitionAdapter) {
            XSDComplexTypeDefinitionAdapter adapter = (XSDComplexTypeDefinitionAdapter) complexType;
            xsdModelGroupList = adapter.getModelGroups();
        }
        for (Iterator i = xsdModelGroupList.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (obj instanceof XSDModelGroup) {
                adapterList.add(XSDAdapterFactory.getInstance().adapt((XSDModelGroup) obj));
            } else if (obj instanceof XSDModelGroupDefinition) {
                adapterList.add(XSDAdapterFactory.getInstance().adapt((XSDModelGroupDefinition) obj));
            }
        }
    } else if (structure instanceof XSDModelGroupDefinitionAdapter) {
        XSDModelGroupDefinitionAdapter adapter = (XSDModelGroupDefinitionAdapter) structure;
        XSDModelGroup group = adapter.getXSDModelGroupDefinition().getModelGroup();
        if (group != null) {
            adapterList.add(XSDAdapterFactory.getInstance().adapt(group));
        }
    }
    return adapterList;
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IStructure(org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) Annotation(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.Annotation) IComplexType(org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType)

Example 4 with XSDModelGroupDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter in project webtools.sourceediting by eclipse.

the class ModelGroupDefinitionReferenceEditPart method getModelChildren.

protected List getModelChildren() {
    List list = new ArrayList();
    XSDModelGroupDefinitionAdapter adapter = (XSDModelGroupDefinitionAdapter) getModel();
    XSDModelGroupDefinition groupDef = ((XSDModelGroupDefinition) adapter.getTarget());
    XSDModelGroupDefinition resolvedGroupDef = groupDef.getResolvedModelGroupDefinition();
    XSDModelGroup xsdModelGroup = resolvedGroupDef.getModelGroup();
    ArrayList listOfVisibleGroupRefs = new ArrayList();
    for (EditPart ep = getParent(); ep != null; ) {
        Object object = ep.getModel();
        if (object instanceof XSDModelGroupDefinitionAdapter) {
            Object model = ((XSDModelGroupDefinitionAdapter) object).getTarget();
            if (model instanceof XSDModelGroupDefinition) {
                listOfVisibleGroupRefs.add(((XSDModelGroupDefinition) model).getResolvedModelGroupDefinition());
            }
        }
        ep = ep.getParent();
    }
    boolean isCyclic = (listOfVisibleGroupRefs.contains(resolvedGroupDef));
    if (xsdModelGroup != null && !isCyclic)
        list.add(XSDAdapterFactory.getInstance().adapt(xsdModelGroup));
    if (isCyclic)
        list.add(new TargetConnectionSpaceFiller(null));
    return list;
}
Also used : XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ArrayList(java.util.ArrayList) BaseEditPart(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) ArrayList(java.util.ArrayList) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) TargetConnectionSpaceFiller(org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller)

Example 5 with XSDModelGroupDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter 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

XSDModelGroupDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter)5 XSDComplexTypeDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter)3 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)3 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 XSDAttributeGroupDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter)2 XSDSimpleTypeDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter)2 Iterator (java.util.Iterator)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 EditPart (org.eclipse.gef.EditPart)1 XSDVisitor (org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor)1 BaseEditPart (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseEditPart)1 Annotation (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.Annotation)1 IComplexType (org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType)1 IStructure (org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure)1 TargetConnectionSpaceFiller (org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller)1 GenericGroupFigure (org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure)1 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)1