| 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.List; |
| 15 |
|
| 16 |
import org.w3c.dom.Element; |
| 17 |
|
| 18 |
import org.eclipse.emf.common.notify.AdapterFactory; |
| 19 |
import org.eclipse.emf.common.notify.Notification; |
| 20 |
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 21 |
import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 22 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 23 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 24 |
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 25 |
import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 26 |
|
| 27 |
import org.eclipse.xsd.XSDAnnotation; |
| 28 |
import org.eclipse.xsd.util.XSDConstants; |
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* This is the item provider adpater for a {@link org.eclipse.xsd.XSDAnnotation} object. |
| 33 |
*/ |
| 34 |
public class XSDAnnotationItemProvider |
| 35 |
extends XSDComponentItemProvider |
| 36 |
implements |
| 37 |
IEditingDomainItemProvider, |
| 38 |
IStructuredItemContentProvider, |
| 39 |
ITreeItemContentProvider, |
| 40 |
IItemLabelProvider, |
| 41 |
IItemPropertySource |
| 42 |
{ |
| 43 |
/** |
| 44 |
* This constructs an instance from a factory and a notifier. |
| 45 |
*/ |
| 46 |
public XSDAnnotationItemProvider(AdapterFactory adapterFactory) |
| 47 |
{ |
| 48 |
super(adapterFactory); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* This returns the property descriptors for the adapted class. |
| 53 |
*/ |
| 54 |
@Override |
| 55 |
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) |
| 56 |
{ |
| 57 |
if (itemPropertyDescriptors == null) |
| 58 |
{ |
| 59 |
super.getPropertyDescriptors(object); |
| 60 |
} |
| 61 |
return itemPropertyDescriptors; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* This returns XSDAnnotation.gif. |
| 66 |
*/ |
| 67 |
@Override |
| 68 |
public Object getImage(Object object) |
| 69 |
{ |
| 70 |
return XSDEditPlugin.INSTANCE.getImage("full/obj16/XSDAnnotation"); |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public String getText(Object object) |
| 75 |
{ |
| 76 |
XSDAnnotation xsdAnnotation = ((XSDAnnotation)object); |
| 77 |
String result = ""; |
| 78 |
List<Element> userInformation = xsdAnnotation.getUserInformation(); |
| 79 |
if (!userInformation.isEmpty()) |
| 80 |
{ |
| 81 |
Element element = userInformation.get(0); |
| 82 |
if (element.hasAttribute(XSDConstants.SOURCE_ATTRIBUTE)) |
| 83 |
{ |
| 84 |
result = element.getAttribute(XSDConstants.SOURCE_ATTRIBUTE); |
| 85 |
} |
| 86 |
else |
| 87 |
{ |
| 88 |
org.w3c.dom.Node text = element.getFirstChild(); |
| 89 |
while (text instanceof Element) |
| 90 |
{ |
| 91 |
text = ((Element)text).getFirstChild(); |
| 92 |
} |
| 93 |
if (text != null && text.getNodeValue() != null) |
| 94 |
{ |
| 95 |
result = text.getNodeValue(); |
| 96 |
result = result.trim(); |
| 97 |
if (result.length() > 50) |
| 98 |
{ |
| 99 |
result = result.substring(0, 50) + XSDEditPlugin.INSTANCE.getString("_UI_DotDotDot_label"); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return result; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}. |
| 110 |
*/ |
| 111 |
@Override |
| 112 |
public void notifyChanged(Notification msg) |
| 113 |
{ |
| 114 |
super.notifyChanged(msg); |
| 115 |
} |
| 116 |
|
| 117 |
} |