| 1 |
/** |
| 2 |
* Copyright (c) 2002-2006 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.Collection; |
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.eclipse.emf.common.command.Command; |
| 19 |
import org.eclipse.emf.common.notify.AdapterFactory; |
| 20 |
import org.eclipse.emf.common.notify.Notification; |
| 21 |
import org.eclipse.emf.ecore.EAttribute; |
| 22 |
import org.eclipse.emf.ecore.EObject; |
| 23 |
import org.eclipse.emf.edit.command.CopyCommand; |
| 24 |
import org.eclipse.emf.edit.command.InitializeCopyCommand; |
| 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 |
|
| 35 |
import org.eclipse.xsd.XSDConcreteComponent; |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDConcreteComponent} object. |
| 40 |
*/ |
| 41 |
public class XSDConcreteComponentItemProvider |
| 42 |
extends XSDItemProviderAdapter |
| 43 |
implements |
| 44 |
IEditingDomainItemProvider, |
| 45 |
IStructuredItemContentProvider, |
| 46 |
ITreeItemContentProvider, |
| 47 |
IItemLabelProvider, |
| 48 |
IItemPropertySource |
| 49 |
{ |
| 50 |
/** |
| 51 |
* This constructs an instance from a factory and a notifier. |
| 52 |
*/ |
| 53 |
public XSDConcreteComponentItemProvider(AdapterFactory adapterFactory) |
| 54 |
{ |
| 55 |
super(adapterFactory); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* This returns the property descriptors for the adapted class. |
| 60 |
*/ |
| 61 |
@Override |
| 62 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 63 |
{ |
| 64 |
if (itemPropertyDescriptors == null) |
| 65 |
{ |
| 66 |
super.getPropertyDescriptors(object); |
| 67 |
|
| 68 |
createElementPropertyDescriptor(object); |
| 69 |
} |
| 70 |
return itemPropertyDescriptors; |
| 71 |
} |
| 72 |
|
| 73 |
protected void createElementPropertyDescriptor(Object object) |
| 74 |
{ |
| 75 |
// This is for the element feature. |
| 76 |
// |
| 77 |
itemPropertyDescriptors.add |
| 78 |
(new ItemPropertyDescriptor |
| 79 |
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 80 |
XSDEditPlugin.INSTANCE.getString("_UI_Element_label"), |
| 81 |
XSDEditPlugin.INSTANCE.getString("_UI_Element_description"), |
| 82 |
xsdPackage.getXSDConcreteComponent_Element(), |
| 83 |
false, |
| 84 |
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE) |
| 85 |
{ |
| 86 |
@Override |
| 87 |
public Object getPropertyValue(Object o) |
| 88 |
{ |
| 89 |
XSDConcreteComponent concreteComponent = ((XSDConcreteComponent)o); |
| 90 |
if (concreteComponent.getElement() == null) |
| 91 |
{ |
| 92 |
return ""; |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
return concreteComponent.getElement().getTagName(); |
| 97 |
} |
| 98 |
} |
| 99 |
}); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* We don't want to copy any references other than containment references. |
| 104 |
*/ |
| 105 |
@Override |
| 106 |
protected Command createInitializeCopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper helper) |
| 107 |
{ |
| 108 |
return |
| 109 |
new InitializeCopyCommand(domain, owner, helper) |
| 110 |
{ |
| 111 |
@Override |
| 112 |
protected Collection<? extends EAttribute> getAttributesToCopy() |
| 113 |
{ |
| 114 |
Collection<EAttribute> result = new ArrayList<EAttribute>(this.owner.eClass().getEAllAttributes()); |
| 115 |
result.remove(xsdPackage.getXSDConcreteComponent_Element()); |
| 116 |
return result; |
| 117 |
} |
| 118 |
}; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 123 |
*/ |
| 124 |
@Override |
| 125 |
public void notifyChanged(Notification msg) |
| 126 |
{ |
| 127 |
if (msg.getFeature() == xsdPackage.getXSDConcreteComponent_Element()) |
| 128 |
{ |
| 129 |
fireNotifyChanged(msg); |
| 130 |
return; |
| 131 |
} |
| 132 |
super.notifyChanged(msg); |
| 133 |
} |
| 134 |
} |