Search in sources :

Example 1 with XSDModelGroupAdapter

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

the class ModelGroupEditPart method getModelChildren.

protected List getModelChildren() {
    // XSDModelGroupAdapter modelGroupAdapter = (XSDModelGroupAdapter)getModel();
    // ArrayList ch = new ArrayList();
    // ITreeElement [] tree = modelGroupAdapter.getChildren();
    // int length = tree.length;
    // for (int i = 0; i < length; i++)
    // {
    // ch.add(tree[i]);
    // }
    List list = new ArrayList();
    XSDModelGroup xsdModelGroup = getXSDModelGroup();
    for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
        XSDParticle next = (XSDParticle) i.next();
        if (next.getContent() instanceof XSDElementDeclaration) {
            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(elementDeclaration);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
        if (next.getContent() instanceof XSDModelGroupDefinition) {
            XSDModelGroupDefinition def = (XSDModelGroupDefinition) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(def);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup modelGroup = (XSDModelGroup) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(modelGroup);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDWildcard) {
            XSDWildcard wildCard = (XSDWildcard) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(wildCard);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
    }
    if (list.size() == 0)
        list.add(new TargetConnectionSpaceFiller(null));
    return list;
// return ch;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) ArrayList(java.util.ArrayList) List(java.util.List) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDModelGroupAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupAdapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) TargetConnectionSpaceFiller(org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 2 with XSDModelGroupAdapter

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

the class ModelGroupEditPart method refreshVisuals.

protected void refreshVisuals() {
    boolean isReadOnly = false;
    GenericGroupFigure modelGroupFigure = (GenericGroupFigure) getFigure();
    XSDModelGroupAdapter adapter = (XSDModelGroupAdapter) getModel();
    isReadOnly = adapter.isReadOnly();
    String nodeName = "";
    Image image;
    switch(getXSDModelGroup().getCompositor().getValue()) {
        case XSDCompositor.ALL:
            {
                image = isReadOnly ? ModelGroupFigure.ALL_ICON_DISABLED_IMAGE : ModelGroupFigure.ALL_ICON_IMAGE;
                modelGroupFigure.getIconFigure().image = XSDCommonUIUtils.getUpdatedImage((XSDConcreteComponent) adapter.getTarget(), image, isReadOnly);
                nodeName = XSDConstants.ALL_ELEMENT_TAG;
                break;
            }
        case XSDCompositor.CHOICE:
            {
                image = isReadOnly ? ModelGroupFigure.CHOICE_ICON_DISABLED_IMAGE : ModelGroupFigure.CHOICE_ICON_IMAGE;
                modelGroupFigure.getIconFigure().image = XSDCommonUIUtils.getUpdatedImage((XSDConcreteComponent) adapter.getTarget(), image, isReadOnly);
                nodeName = XSDConstants.CHOICE_ELEMENT_TAG;
                break;
            }
        case XSDCompositor.SEQUENCE:
            {
                image = isReadOnly ? ModelGroupFigure.SEQUENCE_ICON_DISABLED_IMAGE : ModelGroupFigure.SEQUENCE_ICON_IMAGE;
                modelGroupFigure.getIconFigure().image = XSDCommonUIUtils.getUpdatedImage((XSDConcreteComponent) adapter.getTarget(), image, isReadOnly);
                nodeName = XSDConstants.SEQUENCE_ELEMENT_TAG;
                break;
            }
    }
    // String occurenceDescription = adapter.getNameAnnotationToolTipString();
    // modelGroupFigure.getIconFigure().setToolTip(occurenceDescription);
    // TODO: commmon this up with 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;
        modelGroupFigure.setText(null);
    } else if (minOccurs == 0 && (maxOccurs == -2 || maxOccurs == 1)) {
        // $NON-NLS-1$
        occurenceDescription = nodeName + " [0..1]";
        modelGroupFigure.setText("0..1");
    } else if ((minOccurs == 1 && maxOccurs == 1) || (minOccurs == -2 && maxOccurs == 1) || (minOccurs == 1 && maxOccurs == -2)) {
        // $NON-NLS-1$
        occurenceDescription = nodeName + " [1..1]";
        modelGroupFigure.setText("1..1");
    } else if (minOccurs == -2 && maxOccurs == -2) {
        occurenceDescription = nodeName;
        modelGroupFigure.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 + "]";
        modelGroupFigure.setText(minSymbol + ".." + maxSymbol);
    }
    modelGroupFigure.getIconFigure().setToolTipText(occurenceDescription);
    modelGroupFigure.getIconFigure().repaint();
    refreshConnection();
}
Also used : GenericGroupFigure(org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure) XSDModelGroupAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupAdapter) Image(org.eclipse.swt.graphics.Image)

Aggregations

XSDModelGroupAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupAdapter)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 Image (org.eclipse.swt.graphics.Image)1 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)1 TargetConnectionSpaceFiller (org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller)1 GenericGroupFigure (org.eclipse.wst.xsd.ui.internal.design.figures.GenericGroupFigure)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)1 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)1 XSDParticle (org.eclipse.xsd.XSDParticle)1 XSDWildcard (org.eclipse.xsd.XSDWildcard)1