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: XSDSchemaItemProvider.java,v 1.8 2007/03/22 02:06:24 davidms Exp $
 
 package org.eclipse.xsd.provider;
 
 
 import java.util.List;
 
 
This is the item provider adpater for a org.eclipse.xsd.XSDSchema object.
 
 public class XSDSchemaItemProvider
 {
  
This constructs an instance from a factory and a notifier.
 
   public XSDSchemaItemProvider(AdapterFactory adapterFactory)
   {
     super(adapterFactory);
   }

  
This returns the property descriptors for the adapted class.
 
   @Override
   {
     if ( == null)
     {
       super.getPropertyDescriptors(object);
     }
     return ;
   }
 
 
   protected void createSchemaLocationPropertyDescriptor(Object object)
   {
     // This is for the schemaLocation feature.
     //
       (new ItemPropertyDescriptor
          ..getString("_UI_SchemaLocation_label"),
          ..getString("_UI_SchemaLocationOfSchema_description"),
          false,
   }
 
   protected void createTargetNamespacePropertyDescriptor(Object object)
   {
     // This is for the targetNamespace feature.
     //
       (new ItemPropertyDescriptor
          ..getString("_UI_TargetNamespace_label"),
         ..getString("_UI_TargetNamespaceOfSchema_description"),
         true,
       {
         @Override
        public void setPropertyValue(Object oObject value)
         {
           if ("".equals(value))
           {
             super.setPropertyValue(onull);
           }
           else
           {
             super.setPropertyValue(ovalue);
           }
         }
       });
  }
  protected void createFinalDefaultPropertyDescriptor(Object object)
  {
    // This is for the finalDefault feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_FinalDefault_label"),
         ..getString("_UI_FinalDefault_description"),
         true,
       {
         @Override
        public Object getPropertyValue(Object o)
         {
           return ((XSDSchema)o).getStringFinalDefault();
         }
         @Override
        public void setPropertyValue(Object oObject value)
         {
           ((XSDSchema)o).setStringFinalDefault((String)value);
         }
         @Override
        public Collection<?> getChoiceOfValues(Object o)
         {
           Collection<Objectresult = new ArrayList<Object>();
           result.add("");
           result.add("#all");
           result.add("extension");
           result.add("restriction");
           result.add("restriction extension");
           return result;
         }
       });
  }
  protected void createBlockDefaultPropertyDescriptor(Object object)
  {
    // This is for the blockDefault feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_BlockDefault_label"),
         ..getString("_UI_BlockDefault_description"),
         true,
       {
         @Override
        public Object getPropertyValue(Object o)
         {
           return ((XSDSchema)o).getStringBlockDefault();
         }
         @Override
        public void setPropertyValue(Object oObject value)
         {
           ((XSDSchema)o).setStringBlockDefault((String)value);
         }
         @Override
        public Collection<?> getChoiceOfValues(Object o)
         {
           Collection<Objectresult = new ArrayList<Object>();
           result.add("");
           result.add("#all");
           result.add("extension");
           result.add("restriction");
           result.add("substitution");
           result.add("extension restriction");
           result.add("extension restriction substitution");
           result.add("extension substitution");
           result.add("restriction substitution");
           return result;
         }
       });
  }
  {
    // This is for the elementFormDefault feature.
    //
         ..getString("_UI_ElementFormDefault_label"),
         ..getString("_UI_ElementFormDefault_description"),
         true,
  }
  {
    // This is for the elementFormDefault feature.
    //
         ..getString("_UI_AttributeFormDefault_label"),
         ..getString("_UI_AttributeFormDefault_description"),
         true,
  }

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

  
This returns XSDSchema.gif.
  public Object getImage(Object object)
  {
    return ..getImage("full/obj16/XSDSchema");
  }
  public String getText(Object object)
  {
    XSDSchema xsdSchema = (XSDSchema)object;
    String result = xsdSchema.getSchemaLocation();
    if (result == null)
    {
      return "";
    } 
    else
    {
      return URI.createURI(result).lastSegment();
    }
  }

  
