| 1 |
/** |
| 2 |
* Copyright (c) 2002-2010 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.emf.edit.provider.resource; |
| 12 |
|
| 13 |
|
| 14 |
import java.util.Collection; |
| 15 |
import java.util.Collections; |
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.eclipse.emf.common.notify.AdapterFactory; |
| 19 |
import org.eclipse.emf.common.notify.Notification; |
| 20 |
import org.eclipse.emf.common.util.ResourceLocator; |
| 21 |
import org.eclipse.emf.ecore.EStructuralFeature; |
| 22 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
| 23 |
import org.eclipse.emf.edit.EMFEditPlugin; |
| 24 |
import org.eclipse.emf.edit.domain.EditingDomain; |
| 25 |
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 26 |
import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 27 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 28 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 29 |
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 30 |
import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 31 |
import org.eclipse.emf.edit.provider.ItemProviderAdapter; |
| 32 |
import org.eclipse.emf.edit.provider.ViewerNotification; |
| 33 |
|
| 34 |
|
| 35 |
/** |
| 36 |
* This is the item provider adapter for a {@link org.eclipse.emf.ecore.resource.ResourceSet} object. |
| 37 |
*/ |
| 38 |
public class ResourceSetItemProvider |
| 39 |
extends ItemProviderAdapter |
| 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 ResourceSetItemProvider(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 |
itemPropertyDescriptors.add |
| 65 |
(new IItemPropertyDescriptor() |
| 66 |
{ |
| 67 |
public void setPropertyValue(Object object, Object value) |
| 68 |
{ |
| 69 |
throw new UnsupportedOperationException(); |
| 70 |
} |
| 71 |
|
| 72 |
public void resetPropertyValue(Object object) |
| 73 |
{ |
| 74 |
throw new UnsupportedOperationException(); |
| 75 |
} |
| 76 |
|
| 77 |
public boolean isSortChoices(Object object) |
| 78 |
{ |
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
public boolean isPropertySet(Object object) |
| 83 |
{ |
| 84 |
return !((ResourceSet)object).getResources().isEmpty(); |
| 85 |
} |
| 86 |
|
| 87 |
public boolean isMultiLine(Object object) |
| 88 |
{ |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
public boolean isMany(Object object) |
| 93 |
{ |
| 94 |
return false; |
| 95 |
} |
| 96 |
|
| 97 |
public boolean isCompatibleWith(Object object, Object anotherObject, IItemPropertyDescriptor anotherPropertyDescriptor) |
| 98 |
{ |
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
public Object getPropertyValue(Object object) |
| 103 |
{ |
| 104 |
return ((ResourceSet)object).getResources().size(); |
| 105 |
} |
| 106 |
|
| 107 |
public IItemLabelProvider getLabelProvider(Object object) |
| 108 |
{ |
| 109 |
return |
| 110 |
new IItemLabelProvider() |
| 111 |
{ |
| 112 |
public String getText(Object object) |
| 113 |
{ |
| 114 |
return object.toString(); |
| 115 |
} |
| 116 |
|
| 117 |
public Object getImage(Object object) |
| 118 |
{ |
| 119 |
return null; |
| 120 |
} |
| 121 |
}; |
| 122 |
} |
| 123 |
|
| 124 |
public String getId(Object object) |
| 125 |
{ |
| 126 |
return "resourceCount"; |
| 127 |
} |
| 128 |
|
| 129 |
public Object getHelpContextIds(Object object) |
| 130 |
{ |
| 131 |
return null; |
| 132 |
} |
| 133 |
|
| 134 |
public String[] getFilterFlags(Object object) |
| 135 |
{ |
| 136 |
return null; |
| 137 |
} |
| 138 |
|
| 139 |
public Object getFeature(Object object) |
| 140 |
{ |
| 141 |
return ResourceSet.RESOURCE_SET__RESOURCES; |
| 142 |
} |
| 143 |
|
| 144 |
public String getDisplayName(Object object) |
| 145 |
{ |
| 146 |
// TODO |
| 147 |
return "Size"; |
| 148 |
} |
| 149 |
|
| 150 |
public String getDescription(Object object) |
| 151 |
{ |
| 152 |
// TODO |
| 153 |
return "The number of resources"; |
| 154 |
} |
| 155 |
|
| 156 |
public Collection<?> getChoiceOfValues(Object object) |
| 157 |
{ |
| 158 |
return null; |
| 159 |
} |
| 160 |
|
| 161 |
public String getCategory(Object object) |
| 162 |
{ |
| 163 |
return null; |
| 164 |
} |
| 165 |
|
| 166 |
public boolean canSetProperty(Object object) |
| 167 |
{ |
| 168 |
return false; |
| 169 |
} |
| 170 |
}); |
| 171 |
} |
| 172 |
return itemPropertyDescriptors; |
| 173 |
} |
| 174 |
|
| 175 |
@Override |
| 176 |
public Collection<?> getChildren(Object object) |
| 177 |
{ |
| 178 |
ResourceSet resourceSet = (ResourceSet)object; |
| 179 |
return resourceSet.getResources(); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 184 |
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 185 |
* {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand(Object, EditingDomain, Class, org.eclipse.emf.edit.command.CommandParameter) createCommand}. |
| 186 |
*/ |
| 187 |
@Override |
| 188 |
public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) |
| 189 |
{ |
| 190 |
if (childrenFeatures == null) |
| 191 |
{ |
| 192 |
super.getChildrenFeatures(object); |
| 193 |
/* |
| 194 |
ResourceSet resourceSet = (ResourceSet)object; |
| 195 |
childrenFeatures.add(ResourcePackage.eINSTANCE.getResourceSet_Resources()); |
| 196 |
*/ |
| 197 |
} |
| 198 |
return childrenFeatures; |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* This returns the parent of the ResourceSet. |
| 203 |
*/ |
| 204 |
@Override |
| 205 |
public Object getParent(Object object) |
| 206 |
{ |
| 207 |
return null; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* This returns ResourceSet.gif. |
| 212 |
*/ |
| 213 |
@Override |
| 214 |
public Object getImage(Object object) |
| 215 |
{ |
| 216 |
return getResourceLocator().getImage("full/obj16/ResourceSet"); |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* This returns the label text for the adapted class. |
| 221 |
*/ |
| 222 |
@Override |
| 223 |
public String getText(Object object) |
| 224 |
{ |
| 225 |
return EMFEditPlugin.INSTANCE.getString("_UI_ResourceSet_label"); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* This handles notification by calling {@link #fireNotifyChanged(Notification) fireNotifyChanged}. |
| 230 |
*/ |
| 231 |
@Override |
| 232 |
public void notifyChanged(Notification notification) |
| 233 |
{ |
| 234 |
switch (notification.getFeatureID(ResourceSet.class)) |
| 235 |
{ |
| 236 |
case ResourceSet.RESOURCE_SET__RESOURCES: |
| 237 |
{ |
| 238 |
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); |
| 239 |
return; |
| 240 |
} |
| 241 |
} |
| 242 |
super.notifyChanged(notification); |
| 243 |
} |
| 244 |
|
| 245 |
@Override |
| 246 |
public Collection<?> getNewChildDescriptors(Object object, EditingDomain editingDomain, Object sibling) |
| 247 |
{ |
| 248 |
return Collections.emptyList(); |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 253 |
* that can be created under this object. |
| 254 |
*/ |
| 255 |
@Override |
| 256 |
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) |
| 257 |
{ |
| 258 |
super.collectNewChildDescriptors(newChildDescriptors, object); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Return the resource locator for this item provider's resources. |
| 263 |
*/ |
| 264 |
@Override |
| 265 |
public ResourceLocator getResourceLocator() |
| 266 |
{ |
| 267 |
return EMFEditPlugin.INSTANCE; |
| 268 |
} |
| 269 |
} |