首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse 适配器 方式的使用

2012-10-24 
eclipse 适配器 模式的使用?最原始的方法public class Personimplements IPropertySource适配的方法 publi

eclipse 适配器 模式的使用

?

最原始的方法
public class Person  implements IPropertySource  
适配的方法 

public class Person implements IAdaptable {

public Object getAdapter(Class adapter) {
if (adapter == IPropertySource.class) return new PersonPropertySource(this);return null;
}
}
使用扩展点来实现适配
<plugin>   <extension         point="org.eclipse.core.runtime.adapters">      <factory            adaptableType="org.eclipse.articles.adapters.core.Person"            class="org.eclipse.articles.adapters.properties.PersonPropertiesSourceAdapterFactory">         <adapter               type="org.eclipse.ui.views.properties.IPropertySource">         </adapter>      </factory>   </extension></plugin>
public class PersonPropertiesSourceAdapterFactory implements IAdapterFactory {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 implements IAdaptable {private String name;private Object street;private Object city;public Person(String name) {this.name = name;this.street = "";this.city = "";}public Object getAdapter(Class adapter) {return Platform.getAdapterManager().getAdapter(this, adapter);}}

?

http://www.eclipse.org/articles/article.php?file=Article-Adapters/index.html

热点排行