org.eclipse.xsd.provider.XSDParticleItemProvider Maven / Gradle / Ivy
The newest version!
/**
* 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 v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM - Initial API and implementation
*/
package org.eclipse.xsd.provider;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CommandWrapper;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.command.CommandParameter;
import org.eclipse.emf.edit.command.CreateChildCommand;
import org.eclipse.emf.edit.command.RemoveCommand;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedImage;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorator;
import org.eclipse.xsd.XSDParticle;
import org.eclipse.xsd.XSDParticleContent;
/**
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDParticle} object.
*/
public class XSDParticleItemProvider
extends XSDComplexTypeContentItemProvider
implements
IEditingDomainItemProvider,
IStructuredItemContentProvider,
ITreeItemContentProvider,
IItemLabelProvider,
IItemPropertySource
{
/**
* 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
public List getPropertyDescriptors(Object object)
{
itemPropertyDescriptors = null;
super.getPropertyDescriptors(object);
XSDParticle xsdParticle = (XSDParticle)object;
XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
if (xsdParticleContent != null)
{
for (IItemPropertyDescriptor delegatedItemPropertyDescriptor : itemDelegator.getPropertyDescriptors(xsdParticleContent))
{
itemPropertyDescriptors.add(new ItemPropertyDescriptorDecorator(xsdParticleContent, delegatedItemPropertyDescriptor));
}
}
// This is for the minOccurs feature.
//
itemPropertyDescriptors.add
(new ItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
XSDEditPlugin.INSTANCE.getString("_UI_MinOccurs_label"),
XSDEditPlugin.INSTANCE.getString("_UI_MinOccurs_description"),
xsdPackage.getXSDParticle_MinOccurs(),
true,
ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE));
// This is for the maxOccurs feature.
//
itemPropertyDescriptors.add
(new ItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
XSDEditPlugin.INSTANCE.getString("_UI_MaxOccurs_label"),
XSDEditPlugin.INSTANCE.getString("_UI_MaxOccurs_description"),
xsdPackage.getXSDParticle_MaxOccurs(),
true,
ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE));
return itemPropertyDescriptors;
}
/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
*/
@Override
public Collection extends EStructuralFeature> getChildrenFeatures(Object object)
{
if (childrenFeatures == null)
{
super.getChildrenFeatures(object);
childrenFeatures.clear();
/*
XSDParticle xsdParticle = ((XSDParticle)object);
childrenFeatures.add(xsdPackage.getXSDParticle_Content());
*/
}
return childrenFeatures;
}
@Override
public Collection> getChildren(Object object)
{
XSDParticle xsdParticle = (XSDParticle)object;
XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
if (xsdParticleContent != null)
{
return itemDelegator.getChildren(xsdParticleContent);
}
else
{
return Collections.EMPTY_LIST;
}
}
@Override
public boolean hasChildren(Object object)
{
XSDParticle xsdParticle = (XSDParticle)object;
XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
return
xsdParticleContent != null && itemDelegator.hasChildren(xsdParticleContent);
}
/**
* This returns XSDParticle.gif.
*/
@Override
public Object getImage(Object object)
{
XSDParticle xsdParticle = ((XSDParticle)object);
XSDParticleContent xsdParticleContent = getDelegate(xsdParticle);
if (xsdParticleContent != null)
{
Collection