favoritepropertysource.java

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

JAVA
82
字号
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 FavoritePropertySource implements IPropertySource
{
	private final static String ID_SINGER = "SINGER";

	private final static String ID_FOOD = "FOOD";

	private final static String ID_MOTTO = "MOTTO";

	private Favorite favorite;

	private final static IPropertyDescriptor[] propDescs = new IPropertyDescriptor[] {
			new TextPropertyDescriptor(ID_SINGER, "歌手"),
			new TextPropertyDescriptor(ID_FOOD, "食品"),
			new TextPropertyDescriptor(ID_MOTTO, "座右铭"), };

	public FavoritePropertySource(Favorite favorite)
	{
		super();
		this.favorite = favorite;
	}

	public Object getEditableValue()
	{
		return null;
	}

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

	public Object getPropertyValue(Object id)
	{
		if (id == ID_SINGER)
		{
			return favorite.getSinger();
		}
		if (id == ID_FOOD)
		{
			return favorite.getFood();
		}
		if (id == ID_MOTTO)
		{
			return favorite.getMotto();
		}
		return null;
	}

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

	public void resetPropertyValue(Object id)
	{

	}

	public void setPropertyValue(Object id, Object value)
	{
		if (id == ID_SINGER)
		{
			favorite.setSinger((String) value);
		}
		if (id == ID_FOOD)
		{
			favorite.setFood((String) value);
		}
		if (id == ID_MOTTO)
		{
			favorite.setMotto((String) value);
		}
	}

}

⌨️ 快捷键说明

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