IAdaptable Interface Concept. [message #94686] |
Wed, 17 September 2003 07:08  |
Eclipse User |
|
|
|
Originally posted by: sunilvi.noida.hcltech.com
What does IAdaptable Interface used for. What does it mean by
Can Anybody Give me a practical Example. LOT OF PEOPLE will get help if
somboday can explain it in detail with example.
|
|
|
|
Re: IAdaptable Interface Concept. [message #94802 is a reply to message #94686] |
Wed, 17 September 2003 15:09   |
Eclipse User |
|
|
|
Good question. I was in your situations some months ago.
The IAdaptable pattern is a brilliant idea. It is used extensively in
eclipse and gef, and once you understand them you take them for granted.
That may be the reasson why the javadoc for IAdaptable is so cryptic.
Here is an example:
When you want an EditPart in your GEF application expose properties to the
Eclipse property viewer, you can implement IPropertySource and write its six
methods below directly in your EditPart.
Something like:
class MyOldEditPart extends EditPart implements IPropertySource {
...
public Object getEditableValue() {...}
public IPropertyDescriptor[] getPropertyDescriptors() {...}
public Object getPropertyValue(Object id) {...}
public boolean isPropertySet(Object id) {...}
public void resetPropertyValue(Object id) {...}
public void setPropertyValue(Object id, Object value) {...}
}
When your EditPart gets selected, GEF informs Eclipse by a selection event.
Eclipse doesn't know what an EditPart is, but it sees that it implements
IPropertySource and can interact with it through your IPropertySource
methods to handle the properties in the Property Viewer.
If this was all, you whould have IPropertySource methods spread all over
your EditPart code, even when your editParts have identical or similar
properties.
Fortunately Eclipse does more than just check for implementation of
IPropertySource. Actually it check your EditPart have implemented
IAdaptable, and in that case it makes the call
getAdapter(IPropertySource.class) to it. Now you have the opportunity to
return an object that implements IPropertySource and handles the property
stuff for the EditPart, and Eclipse will use that object for the Property
Viewer.
This way your EditPart delegates the property handling to a special class.
That class can be used by other EditParts with similar properties.
For example:
class MyNewEditPart extends EditPart implements IAdaptable {
MyPropertySourceAdapter propertySourceAdapter;
public setModel(Object model) {
super.setModel(model);
// make an adapter and give it the model to handle properties of
propertySourceAdapter = new MyPropertySourceAdapter(model);
}
public Object getAdapter(Class key) {
if (key == IPropertySource.class) {
return propertySourceAdapter;
}
return super.getAdapter(key);
}
}
class MyPropertySourceAdapter implements IPropertySource {
...
public Object getEditableValue() {...}
public IPropertyDescriptor[] getPropertyDescriptors() {...}
public Object getPropertyValue(Object id) {...}
public boolean isPropertySet(Object id) {...}
public void resetPropertyValue(Object id) {...}
public void setPropertyValue(Object id, Object value) {...}
}
In my applications i write property adapaters that reflects part of the
structure and inheritance of my model objects, which results in good code
reuse.
/Dag Rende
"Sunil Virmani" <sunilvi@noida.hcltech.com> skrev i meddelandet
news:bk9fc4$mva$1@eclipse.org...
> What does IAdaptable Interface used for. What does it mean by
> Can Anybody Give me a practical Example. LOT OF PEOPLE will get help if
> somboday can explain it in detail with example.
>
|
|
|
Re: IAdaptable Interface Concept. [message #95635 is a reply to message #94686] |
Sat, 27 September 2003 06:56  |
Eclipse User |
|
|
|
Originally posted by: ThisisFake.Fakeness.xyz
It is a clandestine way of doing multiple inheritance. Without the
multiple inheritance confusion.
The end result however is just as confusing to the end user if you don't
know their is a second way of 'implementing' an interface.
As I understand it, encapsulation is preferred to inheritance.
CL
On Wed, 17 Sep 2003 11:08:52 +0000, Sunil Virmani wrote:
> What does IAdaptable Interface used for. What does it mean by
> Can Anybody Give me a practical Example. LOT OF PEOPLE will get help if
> somboday can explain it in detail with example.
|
|
|
Powered by
FUDForum. Page generated in 0.03449 seconds