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: XSDParticleItemProvider.java,v 1.8 2007/03/23 17:36:46 marcelop Exp $
 
 package org.eclipse.xsd.provider;
 
 
 import java.util.List;
 
 
This is the item provider adpater for a org.eclipse.xsd.XSDParticle object.
 
 public class XSDParticleItemProvider
   implements 
 {
  
This constructs an instance from a factory and a notifier.
 
   public XSDParticleItemProvider(AdapterFactory adapterFactory)
   {
     super(adapterFactory);
   }
 
   protected XSDParticleContent getDelegate(XSDParticle xsdParticle)
   {
     return xsdParticle.getContent();
   }

  
This returns the property descriptors for the adapted class.
 
   @Override
   {
      = null;
     super.getPropertyDescriptors(object);
 
     XSDParticle xsdParticle = (XSDParticle)object;
     XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
     if (xsdParticleContent != null)
     {
       for (IItemPropertyDescriptor delegatedItemPropertyDescriptor : .getPropertyDescriptors(xsdParticleContent))
       {
         .add(new ItemPropertyDescriptorDecorator(xsdParticleContentdelegatedItemPropertyDescriptor));
       }
     }
 
 
     // This is for the minOccurs feature.
     //
       (new ItemPropertyDescriptor
         ..getString("_UI_MinOccurs_label"),
         ..getString("_UI_MinOccurs_description"),
         true,
    // This is for the maxOccurs feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_MaxOccurs_label"),
         ..getString("_UI_MaxOccurs_description"),
         true,
  }

  
  public Collection<? extends EStructuralFeaturegetChildrenFeatures(Object object)
  {
    if ( == null)
    {
      super.getChildrenFeatures(object);
      .clear();
/*
      XSDParticle xsdParticle = ((XSDParticle)object);
      childrenFeatures.add(xsdPackage.getXSDParticle_Content());
*/
    }
    return ;
  }
  public Collection<?> getChildren(Object object)
  {
    XSDParticle xsdParticle = (XSDParticle)object;
    XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
    if (xsdParticleContent != null)
    {
      return .getChildren(xsdParticleContent);
    }
    else
    {
      return .;
    }
  }
  public boolean hasChildren(Object object)
  {
    XSDParticle xsdParticle = (XSDParticle)object;
    XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
    return 
      xsdParticleContent != null && .hasChildren(xsdParticleContent);
  }

  
This returns XSDParticle.gif.
  public Object getImage(Object object)
  {
    XSDParticle xsdParticle = ((XSDParticle)object);
    XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
    if (xsdParticleContent != null)
    {
      Collection<Objectimages = new ArrayList<Object>();
      images.add(.getImage(xsdParticleContent));
      String imageName = "full/obj16/XSDOccurrence";
      int minOccurs = xsdParticle.getMinOccurs();
      int maxOccurs = xsdParticle.getMaxOccurs();
      if (minOccurs >= 0 && (minOccurs <= maxOccurs || maxOccurs == -1))
      {
        switch (minOccurs)
        {
          case 0:
          {
            imageName += "Zero";
            break;
          }
          case 1:
          {
            imageName += "One";
            break;
          }
          default:
          {
            imageName += "N";
            break;
          }
        }
  
        if (minOccurs != maxOccurs)
        {
          switch (maxOccurs)
          {
            case -1:
            {
              imageName += "ToUnbounded";
              break;
            }
            case 0:
            {
              break;
            }
            case 1:
            {
              imageName += "ToOne";
              break;
            }
            default:
            {
              imageName += xsdParticle.getMinOccurs() <= 1 ? "ToN" : "ToM";
              break;
            }
          }
        }
      }
      else
      {
        imageName += "NToM";
      }
  
      if (!imageName.equals("full/obj16/XSDOccurrenceOne"))
      {
        images.add(..getImage(imageName));
      }
 
      return new ComposedImage(images);
    }
    else
    {
      return ..getImage("full/obj16/XSDParticle");
    }
  }
  public String getText(Object object)
  {
    XSDParticle xsdParticle = ((XSDParticle)object);
    XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
    if (xsdParticleContent != null)
    {
      return .getText(xsdParticleContent);
    }
    else
    {
      return
        xsdParticle.getMinOccurs() +
        ".." +
        (xsdParticle.getMaxOccurs() == -1 ? "unbounded" : Integer.toString(xsdParticle.getMaxOccurs()));
    }
  }

  
This handles notification by calling fireNotifyChanged.
  public void notifyChanged(Notification msg
  {
    if (
         msg.getFeature() == .getXSDParticle_MinOccurs() || 
         msg.getFeature() == .getXSDParticle_MaxOccurs() || 
         msg.getFeature() == .getXSDParticle_Content() || 
         msg.getFeature() == .getXSDParticle_Term()
       )
    {
      fireNotifyChanged(msg);
      return;
    }
    super.notifyChanged(msg);
  }

  
This returns a list of child descriptors based on the particle content, not the particle itself.
  public Collection<?> getNewChildDescriptors(Object objectEditingDomain domainObject sibling)
  {
    Object content = ((XSDParticleobject).getContent();
    return domain.getNewChildDescriptors(contentsibling);
  }

  
This returns Remove and CreateChild commands (at least) that are based on the attributeUse content, not the attributeUse itself.
  public Command createCommand(final Object objectfinal EditingDomain domainClass<? extends CommandcommandClassCommandParameter commandParameter)
  {
    if (commandClass == RemoveCommand.class ||
        commandClass == CreateChildCommand.class)
    {
      Object owner = ((XSDParticleobject).getContent();
      if (owner == null)
      {
        return .;
      }
      commandParameter.setOwner(owner);
      // RemoveCommand requires a wrapper that returns the correct affected
      // object after an execute or redo (the particle or attribute use
      // itself, instead of its content)
      if (commandClass == RemoveCommand.class)
      {
        return new CommandWrapper(
          domain.createCommand(commandClasscommandParameter))
        {
          private Collection<?> affectedObjects = .;
          @Override
          public void execute()
          {
            super.execute();
             = Collections.singleton(object);
          }
            
          @Override
          public void undo()
          {
            super.undo();
             = super.getAffectedObjects();
          }
          @Override
          public void redo()
          {
            super.redo();
             = Collections.singleton(object);
          }
          @Override
          public Collection<?> getAffectedObjects()
          {
            return ;
          }
        };
      }
      // CreateChildCommand handles its affected objects correctly
      return domain.createCommand(commandClasscommandParameter);
    }
    return super.createCommand(objectdomaincommandClasscommandParameter);
  }
/*
  protected Command factorRemoveCommand(EditingDomain domain, CommandParameter commandParameter)
  {
    XSDParticle xsdParticle = (XSDParticle)commandParameter.getRefOwner();
    return 
      domain.createCommand
        (RemoveCommand.class,
         new CommandParameter
           (getDelegate(xsdParticle),
            commandParameter.getFeature(),
            commandParameter.getCollection(),
            commandParameter.getIndex()));
  }
  protected Command factorAddCommand(EditingDomain domain, CommandParameter commandParameter)
  {
    XSDParticle xsdParticle = (XSDParticle)commandParameter.getRefOwner();
    return 
      domain.createCommand
        (AddCommand.class,
         new CommandParameter
           (getDelegate(xsdParticle),
            commandParameter.getFeature(),
            commandParameter.getCollection(),
            commandParameter.getIndex()));
  }
  protected Command factorMoveCommand(EditingDomain domain, CommandParameter commandParameter)
  {
    XSDParticle xsdParticle = (XSDParticle)commandParameter.getRefOwner();
    return 
      domain.createCommand
        (MoveCommand.class,
         new CommandParameter
           (getDelegate(xsdParticle),
            commandParameter.getFeature(),
            commandParameter.getValue(),
            commandParameter.getIndex()));
  }
*/
New to GrepCode? Check out our FAQ X