| 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.emf.edit.ui.provider; |
| 12 |
|
| 13 |
|
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.List; |
| 17 |
|
| 18 |
import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| 19 |
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 20 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 21 |
import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage; |
| 22 |
|
| 23 |
|
| 24 |
/** |
| 25 |
* This is used to encapsulate an {@link IItemPropertySource} along with the object for which it is an item property source |
| 26 |
* and make it behave like an {@link org.eclipse.ui.views.properties.IPropertySource}. |
| 27 |
*/ |
| 28 |
public class PropertySource implements ExtendedPropertySheetPage.IUnsettablePropertySource |
| 29 |
{ |
| 30 |
/** |
| 31 |
* This is the object for which this class is a property source. |
| 32 |
*/ |
| 33 |
protected Object object; |
| 34 |
|
| 35 |
/** |
| 36 |
* This is the descriptor to which we will delegate all the {@link org.eclipse.ui.views.properties.IPropertySource} methods. |
| 37 |
*/ |
| 38 |
protected IItemPropertySource itemPropertySource; |
| 39 |
|
| 40 |
/** |
| 41 |
* An instance is constructed from an object and its item property source. |
| 42 |
*/ |
| 43 |
public PropertySource(Object object, IItemPropertySource itemPropertySource) |
| 44 |
{ |
| 45 |
this.object = object; |
| 46 |
this.itemPropertySource = itemPropertySource; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the object for which this is a property source. |
| 51 |
* |
| 52 |
* @since 2.14 |
| 53 |
*/ |
| 54 |
public Object getObject() |
| 55 |
{ |
| 56 |
return object; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Returns the underlying item property source of this property source. |
| 61 |
* |
| 62 |
* @since 2.14 |
| 63 |
*/ |
| 64 |
public IItemPropertySource getItemPropertySource() |
| 65 |
{ |
| 66 |
return itemPropertySource; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* This delegates to {@link IItemPropertySource#getEditableValue IItemPropertySource.getEditableValue}. |
| 71 |
*/ |
| 72 |
public Object getEditableValue() |
| 73 |
{ |
| 74 |
return itemPropertySource.getEditableValue(object); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* This delegates to {@link IItemPropertySource#getPropertyDescriptors IItemPropertySource.getPropertyDescriptors}. |
| 79 |
*/ |
| 80 |
public IPropertyDescriptor [] getPropertyDescriptors() |
| 81 |
{ |
| 82 |
Collection<IPropertyDescriptor> result = new ArrayList<IPropertyDescriptor>(); |
| 83 |
List<IItemPropertyDescriptor> itemPropertyDescriptors = itemPropertySource.getPropertyDescriptors(object); |
| 84 |
if (itemPropertyDescriptors != null) |
| 85 |
{ |
| 86 |
for (IItemPropertyDescriptor itemPropertyDescriptor : itemPropertyDescriptors) |
| 87 |
{ |
| 88 |
result.add(createPropertyDescriptor(itemPropertyDescriptor)); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
return result.toArray(new IPropertyDescriptor [result.size()]); |
| 93 |
} |
| 94 |
|
| 95 |
protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor) |
| 96 |
{ |
| 97 |
return new PropertyDescriptor(object, itemPropertyDescriptor); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* @since 2.14 |
| 102 |
*/ |
| 103 |
protected IItemPropertyDescriptor getItemPropertyDescriptor(Object propertyId) |
| 104 |
{ |
| 105 |
return itemPropertySource.getPropertyDescriptor(object, propertyId); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* This delegates to {@link IItemPropertyDescriptor#getPropertyValue IItemPropertyDescriptor.getPropertyValue}. |
| 110 |
*/ |
| 111 |
public Object getPropertyValue(Object propertyId) |
| 112 |
{ |
| 113 |
return getItemPropertyDescriptor(propertyId).getPropertyValue(object); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* This delegates to {@link IItemPropertyDescriptor#isPropertySet IItemPropertyDescriptor.isPropertySet}. |
| 118 |
*/ |
| 119 |
public boolean isPropertySet(Object propertyId) |
| 120 |
{ |
| 121 |
return getItemPropertyDescriptor(propertyId).isPropertySet(object); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* This returns <code>true</code> only when {@link IItemPropertyDescriptor#isPropertySet IItemPropertyDescriptor.isPropertySet} |
| 126 |
* and {@link IItemPropertyDescriptor#canSetProperty IItemPropertyDescriptor.canSetProperty} are <code>true</code>. |
| 127 |
* @since 2.10 |
| 128 |
*/ |
| 129 |
public boolean isPropertyResettable(Object propertyId) |
| 130 |
{ |
| 131 |
IItemPropertyDescriptor propertyDescriptor = getItemPropertyDescriptor(propertyId); |
| 132 |
return propertyDescriptor.canSetProperty(object) && propertyDescriptor.isPropertySet(object); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* This delegates to {@link IItemPropertyDescriptor#resetPropertyValue IItemPropertyDescriptor.resetPropertyValue}. |
| 137 |
*/ |
| 138 |
public void resetPropertyValue(Object propertyId) |
| 139 |
{ |
| 140 |
getItemPropertyDescriptor(propertyId).resetPropertyValue(object); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* This delegates to {@link IItemPropertyDescriptor#setPropertyValue IItemPropertyDescriptor.setPropertyValue}. |
| 145 |
*/ |
| 146 |
public void setPropertyValue(Object propertyId, Object value) |
| 147 |
{ |
| 148 |
getItemPropertyDescriptor(propertyId).setPropertyValue(object, value); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* This returns <code>true</code> only when {@link IItemPropertyDescriptor.ValueHandlerProvider#isPropertyUnsettable IItemPropertyDescriptor.ValueHandlerProvider.isPropertyUnsettable} |
| 153 |
* and {@link IItemPropertyDescriptor#canSetProperty IItemPropertyDescriptor.canSetProperty} are <code>true</code>. |
| 154 |
* @since 2.14 |
| 155 |
*/ |
| 156 |
public boolean isPropertyUnsettable(Object propertyId) |
| 157 |
{ |
| 158 |
IItemPropertyDescriptor propertyDescriptor = getItemPropertyDescriptor(propertyId); |
| 159 |
return |
| 160 |
propertyDescriptor.canSetProperty(object) && |
| 161 |
propertyDescriptor instanceof IItemPropertyDescriptor.ValueHandlerProvider && |
| 162 |
((IItemPropertyDescriptor.ValueHandlerProvider)propertyDescriptor).isPropertyUnsettable(object); |
| 163 |
} |
| 164 |
} |