Debian Codegraph @

plugins/org.eclipse.xsd.edit/src/org/eclipse/xsd/provider/XSDIdentityConstraintDefinitionItemProvider.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.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.XSDIdentityConstraintCategory;
30 import org.eclipse.xsd.XSDIdentityConstraintDefinition;
31 import org.eclipse.xsd.XSDXPathDefinition;
32 import org.eclipse.xsd.XSDXPathVariety;
33
34
35 /**
36 * This is the item provider adpater for a {@link org.eclipse.xsd.XSDIdentityConstraintDefinition} object.
37 */
38 public class XSDIdentityConstraintDefinitionItemProvider
39 extends XSDNamedComponentItemProvider
40 implements
41 IEditingDomainItemProvider,
42 IStructuredItemContentProvider,
43 ITreeItemContentProvider,
44 IItemLabelProvider,
45 IItemPropertySource
46 {
47 /**
48 * This constructs an instance from a factory and a notifier.
49 */
50 public XSDIdentityConstraintDefinitionItemProvider(AdapterFactory adapterFactory)
51 {
52 super(adapterFactory);
53 }
54
55 /**
56 * This returns the property descriptors for the adapted class.
57 */
58 @Override
59 public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object)
60 {
61 if (itemPropertyDescriptors == null)
62 {
63 super.getPropertyDescriptors(object);
64
65 // This is for the identityConstraintCategory feature.
66 //
67 itemPropertyDescriptors.add
68 (new ItemPropertyDescriptor
69 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
70 XSDEditPlugin.INSTANCE.getString("_UI_IdentityConstraintCategory_label"),
71 XSDEditPlugin.INSTANCE.getString("_UI_IdentityConstraintCategory_description"),
72 xsdPackage.getXSDIdentityConstraintDefinition_IdentityConstraintCategory(),
73 true,
74 ItemPropertyDescriptor.TEXT_VALUE_IMAGE));
75
76 /*
77 // This is for the selector feature.
78 //
79 itemPropertyDescriptors.add
80 (new ItemPropertyDescriptor
81 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
82 XSDEditPlugin.INSTANCE.getString("_UI_Selector_label"),
83 XSDEditPlugin.INSTANCE.getString("_UI_Selector_description"),
84 xsdPackage.getXSDIdentityConstraintDefinition_Selector(),
85 true,
86 ItemPropertyDescriptor.TEXT_VALUE_IMAGE));
87 */
88
89 // This is for the referencedKey feature.
90 //
91 itemPropertyDescriptors.add
92 (new ItemPropertyDescriptor
93 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
94 XSDEditPlugin.INSTANCE.getString("_UI_ReferencedKey_label"),
95 XSDEditPlugin.INSTANCE.getString("_UI_ReferencedKey_description"),
96 xsdPackage.getXSDIdentityConstraintDefinition_ReferencedKey(),
97 false));
98
99 // This is for the annotation feature.
100 //
101 itemPropertyDescriptors.add
102 (new ItemPropertyDescriptor
103 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
104 XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"),
105 XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfIdentityConstraint_description"),
106 xsdPackage.getXSDIdentityConstraintDefinition_Annotation(),
107 false));
108
109 }
110 return itemPropertyDescriptors;
111 }
112
113 /**
114 * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
115 * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
116 * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
117 */
118 @Override
119 public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object)
120 {
121 if (childrenFeatures == null)
122 {
123 super.getChildrenFeatures(object);
124 childrenFeatures.add(xsdPackage.getXSDIdentityConstraintDefinition_Annotation());
125 childrenFeatures.add(xsdPackage.getXSDIdentityConstraintDefinition_Selector());
126 childrenFeatures.add(xsdPackage.getXSDIdentityConstraintDefinition_Fields());
127 }
128 return childrenFeatures;
129 }
130
131 /**
132 * This returns XSDIdentityConstraintDefinition.gif.
133 */
134 @Override
135 public Object getImage(Object object)
136 {
137 XSDIdentityConstraintDefinition xsdIdentityConstraintDefinition = ((XSDIdentityConstraintDefinition)object);
138 return
139 XSDEditPlugin.INSTANCE.getImage
140 (XSDIdentityConstraintCategory.KEY_LITERAL == xsdIdentityConstraintDefinition.getIdentityConstraintCategory() ?
141 "full/obj16/XSDIdentityConstraintDefinitionKey" :
142 XSDIdentityConstraintCategory.KEYREF_LITERAL == xsdIdentityConstraintDefinition.getIdentityConstraintCategory() ?
143 "full/obj16/XSDIdentityConstraintDefinitionKeyReference" :
144 "full/obj16/XSDIdentityConstraintDefinitionUnique");
145 }
146
147 @Override
148 public String getText(Object object)
149 {
150 XSDIdentityConstraintDefinition xsdIdentityConstraintDefinition = ((XSDIdentityConstraintDefinition)object);
151 String result = xsdIdentityConstraintDefinition.getName();
152 return result == null ? "" : 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.getXSDIdentityConstraintDefinition_IdentityConstraintCategory() ||
163 msg.getFeature() == xsdPackage.getXSDIdentityConstraintDefinition_Selector() ||
164 msg.getFeature() == xsdPackage.getXSDIdentityConstraintDefinition_Fields() ||
165 msg.getFeature() == xsdPackage.getXSDIdentityConstraintDefinition_ReferencedKey() ||
166 msg.getFeature() == xsdPackage.getXSDIdentityConstraintDefinition_Annotation()
167 )
168 {
169 fireNotifyChanged(msg);
170 return;
171 }
172 super.notifyChanged(msg);
173 }
174
175 /**
176 * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
177 * that can be created under this object.
178 */
179 @Override
180 protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object)
181 {
182 super.collectNewChildDescriptors(newChildDescriptors, object);
183
184 // annotation
185 newChildDescriptors.add(createChildParameter(xsdPackage.getXSDIdentityConstraintDefinition_Annotation(), xsdFactory.createXSDAnnotation()));
186
187 // selector xpath
188 XSDXPathDefinition xpd = xsdFactory.createXSDXPathDefinition();
189 xpd.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
190 xpd.setValue("");
191 newChildDescriptors.add(createChildParameter(xsdPackage.getXSDIdentityConstraintDefinition_Selector(), xpd));
192
193 // field xpath
194 xpd = xsdFactory.createXSDXPathDefinition();
195 xpd.setVariety(XSDXPathVariety.FIELD_LITERAL);
196 xpd.setValue("");
197 newChildDescriptors.add(createChildParameter(xsdPackage.getXSDIdentityConstraintDefinition_Fields(), xpd));
198 }
199 }