personpropertysource.java

来自「基于eclipse的工具开发代码」· Java 代码 · 共 70 行

JAVA
70
字号
package propertypagetest.model;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

public class PersonPropertySource implements IPropertySource
{

	private final static String ID_NAME = "NAME";

	private final static String ID_FAVORITE = "ADDRESS";

	private final static IPropertyDescriptor[] propDescs = new IPropertyDescriptor[] {
			new TextPropertyDescriptor(ID_NAME, "姓名"),
			new TextPropertyDescriptor(ID_FAVORITE, "爱好") };

	private Person person;

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

	public IPropertyDescriptor[] getPropertyDescriptors()
	{
		return propDescs;
	}

	public Object getEditableValue()
	{
		return null;
	}

	public Object getPropertyValue(Object id)
	{
		if (id == ID_NAME)
		{
			return person.getName();
		}
		if (id == ID_FAVORITE)
		{
			return person.getFavorite();
		}

		return null;
	}

	public boolean isPropertySet(Object id)
	{
		return false;
	}

	public void resetPropertyValue(Object id)
	{

	}

	public void setPropertyValue(Object id, Object value)
	{
		if (id == ID_NAME)
		{
			person.setName((String) value);
		}
		
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?