| 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.ArrayList; |
| 15 |
import java.util.Arrays; |
| 16 |
import java.util.Collection; |
| 17 |
import java.util.List; |
| 18 |
|
| 19 |
import org.eclipse.emf.common.notify.AdapterFactory; |
| 20 |
import org.eclipse.emf.common.notify.Notification; |
| 21 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 22 |
import org.eclipse.emf.ecore.InternalEObject; |
| 23 |
import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 24 |
import org.eclipse.emf.edit.command.SetCommand; |
| 25 |
import org.eclipse.emf.edit.domain.EditingDomain; |
| 26 |
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
| 27 |
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 28 |
import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 29 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 30 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 31 |
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 32 |
import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 33 |
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| 34 |
import org.eclipse.emf.edit.provider.ItemProviderAdapter; |
| 35 |
|
| 36 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 37 |
import org.eclipse.xsd.XSDElementDeclaration; |
| 38 |
import org.eclipse.xsd.XSDIdentityConstraintCategory; |
| 39 |
import org.eclipse.xsd.XSDIdentityConstraintDefinition; |
| 40 |
import org.eclipse.xsd.XSDParticle; |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDElementDeclaration} object. |
| 45 |
*/ |
| 46 |
public class XSDElementDeclarationItemProvider |
| 47 |
extends XSDFeatureItemProvider |
| 48 |
implements |
| 49 |
IEditingDomainItemProvider, |
| 50 |
IStructuredItemContentProvider, |
| 51 |
ITreeItemContentProvider, |
| 52 |
IItemLabelProvider, |
| 53 |
IItemPropertySource |
| 54 |
{ |
| 55 |
/** |
| 56 |
* This constructs an instance from a factory and a notifier. |
| 57 |
*/ |
| 58 |
public XSDElementDeclarationItemProvider(AdapterFactory adapterFactory) |
| 59 |
{ |
| 60 |
super(adapterFactory); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* This returns the property descriptors for the adapted class. |
| 65 |
*/ |
| 66 |
@Override |
| 67 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 68 |
{ |
| 69 |
if (itemPropertyDescriptors == null) |
| 70 |
{ |
| 71 |
super.getPropertyDescriptors(object); |
| 72 |
|
| 73 |
createLexicalValuePropertyDescriptor(object); |
| 74 |
createConstraintPropertyDescriptor(object); |
| 75 |
createScopePropertyDescriptor(object); |
| 76 |
createNillablePropertyDescriptor(object); |
| 77 |
createDisallowedSubstitutionsPropertyDescriptor(object); |
| 78 |
createSubstitutionGroupExclusionsPropertyDescriptor(object); |
| 79 |
createAbstractPropertyDescriptor(object); |
| 80 |
createTypeDefinitionPropertyDescriptor(object); |
| 81 |
createSubstitutionGroupAffiliationPropertyDescriptor(object); |
| 82 |
createAnnotationPropertyDescriptor(object); |
| 83 |
createResolvedElementDeclarationPropertyDescriptor(object); |
| 84 |
createElementFormDefaultPropertyDescriptor(object); |
| 85 |
createLexicalFinalPropertyDescriptor(object); |
| 86 |
createBlockPropertyDescriptor(object); |
| 87 |
} |
| 88 |
return itemPropertyDescriptors; |
| 89 |
} |
| 90 |
|
| 91 |
protected static class DelegatingItemPropertyDescriptor extends XSDItemProviderAdapter.ItemPropertyDescriptorWithDefault |
| 92 |
{ |
| 93 |
public DelegatingItemPropertyDescriptor |
| 94 |
(AdapterFactory adapterFactory, |
| 95 |
String displayName, |
| 96 |
String description, |
| 97 |
EStructuralFeature feature, |
| 98 |
boolean isSettable, |
| 99 |
Object staticImage) |
| 100 |
{ |
| 101 |
super(adapterFactory, displayName, description, feature, isSettable, staticImage); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
public Object getPropertyValue(Object object) |
| 106 |
{ |
| 107 |
return super.getPropertyValue(((XSDElementDeclaration)object).getResolvedElementDeclaration()); |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public void setPropertyValue(Object object, Object value) |
| 112 |
{ |
| 113 |
super.setPropertyValue(((XSDElementDeclaration)object).getResolvedElementDeclaration(), value); |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
protected void createNamePropertyDescriptor(Object object) |
| 120 |
{ |
| 121 |
|
| 122 |
// This is for the name feature. |
| 123 |
// |
| 124 |
itemPropertyDescriptors.add |
| 125 |
(new DelegatingItemPropertyDescriptor |
| 126 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 127 |
XSDEditPlugin.INSTANCE.getString("_UI_Name_label"), |
| 128 |
XSDEditPlugin.INSTANCE.getString("_UI_Name_description"), |
| 129 |
xsdPackage.getXSDNamedComponent_Name(), |
| 130 |
true, |
| 131 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 132 |
{ |
| 133 |
@Override |
| 134 |
public void setPropertyValue(Object o, Object value) |
| 135 |
{ |
| 136 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)o; |
| 137 |
if (xsdElementDeclaration.isElementDeclarationReference()) |
| 138 |
{ |
| 139 |
XSDElementDeclaration newResolvedElementDeclaration = |
| 140 |
xsdElementDeclaration.resolveElementDeclaration(xsdElementDeclaration.getTargetNamespace(), (String)value); |
| 141 |
EditingDomain editingDomain = getEditingDomain(xsdElementDeclaration); |
| 142 |
if (editingDomain == null) |
| 143 |
{ |
| 144 |
xsdElementDeclaration.setResolvedElementDeclaration(newResolvedElementDeclaration); |
| 145 |
} |
| 146 |
else |
| 147 |
{ |
| 148 |
editingDomain.getCommandStack().execute |
| 149 |
(SetCommand.create |
| 150 |
(editingDomain, |
| 151 |
xsdElementDeclaration, |
| 152 |
xsdPackage.getXSDElementDeclaration_ResolvedElementDeclaration(), |
| 153 |
newResolvedElementDeclaration)); |
| 154 |
} |
| 155 |
} |
| 156 |
else |
| 157 |
{ |
| 158 |
super.setPropertyValue(o, value); |
| 159 |
} |
| 160 |
} |
| 161 |
}); |
| 162 |
} |
| 163 |
|
| 164 |
protected void createLexicalFinalPropertyDescriptor(Object object) |
| 165 |
{ |
| 166 |
|
| 167 |
// This is for the final feature. |
| 168 |
// |
| 169 |
itemPropertyDescriptors.add |
| 170 |
(new XSDItemProviderAdapter.ItemPropertyDescriptorWithDefault |
| 171 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 172 |
XSDEditPlugin.INSTANCE.getString("_UI_Final_label"), |
| 173 |
XSDEditPlugin.INSTANCE.getString("_UI_FinalOfElement_description"), |
| 174 |
xsdPackage.getXSDElementDeclaration_LexicalFinal(), |
| 175 |
true, |
| 176 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 177 |
{ |
| 178 |
@Override |
| 179 |
public Object getPropertyDefaultValue(Object o) |
| 180 |
{ |
| 181 |
return |
| 182 |
XSDEditPlugin.INSTANCE.getString |
| 183 |
("_UI_DefaultValue_label", new Object [] { ((XSDElementDeclaration)o).getStringLexicalFinal() }); |
| 184 |
} |
| 185 |
@Override |
| 186 |
public Object getPropertyValue(Object o) |
| 187 |
{ |
| 188 |
return ((XSDElementDeclaration)o).getStringLexicalFinal(); |
| 189 |
} |
| 190 |
@Override |
| 191 |
public void setPropertyValue(Object o, Object value) |
| 192 |
{ |
| 193 |
((XSDElementDeclaration)o).setStringLexicalFinal((String)value); |
| 194 |
} |
| 195 |
@Override |
| 196 |
public Collection<?> getChoiceOfValues(Object o) |
| 197 |
{ |
| 198 |
Collection<Object> result = new ArrayList<Object>(); |
| 199 |
result.add(""); |
| 200 |
result.add("#all"); |
| 201 |
result.add("restriction"); |
| 202 |
result.add("restriction extension"); |
| 203 |
result.add("extension"); |
| 204 |
return result; |
| 205 |
} |
| 206 |
}); |
| 207 |
} |
| 208 |
protected void createBlockPropertyDescriptor(Object object) |
| 209 |
{ |
| 210 |
|
| 211 |
// This is for the final feature. |
| 212 |
// |
| 213 |
itemPropertyDescriptors.add |
| 214 |
(new XSDItemProviderAdapter.ItemPropertyDescriptorWithDefault |
| 215 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 216 |
XSDEditPlugin.INSTANCE.getString("_UI_Block_label"), |
| 217 |
XSDEditPlugin.INSTANCE.getString("_UI_BlockOfElement_description"), |
| 218 |
xsdPackage.getXSDElementDeclaration_Block(), |
| 219 |
true, |
| 220 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 221 |
{ |
| 222 |
@Override |
| 223 |
public Object getPropertyDefaultValue(Object o) |
| 224 |
{ |
| 225 |
return |
| 226 |
XSDEditPlugin.INSTANCE.getString |
| 227 |
("_UI_DefaultValue_label", new Object [] { ((XSDElementDeclaration)o).getStringBlock() }); |
| 228 |
} |
| 229 |
@Override |
| 230 |
public Object getPropertyValue(Object o) |
| 231 |
{ |
| 232 |
return ((XSDElementDeclaration)o).getStringBlock(); |
| 233 |
} |
| 234 |
@Override |
| 235 |
public void setPropertyValue(Object o, Object value) |
| 236 |
{ |
| 237 |
((XSDElementDeclaration)o).setStringBlock((String)value); |
| 238 |
} |
| 239 |
@Override |
| 240 |
public Collection<?> getChoiceOfValues(Object o) |
| 241 |
{ |
| 242 |
Collection<Object> result = new ArrayList<Object>(); |
| 243 |
result.add(""); |
| 244 |
result.add("#all"); |
| 245 |
result.add("extension"); |
| 246 |
result.add("restriction"); |
| 247 |
result.add("substitution"); |
| 248 |
result.add("extension restriction"); |
| 249 |
result.add("extension restriction substitution"); |
| 250 |
result.add("extension substitution"); |
| 251 |
result.add("restriction substitution"); |
| 252 |
return result; |
| 253 |
} |
| 254 |
}); |
| 255 |
} |
| 256 |
|
| 257 |
@Override |
| 258 |
protected void createTargetNamespacePropertyDescriptor(Object object) |
| 259 |
{ |
| 260 |
|
| 261 |
// This is for the name feature. |
| 262 |
// |
| 263 |
itemPropertyDescriptors.add |
| 264 |
(new DelegatingItemPropertyDescriptor |
| 265 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 266 |
XSDEditPlugin.INSTANCE.getString("_UI_TargetNamespace_label"), |
| 267 |
XSDEditPlugin.INSTANCE.getString("_UI_TargetNamespace_description"), |
| 268 |
xsdPackage.getXSDNamedComponent_TargetNamespace(), |
| 269 |
true, |
| 270 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 271 |
{ |
| 272 |
@Override |
| 273 |
public void setPropertyValue(Object o, Object value) |
| 274 |
{ |
| 275 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)o; |
| 276 |
if (xsdElementDeclaration.isElementDeclarationReference()) |
| 277 |
{ |
| 278 |
String namespace = (String)value; |
| 279 |
if (namespace.length() == 0) |
| 280 |
{ |
| 281 |
namespace = null; |
| 282 |
} |
| 283 |
XSDElementDeclaration newResolvedElementDeclaration = |
| 284 |
xsdElementDeclaration.resolveElementDeclaration(namespace, xsdElementDeclaration.getName()); |
| 285 |
EditingDomain editingDomain = getEditingDomain(xsdElementDeclaration); |
| 286 |
if (editingDomain == null) |
| 287 |
{ |
| 288 |
xsdElementDeclaration.setResolvedElementDeclaration(newResolvedElementDeclaration); |
| 289 |
} |
| 290 |
else |
| 291 |
{ |
| 292 |
editingDomain.getCommandStack().execute |
| 293 |
(SetCommand.create |
| 294 |
(editingDomain, |
| 295 |
xsdElementDeclaration, |
| 296 |
xsdPackage.getXSDElementDeclaration_ResolvedElementDeclaration(), |
| 297 |
newResolvedElementDeclaration)); |
| 298 |
} |
| 299 |
} |
| 300 |
else |
| 301 |
{ |
| 302 |
super.setPropertyValue(o, value); |
| 303 |
} |
| 304 |
} |
| 305 |
}); |
| 306 |
} |
| 307 |
|
| 308 |
protected void createElementFormDefaultPropertyDescriptor(Object object) |
| 309 |
{ |
| 310 |
// This is for the elementFormDefault feature. |
| 311 |
// |
| 312 |
itemPropertyDescriptors.add |
| 313 |
(new XSDItemProviderAdapter.ItemPropertyDescriptorWithDefault |
| 314 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 315 |
XSDEditPlugin.INSTANCE.getString("_UI_Form_label"), |
| 316 |
XSDEditPlugin.INSTANCE.getString("_UI_FormOfElement_description"), |
| 317 |
xsdPackage.getXSDFeature_Form(), |
| 318 |
true, |
| 319 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 320 |
{ |
| 321 |
@Override |
| 322 |
public Object getPropertyDefaultValue(Object o) |
| 323 |
{ |
| 324 |
return |
| 325 |
XSDEditPlugin.INSTANCE.getString |
| 326 |
("_UI_DefaultValue_label", new Object [] { ((XSDElementDeclaration)o).getSchema().getElementFormDefault().getName() }); |
| 327 |
} |
| 328 |
}); |
| 329 |
} |
| 330 |
|
| 331 |
@Override |
| 332 |
protected void createLexicalValuePropertyDescriptor(Object object) |
| 333 |
{ |
| 334 |
// This is for the value feature. |
| 335 |
// |
| 336 |
itemPropertyDescriptors.add |
| 337 |
(new DelegatingItemPropertyDescriptor |
| 338 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 339 |
XSDEditPlugin.INSTANCE.getString("_UI_LexicalValue_label"), |
| 340 |
XSDEditPlugin.INSTANCE.getString("_UI_LexicalValueOfElement_description"), |
| 341 |
xsdPackage.getXSDFeature_LexicalValue(), |
| 342 |
true, |
| 343 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE)); |
| 344 |
} |
| 345 |
|
| 346 |
@Override |
| 347 |
protected void createConstraintPropertyDescriptor(Object object) |
| 348 |
{ |
| 349 |
// This is for the constraint feature. |
| 350 |
// |
| 351 |
itemPropertyDescriptors.add |
| 352 |
(new DelegatingItemPropertyDescriptor |
| 353 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 354 |
XSDEditPlugin.INSTANCE.getString("_UI_Constraint_label"), |
| 355 |
XSDEditPlugin.INSTANCE.getString("_UI_ConstraintOfElement_description"), |
| 356 |
xsdPackage.getXSDFeature_Constraint(), |
| 357 |
true, |
| 358 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE)); |
| 359 |
} |
| 360 |
|
| 361 |
@Override |
| 362 |
protected void createScopePropertyDescriptor(Object object) |
| 363 |
{ |
| 364 |
// This is for the scope feature. |
| 365 |
// |
| 366 |
itemPropertyDescriptors.add |
| 367 |
(new DelegatingItemPropertyDescriptor |
| 368 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 369 |
XSDEditPlugin.INSTANCE.getString("_UI_Scope_label"), |
| 370 |
XSDEditPlugin.INSTANCE.getString("_UI_ScopeOfElement_description"), |
| 371 |
xsdPackage.getXSDFeature_Scope(), |
| 372 |
false, |
| 373 |
null)); |
| 374 |
} |
| 375 |
|
| 376 |
protected void createNillablePropertyDescriptor(Object object) |
| 377 |
{ |
| 378 |
// This is for the nillable feature. |
| 379 |
// |
| 380 |
itemPropertyDescriptors.add |
| 381 |
(new DelegatingItemPropertyDescriptor |
| 382 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 383 |
XSDEditPlugin.INSTANCE.getString("_UI_Nillable_label"), |
| 384 |
XSDEditPlugin.INSTANCE.getString("_UI_Nillable_description"), |
| 385 |
xsdPackage.getXSDElementDeclaration_Nillable(), |
| 386 |
true, |
| 387 |
ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE) |
| 388 |
{ |
| 389 |
@Override |
| 390 |
public Object getPropertyDefaultValue(Object o) |
| 391 |
{ |
| 392 |
return XSDEditPlugin.INSTANCE.getString("_UI_DefaultValue_label", new Object [] { "false" }); |
| 393 |
} |
| 394 |
|
| 395 |
@Override |
| 396 |
public Collection<?> getChoiceOfValues(Object o) |
| 397 |
{ |
| 398 |
return |
| 399 |
Arrays.asList |
| 400 |
(new Object [] |
| 401 |
{ Boolean.FALSE, |
| 402 |
Boolean.TRUE, |
| 403 |
XSDEditPlugin.INSTANCE.getString("_UI_DefaultValue_label", new Object [] { "false" }) |
| 404 |
}); |
| 405 |
} |
| 406 |
}); |
| 407 |
} |
| 408 |
|
| 409 |
protected void createDisallowedSubstitutionsPropertyDescriptor(Object object) |
| 410 |
{ |
| 411 |
// This is for the disallowedSubstitutions feature. |
| 412 |
// |
| 413 |
itemPropertyDescriptors.add |
| 414 |
(new ItemPropertyDescriptor |
| 415 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 416 |
XSDEditPlugin.INSTANCE.getString("_UI_DisallowedSubstitutions_label"), |
| 417 |
XSDEditPlugin.INSTANCE.getString("_UI_DisallowedSubstitutions_description"), |
| 418 |
xsdPackage.getXSDElementDeclaration_DisallowedSubstitutions(), |
| 419 |
false, |
| 420 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 421 |
{ |
| 422 |
@Override |
| 423 |
public Object getPropertyValue(Object o) |
| 424 |
{ |
| 425 |
return ((XSDElementDeclaration)o).getStringDisallowedSubstitutions(); |
| 426 |
} |
| 427 |
}); |
| 428 |
} |
| 429 |
|
| 430 |
protected void createSubstitutionGroupExclusionsPropertyDescriptor(Object object) |
| 431 |
{ |
| 432 |
// This is for the substitutionGroupExclusions feature. |
| 433 |
// |
| 434 |
itemPropertyDescriptors.add |
| 435 |
(new DelegatingItemPropertyDescriptor |
| 436 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 437 |
XSDEditPlugin.INSTANCE.getString("_UI_SubstitutionGroupExclusions_label"), |
| 438 |
XSDEditPlugin.INSTANCE.getString("_UI_SubstitutionGroupExclusions_description"), |
| 439 |
xsdPackage.getXSDElementDeclaration_SubstitutionGroupExclusions(), |
| 440 |
false, |
| 441 |
ItemPropertyDescriptor.TEXT_VALUE_IMAGE) |
| 442 |
{ |
| 443 |
@Override |
| 444 |
public Object getPropertyValue(Object o) |
| 445 |
{ |
| 446 |
return ((XSDElementDeclaration)o).getStringSubstitutionGroupExclusions(); |
| 447 |
} |
| 448 |
}); |
| 449 |
} |
| 450 |
|
| 451 |
protected void createAbstractPropertyDescriptor(Object object) |
| 452 |
{ |
| 453 |
// This is for the abstract feature. |
| 454 |
// |
| 455 |
itemPropertyDescriptors.add |
| 456 |
(new DelegatingItemPropertyDescriptor |
| 457 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 458 |
XSDEditPlugin.INSTANCE.getString("_UI_Abstract_label"), |
| 459 |
XSDEditPlugin.INSTANCE.getString("_UI_AbstractOfElement_description"), |
| 460 |
xsdPackage.getXSDElementDeclaration_Abstract(), |
| 461 |
true, |
| 462 |
ItemPropertyDescriptor.BOOLEAN_VALUE_IMAGE) |
| 463 |
{ |
| 464 |
@Override |
| 465 |
public Object getPropertyDefaultValue(Object o) |
| 466 |
{ |
| 467 |
return XSDEditPlugin.INSTANCE.getString("_UI_DefaultValue_label", new Object [] { "false" }); |
| 468 |
} |
| 469 |
|
| 470 |
@Override |
| 471 |
public Collection<?> getChoiceOfValues(Object o) |
| 472 |
{ |
| 473 |
return |
| 474 |
Arrays.asList |
| 475 |
(new Object [] |
| 476 |
{ Boolean.FALSE, |
| 477 |
Boolean.TRUE, |
| 478 |
XSDEditPlugin.INSTANCE.getString("_UI_DefaultValue_label", new Object [] { "false" }) |
| 479 |
}); |
| 480 |
} |
| 481 |
}); |
| 482 |
} |
| 483 |
|
| 484 |
protected void createTypeDefinitionPropertyDescriptor(Object object) |
| 485 |
{ |
| 486 |
// This is for the typeDefinition feature. |
| 487 |
// |
| 488 |
itemPropertyDescriptors.add |
| 489 |
(new DelegatingItemPropertyDescriptor |
| 490 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 491 |
XSDEditPlugin.INSTANCE.getString("_UI_TypeDefinition_label"), |
| 492 |
XSDEditPlugin.INSTANCE.getString("_UI_TypeDefinitionOfElement_description"), |
| 493 |
xsdPackage.getXSDElementDeclaration_TypeDefinition(), |
| 494 |
false, |
| 495 |
null)); |
| 496 |
} |
| 497 |
|
| 498 |
protected void createSubstitutionGroupAffiliationPropertyDescriptor(Object object) |
| 499 |
{ |
| 500 |
// This is for the substitutionGroupAffiliation feature. |
| 501 |
// |
| 502 |
itemPropertyDescriptors.add |
| 503 |
(new DelegatingItemPropertyDescriptor |
| 504 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 505 |
XSDEditPlugin.INSTANCE.getString("_UI_SubstitutionGroupAffiliation_label"), |
| 506 |
XSDEditPlugin.INSTANCE.getString("_UI_SubstitutionGroupAffiliation_description"), |
| 507 |
xsdPackage.getXSDElementDeclaration_SubstitutionGroupAffiliation(), |
| 508 |
false, |
| 509 |
null)); |
| 510 |
} |
| 511 |
|
| 512 |
protected void createAnnotationPropertyDescriptor(Object object) |
| 513 |
{ |
| 514 |
// This is for the annotation feature. |
| 515 |
// |
| 516 |
itemPropertyDescriptors.add |
| 517 |
(new ItemPropertyDescriptor |
| 518 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 519 |
XSDEditPlugin.INSTANCE.getString("_UI_Annotation_label"), |
| 520 |
XSDEditPlugin.INSTANCE.getString("_UI_AnnotationOfElement_description"), |
| 521 |
xsdPackage.getXSDElementDeclaration_Annotation(), |
| 522 |
false)); |
| 523 |
} |
| 524 |
|
| 525 |
protected void createResolvedElementDeclarationPropertyDescriptor(Object object) |
| 526 |
{ |
| 527 |
// This is for the resolvedElementDeclaration feature. |
| 528 |
// |
| 529 |
itemPropertyDescriptors.add |
| 530 |
(new ItemPropertyDescriptor |
| 531 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 532 |
XSDEditPlugin.INSTANCE.getString("_UI_ResolveElementDeclaration_label"), |
| 533 |
XSDEditPlugin.INSTANCE.getString("_UI_ResolveElementDeclaration_description"), |
| 534 |
xsdPackage.getXSDElementDeclaration_ResolvedElementDeclaration(), |
| 535 |
false)); |
| 536 |
} |
| 537 |
|
| 538 |
/** |
| 539 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 540 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 541 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 542 |
*/ |
| 543 |
@Override |
| 544 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 545 |
{ |
| 546 |
if (childrenFeatures == null) |
| 547 |
{ |
| 548 |
super.getChildrenFeatures(object); |
| 549 |
childrenFeatures.add(xsdPackage.getXSDElementDeclaration_Annotation()); |
| 550 |
childrenFeatures.add(xsdPackage.getXSDElementDeclaration_AnonymousTypeDefinition()); |
| 551 |
childrenFeatures.add(xsdPackage.getXSDElementDeclaration_IdentityConstraintDefinitions()); |
| 552 |
} |
| 553 |
return childrenFeatures; |
| 554 |
} |
| 555 |
|
| 556 |
/** |
| 557 |
* This returns XSDElementDeclaration.gif. |
| 558 |
*/ |
| 559 |
@Override |
| 560 |
public Object getImage(Object object) |
| 561 |
{ |
| 562 |
XSDElementDeclaration xsdElementDeclaration = ((XSDElementDeclaration)object); |
| 563 |
XSDElementDeclaration resolvedElementDeclaration = xsdElementDeclaration.getResolvedElementDeclaration(); |
| 564 |
return |
| 565 |
XSDEditPlugin.INSTANCE.getImage |
| 566 |
(resolvedElementDeclaration.getContainer() == null ? |
| 567 |
"full/obj16/XSDElementUnresolved" : |
| 568 |
xsdElementDeclaration.getResolvedElementDeclaration() == xsdElementDeclaration ? |
| 569 |
"full/obj16/XSDElementDeclaration" : |
| 570 |
"full/obj16/XSDElementUse"); |
| 571 |
} |
| 572 |
|
| 573 |
@Override |
| 574 |
public String getText(Object object) |
| 575 |
{ |
| 576 |
XSDElementDeclaration xsdElementDeclaration = ((XSDElementDeclaration)object); |
| 577 |
XSDElementDeclaration resolvedElementDeclaration = xsdElementDeclaration.getResolvedElementDeclaration(); |
| 578 |
String name = |
| 579 |
xsdElementDeclaration != resolvedElementDeclaration ? |
| 580 |
xsdElementDeclaration.getQName() : |
| 581 |
xsdElementDeclaration.getName(); |
| 582 |
|
| 583 |
StringBuffer result = new StringBuffer(); |
| 584 |
if (name == null) |
| 585 |
{ |
| 586 |
result.append(XSDEditPlugin.INSTANCE.getString("_UI_Absent_label")); |
| 587 |
} |
| 588 |
else |
| 589 |
{ |
| 590 |
result.append(name); |
| 591 |
} |
| 592 |
|
| 593 |
if (resolvedElementDeclaration.getAnonymousTypeDefinition() == null && resolvedElementDeclaration.getTypeDefinition() != null) |
| 594 |
{ |
| 595 |
result.append(" : "); |
| 596 |
result.append(resolvedElementDeclaration.getTypeDefinition().getQName(xsdElementDeclaration)); |
| 597 |
} |
| 598 |
|
| 599 |
return result.toString(); |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 604 |
*/ |
| 605 |
@Override |
| 606 |
public void notifyChanged(Notification msg) |
| 607 |
{ |
| 608 |
XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)msg.getNotifier(); |
| 609 |
if ( |
| 610 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_Nillable() || |
| 611 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_DisallowedSubstitutions() || |
| 612 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_SubstitutionGroupAffiliation() || |
| 613 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_SubstitutionGroupExclusions() || |
| 614 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_Abstract() || |
| 615 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_IdentityConstraintDefinitions() || |
| 616 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_TypeDefinition() || |
| 617 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_AnonymousTypeDefinition() || |
| 618 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_SubstitutionGroupAffiliation() || |
| 619 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_ResolvedElementDeclaration() || |
| 620 |
msg.getFeature() == xsdPackage.getXSDElementDeclaration_Annotation() |
| 621 |
) |
| 622 |
{ |
| 623 |
fireNotifyChanged(msg); |
| 624 |
XSDConcreteComponent container = xsdElementDeclaration.getContainer(); |
| 625 |
if (container instanceof XSDParticle) |
| 626 |
{ |
| 627 |
((ItemProviderAdapter)adapterFactory.adapt(container, IItemLabelProvider.class)).fireNotifyChanged |
| 628 |
(new ENotificationImpl |
| 629 |
((InternalEObject)container, |
| 630 |
msg.getEventType(), |
| 631 |
(EStructuralFeature)msg.getFeature(), |
| 632 |
msg.getOldValue(), |
| 633 |
msg.getNewValue(), |
| 634 |
msg.getPosition())); |
| 635 |
} |
| 636 |
return; |
| 637 |
} |
| 638 |
super.notifyChanged(msg); |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 643 |
* that can be created under this object. |
| 644 |
*/ |
| 645 |
@Override |
| 646 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 647 |
{ |
| 648 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 649 |
XSDElementDeclaration ed = (XSDElementDeclaration) object; |
| 650 |
|
| 651 |
if (!ed.isElementDeclarationReference()) |
| 652 |
{ |
| 653 |
// annotation |
| 654 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDElementDeclaration_Annotation(), xsdFactory.createXSDAnnotation())); |
| 655 |
|
| 656 |
// atomic, list, and union simple type definitions |
| 657 |
addSimpleTypeDefinitionChildParameters(newChildDescriptors, ed, xsdPackage.getXSDElementDeclaration_AnonymousTypeDefinition(), true, true, true); |
| 658 |
|
| 659 |
// complex type definition |
| 660 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDElementDeclaration_AnonymousTypeDefinition(), createComplexTypeDefinition(ed))); |
| 661 |
|
| 662 |
// unique identity constraint definition |
| 663 |
XSDIdentityConstraintDefinition icd = |
| 664 |
createIdentityConstraintDefinition(ed); |
| 665 |
icd.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL); |
| 666 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDElementDeclaration_IdentityConstraintDefinitions(), icd)); |
| 667 |
|
| 668 |
// key identity constraint definition |
| 669 |
icd = createIdentityConstraintDefinition(ed); |
| 670 |
icd.setIdentityConstraintCategory(XSDIdentityConstraintCategory.KEY_LITERAL); |
| 671 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDElementDeclaration_IdentityConstraintDefinitions(), icd)); |
| 672 |
|
| 673 |
// keyref identity constraint definition |
| 674 |
XSDIdentityConstraintDefinition icdRef = xsdFactory.createXSDIdentityConstraintDefinition(); |
| 675 |
icdRef.setIdentityConstraintCategory(XSDIdentityConstraintCategory.KEYREF_LITERAL); |
| 676 |
icdRef.setName(icd.getName()); |
| 677 |
if (icd.getTargetNamespace() != null) |
| 678 |
{ |
| 679 |
icdRef.setTargetNamespace(icd.getTargetNamespace()); |
| 680 |
} |
| 681 |
icd = ed.resolveIdentityConstraintDefinition(""); |
| 682 |
icdRef.setReferencedKey(icd); |
| 683 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDElementDeclaration_IdentityConstraintDefinitions(), icdRef)); |
| 684 |
} |
| 685 |
} |
| 686 |
} |