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: XSDAttributeUseItemProvider.java,v 1.7 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.XSDAttributeUse object.
 
   implements 
 {
  
This constructs an instance from a factory and a notifier.
 
   public XSDAttributeUseItemProvider(AdapterFactory adapterFactory)
   {
     super(adapterFactory);
   }
 
   protected XSDAttributeDeclaration getDelegate(XSDAttributeUse xsdAttributeUse)
   {
     return xsdAttributeUse.getContent();
   }

  
This returns the property descriptors for the adapted class.
 
   @Override
   {
      = null;
     super.getPropertyDescriptors(object);
 
     XSDAttributeUse xsdAttributeUse = ((XSDAttributeUse)object);
     XSDAttributeDeclaration xsdAttributeDeclaration = getDelegate(xsdAttributeUse);
     if (xsdAttributeDeclaration != null)
     {
       for (IItemPropertyDescriptor delegatedItemPropertyDescriptor : .getPropertyDescriptors(xsdAttributeDeclaration))
       {
         Object feature = delegatedItemPropertyDescriptor.getFeature(object);
         if (feature != ..getXSDFeature_Constraint() && 
               feature != ..getXSDFeature_Value() &&
               feature != ..getXSDFeature_LexicalValue())
         {
           .add(new ItemPropertyDescriptorDecorator(xsdAttributeDeclarationdelegatedItemPropertyDescriptor));
         }
       }
     }
    // This is for the required feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_Required_label"),
         ..getString("_UI_Required_description"),
         true,
    // This is for the use feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_Use_label"),
         ..getString("_UI_Use_description"),
         true,
    // This is for the value feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_LexicalValue_label"),
         ..getString("_UI_LexicalValueOfAttributeUse_description"),
         true,
    // This is for the constraint feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_Constraint_label"),
         ..getString("_UI_ConstraintOfAttributeUse_description"),
         true,
    // This is for the attributeDeclaration feature.
    //
      (new ItemPropertyDescriptor
         ..getString("_UI_AttributeDeclaration_label"),
         ..getString("_UI_AttributeDeclaration_description"),
         false));
  }
  public Collection<? extends EStructuralFeaturegetChildrenFeatures(Object object)
  {
    if ( == null)
    {
      super.getChildrenFeatures(object);
      .clear();
/*
      XSDAttributeUse xsdAttributeUse = ((XSDAttributeUse)object);
      childrenFeatures.add(xsdPackage.getXSDAttributeUse_Content());
*/
    }
    return ;
  }
  public Collection<?> getChildren(Object object)
  {
    XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)object;
    XSDAttributeDeclaration xsdAttributeDeclaration = getDelegate(xsdAttributeUse);
    if (xsdAttributeDeclaration != null)
    {
      return .getChildren(xsdAttributeDeclaration);
    }
    else
    {
      return .;
    }
  }
  public boolean hasChildren(Object object)
  {
    XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)object;
    XSDAttributeDeclaration xsdAttributeDeclaration = getDelegate(xsdAttributeUse);
    return
      xsdAttributeDeclaration != null && .hasChildren(xsdAttributeDeclaration);
  }

  
This returns XSDAttributeUse.gif.
  public Object getImage(Object object)
  {
    XSDAttributeUse xsdAttributeUse = ((XSDAttributeUse)object);
    XSDAttributeDeclaration xsdAttributeDeclaration = getDelegate(xsdAttributeUse);
    if (xsdAttributeDeclaration != null)
    {
      Collection<Objectimages = new ArrayList<Object>();
      images.add(.getImage(xsdAttributeDeclaration));
      // Try this way, i.e., not showing the 1 case.
      //
      if (. != xsdAttributeUse.getUse())
      {
        String imageName = 
          "full/obj16/XSDOccurrence" +
             (. == xsdAttributeUse.getUse() ?
               "Zero" : 
               . == xsdAttributeUse.getUse() ?
                 "One" : 
                 "ZeroToOne");
        images.add(..getImage(imageName));
      }
      return new ComposedImage(images);
    }
    else
    {
      return ..getImage("full/obj16/XSDAttributeUse");
    }
  }
  public String getText(Object object)
  {
    return getText(objecttrue);
  }
  public String getText(Object objectboolean showType)
  {
    XSDAttributeUse xsdAttributeUse = ((XSDAttributeUse)object);
    XSDAttributeDeclaration xsdAttributeDeclaration = getDelegate(xsdAttributeUse);
    StringBuffer result  = new StringBuffer();
    if (xsdAttributeDeclaration != null)
    {
      result.append(.getText(xsdAttributeDeclaration));
    }
    if (xsdAttributeUse.isSetConstraint())
    {
      if (result.length() != 0)
      {
        result.append("  ");
      }
      result.append('<');
      result.append(xsdAttributeUse.getConstraint());
      result.append("=\"");
      result.append(xsdAttributeUse.getLexicalValue());
      result.append("\">");
    }
    return result.toString();
  }

  
This handles notification by calling fireNotifyChanged.
  public void notifyChanged(Notification msg
  {
    if (msg.getFeature() == .getXSDAttributeUse_Required() || 
         msg.getFeature() == .getXSDAttributeUse_LexicalValue() || 
         msg.getFeature() == .getXSDAttributeUse_Constraint() || 
         msg.getFeature() == .getXSDAttributeUse_Use())
    {
      fireNotifyChanged(msg);
      return;
    }
    super.notifyChanged(msg);
  }

  
This returns a list of child descriptors based on the attributeUse content, not the attributeUse itself.
  public Collection<?> getNewChildDescriptors(Object objectEditingDomain domainObject sibling)
  {
    Object content = ((XSDAttributeUseobject).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 = ((XSDAttributeUseobject).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);
  }
New to GrepCode? Check out our FAQ X