Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<copyright> Copyright (c) 2002-2007 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 - Initial API and implementation </copyright> $Id: XSDSimpleTypeDefinitionItemProvider.java,v 1.7 2007/03/22 02:06:23 davidms Exp $
 
 package org.eclipse.xsd.provider;
 
 
 import java.util.List;
 
 
This is the item provider adpater for a org.eclipse.xsd.XSDSimpleTypeDefinition object.
 
 {
  
This constructs an instance from a factory and a notifier.
 
   {
     super(adapterFactory);
   }

  
This returns the property descriptors for the adapted class.
 
   @Override
   {
     if ( == null)
     {
       super.getPropertyDescriptors(object);
 
       // This is for the annotation feature.
       //
         (new ItemPropertyDescriptor
            ..getString("_UI_Annotation_label"),
            ..getString("_UI_AnnotationOfType_description"),
            .getXSDTypeDefinition_Annotation(), 
            false));
 
       // This is for the ordered facet.
       //
         (new ItemPropertyDescriptor
            ..getString("_UI_Ordered_label"),
            ..getString("_UI_Ordered_description"),
           false,
         {
           @Override
          public Object getPropertyValue(Object o)
           {
             XSDSimpleTypeDefinition simpleTypeDefinition = (XSDSimpleTypeDefinition)o;
             for (XSDFundamentalFacet xsdFundamentalFacet : simpleTypeDefinition.getFundamentalFacets())
             {
               if (xsdFundamentalFacet instanceof XSDOrderedFacet)
               {
                 return ((XSDOrderedFacet)xsdFundamentalFacet).getValue().getName();
               }
             }
             return ..getString("_UI_DefaultValue_label"new Object [] { "false" });
           }
         });
      // This is for the cardinality facet.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_Cardinality_label"),
           ..getString("_UI_Cardinality_description"),
           false,
         {
           @Override
          public Object getPropertyValue(Object o)
           {
             XSDSimpleTypeDefinition simpleTypeDefinition = (XSDSimpleTypeDefinition)o;
             for (XSDFundamentalFacet xsdFundamentalFacet : simpleTypeDefinition.getFundamentalFacets())
             {
               if (xsdFundamentalFacet instanceof XSDCardinalityFacet)
               {
                 String result = ((XSDCardinalityFacet)xsdFundamentalFacet).getValue().getName();
                 if ("countablyInfinite".equals(result))
                 {
                   result = "countably infinite";
                 }
                 return result;
               }
             }
             return ..getString("_UI_DefaultValue_label"new Object [] { "false" });
           }
         });
      // This is for the bounded facet.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_Bounded_label"),
           ..getString("_UI_Bounded_description"),
           false,
         {
           @Override
          public Object getPropertyValue(Object o)
           {
             XSDSimpleTypeDefinition simpleTypeDefinition = (XSDSimpleTypeDefinition)o;
             for (XSDFundamentalFacet xsdFundamentalFacet : simpleTypeDefinition.getFundamentalFacets())
             {
               if (xsdFundamentalFacet instanceof XSDBoundedFacet)
               {
                 return ((XSDBoundedFacet)xsdFundamentalFacet).isValue() ? "true" : "false";
               }
             }
             return ..getString("_UI_DefaultValue_label"new Object [] { "false" });
           }
         });
      // This is for the numeric facet.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_Numeric_label"),
           ..getString("_UI_Numeric_description"),
           false,
         {
           @Override
          public Object getPropertyValue(Object o)
           {
             XSDSimpleTypeDefinition simpleTypeDefinition = (XSDSimpleTypeDefinition)o;
             for (XSDFundamentalFacet xsdFundamentalFacet : simpleTypeDefinition.getFundamentalFacets())
             {
               if (xsdFundamentalFacet instanceof XSDNumericFacet)
               {
                 return ((XSDNumericFacet)xsdFundamentalFacet).isValue() ? "true" : "false";
               }
             }
             return ..getString("_UI_DefaultValue_label"new Object [] { "false" });
           }
         });
      // This is for the baseTypeDefinition feature.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_BaseTypeDefinition_label"),
           ..getString("_UI_BaseTypeDefinition_description"),
           false));
      // This is for the itemTypeDefinition feature.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_ItemTypeDefinition_label"),
           ..getString("_UI_ItemTypeDefinition_description"),
           false));
      // This is for the variety feature.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_Variety_label"),
           ..getString("_UI_Variety_description"),
           false)
         {
           @Override
          public Object getPropertyValue(Object o)
           {
             if (((XSDSimpleTypeDefinition)o).isSetVariety())
             {
               return super.getPropertyValue(o);
             }
             else
             {
               return ..getString("_UI_Absent_label");
             }
           }
         });
      // This is for the primitive type definition feature.
      //
        (new ItemPropertyDescriptor
           ..getString("_UI_PrimitiveTypeDefinition_label"),
           ..getString("_UI_PrimitiveTypeDefinition_description"),
           false));
    }
  }
  protected void createLexicalFinalPropertyDescriptor(Object object)
  {
    // This is for the final feature.
    //
         ..getString("_UI_LexicalFinal_label"),
         ..getString("_UI_LexicalFinal_description"),
         true,
       {
         @Override
        public Object getPropertyDefaultValue(Object o)
         {
           return 
             ..getString("_UI_DefaultValue_label"new Object [] { ((XSDSimpleTypeDefinition)o).getStringLexicalFinal() });
         }
         @Override
        public Object getPropertyValue(Object o)
         {
           return ((XSDSimpleTypeDefinition)o).getStringLexicalFinal();
         }
         @Override
        public void setPropertyValue(Object oObject value)
         {
           ((XSDSimpleTypeDefinition)o).setStringLexicalFinal((String)value);
         }
         @Override
        public Collection<?> getChoiceOfValues(Object o)
         {
           Collection<Objectresult = new ArrayList<Object>();
           result.add("");
           result.add("#all");
           result.add("restriction");
           result.add("restriction list");
           result.add("restriction list union");
           result.add("restriction union");
           result.add("list");
           result.add("list union");
           result.add("union");
           return result;
         }
       });
  }
  protected void createFinalPropertyDescriptor(Object object)
  {
    // This is for the final feature.
    //
         ..getString("_UI_Final_label"),
         ..getString("_UI_FinalOfType_description"),
         false,
       {
         @Override
        public Object getPropertyValue(Object o)
         {
           return ((XSDSimpleTypeDefinition)o).getStringFinal();
         }
       });
  }

  
  public Collection<? extends EStructuralFeaturegetChildrenFeatures(Object object)
  {
    if ( == null)
    {
      super.getChildrenFeatures(object);
    }
    return ;
  }

  
