⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personpropertysource.java

📁 基于eclipse的工具开发代码
💻 JAVA
字号:
package propertypagetest.model;

import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.views.properties.ColorPropertyDescriptor;
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
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_COLOR = "COLOR";

	private final static String ID_SEX = "SEX";

	private final static IPropertyDescriptor[] propDescs;

	static
	{
		ComboBoxPropertyDescriptor sexPropDesc = new ComboBoxPropertyDescriptor(
				ID_SEX, "性别", new String[] { "男", "女", "未知" });
		propDescs = new IPropertyDescriptor[] {
				new TextPropertyDescriptor(ID_NAME, "姓名"),
				new ColorPropertyDescriptor(ID_COLOR, "肤色"), sexPropDesc };
	}

	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_COLOR)
		{
			return person.getColor();
		}
		if (id == ID_SEX)
		{
			SexEnum sex = person.getSex();
			if (sex == SexEnum.MALE)
			{
				return 0;
			}
			if (sex == SexEnum.FEMALE)
			{
				return 1;
			}
			if (sex == SexEnum.UNKOWN)
			{
				return 2;
			}
			throw new IllegalArgumentException();
		}
		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);
		}
		if (id == ID_COLOR)
		{
			person.setColor((RGB) value);
		}
		if (id == ID_SEX)
		{
			Integer integer = (Integer) value;
			int i = integer.intValue();
			switch (i)
			{
			case 0:
				person.setSex(SexEnum.MALE);
				break;
			case 1:
				person.setSex(SexEnum.FEMALE);
				break;
			case 2:
				person.setSex(SexEnum.UNKOWN);
				break;
			default:
				break;
			}

		}

	}

}

⌨️ 快捷键说明

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