Debian Codegraph @

plugins/org.eclipse.xsd.edit/src/org/eclipse/xsd/provider/XSDAttributeGroupDefinitionItemProvider.java

raw
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.EObject;
20 import org.eclipse.emf.ecore.EStructuralFeature;
21 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
22 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
23 import org.eclipse.emf.edit.provider.IItemLabelProvider;
24 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
25 import org.eclipse.emf.edit.provider.IItemPropertySource;
26 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
27 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
28 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
29
30 import org.eclipse.xsd.XSDAttributeDeclaration;
31 import org.eclipse.xsd.XSDAttributeGroupDefinition;
32
33
34 /**
35 * This is the item provider adpater for a {@link org.eclipse.xsd.XSDAttributeGroupDefinition} object.
36 */
37 public class XSDAttributeGroupDefinitionItemProvider
38 extends XSDRedefinableComponentItemProvider
39 implements
40 IEditingDomainItemProvider,
41 IStructuredItemContentProvider,
42 ITreeItemContentProvider,
43 IItemLabelProvider,
44 IItemPropertySource
45 {
46 /**
47 * This constructs an instance from a factory and a notifier.
48 */
49 public XSDAttributeGroupDefinitionItemProvider(AdapterFactory adapterFactory)
50 {
51 super(adapterFactory);
52 }
53
54 /**
55 * This returns the property descriptors for the adapted class.
56 */
57 @Override
58 public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object)
59 {
60 if (itemPropertyDescriptors == null)
61 {
62 super.getPropertyDescriptors(object);
63
64 // This is for the attributeWildcard feature.
65 //
66 itemPropertyDescriptors.add
67 (new ItemPropertyDescriptor
68 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
69 XSDEditPlugin.INSTANCE.getString("_UI_AttributeWildcard_label"),
70 XSDEditPlugin.INSTANCE.getString("_UI_AttributeWildcardOfAttributeGroup_description"),
71 xsdPackage.getXSDAttributeGroupDefinition_AttributeWildcardContent(),
72 false));
73
74 // This is for the annotation feature.
75 //
76 itemPropertyDescriptors.add
77 (new ItemPropertyDescriptor
78 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
79 XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"),
80 XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfAttributeGroup_description"),
81 xsdPackage.getXSDAttributeGroupDefinition_Annotation(),
82 false));
83
84 // This is for the resolvedAttributeGroupDefinition feature.
85 //
86 itemPropertyDescriptors.add
87 (new ItemPropertyDescriptor
88 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
89 XSDEditPlugin.INSTANCE.getString("_UI_ResolvedAttributeGroupDefinition_label"),
90 XSDEditPlugin.INSTANCE.getString("_UI_ResolvedAttributeGroupDefinition_description"),
91 xsdPackage.getXSDAttributeGroupDefinition_ResolvedAttributeGroupDefinition(),
92 false));
93 }
94 return itemPropertyDescriptors;
95 }
96
97 /**
98 * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
99 * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
100 * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
101 */
102 @Override
103 public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object)
104 {
105 if (childrenFeatures == null)
106 {
107 super.getChildrenFeatures(object);
108 childrenFeatures.add(xsdPackage.getXSDAttributeGroupDefinition_Annotation());
109 childrenFeatures.add(xsdPackage.getXSDAttributeGroupDefinition_Contents());
110 childrenFeatures.add(xsdPackage.getXSDAttributeGroupDefinition_AttributeWildcardContent());
111 }
112 return childrenFeatures;
113 }
114
115 @Override
116 protected EStructuralFeature getChildFeature(Object object, Object child)
117 {
118 EObject refObject = (EObject)child;
119 if (refObject instanceof XSDAttributeDeclaration)
120 {
121 // TODO: check that this is what you want.
122 return xsdPackage.getXSDAttributeGroupDefinition_Contents();
123 }
124 return super.getChildFeature(object, child);
125 }
126
127 /**
128 * This returns XSDAttributeGroupDefinition.gif.
129 */
130 @Override
131 public Object getImage(Object object)
132 {
133 XSDAttributeGroupDefinition xsdAttributeGroupDefinition = ((XSDAttributeGroupDefinition)object);
134 XSDAttributeGroupDefinition resolvedAttributeGroupDefinition = xsdAttributeGroupDefinition.getResolvedAttributeGroupDefinition();
135 return
136 XSDEditPlugin.INSTANCE.getImage
137 (resolvedAttributeGroupDefinition.getContainer() == null ?
138 "full/obj16/XSDAttributeGroupUnresolved" :
139 xsdAttributeGroupDefinition.getResolvedAttributeGroupDefinition() == xsdAttributeGroupDefinition ?
140 "full/obj16/XSDAttributeGroupDefinition" :
141 "full/obj16/XSDAttributeGroupUse");
142 }
143
144 @Override
145 public String getText(Object object)
146 {
147 XSDAttributeGroupDefinition xsdAttributeGroupDefinition = ((XSDAttributeGroupDefinition)object);
148 String result =
149 xsdAttributeGroupDefinition.isAttributeGroupDefinitionReference() ?
150 xsdAttributeGroupDefinition.getQName() :
151 xsdAttributeGroupDefinition.getName();
152 return result == null ? XSDEditPlugin.INSTANCE.getString("_UI_Absent_label") : result;
153 }
154
155 /**
156 * This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}.
157 */
158 @Override
159 public void notifyChanged(Notification msg)
160 {
161 if (
162 msg.getFeature() == xsdPackage.getXSDAttributeGroupDefinition_Contents() ||
163 msg.getFeature() == xsdPackage.getXSDAttributeGroupDefinition_AttributeUses() ||
164 msg.getFeature() == xsdPackage.getXSDAttributeGroupDefinition_AttributeWildcardContent() ||
165 msg.getFeature() == xsdPackage.getXSDAttributeGroupDefinition_Annotation()
166 )
167 {
168 fireNotifyChanged(msg);
169 return;
170 }
171 super.notifyChanged(msg);
172 }
173
174 /**
175 * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
176 * that can be created under this object.
177 */
178 @Override
179 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object)
180 {
181 super.collectNewChildDescriptors(newChildDescriptors, object);
182 XSDAttributeGroupDefinition xsdAttributeGroupDefinition = (XSDAttributeGroupDefinition) object;
183
184 if (!xsdAttributeGroupDefinition.isAttributeGroupDefinitionReference())
185 {
186 // annotation
187 //
188 newChildDescriptors.add
189 (createChildParameter
190 (xsdPackage.getXSDAttributeGroupDefinition_Annotation(),
191 xsdFactory.createXSDAnnotation()));
192
193 // attribute declaration under attribute use
194 //
195 XSDAttributeDeclaration xsdAttributeDeclaration = createAttributeDeclaration(xsdAttributeGroupDefinition);
196 newChildDescriptors.add
197 (createChildParameter
198 (xsdPackage.getXSDAttributeGroupDefinition_Contents(),
199 createAttributeUse(xsdAttributeDeclaration, false)));
200
201 // attribute declaration reference under attribute use
202 //
203 newChildDescriptors.add
204 (createChildParameter
205 (xsdPackage.getXSDAttributeGroupDefinition_Contents(),
206 createAttributeUse(xsdAttributeGroupDefinition.resolveAttributeDeclaration(""), true)));
207
208 // attribute group definition reference
209 //
210 newChildDescriptors.add
211 (createChildParameter
212 (xsdPackage.getXSDAttributeGroupDefinition_Contents(),
213 createAttributeGroupDefinitionReference(xsdAttributeGroupDefinition.resolveAttributeGroupDefinition(""))));
214
215 // attribute wildcard
216 //
217 newChildDescriptors.add
218 (createChildParameter
219 (xsdPackage.getXSDAttributeGroupDefinition_AttributeWildcardContent(),
220 xsdFactory.createXSDWildcard()));
221 }
222 }
223 }