0
我使用DI
(依賴注入)從我的處理程序訪問IEclipsePreferences
。 但我需要從其他代碼部分訪問相同的IEclipsePreferences
以保存/加載這些設置。Eclipse e4開普勒:IEclipsePreferences讀取/寫入
這就是例子,我如何讓喜好和顯示時間在一個對話框:
import java.lang.reflect.InvocationTargetException;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.extensions.Preference;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.prefs.BackingStoreException;
public class PojoShowPersistencePreferencesHandler {
@Inject
@Preference
IEclipsePreferences preferences;
@Inject
MApplication application;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell
) throws InvocationTargetException, InterruptedException {
System.out.println(getClass().getSimpleName() + ".execute()");
System.out.println("preferences: " + preferences);
System.out.println("application: " + application);
try {
String msg = "Driver:\t" + preferences.get("jdbc_driver", "404") + "\n" + //
"URL:\t" + preferences.get("jdbc_url", "404") + "\n" + //
"User:\t" + preferences.get("jdbc_user", "404") + "\n" + //
"Password:\t" + preferences.get("jdbc_pwd", "404");
preferences.flush();
MessageDialog.openInformation(shell,
"Info :: Save Persistence Preferences",msg //
);
System.out.println(msg);
} catch (BackingStoreException e) {
e.printStackTrace();
}
}
}
一)我怎麼可以這樣做不使用Handler
? 二)我需要設置通過這些代碼值,而不DI
或帶有參數的處理程序,它可以通過編程被稱爲
我一直試圖this (Vogella) article,但不知何故,我無法找到存儲在這些值(Instance
,Configuration
)範圍,但它們被存儲,因爲它們與Handler
一起顯示!
注:我使用3.x Plugin
風格,所以使用舊式不是問題。