Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 80b5f429921525f8aed3c6f275ce85d4bfdf48cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.properties.section;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.wst.common.ui.properties.ISection;
import org.eclipse.xsd.XSDAttributeGroupDefinition;
import org.eclipse.xsd.XSDComplexTypeDefinition;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDModelGroup;
import org.eclipse.xsd.XSDWildcard;

public class MinMaxSectionDescriptor extends AbstractSectionDescriptor
{
  /**
   * 
   */
  public MinMaxSectionDescriptor()
  {
    super();
  }

  /* (non-Javadoc)
   * @see org.eclipse.wst.common.ui.properties.ISectionDescriptor#getId()
   */
  public String getId()
  {
    return "com.ibm.xsdeditor.section.minmax";
  }

  /* (non-Javadoc)
   * @see org.eclipse.wst.common.ui.properties.ISectionDescriptor#getInputTypes()
   */
  public List getInputTypes()
  {
    List list = new ArrayList();
    list.add(XSDElementDeclaration.class);
    list.add(XSDModelGroup.class);
    list.add(XSDWildcard.class);
    return list;
  }

  /* (non-Javadoc)
   * @see org.eclipse.wst.common.ui.properties.ISectionDescriptor#getSectionClass()
   */
  public ISection getSectionClass()
  {
    return new MinMaxSection();
  }

  /* (non-Javadoc)
   * @see org.eclipse.wst.common.ui.properties.ISectionDescriptor#getTargetTab()
   */
  public String getTargetTab()
  {
    return "com.ibm.xmlwebservices.general";
  }

  /* (non-Javadoc)
   * @see org.eclipse.wst.common.ui.properties.ISectionDescriptor#appliesTo(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
  public boolean appliesTo(IWorkbenchPart part, ISelection selection)
  {
    Object object = null;
    if (selection instanceof StructuredSelection)
    {
      StructuredSelection structuredSelection = (StructuredSelection)selection;
      object = structuredSelection.getFirstElement();
//      if (object instanceof XSDElementDeclaration)
//      {
//        Element element = ((XSDElementDeclaration)object).getElement();
//        Object parentNode = element.getParentNode();
//        // minOccurs and maxOccurs apply to non-global elements
//        boolean isGlobalElement = XSDDOMHelper.inputEquals(parentNode, XSDConstants.SCHEMA_ELEMENT_TAG, false);
//        return !isGlobalElement;
//      }
//      if (object instanceof XSDParticle)
//      {
//        XSDParticle particle = (XSDParticle)object;
//        Element element = particle.getElement();
//        if (inputEquals(element, XSDConstants.ELEMENT_ELEMENT_TAG, false))
//        {
//          return true;
//        }
//        else if (inputEquals(element, XSDConstants.ELEMENT_ELEMENT_TAG, true))
//        {
//          return false;
//        }
//        else
//        {
//          return true;
//        }
//      }
      if (object instanceof XSDModelGroup)
      {
        return true;
      }
      else if (object instanceof XSDElementDeclaration)
      {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)object;
        if (xsdElementDeclaration.isGlobal())
        {
          return false;
        }
        else
        {
          return true;
        }
      }
      else if (object instanceof XSDWildcard)
      {
        XSDWildcard wildcard = (XSDWildcard)object;
        if (wildcard.getContainer() instanceof XSDComplexTypeDefinition ||
            wildcard.getContainer() instanceof XSDAttributeGroupDefinition)
        {
          return false;
        }
        else
        {
          return true;
        }
      }
    }
    return false;
  }
  
  public String getAfterSection()
  {
    return "org.eclipse.wst.wsdleditor.section.reference";
  }

}

Back to the top