diff options
author | Eike Stepper | 2015-02-09 08:59:43 +0000 |
---|---|---|
committer | Eike Stepper | 2015-02-18 14:40:52 +0000 |
commit | be4a714a1d9b2bdad7d45eaf4fb1714130e0f748 (patch) | |
tree | d20ee6a33c831449790b5a1f7e996d32034968da /plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j | |
parent | 8f64246fab05a52e74011c1d4d1aa6cc58189ee2 (diff) | |
download | cdo-be4a714a1d9b2bdad7d45eaf4fb1714130e0f748.tar.gz cdo-be4a714a1d9b2bdad7d45eaf4fb1714130e0f748.tar.xz cdo-be4a714a1d9b2bdad7d45eaf4fb1714130e0f748.zip |
[458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
Diffstat (limited to 'plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j')
-rw-r--r-- | plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java index 58e0d32e80..48ea677926 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java @@ -22,7 +22,9 @@ import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertyDescriptor; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author Eike Stepper @@ -50,13 +52,21 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource return receiver; } + /** + * @since 3.5 + */ + public void addDescriptor(IPropertyDescriptor descriptor) + { + descriptors.add(descriptor); + } + public PropertyDescriptor addDescriptor(String category, Object id, String displayName, String description) { PropertyDescriptor descriptor = new PropertyDescriptor(id, displayName); descriptor.setCategory(category); descriptor.setDescription(description); - descriptors.add(descriptor); + addDescriptor(descriptor); return descriptor; } @@ -78,10 +88,8 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource public IPropertyDescriptor getPropertyDescriptor(Object id) { - IPropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(); - for (int i = 0; i < propertyDescriptors.length; i++) + for (IPropertyDescriptor propertyDescriptor : descriptors) { - IPropertyDescriptor propertyDescriptor = propertyDescriptors[i]; if (propertyDescriptor.getId().equals(id)) { return propertyDescriptor; @@ -135,6 +143,60 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource /** * @author Eike Stepper + * @since 3.5 + */ + public static abstract class Augmented<RECEIVER, AUGMENTING_RECEIVER> extends DefaultPropertySource<RECEIVER> + { + private final Map<String, Object> propertyValues = new HashMap<String, Object>(); + + public Augmented(RECEIVER object, IPropertyProvider<RECEIVER> provider, AUGMENTING_RECEIVER augmentingObject) + { + super(object, provider); + if (augmentingObject != null) + { + IPropertySource augmentingPropertySource = createAugmentingPropertySource(augmentingObject); + for (IPropertyDescriptor propertyDescriptor : augmentingPropertySource.getPropertyDescriptors()) + { + if (propertyDescriptor instanceof DelegatingPropertyDescriptor) + { + @SuppressWarnings("unchecked") + DelegatingPropertyDescriptor<AUGMENTING_RECEIVER> viewPropertyDescriptor = (DelegatingPropertyDescriptor<AUGMENTING_RECEIVER>)propertyDescriptor; + + Property<AUGMENTING_RECEIVER> property = viewPropertyDescriptor.getProperty(); + if (property != null) + { + String category = propertyDescriptor.getCategory(); + String id = "___VIEW___" + propertyDescriptor.getId(); + String displayName = propertyDescriptor.getDisplayName(); + String description = propertyDescriptor.getDescription(); + + Object value = property.getValue(augmentingObject); + propertyValues.put(id, value); + + addDescriptor(category, id, displayName, description); + } + } + } + } + } + + @Override + public Object getPropertyValue(Object id) + { + Object value = propertyValues.get(id); + if (value != null) + { + return value; + } + + return super.getPropertyValue(id); + } + + protected abstract IPropertySource createAugmentingPropertySource(AUGMENTING_RECEIVER augmentingObject); + } + + /** + * @author Eike Stepper */ public static final class DelegatingPropertyDescriptor<RECEIVER> implements IPropertyDescriptor { |