| 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.XSDConcreteComponent; |
| 33 |
import org.eclipse.xsd.XSDParticle; |
| 34 |
import org.eclipse.xsd.XSDWildcard; |
| 35 |
|
| 36 |
|
| 37 |
/** |
| 38 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDWildcard} object. |
| 39 |
*/ |
| 40 |
public class XSDWildcardItemProvider |
| 41 |
extends XSDTermItemProvider |
| 42 |
implements |
| 43 |
IEditingDomainItemProvider, |
| 44 |
IStructuredItemContentProvider, |
| 45 |
ITreeItemContentProvider, |
| 46 |
IItemLabelProvider, |
| 47 |
IItemPropertySource |
| 48 |
{ |
| 49 |
/** |
| 50 |
* This constructs an instance from a factory and a notifier. |
| 51 |
*/ |
| 52 |
public XSDWildcardItemProvider(AdapterFactory adapterFactory) |
| 53 |
{ |
| 54 |
super(adapterFactory); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* This returns the property descriptors for the adapted class. |
| 59 |
*/ |
| 60 |
@Override |
| 61 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 62 |
{ |
| 63 |
if (itemPropertyDescriptors == null) |
| 64 |
{ |
| 65 |
super.getPropertyDescriptors(object); |
| 66 |
|
| 67 |
// This is for the namespaceConstraint feature. |
| 68 |
// |
| 69 |
itemPropertyDescriptors.add |
| 70 |
(new ItemPropertyDescriptor |
| 71 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 72 |
XSDEditPlugin.INSTANCE.getString("_UI_LexicalNamespaceConstraint_label"), |
| 73 |
XSDEditPlugin.INSTANCE.getString("_UI_LexicalNamespaceConstraint_description"), |
| 74 |
xsdPackage.getXSDWildcard_LexicalNamespaceConstraint(), |
| 75 |
true, |
| 76 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 77 |
{ |
| 78 |
@Override |
| 79 |
public Object getPropertyValue(Object o) |
| 80 |
{ |
| 81 |
return ((XSDWildcard)o).getStringLexicalNamespaceConstraint(); |
| 82 |
} |
| 83 |
@Override |
| 84 |
public void setPropertyValue(Object o, Object v) |
| 85 |
{ |
| 86 |
XSDWildcard thisWildcard = (XSDWildcard)o; |
| 87 |
thisWildcard.setStringLexicalNamespaceConstraint((String)v); |
| 88 |
/* |
| 89 |
EATM TODO |
| 90 |
It looks like you can't set a multi-value anymore with the latest generated code. |
| 91 |
|
| 92 |
EditingDomain editingDomain = getEditingDomain(thisWildcard); |
| 93 |
if (editingDomain == null) |
| 94 |
{ |
| 95 |
thisWildcard.setStringLexicalNamespaceConstraint((String)v); |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
//List newLexicalNamespaceConstraint = new ArrayList(); |
| 100 |
List newLexicalNamespaceConstraint = new org.eclipse.emf.ecore.ref.impl.EListImpl(); |
| 101 |
for (StringTokenizer stringTokenizer = new StringTokenizer((String)v); stringTokenizer.hasMoreTokens(); ) |
| 102 |
{ |
| 103 |
String token = stringTokenizer.nextToken(); |
| 104 |
newLexicalNamespaceConstraint.add(token); |
| 105 |
} |
| 106 |
editingDomain.getCommandStack().execute |
| 107 |
(SetCommand.create |
| 108 |
(editingDomain, |
| 109 |
thisWildcard, |
| 110 |
xsdPackage.getXSDWildcard_LexicalNamespaceConstraint(), |
| 111 |
newLexicalNamespaceConstraint)); |
| 112 |
} |
| 113 |
*/ |
| 114 |
} |
| 115 |
}); |
| 116 |
|
| 117 |
// This is for the namespaceConstraint feature. |
| 118 |
// |
| 119 |
itemPropertyDescriptors.add |
| 120 |
(new ItemPropertyDescriptor |
| 121 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 122 |
XSDEditPlugin.INSTANCE.getString("_UI_NamespaceConstraint_label"), |
| 123 |
XSDEditPlugin.INSTANCE.getString("_UI_NamespaceConstraint_description"), |
| 124 |
xsdPackage.getXSDWildcard_NamespaceConstraint(), |
| 125 |
false, |
| 126 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 127 |
{ |
| 128 |
@Override |
| 129 |
public Object getPropertyValue(Object o) |
| 130 |
{ |
| 131 |
return ((XSDWildcard)o).getStringNamespaceConstraint(); |
| 132 |
} |
| 133 |
}); |
| 134 |
|
| 135 |
// This is for the namespaceConstraintCategory feature. |
| 136 |
// |
| 137 |
itemPropertyDescriptors.add |
| 138 |
(new ItemPropertyDescriptor |
| 139 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 140 |
XSDEditPlugin.INSTANCE.getString("_UI_NamespaceConstraintCategory_label"), |
| 141 |
XSDEditPlugin.INSTANCE.getString("_UI_NamespaceConstraintCategory_description"), |
| 142 |
xsdPackage.getXSDWildcard_NamespaceConstraintCategory(), |
| 143 |
false, |
| 144 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE)); |
| 145 |
|
| 146 |
// This is for the processContents feature. |
| 147 |
// |
| 148 |
itemPropertyDescriptors.add |
| 149 |
(new ItemPropertyDescriptor |
| 150 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 151 |
XSDEditPlugin.INSTANCE.getString("_UI_ProcessContents_label"), |
| 152 |
XSDEditPlugin.INSTANCE.getString("_UI_ProcessContents_description"), |
| 153 |
xsdPackage.getXSDWildcard_ProcessContents(), |
| 154 |
true, |
| 155 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE)); |
| 156 |
|
| 157 |
// This is for the annotation feature. |
| 158 |
// |
| 159 |
itemPropertyDescriptors.add |
| 160 |
(new ItemPropertyDescriptor |
| 161 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 162 |
XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"), |
| 163 |
XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfWildcard_description"), |
| 164 |
xsdPackage.getXSDWildcard_Annotation(), |
| 165 |
false)); |
| 166 |
|
| 167 |
} |
| 168 |
return itemPropertyDescriptors; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 173 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 174 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 175 |
*/ |
| 176 |
@Override |
| 177 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 178 |
{ |
| 179 |
if (childrenFeatures == null) |
| 180 |
{ |
| 181 |
super.getChildrenFeatures(object); |
| 182 |
childrenFeatures.add(xsdPackage.getXSDWildcard_Annotation()); |
| 183 |
} |
| 184 |
return childrenFeatures; |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* This returns XSDWildcard.gif. |
| 189 |
*/ |
| 190 |
@Override |
| 191 |
public Object getImage(Object object) |
| 192 |
{ |
| 193 |
XSDWildcard xsdWildcard = ((XSDWildcard)object); |
| 194 |
return |
| 195 |
XSDEditPlugin.INSTANCE.getImage |
| 196 |
(xsdWildcard.eContainer() instanceof XSDParticle ? |
| 197 |
"full/obj16/XSDWildcardElement" : |
| 198 |
"full/obj16/XSDWildcardAttribute"); |
| 199 |
} |
| 200 |
|
| 201 |
@Override |
| 202 |
public String getText(Object object) |
| 203 |
{ |
| 204 |
XSDWildcard xsdWildcard = ((XSDWildcard)object); |
| 205 |
String result = xsdWildcard.getStringLexicalNamespaceConstraint(); |
| 206 |
return result == null ? "" : result; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 211 |
*/ |
| 212 |
@Override |
| 213 |
public void notifyChanged(Notification msg) |
| 214 |
{ |
| 215 |
XSDWildcard xsdWildcard = (XSDWildcard)msg.getNotifier(); |
| 216 |
if (msg.getFeature() == xsdPackage.getXSDWildcard_LexicalNamespaceConstraint() || |
| 217 |
msg.getFeature() == xsdPackage.getXSDWildcard_NamespaceConstraint()) |
| 218 |
{ |
| 219 |
fireNotifyChanged |
| 220 |
(new ENotificationImpl((InternalEObject)msg.getNotifier(), Notification.SET, null, null, null, Notification.NO_INDEX)); |
| 221 |
|
| 222 |
XSDConcreteComponent container = xsdWildcard.getContainer(); |
| 223 |
if (container instanceof XSDParticle) |
| 224 |
{ |
| 225 |
((ItemProviderAdapter)adapterFactory.adapt(container, IItemLabelProvider.class)).fireNotifyChanged |
| 226 |
(new ENotificationImpl((InternalEObject)container, Notification.SET, null, null, null, Notification.NO_INDEX)); |
| 227 |
} |
| 228 |
return; |
| 229 |
} |
| 230 |
else if (msg.getFeature() == xsdPackage.getXSDWildcard_ProcessContents() || |
| 231 |
msg.getFeature() == xsdPackage.getXSDWildcard_NamespaceConstraintCategory() || |
| 232 |
msg.getFeature() == xsdPackage.getXSDWildcard_Annotation()) |
| 233 |
{ |
| 234 |
fireNotifyChanged(msg); |
| 235 |
XSDConcreteComponent container = xsdWildcard.getContainer(); |
| 236 |
if (container instanceof XSDParticle) |
| 237 |
{ |
| 238 |
((ItemProviderAdapter)adapterFactory.adapt(container, IItemLabelProvider.class)).fireNotifyChanged |
| 239 |
(new ENotificationImpl |
| 240 |
((InternalEObject)container, |
| 241 |
msg.getEventType(), |
| 242 |
(EStructuralFeature)msg.getFeature(), |
| 243 |
msg.getOldValue(), |
| 244 |
msg.getNewValue(), |
| 245 |
msg.getPosition())); |
| 246 |
} |
| 247 |
return; |
| 248 |
} |
| 249 |
super.notifyChanged(msg); |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 254 |
* that can be created under this object. |
| 255 |
*/ |
| 256 |
@Override |
| 257 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 258 |
{ |
| 259 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 260 |
|
| 261 |
// annotation |
| 262 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDWildcard_Annotation(), xsdFactory.createXSDAnnotation())); |
| 263 |
} |
| 264 |
} |