@山风小子
public class Model implements IAdaptable
{
private Object data;
public Model()
{
}
public Object getAdapter(Class clazz)
{
if(clazz==UserViewInfo.class){
return getUserViewInfoAdapter();
}
if(clazz==AddressViewInfo.class){
return getAddressViewInfoAdapter();
}
return null;
}
private Object getAddressViewInfoAdapter()
{
if(data instanceof Address){
Address address = (Address)data;
AddressViewInfo info = new AddressViewInfo();
info.setData(address);
Image icon = new Image(getAddressIcon());
//...其他
return info;
}
return null;
}
private Object getUserViewInfoAdapter()
{
if(data instanceof User){
User user = (User)data;
UserViewInfo info = new UserViewInfo();
info.setData(user);
Image icon = new Image(getUserIcon());
//...其他
return info;
}
return null;
}
public Object getData()
{
return data;
}
public void setData(Object data)
{
this.data = data;
}
}
eclipse在emf上使用adapter来获取一个对象的监听器,有兴趣可以看看,还配合factory使用,内容也不多。eclipse的机制实在很好,可惜还没有时间抽得出来好好研究~~~~~~~~~
回复 更多评论