This handles notification by calling fireNotifyChanged.
  public void notifyChanged(Notification msg
  {
    if (
         msg.getFeature() == .getXSDSchema_SchemaLocation() || 
         msg.getFeature() == .getXSDSchema_TypeDefinitions() || 
         msg.getFeature() == .getXSDSchema_ElementDeclarations() || 
         msg.getFeature() == .getXSDSchema_NotationDeclarations() || 
         msg.getFeature() == .getXSDSchema_Contents() || 
         msg.getFeature() == .getXSDSchema_ModelGroupDefinitions() || 
         msg.getFeature() == .getXSDSchema_AttributeDeclarations() || 
         msg.getFeature() == .getXSDSchema_AttributeFormDefault() || 
         msg.getFeature() == .getXSDSchema_ElementFormDefault() || 
         msg.getFeature() == .getXSDSchema_BlockDefault() || 
         msg.getFeature() == .getXSDSchema_FinalDefault() || 
         msg.getFeature() == .getXSDSchema_Annotations()
       )
    {
      fireNotifyChanged(msg);
      return;
    }
    super.notifyChanged(msg);
  }

  
This adds org.eclipse.emf.edit.command.CommandParameters describing the children that can be created under this object.
  protected void collectNewChildDescriptors(Collection<ObjectnewChildDescriptorsObject object)
  {
    super.collectNewChildDescriptors(newChildDescriptorsobject);
    XSDSchema xsdSchema = (XSDSchemaobject;
    // If the schema isn't a really bad one...
    //
    if (xsdSchema.getSchemaForSchema() != null)
    {
      EReference schemaContents = .getXSDSchema_Contents();
      // annotation
      newChildDescriptors.add(createChildParameter(schemaContents.createXSDAnnotation()));
      // import
      newChildDescriptors.add(createChildParameter(schemaContents.createXSDImport()));
      // include
      i.setSchemaLocation("");
      newChildDescriptors.add(createChildParameter(schemaContentsi));
      // redefine
      r.setSchemaLocation("");
      newChildDescriptors.add(createChildParameter(schemaContentsr));
      // element declaration
      newChildDescriptors.add(createChildParameter(schemaContentscreateElementDeclaration(xsdSchema)));
      // attribute declaration
      newChildDescriptors.add(createChildParameter(schemaContentscreateAttributeDeclaration(xsdSchema)));
      // model group definition
      newChildDescriptors.add(createChildParameter(schemaContentscreateModelGroupDefinition(xsdSchema)));
      // attribute group definition
      newChildDescriptors.add(createChildParameter(schemaContentscreateAttributeGroupDefinition(xsdSchema)));
      // atomic, list, and union simple type definitions
      addSimpleTypeDefinitionChildParameters(newChildDescriptorsxsdSchemaschemaContentstruetruetrue);
      // complex type definition
      newChildDescriptors.add(createChildParameter(schemaContentscreateComplexTypeDefinition(xsdSchema)));
      // notation declaration
      newChildDescriptors.add(createChildParameter(schemaContentscreateNotationDeclaration(xsdSchema)));
    }
  }

  
We need to copy the prefix to namespace map as well as the schema for schema prefix.
  {
    return 
      new InitializeCopyCommand(domainownerhelper)
      {
        @Override
        protected Collection<? extends EAttributegetAttributesToCopy()
        {
          Collection<EAttributeresult = new ArrayList<EAttribute>(this..eClass().getEAllAttributes());
          result.remove(.getXSDSchema_Document());
          return result;
        }
        
        @Override
        protected void copyAttributes()
        {
          XSDSchema ownerSchema = (XSDSchema);
          XSDSchema copySchema = (XSDSchema);
          copySchema.getQNamePrefixToNamespaceMap().putAll(ownerSchema.getQNamePrefixToNamespaceMap());
          copySchema.setSchemaForSchemaQNamePrefix(ownerSchema.getSchemaForSchemaQNamePrefix());
          super.copyAttributes();
        }
      };
  }
New to GrepCode? Check out our FAQ X