读书人

eclipse 适配器 方式的使用

发布时间: 2012-10-24 14:15:58 作者: rapoo

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

读书人网 >Eclipse开发

热点推荐