KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > ui > provider > PropertySource


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: PropertySource.java,v 1.2 2005/06/08 06:20:52 nickb Exp $
16  */

17 package org.eclipse.emf.edit.ui.provider;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.eclipse.ui.views.properties.IPropertyDescriptor;
26 import org.eclipse.ui.views.properties.IPropertySource;
27
28 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
29 import org.eclipse.emf.edit.provider.IItemPropertySource;
30
31
32 /**
33  * This is used to encapsulate an {@link IItemPropertySource} along with the object for which it is an item property source
34  * and make it behave like an {@link org.eclipse.ui.views.properties.IPropertySource}.
35  */

36 public class PropertySource implements IPropertySource
37 {
38   /**
39    * This is the object for which this class is a property source.
40    */

41   protected Object JavaDoc object;
42
43   /**
44    * This is the descriptor to which we will delegate all the {@link org.eclipse.ui.views.properties.IPropertySource} methods.
45    */

46   protected IItemPropertySource itemPropertySource;
47
48   /**
49    * An instance is constructed from an object and its item property source.
50    */

51   public PropertySource(Object JavaDoc object, IItemPropertySource itemPropertySource)
52   {
53     this.object = object;
54     this.itemPropertySource = itemPropertySource;
55   }
56
57   /**
58    * This delegates to {@link IItemPropertySource#getEditableValue IItemPropertySource.getEditableValue}.
59    */

60   public Object JavaDoc getEditableValue()
61   {
62     return itemPropertySource.getEditableValue(object);
63   }
64
65   /**
66    * This delegates to {@link IItemPropertySource#getPropertyDescriptors IItemPropertySource.getPropertyDescriptors}.
67    */

68   public IPropertyDescriptor [] getPropertyDescriptors()
69   {
70     Collection JavaDoc result = new ArrayList JavaDoc();
71     List JavaDoc itemPropertyDescriptors = itemPropertySource.getPropertyDescriptors(object);
72     if (itemPropertyDescriptors != null)
73     {
74       for (Iterator JavaDoc i = itemPropertyDescriptors.iterator(); i.hasNext(); )
75       {
76         IItemPropertyDescriptor itemPropertyDescriptor = (IItemPropertyDescriptor)i.next();
77         result.add(createPropertyDescriptor(itemPropertyDescriptor));
78       }
79     }
80
81     return (IPropertyDescriptor [])result.toArray(new IPropertyDescriptor [result.size()]);
82   }
83
84   protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor)
85   {
86     return new PropertyDescriptor(object, itemPropertyDescriptor);
87   }
88
89   /**
90    * This delegates to {@link IItemPropertyDescriptor#getPropertyValue IItemPropertyDescriptor.getPropertyValue}.
91    */

92   public Object JavaDoc getPropertyValue(Object JavaDoc propertyId)
93   {
94     return itemPropertySource.getPropertyDescriptor(object, propertyId).getPropertyValue(object);
95   }
96
97   /**
98    * This delegates to {@link IItemPropertyDescriptor#isPropertySet IItemPropertyDescriptor.isPropertySet}.
99    */

100   public boolean isPropertySet(Object JavaDoc propertyId)
101   {
102     return itemPropertySource.getPropertyDescriptor(object, propertyId).isPropertySet(object);
103   }
104
105   /**
106    * This delegates to {@link IItemPropertyDescriptor#resetPropertyValue IItemPropertyDescriptor.resetPropertyValue}.
107    */

108   public void resetPropertyValue(Object JavaDoc propertyId)
109   {
110     itemPropertySource.getPropertyDescriptor(object, propertyId).resetPropertyValue(object);
111   }
112
113   /**
114    * This delegates to {@link IItemPropertyDescriptor#setPropertyValue IItemPropertyDescriptor.setPropertyValue}.
115    */

116   public void setPropertyValue(Object JavaDoc propertyId, Object JavaDoc value)
117   {
118     itemPropertySource.getPropertyDescriptor(object, propertyId).setPropertyValue(object, value);
119   }
120 }
121
Popular Tags