This returns XSDSimpleTypeDefinition.gif.
  public Object getImage(Object object)
  {
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = ((XSDSimpleTypeDefinition)object);
    return 
        (xsdSimpleTypeDefinition.getContainer() == null ?
           "full/obj16/XSDSimpleTypeDefinitionUnresolved" :
           . == xsdSimpleTypeDefinition.getVariety() ? 
             "full/obj16/XSDSimpleTypeDefinitionList" :  
              . == xsdSimpleTypeDefinition.getVariety() ? 
                "full/obj16/XSDSimpleTypeDefinitionUnion" :
                  xsdSimpleTypeDefinition.isSetVariety() ?
                    "full/obj16/XSDSimpleTypeDefinitionAtomic"  :
                    "full/obj16/XSDSimpleTypeDefinition");
  }
  public String getText(Object object)
  {
    return getText(objecttrue);
  }
  public String getText(Object objectboolean showType)
  {
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = ((XSDSimpleTypeDefinition)object);
    StringBuffer result = new StringBuffer();
    result.append
      (xsdSimpleTypeDefinition.getName() == null ? 
         xsdSimpleTypeDefinition.getAliasName() :
         xsdSimpleTypeDefinition.getName());
    if (showType)
    {
      XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition();
      if (baseTypeDefinition != null && . == xsdSimpleTypeDefinition.getVariety())
      {
        if (baseTypeDefinition.getName() != null && 
              !xsdSimpleTypeDefinition.getContents().contains(baseTypeDefinition) &&
              !XSDConstants.isAnySimpleType(baseTypeDefinition)) 
        {
          result.append(" : ");
          result.append(baseTypeDefinition.getQName(xsdSimpleTypeDefinition));
        }
      }
      else
      {
        XSDSimpleTypeDefinition itemTypeDefinition = xsdSimpleTypeDefinition.getItemTypeDefinition();
        if (itemTypeDefinition != null)
        {
          if (itemTypeDefinition.getName() != null
          {
            result.append(" : ");
            result.append(itemTypeDefinition.getQName());
          }
        }
        else 
        {
          List<XSDSimpleTypeDefinitionmemberTypeDefinitions = xsdSimpleTypeDefinition.getMemberTypeDefinitions();
          if (!memberTypeDefinitions.isEmpty())
          {
            boolean first = true;
            for (XSDSimpleTypeDefinition memberTypeDefinition : memberTypeDefinitions)
            {
              if (memberTypeDefinition.getName() != null
              {
                if (first)
                {
                  result.append(" : ");
                  first = false;
                }
                else
                {
                  result.append(" | ");
                }
                result.append(memberTypeDefinition.getQName());
              }
              else
              {
                break;
              }
            }
          } 
          else if (result.length() == 0)
          {
            result.append(..getString("_UI_Absent_label"));
          }
        }
      }
    }
    return result.toString();
  }

  
This handles notification by calling fireNotifyChanged.
  public void notifyChanged(Notification msg
  {
          msg.getFeature() == .getXSDSimpleTypeDefinition_Contents() || 
          msg.getFeature() == .getXSDTypeDefinition_Annotation() || 
          msg.getFeature() == .getXSDSimpleTypeDefinition_Variety() || 
          msg.getFeature() == .getXSDSimpleTypeDefinition_Final() || 
    {
      fireNotifyChanged(msg);
      return;
    }
    {
        (new ENotificationImpl((InternalEObject)msg.getNotifier(), .nullnullnull.));
      return;
    }
    super.notifyChanged(msg);
  }

  
This adds org.eclipse.emf.edit.command.CommandParameters describing the children that can be created under this object. The allowable simple type definition and facet children depend upon the variety and (if atomic) the primitive type of this simple type definition, as well as upon its existing children. For an option to be displayed, but disabled, org.eclipse.emf.edit.command.CommandParameter.feature is null.
  protected void collectNewChildDescriptors(Collection<ObjectnewChildDescriptorsObject object)
  {
    super.collectNewChildDescriptors(newChildDescriptorsobject);
    // type annotation
    // derivation annotation
    // children for simple type derivation, except on simple type definition
    // content of a complex type definition with extension derivation
    // method...
    if (!(std.eContainer() instanceof XSDComplexTypeDefinition) ||
    {
      boolean isAtomic = std.getVariety() == .;
      boolean isUnion = std.getVariety() == .;
      Collection<StringvalidFacets = std.getValidFacets();
      // anonymous simple type definition(s) for derivation (single-valued
      // for non-list varieties)
      EReference feature = !isUnion && !std.getContents().isEmpty() ?
      addSimpleTypeDefinitionChildParameters(newChildDescriptorsstdfeature,
                                             trueisUnion, !isAtomic);
      // facets
      for (String validFacet : validFacets)
      {
        facet.setLexicalValue("");
        feature = !canAccomodateFacet(stdfacet) ? null :
        newChildDescriptors.add(createChildParameter(featurefacet));
      }
    }
  }

  
This forms the name for a facet MOF type, from the string (with Object static type) obtained from the collection returned by org.eclipse.xsd.XSDSimpleTypeDefinition.getValidFacets(). The object is cast to a String, the first character is capitalized, "XSD" is prepended, and "Facet" appended.
  protected String formFacetTypeName(Object facetName)
  {
    StringBuffer buffer = new StringBuffer((StringfacetName);
    char c = buffer.charAt(0);
    buffer.setCharAt(0, Character.toUpperCase(c));
    buffer.insert(0, "XSD");
    buffer.append("Facet");
    return buffer.toString();
  }

  
This tests whether the specified simple type definition, s, can accomodate the given constraining facet, f, based on its existing facet children.
                                       XSDConstrainingFacet f)
  {
    return
      (f instanceof XSDRepeatableFacet) ||
      (f instanceof XSDLengthFacet && s.getLengthFacet() == null &&
       s.getMinLengthFacet() == null && s.getMaxLengthFacet() == null) ||
      (f instanceof XSDMinLengthFacet && s.getMinLengthFacet() == null &&
        s.getLengthFacet() == null) ||
      (f instanceof XSDMaxLengthFacet && s.getMaxLengthFacet() == null &&
        s.getLengthFacet() == null) ||
      (f instanceof XSDWhiteSpaceFacet && s.getWhiteSpaceFacet() == null) ||
      (f instanceof XSDMinInclusiveFacet && s.getMinFacet() == null) ||
      (f instanceof XSDMinExclusiveFacet && s.getMinFacet() == null) ||
      (f instanceof XSDMaxInclusiveFacet && s.getMaxFacet() == null) ||
      (f instanceof XSDMaxExclusiveFacet && s.getMaxFacet() == null) ||
      (f instanceof XSDTotalDigitsFacet && s.getTotalDigitsFacet() == null) ||
      (f instanceof XSDFractionDigitsFacet 
       && s.getFractionDigitsFacet() == null);
  }
New to GrepCode? Check out our FAQ X