| 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.edit.provider.ComposeableAdapterFactory; |
| 21 |
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 22 |
import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 23 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 24 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 25 |
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 26 |
import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 27 |
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| 28 |
|
| 29 |
import org.eclipse.xsd.XSDModelGroupDefinition; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDModelGroupDefinition} object. |
| 34 |
*/ |
| 35 |
public class XSDModelGroupDefinitionItemProvider |
| 36 |
extends XSDRedefinableComponentItemProvider |
| 37 |
implements |
| 38 |
IEditingDomainItemProvider, |
| 39 |
IStructuredItemContentProvider, |
| 40 |
ITreeItemContentProvider, |
| 41 |
IItemLabelProvider, |
| 42 |
IItemPropertySource |
| 43 |
{ |
| 44 |
/** |
| 45 |
* This constructs an instance from a factory and a notifier. |
| 46 |
*/ |
| 47 |
public XSDModelGroupDefinitionItemProvider(AdapterFactory adapterFactory) |
| 48 |
{ |
| 49 |
super(adapterFactory); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* This returns the property descriptors for the adapted class. |
| 54 |
*/ |
| 55 |
@Override |
| 56 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 57 |
{ |
| 58 |
if (itemPropertyDescriptors == null) |
| 59 |
{ |
| 60 |
super.getPropertyDescriptors(object); |
| 61 |
|
| 62 |
// This is for the annotation feature. |
| 63 |
// |
| 64 |
itemPropertyDescriptors.add |
| 65 |
(new ItemPropertyDescriptor |
| 66 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 67 |
XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"), |
| 68 |
XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfModelGroupDefinition_description"), |
| 69 |
xsdPackage.getXSDModelGroupDefinition_Annotation(), |
| 70 |
false)); |
| 71 |
|
| 72 |
// This is for the resolvedModelGroupDefinition feature. |
| 73 |
// |
| 74 |
itemPropertyDescriptors.add |
| 75 |
(new ItemPropertyDescriptor |
| 76 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 77 |
XSDEditPlugin.INSTANCE.getString("_UI_ResolvedModelGroupDefinition_label"), |
| 78 |
XSDEditPlugin.INSTANCE.getString("_UI_ResolvedModelGroupDefinition_description"), |
| 79 |
xsdPackage.getXSDModelGroupDefinition_ResolvedModelGroupDefinition(), |
| 80 |
false)); |
| 81 |
|
| 82 |
} |
| 83 |
return itemPropertyDescriptors; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 88 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 89 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 90 |
*/ |
| 91 |
@Override |
| 92 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 93 |
{ |
| 94 |
if (childrenFeatures == null) |
| 95 |
{ |
| 96 |
super.getChildrenFeatures(object); |
| 97 |
childrenFeatures.add(xsdPackage.getXSDModelGroupDefinition_Annotation()); |
| 98 |
childrenFeatures.add(xsdPackage.getXSDModelGroupDefinition_ModelGroup()); |
| 99 |
} |
| 100 |
return childrenFeatures; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* This returns XSDModelGroupDefinition.gif. |
| 105 |
*/ |
| 106 |
@Override |
| 107 |
public Object getImage(Object object) |
| 108 |
{ |
| 109 |
XSDModelGroupDefinition xsdModelGroupDefinition = ((XSDModelGroupDefinition)object); |
| 110 |
XSDModelGroupDefinition resolvedModelGroupDefinition = xsdModelGroupDefinition.getResolvedModelGroupDefinition(); |
| 111 |
return |
| 112 |
XSDEditPlugin.INSTANCE.getImage |
| 113 |
(resolvedModelGroupDefinition.getContainer() == null ? |
| 114 |
"full/obj16/XSDModelGroupDefinition" : |
| 115 |
xsdModelGroupDefinition.getResolvedModelGroupDefinition() == xsdModelGroupDefinition ? |
| 116 |
"full/obj16/XSDModelGroupDefinition" : |
| 117 |
"full/obj16/XSDModelGroupUse"); |
| 118 |
} |
| 119 |
|
| 120 |
@Override |
| 121 |
public String getText(Object object) |
| 122 |
{ |
| 123 |
XSDModelGroupDefinition xsdModelGroupDefinition = ((XSDModelGroupDefinition)object); |
| 124 |
String result = |
| 125 |
xsdModelGroupDefinition.isModelGroupDefinitionReference() ? |
| 126 |
xsdModelGroupDefinition.getQName() : |
| 127 |
xsdModelGroupDefinition.getName(); |
| 128 |
return result == null ? XSDEditPlugin.INSTANCE.getString("_UI_Absent_label") : result; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 133 |
*/ |
| 134 |
@Override |
| 135 |
public void notifyChanged(Notification msg) |
| 136 |
{ |
| 137 |
if (msg.getFeature() == xsdPackage.getXSDModelGroupDefinition_ModelGroup() || |
| 138 |
msg.getFeature() == xsdPackage.getXSDModelGroupDefinition_ResolvedModelGroupDefinition() || |
| 139 |
msg.getFeature() == xsdPackage.getXSDModelGroupDefinition_Annotation()) |
| 140 |
{ |
| 141 |
fireNotifyChanged(msg); |
| 142 |
return; |
| 143 |
} |
| 144 |
super.notifyChanged(msg); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 149 |
* that can be created under this object. |
| 150 |
*/ |
| 151 |
@Override |
| 152 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 153 |
{ |
| 154 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 155 |
XSDModelGroupDefinition mgd = (XSDModelGroupDefinition) object; |
| 156 |
|
| 157 |
if (!mgd.isModelGroupDefinitionReference()) |
| 158 |
{ |
| 159 |
// annotation |
| 160 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDModelGroupDefinition_Annotation(), xsdFactory.createXSDAnnotation())); |
| 161 |
|
| 162 |
// all, choice, and sequence model groups |
| 163 |
addModelGroupChildParameters(newChildDescriptors, xsdPackage.getXSDModelGroupDefinition_ModelGroup(), true, false); |
| 164 |
} |
| 165 |
} |
| 166 |
} |