Eclipse/プラグイン開発のTIPS集/org.eclipse.core.runtime.IAdaptable(cont.)2
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
// 下階層用テンプレート
#topicpath
----
#contents
**ここまでで [#j466e50d]
//ここにコンテンツを記述します。
[[Eclipse/プラグイン開発のTIPS集/org.eclipse.core.runtime...
org.eclipse.core.runtime.IAdaptable インタフェース
org.eclipse.core.runtime.PlatformObject オブジェクト
org.eclipse.core.runtime.IAdapterFactory ファクトリ
の機構のまとめとその応用をまとめたいと思います。
[[Viewerへのモデルオブジェクトの表示>Eclipse/プラグイン開...
次の題材は[[Eclipse/プラグイン開発のTIPS集/プロパティシー...
このプロパティビューへの表示ですが、一般的には
-モデルのオブジェクトがIPropertySourceを実装していること
-モデルのオブジェクトがIAdaptableを実装していて、IPropert...
を要求されています。が、これって動的にやることでモデルオ...
**プロパティビューのまとめ [#a415cb53]
詳細は[[Eclipse/プラグイン開発のTIPS集/プロパティシートを...
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
return new PropertySheetPage();
}
return super.getAdapter(adapter);
}
とOverrideしておくと、ビュー内のモデルとなるオブジェクト...
PropertySheetクラス(まさにプロパティビュー)は
public void init(IViewSite site) throws PartInitExceptio...
site.getPage().addSelectionListener(this);
super.init(site);
}
と初期化時にpageにaddSelectionListenerされ、
public void dispose() {
// run super.
super.dispose();
// remove ourselves as a selection listener
getSite().getPage().removeSelectionListener(this);
}
とdispose時にpageからremoveSelectionListenerされてます。...
さてあるビューでモデルオブジェクトを選択したときに、モデ...
protected IPropertySource getPropertySource(Object objec...
というメソッドが行っています。何とかしてIPropertySourceを...
具体的には
↓ViewPart(id: org.eclipse.ui.views.PropertySheet まさに...
PropertySheet#selectionChanged -> PropertySheetPage#sele...
-> PropertySheetViewer#setInput -> PropertySheetEntry#...
-> PropertySheetEntry#getPropertySource <-このメソッド...
という流れ。なげー。((ちなみにPropertySheetはISelectionLi...
このメソッドでIPropertySourceを取得し、プロパティビューへ...
**プロパティビューの処理の詳細 [#edc2ceff]
***なぜモデルがIAdaptableだったりIPropertySourceを実装し...
さて、
モデルオブジェクトはIAdaptableだったりIPropertySourceを実...
protected IPropertySource getPropertySource(Object objec...
if (sources.containsKey(object))
return (IPropertySource) sources.get(object);
IPropertySource result = null;
if (propertySourceProvider != null)
result = propertySourceProvider.getPropertySource(ob...
else if (object instanceof IPropertySource)
result = (IPropertySource) object;
else if (object instanceof IAdaptable)
result = (IPropertySource) ((IAdaptable) object)
.getAdapter(IPropertySource.class);
sources.put(object, result);
return result;
}
などとやってるからなんですね。モデル(objectインスタンス)...
***IAdaptableでもIPropertySourceでもないモデルに対しては ...
さて今回の目的は、IAdaptableでもIPropertySourceでもないモ...
IPropertySource result = null;
if (propertySourceProvider != null)
result = propertySourceProvider.getPropertySource(obje...
ですね。
ではこのpropertySourceProviderのセンで調べてみます。Eclip...
public void setPropertySourceProvider(IPropertySourcePro...
でこのpropertySourceProviderを設定できそうです。これを呼...
**で、IAdaptableの話 [#y1ae2f56]
ここまでで、ビューのgetAdapterメソッドを
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
// return new PropertySheetPage();
PropertySheetPage page = new PropertySheetPage();
page.setPropertySourceProvider(hogehoge);
return page;
}
return super.getAdapter(adapter);
}
などと実装すれば、モデルオブジェクトをIAdaptableやIProper...
ここでようやく、IAdaptableをいろいろ調べてた苦労が実りそ...
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
// return new PropertySheetPage();
PropertySheetPage page = new PropertySheetPage();
page.setPropertySourceProvider(new IPropertySourcePr...
public IPropertySource getPropertySource(Object ob...
if (object instanceof Model) {
Model model = (Model) object;
IPropertySource adapter = (IPropertySource) Pl...
.getAdapterManager().loadAdapter(model,
IPropertySource.class.getName());
↑ ModelのインスタンスmodelとIPropertySourc...
↑ の組み合わせでオブジェクトをローディング
↑ adapterの拡張ポイントで登録が必要。
return adapter;
}
return null;
}
});
return page;
}
return super.getAdapter(adapter);
}
このように実装し((ここではModel型かどうかとかやってますが...
***拡張ポイント [#l9655303]
<extension point="org.eclipse.core.runtime.adapters">
<factory adaptableType="nu.mine.kino.plugin.samples.mo...
class="nu.mine.kino.plugin.samples.model.Prop...
<adapter type="org.eclipse.ui.views.properties.IProp...
</factory>
</extension>
***IAdapterFactoryの実装クラス [#i39ffccf]
public class PropertySourceAdapterFactory implements IAd...
private static final Class[] Types = new Class[] { IPr...
public Object getAdapter(Object adaptableObject, Class...
if (adapterType == Types[0] && adaptableObject insta...
final Model model = (Model) adaptableObject;
IPropertySource source = new IPropertySource() {
public IPropertyDescriptor[] getPropertyDescript...
IPropertyDescriptor[] descriptor = new IProper...
new TextPropertyDescriptor("id", "コード"),
new TextPropertyDescriptor("name", "名前"),
new TextPropertyDescriptor("mail", "メール...
return descriptor;
}
public Object getPropertyValue(Object id) {
if (id.equals("id")) {
return model.getId();
}
if (id.equals("name")) {
return model.getName();
}
if (id.equals("mail")) {
return model.getMail();
}
return null;
}
public boolean isPropertySet(Object id) {return ...
public void resetPropertyValue(Object id) {}
public void setPropertyValue(Object id, Object v...
public Object getEditableValue() {return null;}
};
return source;
}
return null;
}
public Class[] getAdapterList() {
return Types;
}
}
以上で完成です。ビュー上で、モデルオブジェクトを選択する...
#ref(pic02.png)
**よくよく考えたら、この例ではこんなややこしいこと必要な...
今回の場合はこんなややこしいこと必要なかったです。
public IPropertySource getPropertySource(Object object) {
if (object instanceof Model) {
Model model = (Model) object;
IPropertySource adapter = (IPropertySource) Platform
.getAdapterManager().loadAdapter(model,
IPropertySource.class.getName());
↑ ModelのインスタンスmodelとIPropertySource.class
↑ の組み合わせでオブジェクトをローディング
↑ adapterの拡張ポイントで登録が必要。
return adapter;
}
return null;
}
なんてことをやりましたが、ここは
public IPropertySource getPropertySource(Object object) {
if (object instanceof Model) {
Model model = (Model) object;
return new IPropertySourceImpl(model);
}
return null;
}
などとしておくだけで十分でした。IPropertySourceImplは適当に
private class IPropertySourceImpl implements IPropertySo...
private Model model;
public IPropertySourceImpl(Model model) {
this.model = model;
}
public IPropertyDescriptor[] getPropertyDescriptors() {
IPropertyDescriptor[] descriptor = new IPropertyDesc...
new TextPropertyDescriptor("id", "コード"),
new TextPropertyDescriptor("name", "名前"),
new TextPropertyDescriptor("mail", "メール") };
return descriptor;
}
public Object getPropertyValue(Object id) {
if (id.equals("id")) {
return model.getId();
}
if (id.equals("name")) {
return model.getName();
}
if (id.equals("mail")) {
return model.getMail();
}
return null;
}
public boolean isPropertySet(Object id) {return false;}
public void resetPropertyValue(Object id) {}
public void setPropertyValue(Object id, Object value) {}
public Object getEditableValue() {return null;}
};
でOKです。これでorg.eclipse.core.runtime.adapters 拡張...
。。。何やっってたんだー(´д`;)。。。。まあ、org.eclips...
----
この記事は
#vote(おもしろかった[12],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
// 下階層用テンプレート
#topicpath
----
#contents
**ここまでで [#j466e50d]
//ここにコンテンツを記述します。
[[Eclipse/プラグイン開発のTIPS集/org.eclipse.core.runtime...
org.eclipse.core.runtime.IAdaptable インタフェース
org.eclipse.core.runtime.PlatformObject オブジェクト
org.eclipse.core.runtime.IAdapterFactory ファクトリ
の機構のまとめとその応用をまとめたいと思います。
[[Viewerへのモデルオブジェクトの表示>Eclipse/プラグイン開...
次の題材は[[Eclipse/プラグイン開発のTIPS集/プロパティシー...
このプロパティビューへの表示ですが、一般的には
-モデルのオブジェクトがIPropertySourceを実装していること
-モデルのオブジェクトがIAdaptableを実装していて、IPropert...
を要求されています。が、これって動的にやることでモデルオ...
**プロパティビューのまとめ [#a415cb53]
詳細は[[Eclipse/プラグイン開発のTIPS集/プロパティシートを...
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
return new PropertySheetPage();
}
return super.getAdapter(adapter);
}
とOverrideしておくと、ビュー内のモデルとなるオブジェクト...
PropertySheetクラス(まさにプロパティビュー)は
public void init(IViewSite site) throws PartInitExceptio...
site.getPage().addSelectionListener(this);
super.init(site);
}
と初期化時にpageにaddSelectionListenerされ、
public void dispose() {
// run super.
super.dispose();
// remove ourselves as a selection listener
getSite().getPage().removeSelectionListener(this);
}
とdispose時にpageからremoveSelectionListenerされてます。...
さてあるビューでモデルオブジェクトを選択したときに、モデ...
protected IPropertySource getPropertySource(Object objec...
というメソッドが行っています。何とかしてIPropertySourceを...
具体的には
↓ViewPart(id: org.eclipse.ui.views.PropertySheet まさに...
PropertySheet#selectionChanged -> PropertySheetPage#sele...
-> PropertySheetViewer#setInput -> PropertySheetEntry#...
-> PropertySheetEntry#getPropertySource <-このメソッド...
という流れ。なげー。((ちなみにPropertySheetはISelectionLi...
このメソッドでIPropertySourceを取得し、プロパティビューへ...
**プロパティビューの処理の詳細 [#edc2ceff]
***なぜモデルがIAdaptableだったりIPropertySourceを実装し...
さて、
モデルオブジェクトはIAdaptableだったりIPropertySourceを実...
protected IPropertySource getPropertySource(Object objec...
if (sources.containsKey(object))
return (IPropertySource) sources.get(object);
IPropertySource result = null;
if (propertySourceProvider != null)
result = propertySourceProvider.getPropertySource(ob...
else if (object instanceof IPropertySource)
result = (IPropertySource) object;
else if (object instanceof IAdaptable)
result = (IPropertySource) ((IAdaptable) object)
.getAdapter(IPropertySource.class);
sources.put(object, result);
return result;
}
などとやってるからなんですね。モデル(objectインスタンス)...
***IAdaptableでもIPropertySourceでもないモデルに対しては ...
さて今回の目的は、IAdaptableでもIPropertySourceでもないモ...
IPropertySource result = null;
if (propertySourceProvider != null)
result = propertySourceProvider.getPropertySource(obje...
ですね。
ではこのpropertySourceProviderのセンで調べてみます。Eclip...
public void setPropertySourceProvider(IPropertySourcePro...
でこのpropertySourceProviderを設定できそうです。これを呼...
**で、IAdaptableの話 [#y1ae2f56]
ここまでで、ビューのgetAdapterメソッドを
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
// return new PropertySheetPage();
PropertySheetPage page = new PropertySheetPage();
page.setPropertySourceProvider(hogehoge);
return page;
}
return super.getAdapter(adapter);
}
などと実装すれば、モデルオブジェクトをIAdaptableやIProper...
ここでようやく、IAdaptableをいろいろ調べてた苦労が実りそ...
public Object getAdapter(Class adapter) {
if (adapter.equals(IPropertySheetPage.class)) {
// return new PropertySheetPage();
PropertySheetPage page = new PropertySheetPage();
page.setPropertySourceProvider(new IPropertySourcePr...
public IPropertySource getPropertySource(Object ob...
if (object instanceof Model) {
Model model = (Model) object;
IPropertySource adapter = (IPropertySource) Pl...
.getAdapterManager().loadAdapter(model,
IPropertySource.class.getName());
↑ ModelのインスタンスmodelとIPropertySourc...
↑ の組み合わせでオブジェクトをローディング
↑ adapterの拡張ポイントで登録が必要。
return adapter;
}
return null;
}
});
return page;
}
return super.getAdapter(adapter);
}
このように実装し((ここではModel型かどうかとかやってますが...
***拡張ポイント [#l9655303]
<extension point="org.eclipse.core.runtime.adapters">
<factory adaptableType="nu.mine.kino.plugin.samples.mo...
class="nu.mine.kino.plugin.samples.model.Prop...
<adapter type="org.eclipse.ui.views.properties.IProp...
</factory>
</extension>
***IAdapterFactoryの実装クラス [#i39ffccf]
public class PropertySourceAdapterFactory implements IAd...
private static final Class[] Types = new Class[] { IPr...
public Object getAdapter(Object adaptableObject, Class...
if (adapterType == Types[0] && adaptableObject insta...
final Model model = (Model) adaptableObject;
IPropertySource source = new IPropertySource() {
public IPropertyDescriptor[] getPropertyDescript...
IPropertyDescriptor[] descriptor = new IProper...
new TextPropertyDescriptor("id", "コード"),
new TextPropertyDescriptor("name", "名前"),
new TextPropertyDescriptor("mail", "メール...
return descriptor;
}
public Object getPropertyValue(Object id) {
if (id.equals("id")) {
return model.getId();
}
if (id.equals("name")) {
return model.getName();
}
if (id.equals("mail")) {
return model.getMail();
}
return null;
}
public boolean isPropertySet(Object id) {return ...
public void resetPropertyValue(Object id) {}
public void setPropertyValue(Object id, Object v...
public Object getEditableValue() {return null;}
};
return source;
}
return null;
}
public Class[] getAdapterList() {
return Types;
}
}
以上で完成です。ビュー上で、モデルオブジェクトを選択する...
#ref(pic02.png)
**よくよく考えたら、この例ではこんなややこしいこと必要な...
今回の場合はこんなややこしいこと必要なかったです。
public IPropertySource getPropertySource(Object object) {
if (object instanceof Model) {
Model model = (Model) object;
IPropertySource adapter = (IPropertySource) Platform
.getAdapterManager().loadAdapter(model,
IPropertySource.class.getName());
↑ ModelのインスタンスmodelとIPropertySource.class
↑ の組み合わせでオブジェクトをローディング
↑ adapterの拡張ポイントで登録が必要。
return adapter;
}
return null;
}
なんてことをやりましたが、ここは
public IPropertySource getPropertySource(Object object) {
if (object instanceof Model) {
Model model = (Model) object;
return new IPropertySourceImpl(model);
}
return null;
}
などとしておくだけで十分でした。IPropertySourceImplは適当に
private class IPropertySourceImpl implements IPropertySo...
private Model model;
public IPropertySourceImpl(Model model) {
this.model = model;
}
public IPropertyDescriptor[] getPropertyDescriptors() {
IPropertyDescriptor[] descriptor = new IPropertyDesc...
new TextPropertyDescriptor("id", "コード"),
new TextPropertyDescriptor("name", "名前"),
new TextPropertyDescriptor("mail", "メール") };
return descriptor;
}
public Object getPropertyValue(Object id) {
if (id.equals("id")) {
return model.getId();
}
if (id.equals("name")) {
return model.getName();
}
if (id.equals("mail")) {
return model.getMail();
}
return null;
}
public boolean isPropertySet(Object id) {return false;}
public void resetPropertyValue(Object id) {}
public void setPropertyValue(Object id, Object value) {}
public Object getEditableValue() {return null;}
};
でOKです。これでorg.eclipse.core.runtime.adapters 拡張...
。。。何やっってたんだー(´д`;)。。。。まあ、org.eclips...
----
この記事は
#vote(おもしろかった[12],そうでもない[0])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: