| 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.XSDInclude; |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDInclude} object. |
| 34 |
*/ |
| 35 |
public class XSDIncludeItemProvider |
| 36 |
extends XSDSchemaCompositorItemProvider |
| 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 XSDIncludeItemProvider(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_AnnotationOfInclude_description"), |
| 69 |
xsdPackage.getXSDInclude_Annotation(), |
| 70 |
false)); |
| 71 |
|
| 72 |
} |
| 73 |
return itemPropertyDescriptors; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 78 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 79 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 80 |
*/ |
| 81 |
@Override |
| 82 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 83 |
{ |
| 84 |
if (childrenFeatures == null) |
| 85 |
{ |
| 86 |
super.getChildrenFeatures(object); |
| 87 |
childrenFeatures.add(xsdPackage.getXSDInclude_Annotation()); |
| 88 |
} |
| 89 |
return childrenFeatures; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* This returns XSDInclude.gif. |
| 94 |
*/ |
| 95 |
@Override |
| 96 |
public Object getImage(Object object) |
| 97 |
{ |
| 98 |
return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDInclude"); |
| 99 |
} |
| 100 |
|
| 101 |
@Override |
| 102 |
public String getText(Object object) |
| 103 |
{ |
| 104 |
XSDInclude xsdInclude = ((XSDInclude)object); |
| 105 |
String result = xsdInclude.getSchemaLocation(); |
| 106 |
return result == null ? "" : result; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 111 |
*/ |
| 112 |
@Override |
| 113 |
public void notifyChanged(Notification msg) |
| 114 |
{ |
| 115 |
if ( |
| 116 |
msg.getFeature() == xsdPackage.getXSDInclude_Annotation() |
| 117 |
) |
| 118 |
{ |
| 119 |
fireNotifyChanged(msg); |
| 120 |
return; |
| 121 |
} |
| 122 |
super.notifyChanged(msg); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 127 |
* that can be created under this object. |
| 128 |
*/ |
| 129 |
@Override |
| 130 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 131 |
{ |
| 132 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 133 |
|
| 134 |
// annotation |
| 135 |
newChildDescriptors.add(createChildParameter(xsdPackage.getXSDInclude_Annotation(), xsdFactory.createXSDAnnotation())); |
| 136 |
} |
| 137 |
} |