private static boolean updateConfigurationFromSettings(AsciidocConfiguration configuration, IProject project) { final IScopeContext projectScope = new ProjectScope(project); IEclipsePreferences preferences = projectScope.getNode(Activator.PLUGIN_ID); try { createSettings(project, BACKEND_DEFAULT, RESOURCESPATH_DEFAULT, SOURCESPATH_DEFAULT, STYLESHEETPATH_DEFAULT, TARGETPATH_DEFAULT); configuration.setBackend(preferences.get(BACKEND_PROPERTY, BACKEND_DEFAULT)); configuration.setResourcesPath(preferences.get(RESOURCESPATH_PROPERTY, RESOURCESPATH_DEFAULT)); configuration.setSourcesPath(preferences.get(SOURCESPATH_PROPERTY, SOURCESPATH_DEFAULT)); configuration.setStylesheetPath(preferences.get(STYLESHEETPATH_PROPERTY, STYLESHEETPATH_DEFAULT)); configuration.setTargetPath(preferences.get(TARGETPATH_PROPERTY, TARGETPATH_DEFAULT)); } catch (BackingStoreException e) { Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, e.getMessage(), e)); return false; } configuration.source = AsciidocConfigurationSource.SETTINGS; return true; }
private static void addSettings(IProject project, String workspaceRoot, List<String> targets, List<String> buildFlags) throws BackingStoreException { IScopeContext projectScope = new ProjectScope(project); Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID); int i = 0; for (String target : targets) { projectNode.put("target" + i, target); i++; } projectNode.put("workspaceRoot", workspaceRoot); i = 0; for (String flag : buildFlags) { projectNode.put("buildFlag" + i, flag); i++; } projectNode.flush(); }
private boolean getChanges(IScopeContext currContext, List<Key> changedSettings) { boolean needsBuild = false; for (int i = 0; i < fAllKeys.length; i++) { Key key = fAllKeys[i]; String oldVal = key.getStoredValue(currContext, null); String val = key.getStoredValue(currContext, fManager); if (val == null) { if (oldVal != null) { changedSettings.add(key); needsBuild |= !oldVal.equals(key.getStoredValue(fLookupOrder, true, fManager)); } } else if (!val.equals(oldVal)) { changedSettings.add(key); needsBuild |= oldVal != null || !val.equals(key.getStoredValue(fLookupOrder, true, fManager)); } } return needsBuild; }
@SuppressWarnings("deprecation") public IPreferenceStore getWritablePreferenceStore(Object context) { lazyInitialize(); if (context instanceof IFileEditorInput) { context = ((IFileEditorInput) context).getFile().getProject(); } if (context instanceof IProject) { ProjectScope projectScope = new ProjectScope((IProject) context); FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(projectScope, getQualifier()); result.setSearchContexts(new IScopeContext[] { projectScope, new InstanceScope(), new ConfigurationScope() }); return result; } return getWritablePreferenceStore(); }
public static String getLineDelimiterPreference(IProject project) { IScopeContext[] scopeContext; if (project != null) { // project preference scopeContext = new IScopeContext[] {new ProjectScope(project)}; String lineDelimiter = Platform.getPreferencesService() .getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); if (lineDelimiter != null) return lineDelimiter; } // workspace preference scopeContext = new IScopeContext[] {InstanceScope.INSTANCE}; String platformDefault = System.getProperty("line.separator", "\n"); // $NON-NLS-1$ //$NON-NLS-2$ return Platform.getPreferencesService() .getString( Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefault, scopeContext); }
private final IEclipsePreferences getProjectPreferences() { final IAdaptable element = getElement(); IProject project = null; if (element instanceof IJavaProject) { project = ((IJavaProject) element).getProject(); } else if (element instanceof IProject) { project = (IProject) element; } if (project != null) { final IScopeContext context = new ProjectScope(project); return context.getNode(BaseIds.ID); } return null; }
private void initPreferencesStore() { IScopeContext projectScope = new ProjectScope(project); preferences = projectScope.getNode(FileSyncPlugin.PLUGIN_ID); buildPathMap(preferences); preferences.addPreferenceChangeListener(this); preferences.addNodeChangeListener(this); IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); manager.addValueVariableListener(this); jobChangeAdapter = new JobChangeAdapter(){ @Override public void done(IJobChangeEvent event) { // XXX dirty trick to re-evaluate dynamic egit variables on branch change if(!event.getJob().getClass().getName().contains("org.eclipse.egit.ui.internal.branch.BranchOperationUI")){ return; } rebuildPathMap(); } }; Job.getJobManager().addJobChangeListener(jobChangeAdapter); ResourcesPlugin.getWorkspace().addResourceChangeListener(this); }
protected IScopeContext[] createPreferenceScopes( NestedValidatorContext context) { if (context != null) { final IProject project = context.getProject(); if (project != null && project.isAccessible()) { final ProjectScope projectScope = new ProjectScope(project); if (projectScope.getNode( JSONCorePlugin.getDefault().getBundle() .getSymbolicName()).getBoolean( JSONCorePreferenceNames.USE_PROJECT_SETTINGS, false)) return new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() }; } } return new IScopeContext[] { new InstanceScope(), new DefaultScope() }; }
/** * Looks up the task tag strings an priorities from preferences. * * @return */ protected static List<TaskTag> getCurrentTaskTags() { try { final IScopeContext[] contexts = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() }; String rawTagNames = Platform.getPreferencesService().getString(PREF_PLUGIN_ID, ICorePreferenceConstants.TASK_TAG_NAMES, null, contexts); String rawTagPriorities = Platform.getPreferencesService().getString(PREF_PLUGIN_ID, ICorePreferenceConstants.TASK_TAG_PRIORITIES, null, contexts); return createTaskTags(rawTagNames, rawTagPriorities); } catch (Exception e) { IdeLog.logError(CorePlugin.getDefault(), "Failed to lookup task tag strings and priorities", e); //$NON-NLS-1$ return Collections.emptyList(); } }
/** * Returns preferences-specified local webserver address * * @return */ public static InetAddress getServerAddress() { String address = Platform.getPreferencesService().getString(WebServerCorePlugin.PLUGIN_ID, IWebServerPreferenceConstants.PREF_HTTP_SERVER_ADDRESS, null, new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() }); for (InetAddress i : SocketUtil.getLocalAddresses()) { if (i.getHostAddress().equals(address)) { return i; } } try { return InetAddress.getByName(IWebServerPreferenceConstants.DEFAULT_HTTP_SERVER_ADDRESS); } catch (UnknownHostException e) { return null; } }
public boolean hasProjectSpecificOptions(IProject project) { if (project != null) { IScopeContext projectContext = new ProjectScope(project); PreferenceKey[] allKeys = fAllKeys; for (int i = 0; i < allKeys.length; i++) { if (allKeys[i].getStoredValue(projectContext, fManager) != null) { return true; } } } return false; }
public AbstractFormatterSelectionBlock(IStatusChangeListener context, IProject project, IWorkbenchPreferenceContainer container) { super(context, project, ProfileManager.collectPreferenceKeys(TEMP_LIST, true), container); Collections.sort(TEMP_LIST, new Comparator<IScriptFormatterFactory>() { public int compare(IScriptFormatterFactory s1, IScriptFormatterFactory s2) { return s1.getName().compareToIgnoreCase(s2.getName()); } }); factories = TEMP_LIST.toArray(new IScriptFormatterFactory[TEMP_LIST.size()]); TEMP_LIST = new ArrayList<IScriptFormatterFactory>(); sourcePreviewViewers = new ArrayList<SourceViewer>(); // Override the super preferences lookup order. // All the changes to the formatter settings should go to the instance scope (no project scope here). Only the // selected profile will be picked from the project scope and then the instance scope when requested. fLookupOrder = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() }; }
private void createProject(IProject project) throws CoreException { project.create(null); project.open(null); project.setDefaultCharset("UTF-8", null); updateProjectNature(project); IScopeContext context = new ProjectScope(project); System.err.println(context.getName() + ", " + context.getLocation()); /* projectPreferences.put(key, value); projectPreferences.flush();*/ Properties config = new Properties(); config.setProperty("appName", app_name); config.setProperty("appVersion", app_version); config.setProperty("appDeveloper.knuddelsDEV", app_nickname); config.setProperty("appDeveloper.knuddelsDE", app_nickname); config.setProperty("mayBeInstalledBy.1", "*.knuddelsDE"); saveProperties(config, project.getFile("app.config")); loadTemplate(project); }
protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) { IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i= 0; i < projects.length; i++) { IScopeContext projectScope= fPreferencesAccess.getProjectScope(projects[i]); IEclipsePreferences node= projectScope.getNode(JavaUI.ID_PLUGIN); String profileId= node.get(fProfileKey, null); if (oldName.equals(profileId)) { if (newProfile == null) { node.remove(fProfileKey); } else { if (applySettings) { writeToPreferenceStore(newProfile, projectScope); } else { node.put(fProfileKey, newProfile.getID()); } } } } IScopeContext instanceScope= fPreferencesAccess.getInstanceScope(); final IEclipsePreferences uiPrefs= instanceScope.getNode(JavaUI.ID_PLUGIN); if (newProfile != null && oldName.equals(uiPrefs.get(fProfileKey, null))) { writeToPreferenceStore(newProfile, instanceScope); } }
/** * Returns a list of {@link org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.Profile} stored in the <code>scope</code>, * including the built-in profiles. * @param scope the context from which to retrieve the profiles * @return list of profiles, not null * @since 3.3 */ public static List<Profile> loadProfiles(IScopeContext scope) { CleanUpProfileVersioner versioner= new CleanUpProfileVersioner(); ProfileStore profileStore= new ProfileStore(CleanUpConstants.CLEANUP_PROFILES, versioner); List<Profile> list= null; try { list= profileStore.readProfiles(scope); } catch (CoreException e1) { JavaPlugin.log(e1); } if (list == null) { list= getBuiltInProfiles(); } else { list.addAll(getBuiltInProfiles()); } return list; }
/** * {@inheritDoc} */ @Override public void initialize(final IScopeContext context, IAdaptable element) { fContext= context; fSettings= CleanUpPreferenceUtil.loadSaveParticipantOptions(context); settingsChanged(); IJavaProject javaProject= null; if (element != null) { IProject project= (IProject)element.getAdapter(IProject.class); if (project != null) { IJavaProject jProject= JavaCore.create(project); if (jProject != null && jProject.exists()) { javaProject= jProject; } } } configurePreferenceLink(fFormatConfigLink, javaProject, CodeFormatterPreferencePage.PREF_ID, CodeFormatterPreferencePage.PROP_ID); configurePreferenceLink(fOrganizeImportsConfigLink, javaProject, ImportOrganizePreferencePage.PREF_ID, ImportOrganizePreferencePage.PROP_ID); super.initialize(context, element); }
/** * Returns an array of <code>IPostSaveListener</code> which are * enabled in the given context. * * @param context the context from which to retrieve the settings from, not null * @return the current enabled post save listeners according to the preferences */ public synchronized IPostSaveListener[] getEnabledPostSaveListeners(IScopeContext context) { ensureRegistered(); ArrayList<IPostSaveListener> result= null; for (Iterator<SaveParticipantDescriptor> iterator= fDescriptors.values().iterator(); iterator.hasNext();) { SaveParticipantDescriptor descriptor= iterator.next(); if (descriptor.getPreferenceConfiguration().isEnabled(context)) { if (result == null) { result= new ArrayList<IPostSaveListener>(); } result.add(descriptor.getPostSaveListener()); } } if (result == null) { return EMPTY_ARRAY; } else { return result.toArray(new IPostSaveListener[result.size()]); } }
/** * {@inheritDoc} */ public void initialize(final IScopeContext context, IAdaptable element) { boolean enabled= isEnabled(context); fEnableField.setSelection(enabled); fEnableField.setDialogFieldListener(new IDialogFieldListener() { public void dialogFieldChanged(DialogField field) { fContext.getNode(JavaUI.ID_PLUGIN).putBoolean(getPreferenceKey(), fEnableField.isSelected()); enabled(fEnableField.isSelected()); } }); fContext= context; enabled(enabled); }
@Override protected String getSelectedProfileId(IScopeContext instanceScope) { String profileId= instanceScope.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null); if (profileId == null) { // request from bug 129427 profileId= DefaultScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).get(PROFILE_KEY, null); // fix for bug 89739 if (DEFAULT_PROFILE.equals(profileId)) { // default default: IEclipsePreferences node= instanceScope.getNode(JavaCore.PLUGIN_ID); if (node != null) { String tabSetting= node.get(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, null); if (JavaCore.SPACE.equals(tabSetting)) { profileId= JAVA_PROFILE; } } } } return profileId; }
/** * Update all formatter settings with the settings of the specified profile. * @param profile The profile to write to the preference store */ private void writeToPreferenceStore(Profile profile, IScopeContext context) { final Map<String, String> profileOptions= profile.getSettings(); for (int i= 0; i < fKeySets.length; i++) { updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), profileOptions); } final IEclipsePreferences uiPrefs= context.getNode(JavaUI.ID_PLUGIN); if (uiPrefs.getInt(fProfileVersionKey, 0) != fProfileVersioner.getCurrentVersion()) { uiPrefs.putInt(fProfileVersionKey, fProfileVersioner.getCurrentVersion()); } if (context.getName() == InstanceScope.SCOPE) { uiPrefs.put(fProfileKey, profile.getID()); } else if (context.getName() == ProjectScope.SCOPE && !profile.isSharedProfile()) { uiPrefs.put(fProfileKey, profile.getID()); } }
public static String determineProjectLineEnding(IFile file) { String lineEnding = null; if (file != null && file.getProject() != null) { lineEnding = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, new IScopeContext[] { new ProjectScope(file.getProject()) }); } if (lineEnding == null) { lineEnding = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, new IScopeContext[] { InstanceScope.INSTANCE}); } if (lineEnding == null) { lineEnding = System.getProperty(Platform.PREF_LINE_SEPARATOR); } return lineEnding; }
public void save(final IProject project, List<StandaloneRetrieveSetup> retrieveSetups) throws IOException { StandaloneRetrieveSerializer serializer = new StandaloneRetrieveSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer.write(out, retrieveSetups); } finally { try { out.close(); } catch (IOException e) { // we don't care } } final String retrieveSetup = new String(out.toByteArray()); synchronized (projectPrefs) { IEclipsePreferences pref = projectPrefs.get(project); if (pref == null) { IScopeContext projectScope = new ProjectScope(project); pref = projectScope.getNode(IvyPlugin.ID); projectPrefs.put(project, pref); } pref.put(PREF_ID, retrieveSetup); } }
private boolean getChanges(IScopeContext currContext, List<Key> changedSettings) { boolean completeSettings= fProject != null && fDisabledProjectSettings == null; // complete when project settings are enabled boolean needsBuild= false; for (int i= 0; i < fAllKeys.length; i++) { Key key= fAllKeys[i]; String oldVal= key.getStoredValue(currContext, null); String val= key.getStoredValue(currContext, fManager); if (val == null) { if (oldVal != null) { changedSettings.add(key); needsBuild |= !oldVal.equals(key.getStoredValue(fLookupOrder, true, fManager)); } else if (completeSettings) { key.setStoredValue(currContext, key.getStoredValue(fLookupOrder, true, fManager), fManager); changedSettings.add(key); // no build needed } } else if (!val.equals(oldVal)) { changedSettings.add(key); needsBuild |= oldVal != null || !val.equals(key.getStoredValue(fLookupOrder, true, fManager)); } } return needsBuild; }
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; }
/** * Returns the eclipse preferences. * @return the eclipse preferences */ public IEclipsePreferences getEclipsePreferences() { if (eclipsePreferences==null) { IScopeContext iScopeContext = ConfigurationScope.INSTANCE; eclipsePreferences = iScopeContext.getNode(PlugInActivator.PLUGIN_ID); eclipsePreferences.addPreferenceChangeListener(this.getChangeListener()); } return eclipsePreferences; }
public static TimeZone getTimeZone () { final IScopeContext[] scopeContext = new IScopeContext[] { ConfigurationScope.INSTANCE }; final String tzId = Platform.getPreferencesService ().getString ( PLUGIN_ID, TIME_ZONE_KEY, TimeZone.getDefault ().getID (), scopeContext ); if ( Arrays.asList ( TimeZone.getAvailableIDs () ).contains ( tzId ) ) { return TimeZone.getTimeZone ( tzId ); } return TimeZone.getDefault (); }
@Test public void testRemove() throws Exception { IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, false, false); String[] values = new String[] { PreferenceManager.SUFFIX_PREFERENCE_FOR_TEST_IMPLEMENTATION }; SettingsManager.remove(pj.getProject(), values); IScopeContext context = new ProjectScope(pj.getProject()); IEclipsePreferences projectPreferences = context.getNode(Activator.PLUGIN_ID); String val = projectPreferences.get(PreferenceManager.SUFFIX_PREFERENCE_FOR_TEST_IMPLEMENTATION, ""); assertEquals("", val); }
protected void addNodeListeners() { for (IScopeContext scopeContext : SCOPE_CONTEXTS) { try { IEclipsePreferences node = scopeContext.getNode(""); node.accept((curNode) -> { curNode.addPreferenceChangeListener(changeListener); return true; }); node.addNodeChangeListener(nodeListener); } catch (BackingStoreException e) { PrefEditorPlugin.log(e); } } }
protected void removeNodeListeners() { for (IScopeContext scopeContext : SCOPE_CONTEXTS) { try { IEclipsePreferences node = scopeContext.getNode(""); node.removeNodeChangeListener(nodeListener); node.accept((curNode) -> { curNode.removePreferenceChangeListener(changeListener); return true; }); } catch (BackingStoreException e) { PrefEditorPlugin.log(e); } } }
protected void loadPrefs() { try { for (IScopeContext scopeContext : SCOPE_CONTEXTS) { IEclipsePreferences node = scopeContext.getNode(""); node.accept((curNode) -> { loadPrefsFromNode(curNode); return true; }); } } catch (BackingStoreException e) { PrefEditorPlugin.log(e); } }
protected IEclipsePreferences getNode(String categoryName) { for (IScopeContext scopeContext : SCOPE_CONTEXTS) { String preffix = "/" + scopeContext.getName() + "/"; if (categoryName.startsWith(preffix)) { IEclipsePreferences node = scopeContext.getNode(categoryName.substring(preffix.length())); return node; } } return null; }
private String readExportDataDefaultPathFromFile() { IScopeContext context = InstanceScope.INSTANCE; IEclipsePreferences eclipsePreferences = context.getNode(Activator.PLUGIN_ID); String exportDataDefaultpath = eclipsePreferences.get(EXPORT_DATA_DEFAULT_PATH, DEFAULT); exportDataDefaultpath = exportDataDefaultpath.equalsIgnoreCase(DEFAULT) ? " " : exportDataDefaultpath; return exportDataDefaultpath; }
private static String getLineDelimiterPreference(IContainer file) { IScopeContext[] scopeContext; if (file != null && file.getProject() != null) { // project preference scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) }; String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); if (lineDelimiter != null) return lineDelimiter; } // workspace preference scopeContext = new IScopeContext[] { InstanceScope.INSTANCE }; return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext); }
public void createPreferences() { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(GlobalSettings.get("AnalysisProject")); IScopeContext projectScope = new ProjectScope(project); IEclipsePreferences pref = projectScope.getNode(Activator.PLUGIN_ID); for (String stmt : getStatementTypes()) { // pref.putInt(stmt, -16743169); pref.putInt(stmt, -6037505); } try { pref.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } }
public void updateColorPreferences(String stmtType, int color) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(GlobalSettings.get("AnalysisProject")); IScopeContext projectScope = new ProjectScope(project); IEclipsePreferences pref = projectScope.getNode(Activator.PLUGIN_ID); pref.putInt(stmtType, color); try { pref.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } }