下面列出了org.eclipse.ui.views.contentoutline.IContentOutlinePage#org.eclipse.core.runtime.preferences.InstanceScope 实例代码,或者点击链接到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;
}
@Override
public IStatus save() {
try {
final IEclipsePreferences node = InstanceScope.INSTANCE.getNode(QUALIFIER);
for (final Entry<Binary, URI> entry : getOrCreateState().entrySet()) {
final URI path = entry.getValue();
if (null != path) {
final File file = new File(path);
if (file.isDirectory()) {
node.put(entry.getKey().getId(), file.getAbsolutePath());
}
} else {
// Set to default.
node.put(entry.getKey().getId(), "");
}
}
node.flush();
return OK_STATUS;
} catch (final BackingStoreException e) {
final String message = "Unexpected error when trying to persist binary preferences.";
LOGGER.error(message, e);
return statusHelper.createError(message, e);
}
}
public static Map<String, String> loadSaveParticipantOptions(IScopeContext context) {
IEclipsePreferences node;
if (hasSettingsInScope(context)) {
node= context.getNode(JavaUI.ID_PLUGIN);
} else {
IScopeContext instanceScope= InstanceScope.INSTANCE;
if (hasSettingsInScope(instanceScope)) {
node= instanceScope.getNode(JavaUI.ID_PLUGIN);
} else {
return JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getMap();
}
}
Map<String, String> result= new HashMap<String, String>();
Set<String> keys= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getKeys();
for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
String key= iterator.next();
result.put(key, node.get(SAVE_PARTICIPANT_KEY_PREFIX + key, CleanUpOptions.FALSE));
}
return result;
}
/**
* Load TextMate Themes from preferences.
*/
private void loadThemesFromPreferences() {
// Load Theme definitions from the
// "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.ui.prefs"
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID);
String json = prefs.get(PreferenceConstants.THEMES, null);
if (json != null) {
ITheme[] themes = PreferenceHelper.loadThemes(json);
for (ITheme theme : themes) {
super.registerTheme(theme);
}
}
json = prefs.get(PreferenceConstants.THEME_ASSOCIATIONS, null);
if (json != null) {
IThemeAssociation[] themeAssociations = PreferenceHelper.loadThemeAssociations(json);
for (IThemeAssociation association : themeAssociations) {
super.registerThemeAssociation(association);
}
}
}
/**
* Gets the manifest URL.
*
* @return the manifest URL
*/
private String getManifestURL() {
final String res;
final Preferences preferences = InstanceScope.INSTANCE.getNode(AddInPreferenceInitializer.SCOPE);
final String host = preferences.get(AddInPreferenceInitializer.HOST_PREFERENCE,
AddInPreferenceInitializer.DEFAULT_HOST);
final String port = preferences.get(AddInPreferenceInitializer.PORT_PREFERENCE,
String.valueOf(AddInPreferenceInitializer.DEFAULT_PORT));
if (AddInPreferenceInitializer.DEFAULT_HOST.equals(host)) {
res = "http://localhost:" + port + "/assets/manifest.xml";
} else {
res = "http://" + host + ":" + port + "/assets/manifest.xml";
}
return res;
}
@Override
public Map<String, String> getCurrentState() {
Map<String, String> map = new HashMap<String, String>(1);
boolean enableOption = false;
Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
String platformHomeStr = preferences.get("platform_home", null);
if (platformHomeStr == null) {
IProject platformProject = ResourcesPlugin.getWorkspace().getRoot().getProject("platform");
IPath platformProjectPath = platformProject.getLocation();
if (platformProjectPath != null) {
enableOption = true;
}
}
else {
enableOption = true;
}
if (enableOption) {
map.put(ID, ENABLED);
}
else {
map.put(ID, DISABLED);
}
return map;
}
/**
* Switches the search scope of the preference store to use [Project, Instance, Configuration] if values are project
* specific, and [Instance, Configuration] otherwise. This implementation requires that the given preference store
* is based on the Project preference store when the page is used as a Properties page. (This is done in
* {@link #doGetPreferenceStore()}).
*/
@SuppressWarnings("deprecation")
private void handleUseProjectSettings() {
// Note: uses the pre Eclipse 3.6 way of specifying search scopes (deprecated since 3.6)
boolean isUseProjectSettings = useProjectSettingsButton.getSelection();
link.setEnabled(!isUseProjectSettings);
if (!isUseProjectSettings) {
((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
new InstanceScope(), new ConfigurationScope() });
} else {
((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
new ProjectScope(currentProject()), new InstanceScope(), new ConfigurationScope() });
setProjectSpecificValues();
}
updateFieldEditors(isUseProjectSettings);
}
/**
* Before Test
*/
@Override
@Before
public void before() {
try {
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00");
TmfTimestampFormat.updateDefaultFormats();
String tracePath = FileUtils.toFile(FileLocator.toFileURL(CtfTestTrace.SYNC_DEST.getTraceURL())).getAbsolutePath();
fViewBot = fBot.viewByTitle("Control Flow");
fViewBot.show();
SWTBotUtils.openTrace(TRACE_PROJECT_NAME, tracePath, KERNEL_TRACE_TYPE);
fViewBot.setFocus();
} catch (IOException e) {
fail();
}
}
/**
* Initialization, creates a temp trace
*
* @throws IOException
* should not happen
*/
@Before
public void init() throws IOException {
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBot Thread"); // for the debugger
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
fBot = new SWTWorkbenchBot();
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00");
TmfTimestampFormat.updateDefaultFormats();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
fLocation = File.createTempFile("sample", ".xml");
try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fLocation, "rw")) {
braf.writeBytes(TRACE_START);
for (int i = 0; i < NUM_EVENTS; i++) {
braf.writeBytes(makeEvent(i * 100, i % 4));
}
braf.writeBytes(TRACE_END);
}
}
/**
* Initialization, creates a temp trace
*
* @throws IOException
* should not happen
*/
@BeforeClass
public static void init() throws IOException {
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
defaultPreferences.put(ITmfTimePreferencesConstants.TIME_ZONE, "GMT-05:00");
TmfTimestampFormat.updateDefaultFormats();
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBot Thread"); // for the debugger
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
fBot = new SWTWorkbenchBot();
/* finish waiting for eclipse to load */
WaitUtils.waitForJobs();
fFileLocation = File.createTempFile("sample", ".xml");
try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) {
braf.writeBytes(TRACE_START);
for (int i = 0; i < 100; i++) {
braf.writeBytes(makeEvent(i * 100, i % 4));
}
braf.writeBytes(TRACE_END);
}
}
/**
* This operation loads the ExecutableEntry from Eclipse Preferences.
* @param prefId
*/
public void loadFromPreferences(String prefId) {
// Get the Application preferences
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(prefId);
try {
for (String key : prefs.keys()) {
String pref = prefs.get(key, "");
if (!pref.isEmpty()) {
allowedValues.add(pref);
allowedValueToURI.put(pref, URI.create(key));
}
}
} catch (BackingStoreException e) {
logger.error(getClass().getName() + " Exception!", e);
}
if (!allowedValues.isEmpty()) {
allowedValues.add(0, "Select Application");
setDefaultValue(allowedValues.get(0));
} else {
allowedValues.add("Import Application");
setDefaultValue(allowedValues.get(0));
}
}
/**
* Set the debug request timeout of a vm in ms, if supported by the vm implementation.
*/
public static void setDebugTimeout(VirtualMachine vm) {
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(JDIDebugPlugin.getUniqueIdentifier());
int timeOut = node.getInt(JDIDebugModel.PREF_REQUEST_TIMEOUT, 0);
if (timeOut <= 0) {
return;
}
if (vm instanceof org.eclipse.jdi.VirtualMachine) {
org.eclipse.jdi.VirtualMachine vm2 = (org.eclipse.jdi.VirtualMachine) vm;
vm2.setRequestTimeout(timeOut);
}
}
private static IPreferenceStore createProjectSpecificPreferenceStore(IProject project) {
List<IPreferenceStore> stores = new ArrayList<IPreferenceStore>();
if (project != null) {
stores.add(new EclipsePreferencesAdapter(new ProjectScope(project), TypeScriptUIPlugin.PLUGIN_ID));
stores.add(new EclipsePreferencesAdapter(new ProjectScope(project), TypeScriptCorePlugin.PLUGIN_ID));
}
stores.add(new ScopedPreferenceStore(InstanceScope.INSTANCE, TypeScriptUIPlugin.PLUGIN_ID));
stores.add(new ScopedPreferenceStore(InstanceScope.INSTANCE, TypeScriptCorePlugin.PLUGIN_ID));
stores.add(new ScopedPreferenceStore(DefaultScope.INSTANCE, TypeScriptUIPlugin.PLUGIN_ID));
stores.add(new ScopedPreferenceStore(DefaultScope.INSTANCE, TypeScriptCorePlugin.PLUGIN_ID));
return new ChainedPreferenceStore(stores.toArray(new IPreferenceStore[stores.size()]));
}
/**
* Initialize preferences lookups for JavaCore plug-in.
*/
public void initializePreferences() {
// Create lookups
this.preferencesLookup[PREF_INSTANCE] = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
this.preferencesLookup[PREF_DEFAULT] = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
// Listen to instance preferences node removal from parent in order to refresh stored one
this.instanceNodeListener = new IEclipsePreferences.INodeChangeListener() {
public void added(IEclipsePreferences.NodeChangeEvent event) {
// do nothing
}
public void removed(IEclipsePreferences.NodeChangeEvent event) {
if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_INSTANCE]) {
JavaModelManager.this.preferencesLookup[PREF_INSTANCE] = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
JavaModelManager.this.preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
}
}
};
((IEclipsePreferences) this.preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(this.instanceNodeListener);
this.preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(this.instancePreferencesListener = new EclipsePreferencesListener());
// Listen to default preferences node removal from parent in order to refresh stored one
this.defaultNodeListener = new IEclipsePreferences.INodeChangeListener() {
public void added(IEclipsePreferences.NodeChangeEvent event) {
// do nothing
}
public void removed(IEclipsePreferences.NodeChangeEvent event) {
if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_DEFAULT]) {
JavaModelManager.this.preferencesLookup[PREF_DEFAULT] = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
}
}
};
((IEclipsePreferences) this.preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(this.defaultNodeListener);
}
private Color getDebugColor(String key) {
IEclipsePreferences node = new InstanceScope().getNode("org.eclipse.debug.ui");
String color = node.get(key, null);
if (color != null) {
try {
return getDefault().getColor(StringConverter.asRGB(color));
} catch (Exception e) {
Log.log(e);
}
}
return null;
}
@Before
public void setUpProject() throws Exception {
ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.lsp4e");
prefs.putValue("org.eclipse.wildwebdeveloper.angular.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.css.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.html.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.json.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true));
prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true));
this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.nanoTime());
project.create(null);
project.open(null);
// Setup ESLint configuration and dependencies
IFile eslintConfig = project.getFile(".eslintrc");
eslintConfig.create(getClass().getResourceAsStream("/testProjects/eslint/.eslintrc"), true, null);
IFile tsConfig = project.getFile("tsconfig.json");
tsConfig.create(getClass().getResourceAsStream("/testProjects/eslint/tsconfig.json"), true, null);
IFile packageJson = project.getFile("package.json");
packageJson.create(getClass().getResourceAsStream("/testProjects/eslint/package.json"), true, null);
Process dependencyInstaller = new ProcessBuilder(TestAngular.getNpmLocation(), "install")
.directory(project.getLocation().toFile()).start();
assertEquals("npm install didn't complete properly", 0, dependencyInstaller.waitFor());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (IViewReference ref : activePage.getViewReferences()) {
activePage.hideView(ref);
}
}
@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);
}
/**
* Test class tear down method.
*/
@AfterClass
public static void tearDown() {
SWTBotUtils.deleteProject(SOME_PROJECT_NAME, fBot);
fLogger.removeAllAppenders();
/* Set timestamp defaults */
IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, ITmfTimePreferencesConstants.TIME_HOUR_FMT);
defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NANO_FMT);
TmfTimestampFormat.updateDefaultFormats();
}
@Override
protected ExternalLibraryPreferenceModel doLoad() {
final Preferences node = InstanceScope.INSTANCE.getNode(QUALIFIER);
final String jsonString = node.get(CONFIGURATION_KEY, "");
if (isNullOrEmpty(jsonString)) {
return ExternalLibraryPreferenceModel.createDefaultForN4Product();
}
return ExternalLibraryPreferenceModel.createFromJson(jsonString);
}
@Override
public boolean performOk() {
storeValues();
try {
InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).flush();
}
catch (BackingStoreException e) {
Activator.getDefault().logError(e, "Failed to store preferences. Please report this bug to the maintainers.");
}
return true;
}
/**
* Returns a preference store for org.eclipse.tracecompass.tmf.analysis.xml.core preferences
* @return the preference store
*/
public IEclipsePreferences getCorePreferenceStore() {
if (fCorePreferenceStore == null) {
fCorePreferenceStore = InstanceScope.INSTANCE.getNode(PLUGIN_ID);
}
return fCorePreferenceStore;
}
@Execute
public void execute() {
try {
String adress = String.format("http://%s:%s/bdm/graphical", InetAddress.getByName(null).getHostAddress(),
InstanceScope.INSTANCE.getNode(BonitaStudioPreferencesPlugin.PLUGIN_ID)
.get(BonitaPreferenceConstants.DATA_REPOSITORY_PORT, "-1"));
new OpenBrowserOperation(new URL(adress))
.withExternalBrowser(getBrowser())
.withName(Messages.bdmVoyager)
.execute();
} catch (MalformedURLException | UnknownHostException | PartInitException e) {
BonitaStudioLog.error(e);
}
}
/**
* Flushes the instance scope of this plug-in.
*
*/
public static void flushInstanceScope() {
try {
InstanceScope.INSTANCE.getNode(EditorConfigUIPlugin.PLUGIN_ID).flush();
} catch (BackingStoreException e) {
log(e);
}
}
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
XdsPlugin.context = context;
// to force load com.excelsior.core.ide plugin
IdeCore.instance();
TodoTaskMarkerBuilder.install();
// Set default encoding to cp866 if it exists in jvm:
if (TextEncoding.isCodepageSupported(TextEncoding.CodepageId.CODEPAGE_866.charsetName)) {
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES).put(ResourcesPlugin.PREF_ENCODING, EncodingUtils.DOS_ENCODING); //$NON-NLS-1$
}
InjectorFactory.getDefault().
addBinding(IXdsConsoleFactory.class).implementedBy(XdsConsoleManager.class);
new RefreshXdsDecoratorJob().schedule();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
for (ColorStreamType colorStreamType : ColorStreamType.values()) {
SharedResourceManager.createColor(colorStreamType.getRgb());
}
// force loading of the editor plugin, because it contributes the IModulaSyntaxColorer service.
loadPlugins(Arrays.asList("com.excelsior.xds.ui.editor")); //$NON-NLS-1$
}
});
}
public Preferences setFilteredTypes(List<String> filteredTypes) {
this.filteredTypes = (filteredTypes == null) ? Collections.emptyList() : filteredTypes;
IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
pref.put(TypeFilter.TYPEFILTER_ENABLED, String.join(";", filteredTypes));
JavaLanguageServerPlugin.getInstance().getTypeFilter().dispose();
return this;
}
private void installPreferenceListener() {
fPreferenceChangeListener= new IPreferenceChangeListener() {
public void preferenceChange(PreferenceChangeEvent event) {
if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
updateActionLabel();
}
}
};
InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
}
/**
* Load TextMate grammars from preferences.
*/
private void loadGrammarsFromPreferences() {
// Load grammar definitions from the
// "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.registry.prefs"
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(TMEclipseRegistryPlugin.PLUGIN_ID);
String json = prefs.get(PreferenceConstants.GRAMMARS, null);
if (json != null) {
IGrammarDefinition[] definitions = PreferenceHelper.loadGrammars(json);
for (IGrammarDefinition definition : definitions) {
userCache.registerGrammarDefinition(definition);
}
}
}
private IPreferenceChangeListener createPreferenceListener() {
IPreferenceChangeListener listener = event -> {
if (event.getKey().equals(ITmfUIPreferences.PREF_ALIGN_VIEWS)) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (Boolean.toString(false).equals(oldValue) && Boolean.toString(true).equals(newValue)) {
realignViews();
} else if (Boolean.toString(true).equals(oldValue) && Boolean.toString(false).equals(newValue)) {
restoreViews();
}
}
};
InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).addPreferenceChangeListener(listener);
return listener;
}
@Override
public void engineFound(HybridMobileEngine engine) {
initEngineList();
if(engineList.add(engine)){
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(HybridCore.PLUGIN_ID);
preferences.put(engine.getName(), engine.getSpec());
}
}
public static void initializeMavenPreferences() {
IEclipsePreferences m2eAptPrefs = DefaultScope.INSTANCE.getNode(M2E_APT_ID);
if (m2eAptPrefs != null) {
m2eAptPrefs.put(M2E_APT_ID + ".mode", "jdt_apt");
}
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID);
store.put(MavenPreferenceConstants.P_OUT_OF_DATE_PROJECT_CONFIG_PB, ProblemSeverity.warning.toString());
}