下面列出了org.eclipse.ui.preferences.ScopedPreferenceStore#setValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Reads the extension points for the plotting systems registered and returns
* a plotting system based on the users current preferences.
*
* @return
*/
@SuppressWarnings("unchecked")
public static <T> IPlottingSystem<T> createPlottingSystem() throws Exception {
final ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE,"org.dawb.workbench.ui");
String plotType = store.getString("org.dawb.plotting.system.choice");
if (plotType.isEmpty()) plotType = System.getProperty("org.dawb.plotting.system.choice");// For Geoff et. al. can override.
if (plotType==null) plotType = "org.dawb.workbench.editors.plotting.lightWeightPlottingSystem"; // That is usually around
IPlottingSystem<T> system = createPlottingSystem(plotType);
if (system!=null) return system;
IConfigurationElement[] systems = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.dawnsci.plotting.api.plottingClass");
if (systems.length == 0) {
return null;
}
IPlottingSystem<T> ifnotfound = (IPlottingSystem<T>)systems[0].createExecutableExtension("class");
store.setValue("org.dawb.plotting.system.choice", systems[0].getAttribute("id"));
return ifnotfound;
}
@Before
public void setUpLaunch() throws DebugException {
this.launchManager = DebugPlugin.getDefault().getLaunchManager();
removeAllLaunches();
ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.debug.ui");
prefs.setValue("org.eclipse.debug.ui.switch_perspective_on_suspend", MessageDialogWithToggle.ALWAYS);
}
@SuppressWarnings("deprecation")
@Test public void testChainedPreferenceStore() {
ScopedPreferenceStore configurationStore = new ScopedPreferenceStore(new ConfigurationScope(), LANGUAGE_ID);
configurationStore.setValue("someInt", 12);
configurationStore.setValue("anotherInt", 12);
configurationStore.setDefault("thirdInt", 12);
ScopedPreferenceStore instanceStore = new ScopedPreferenceStore(new InstanceScope(), LANGUAGE_ID);
instanceStore.setValue("someInt", 13);
instanceStore.setDefault("anotherInt", 13);
ChainedPreferenceStore chainedStore = new ChainedPreferenceStore(new IPreferenceStore[] { instanceStore, configurationStore });
assertEquals(13, chainedStore.getInt("someInt"));
assertEquals(13, chainedStore.getInt("anotherInt"));
assertEquals(12, chainedStore.getInt("thirdInt"));
}
private IProject getProject(String encoding) throws CoreException {
IProject project = workbenchTestHelper.getProject();
ScopedPreferenceStore projectPreferenceStore = new ScopedPreferenceStore(new ProjectScope(project), Platform.PI_RUNTIME);
projectPreferenceStore.setValue(Platform.PREF_LINE_SEPARATOR, "\n");
project.setDefaultCharset(encoding, null);
return project;
}
private void testSeparator(String separator) throws Exception {
IProject project = workbenchTestHelper.getProject();
ScopedPreferenceStore projectPreferenceStore = new ScopedPreferenceStore(new ProjectScope(project), Platform.PI_RUNTIME);
projectPreferenceStore.setValue(Platform.PREF_LINE_SEPARATOR, separator);
workbenchTestHelper.createFile("Foo.xtend", "class Foo {}");
waitForBuild();
IFile compiledFile = project.getFile("xtend-gen/Foo.java");
workbenchTestHelper.getFiles().add(compiledFile);
String contents = WorkbenchTestHelper.getContentsAsString(compiledFile);
List<String> expectedLines = ImmutableList.of("@SuppressWarnings(\"all\")", "public class Foo {", "}", "");
String expectedContent = Joiner.on(separator).join(expectedLines);
assertEquals(expectedContent, contents);
}
private void saveUseProjectSettings(boolean isProjectSpecific) throws IOException {
ScopedPreferenceStore store = (ScopedPreferenceStore) getPreferenceStore();
store.setValue(useProjectSettingsPreferenceName(), Boolean.toString(isProjectSpecific));
store.save();
}