Eclipse/プラグイン開発のTIPS集/GooglePlugin/設定を保持するIPreferenceStoreを使う
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
さて、ここではプラグインが使用する設定値の保存とリストア...
-[[org.eclipse.ui.IWorkbenchPreferencePage(設定ページ)>Ec...
-[[IPreferenceStoreのサンプル:http://www.masatom.in/pukiw...
などでちょっとサンプルがあります。
目的は
String myGoogleKey = GooglePlugin.getDefault().getPrefer...
.getString(PreferenceConstants.GOOGLE_KEY);
などとしてプラグインの設定情報を取得することです。
基本的には
-UIプラグインごとに存在する、設定を保存する箱となる org.e...
-上の箱に値を設定するためのダイアログを形成するorg.eclips...
-初期値を設定するための拡張ポイント org.eclipse.core.runt...
を作成することになります((IPreferenceStoreは作成しないけ...
***org.eclipse.core.runtime.preferences [#r6a0d150]
まずは初期値を設定するための拡張ポイントと実装クラスを作...
この拡張ポイントのplugin.xmlの記述は以下のようになりまし...
<extension
point="org.eclipse.core.runtime.preferences">
<initializer class="nu.mine.kino.plugin.google.ui.
initializer.GooglePreferenceIniti...
</extension>
実装クラスは以下の通り:
package nu.mine.kino.plugin.google.ui.initializer;
import nu.mine.kino.plugin.google.ui.GooglePlugin;
import nu.mine.kino.plugin.google.ui.preferences.Prefere...
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.preferences.AbstractPref...
import org.eclipse.jface.preference.IPreferenceStore;
public class GooglePreferenceInitializer extends Abstrac...
private static final Logger logger = Logger
.getLogger(GooglePreferenceInitializer.class);
public void initializeDefaultPreferences() {
logger.debug("initializeDefaultPreferences() - start...
IPreferenceStore store = GooglePlugin.getDefault().g...
logger.debug(store);
store.setDefault(PreferenceConstants.GOOGLE_KEY, "");
// ↑ここで初期値を設定している
logger.debug(GooglePlugin.getDefault().getPreference...
PreferenceConstants.GOOGLE_KEY));
logger.debug("initializeDefaultPreferences() - end");
}
}
***org.eclipse.ui.IWorkbenchPreferencePage [#t9d47523]
最後に設定画面を作成します。設定画面は
org.eclipse.ui.preferencePages
拡張ポイントと、その実装クラスを作成します。
拡張ポイントの記述は以下の通り:
<extension
point="org.eclipse.ui.preferencePages">
<page
class="nu.mine.kino.plugin.google.ui.preferences.G...
name="Google検索"
id="nu.mine.kino.plugin.google.ui.preferences.Goog...
</extension>
実装クラスは以下の通り:
package nu.mine.kino.plugin.google.ui.preferences;
import nu.mine.kino.plugin.google.ui.GooglePlugin;
import org.eclipse.jface.preference.FieldEditorPreferenc...
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class GooglePreferencePage extends FieldEditorPre...
IWorkbenchPreferencePage {
public GooglePreferencePage() {
super(GRID);
// 実際のKey,Valueを格納する、PreferenceStoreを設定。
setPreferenceStore(GooglePlugin.getDefault().getPref...
setDescription("Google検索時のキーを設定します");
}
protected void createFieldEditors() {
{
addField(new StringFieldEditor(PreferenceConstants...
"&Google Key:", getFieldEditorParent()));
}
}
public void init(IWorkbench workbench) {
}
}
***スクリーンショット [#reecb6fd]
#ref(preference.png)
----
この記事は
#vote(おもしろかった[7],そうでもない[1])
-できればjavaのエディタからコントロールを押下しながら文字...
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
さて、ここではプラグインが使用する設定値の保存とリストア...
-[[org.eclipse.ui.IWorkbenchPreferencePage(設定ページ)>Ec...
-[[IPreferenceStoreのサンプル:http://www.masatom.in/pukiw...
などでちょっとサンプルがあります。
目的は
String myGoogleKey = GooglePlugin.getDefault().getPrefer...
.getString(PreferenceConstants.GOOGLE_KEY);
などとしてプラグインの設定情報を取得することです。
基本的には
-UIプラグインごとに存在する、設定を保存する箱となる org.e...
-上の箱に値を設定するためのダイアログを形成するorg.eclips...
-初期値を設定するための拡張ポイント org.eclipse.core.runt...
を作成することになります((IPreferenceStoreは作成しないけ...
***org.eclipse.core.runtime.preferences [#r6a0d150]
まずは初期値を設定するための拡張ポイントと実装クラスを作...
この拡張ポイントのplugin.xmlの記述は以下のようになりまし...
<extension
point="org.eclipse.core.runtime.preferences">
<initializer class="nu.mine.kino.plugin.google.ui.
initializer.GooglePreferenceIniti...
</extension>
実装クラスは以下の通り:
package nu.mine.kino.plugin.google.ui.initializer;
import nu.mine.kino.plugin.google.ui.GooglePlugin;
import nu.mine.kino.plugin.google.ui.preferences.Prefere...
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.preferences.AbstractPref...
import org.eclipse.jface.preference.IPreferenceStore;
public class GooglePreferenceInitializer extends Abstrac...
private static final Logger logger = Logger
.getLogger(GooglePreferenceInitializer.class);
public void initializeDefaultPreferences() {
logger.debug("initializeDefaultPreferences() - start...
IPreferenceStore store = GooglePlugin.getDefault().g...
logger.debug(store);
store.setDefault(PreferenceConstants.GOOGLE_KEY, "");
// ↑ここで初期値を設定している
logger.debug(GooglePlugin.getDefault().getPreference...
PreferenceConstants.GOOGLE_KEY));
logger.debug("initializeDefaultPreferences() - end");
}
}
***org.eclipse.ui.IWorkbenchPreferencePage [#t9d47523]
最後に設定画面を作成します。設定画面は
org.eclipse.ui.preferencePages
拡張ポイントと、その実装クラスを作成します。
拡張ポイントの記述は以下の通り:
<extension
point="org.eclipse.ui.preferencePages">
<page
class="nu.mine.kino.plugin.google.ui.preferences.G...
name="Google検索"
id="nu.mine.kino.plugin.google.ui.preferences.Goog...
</extension>
実装クラスは以下の通り:
package nu.mine.kino.plugin.google.ui.preferences;
import nu.mine.kino.plugin.google.ui.GooglePlugin;
import org.eclipse.jface.preference.FieldEditorPreferenc...
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class GooglePreferencePage extends FieldEditorPre...
IWorkbenchPreferencePage {
public GooglePreferencePage() {
super(GRID);
// 実際のKey,Valueを格納する、PreferenceStoreを設定。
setPreferenceStore(GooglePlugin.getDefault().getPref...
setDescription("Google検索時のキーを設定します");
}
protected void createFieldEditors() {
{
addField(new StringFieldEditor(PreferenceConstants...
"&Google Key:", getFieldEditorParent()));
}
}
public void init(IWorkbench workbench) {
}
}
***スクリーンショット [#reecb6fd]
#ref(preference.png)
----
この記事は
#vote(おもしろかった[7],そうでもない[1])
-できればjavaのエディタからコントロールを押下しながら文字...
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: