| 1 |
/** |
| 2 |
* Copyright (c) 2002-2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.xsd.provider; |
| 12 |
|
| 13 |
|
| 14 |
import java.util.Collection; |
| 15 |
import java.util.List; |
| 16 |
|
| 17 |
import org.eclipse.emf.common.notify.AdapterFactory; |
| 18 |
import org.eclipse.emf.common.notify.Notification; |
| 19 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 20 |
import org.eclipse.emf.ecore.InternalEObject; |
| 21 |
import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 22 |
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
| 23 |
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 24 |
import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 25 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 26 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 27 |
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 28 |
import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 29 |
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| 30 |
import org.eclipse.emf.edit.provider.ItemProviderAdapter; |
| 31 |
|
| 32 |
import org.eclipse.xsd.XSDCompositor; |
| 33 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 34 |
import org.eclipse.xsd.XSDElementDeclaration; |
| 35 |
import org.eclipse.xsd.XSDModelGroup; |
| 36 |
import org.eclipse.xsd.XSDParticle; |
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDModelGroup} object. |
| 41 |
*/ |
| 42 |
public class XSDModelGroupItemProvider |
| 43 |
extends XSDTermItemProvider |
| 44 |
implements |
| 45 |
IEditingDomainItemProvider, |
| 46 |
IStructuredItemContentProvider, |
| 47 |
ITreeItemContentProvider, |
| 48 |
IItemLabelProvider, |
| 49 |
IItemPropertySource |
| 50 |
{ |
| 51 |
/** |
| 52 |
* This constructs an instance from a factory and a notifier. |
| 53 |
*/ |
| 54 |
public XSDModelGroupItemProvider(AdapterFactory adapterFactory) |
| 55 |
{ |
| 56 |
super(adapterFactory); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* This returns the property descriptors for the adapted class. |
| 61 |
*/ |
| 62 |
@Override |
| 63 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 64 |
{ |
| 65 |
if (itemPropertyDescriptors == null) |
| 66 |
{ |
| 67 |
super.getPropertyDescriptors(object); |
| 68 |
|
| 69 |
// This is for the compositor feature. |
| 70 |
// |
| 71 |
itemPropertyDescriptors.add |
| 72 |
(new ItemPropertyDescriptor |
| 73 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 74 |
XSDEditPlugin.INSTANCE.getString("_UI_Compositor_label"), |
| 75 |
XSDEditPlugin.INSTANCE.getString("_UI_Compositor_description"), |
| 76 |
xsdPackage.getXSDModelGroup_Compositor(), |
| 77 |
true, |
| 78 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE)); |
| 79 |
|
| 80 |
// This is for the annotation feature. |
| 81 |
// |
| 82 |
itemPropertyDescriptors.add |
| 83 |
(new ItemPropertyDescriptor |
| 84 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 85 |
XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"), |
| 86 |
XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfModelGroup_description"), |
| 87 |
xsdPackage.getXSDModelGroup_Annotation(), |
| 88 |
false)); |
| 89 |
|
| 90 |
} |
| 91 |
return itemPropertyDescriptors; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 96 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 97 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 98 |
*/ |
| 99 |
@Override |
| 100 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 101 |
{ |
| 102 |
if (childrenFeatures == null) |
| 103 |
{ |
| 104 |
super.getChildrenFeatures(object); |
| 105 |
childrenFeatures.add(xsdPackage.getXSDModelGroup_Annotation()); |
| 106 |
childrenFeatures.add(xsdPackage.getXSDModelGroup_Contents()); |
| 107 |
} |
| 108 |
return childrenFeatures; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* This returns XSDModelGroup.gif. |
| 113 |
*/ |
| 114 |
@Override |
| 115 |
public Object getImage(Object object) |
| 116 |
{ |
| 117 |
XSDModelGroup xsdModelGroup = ((XSDModelGroup)object); |
| 118 |
if (XSDCompositor.CHOICE_LITERAL == xsdModelGroup.getCompositor()) |
| 119 |
{ |
| 120 |
return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDModelGroupChoice"); |
| 121 |
} |
| 122 |
else if (XSDCompositor.ALL_LITERAL == xsdModelGroup.getCompositor()) |
| 123 |
{ |
| 124 |
return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDModelGroupAll"); |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDModelGroupSequence"); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
@Override |
| 133 |
public String getText(Object object) |
| 134 |
{ |
| 135 |
XSDModelGroup xsdModelGroup = ((XSDModelGroup)object); |
| 136 |
return xsdModelGroup.getCompositor().getName(); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 141 |
*/ |
| 142 |
@Override |
| 143 |
public void notifyChanged(Notification msg) |
| 144 |
{ |
| 145 |
XSDModelGroup xsdModelGroup = (XSDModelGroup)msg.getNotifier(); |
| 146 |
if (msg.getFeature() == xsdPackage.getXSDModelGroup_Compositor() || |
| 147 |
msg.getFeature() == xsdPackage.getXSDModelGroup_Contents() || |
| 148 |
msg.getFeature() == xsdPackage.getXSDModelGroup_Annotation()) |
| 149 |
{ |
| 150 |
fireNotifyChanged(msg); |
| 151 |
|
| 152 |
XSDConcreteComponent container = xsdModelGroup.getContainer(); |
| 153 |
if (container instanceof XSDParticle) |
| 154 |
{ |
| 155 |
((ItemProviderAdapter)adapterFactory.adapt(container, IItemLabelProvider.class)).fireNotifyChanged |
| 156 |
(new ENotificationImpl |
| 157 |
((InternalEObject)container, |
| 158 |
msg.getEventType(), |
| 159 |
(EStructuralFeature)msg.getFeature(), |
| 160 |
msg.getOldValue(), |
| 161 |
msg.getNewValue(), |
| 162 |
msg.getPosition())); |
| 163 |
} |
| 164 |
return; |
| 165 |
} |
| 166 |
super.notifyChanged(msg); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 171 |
* that can be created under this object. |
| 172 |
*/ |
| 173 |
@Override |
| 174 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 175 |
{ |
| 176 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 177 |
XSDModelGroup mg = (XSDModelGroup) object; |
| 178 |
|
| 179 |
// annotation |
| 180 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroup_Annotation(), xsdFactory.createXSDAnnotation())); |
| 181 |
|
| 182 |
// element declaration under particle |
| 183 |
XSDElementDeclaration ed = createElementDeclaration(mg); |
| 184 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroup_Contents(), createParticle(ed, false))); |
| 185 |
|
| 186 |
// element declaration reference under particle |
| 187 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroup_Contents(), createParticle(mg.resolveElementDeclaration(""), true))); |
| 188 |
|
| 189 |
// for choice and sequence model groups only... |
| 190 |
if (mg.getCompositor() != XSDCompositor.ALL_LITERAL) |
| 191 |
{ |
| 192 |
// choice and sequence model groups under particles |
| 193 |
addModelGroupChildParameters(newChildDescriptors, xsdPackage.getXSDModelGroup_Contents(), false, true); |
| 194 |
|
| 195 |
// model group definition reference under particle |
| 196 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroup_Contents(), createParticle(mg.resolveModelGroupDefinition(""), true))); |
| 197 |
|
| 198 |
// element wildcard under particle |
| 199 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroup_Contents(), createParticle(xsdFactory.createXSDWildcard(), false))); |
| 200 |
} |
| 201 |
} |
| 202 |
} |