11/2/2015 - 4:45 PM

Eclipse >> Core >> Adapter

Eclipse >> Core >> Adapter

public class PersonPropertySource implements IPropertySource {
	private final Person person;

	public PersonPropertySource(Person person) {
		this.person = person;

	public Object getEditableValue() {
		return this;

	public IPropertyDescriptor[] getPropertyDescriptors() {
		return new IPropertyDescriptor[] {
				new TextPropertyDescriptor("name", "Name"),
				new TextPropertyDescriptor("street", "Street"),
				new TextPropertyDescriptor("city", "City")

	public Object getPropertyValue(Object id) {
		if ("name".equals(id)) return person.getName();
		else if ("street".equals(id)) return person.getStreet();
		else if ("city".equals(id)) return person.getCity();
		return null;

	public boolean isPropertySet(Object id) {
		return false;

	public void resetPropertyValue(Object id) {

	public void setPropertyValue(Object id, Object value) {
		if ("name".equals(id)) person.setName((String)value);
		else if ("street".equals(id)) person.setStreet((String)value);
		else if ("city".equals(id)) person.setCity((String)value);

IAdapterManager manager = Platform.getAdapterManager();
IAdapter adapter. = manager.getAdapter(object, IResource.class);
public class PersonPropertiesSourceAdapterFactory implements IAdapterFactory {
  //*** The method takes care of figuring out how to adapt the instance
	public Object getAdapter(Object adaptableObject, Class adapterType) {
		if (adapterType == IPropertySource.class)
			return new PersonPropertySource((Person)adaptableObject);
		return null;

	public Class[] getAdapterList() {
		return new Class[] {IPropertySource.class};
public class Person {
	private String name;
	private Object street;
	private Object city;

	public Person(String name) { = name;
		this.street = ""; = "";

The use of the Adapter pattern is to allow plug-ins to be loosely coupled
Instances of the person class, when selected in the favourite view, will populate the Properties view.
Source code: