Java Code Examples for org.eclipse.core.runtime.preferences.IScopeContext

The following are top voted examples for showing how to use org.eclipse.core.runtime.preferences.IScopeContext. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: eclipse-asciidoctools   File: AsciidocConfiguration.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 2
Project: eclipse   File: BazelProjectSupport.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 3
Project: typescript.java   File: OptionsConfigurationBlock.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 4
Project: bts   File: PreferenceStoreAccessImpl.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 5
Project: che   File: StubUtility.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 6
Project: PerformanceHat   File: AbstractFeedbackPropertyPage.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 7
Project: filesync4eclipse   File: ProjectProperties.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 8
Project: eclipse-wtp-json   File: Validator.java   Source Code and License 6 votes vote down vote up
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() };
}
 
Example 9
Project: APICloud-Studio   File: TaskTag.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
	}
}
 
Example 10
Project: APICloud-Studio   File: WebServerPreferences.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example 11
Project: APICloud-Studio   File: OptionsConfigurationBlock.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 12
Project: APICloud-Studio   File: AbstractFormatterSelectionBlock.java   Source Code and License 6 votes vote down vote up
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() };
}
 
Example 13
Project: Extensions   File: KnuddelsWizard.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 14
Project: Eclipse-Postfix-Code-Completion-Juno38   File: ProfileManager.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 15
Project: Eclipse-Postfix-Code-Completion   File: CleanUpPreferenceUtil.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
   }
 
Example 16
Project: Eclipse-Postfix-Code-Completion-Juno38   File: CleanUpSaveParticipantPreferenceConfiguration.java   Source Code and License 6 votes vote down vote up
/**
 * {@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);
}
 
Example 17
Project: Eclipse-Postfix-Code-Completion   File: SaveParticipantRegistry.java   Source Code and License 6 votes vote down vote up
/**
 * 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()]);
	}
}
 
Example 18
Project: Eclipse-Postfix-Code-Completion   File: AbstractSaveParticipantPreferenceConfiguration.java   Source Code and License 6 votes vote down vote up
/**
 * {@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);
}
 
Example 19
Project: Eclipse-Postfix-Code-Completion   File: FormatterProfileManager.java   Source Code and License 6 votes vote down vote up
@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;
   }
 
Example 20
Project: Eclipse-Postfix-Code-Completion   File: ProfileManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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());
	}
}
 
Example 21
Project: Eclipse-Postfix-Code-Completion   File: ProfileManager.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 22
Project: wt-studio   File: LineEndingUtil.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 23
Project: ant-ivyde   File: RetrieveSetupManager.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 24
Project: Eclipse-Postfix-Code-Completion   File: OptionsConfigurationBlock.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 25
Project: Eclipse-Postfix-Code-Completion-Juno38   File: FormatterProfileManager.java   Source Code and License 6 votes vote down vote up
@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;
   }
 
Example 26
Project: Eclipse-Postfix-Code-Completion-Juno38   File: CleanUpPreferenceUtil.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 27
Project: Eclipse-Postfix-Code-Completion-Juno38   File: CleanUpPreferenceUtil.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
   }
 
Example 28
Project: Eclipse-Postfix-Code-Completion-Juno38   File: SaveParticipantRegistry.java   Source Code and License 6 votes vote down vote up
/**
 * 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()]);
	}
}
 
Example 29
Project: Eclipse-Postfix-Code-Completion-Juno38   File: AbstractSaveParticipantPreferenceConfiguration.java   Source Code and License 6 votes vote down vote up
/**
 * {@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);
}
 
Example 30
Project: AgentWorkbench   File: BundleProperties.java   Source Code and License 5 votes vote down vote up
/**
 * 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;
}
 
Example 31
Project: neoscada   File: Activator.java   Source Code and License 5 votes vote down vote up
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 ();
}
 
Example 32
Project: gw4e.project   File: SettingsManagerTest.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 33
Project: com.onpositive.prefeditor   File: PlatformPreferenceProvider.java   Source Code and License 5 votes vote down vote up
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);
		}
	}
}
 
Example 34
Project: com.onpositive.prefeditor   File: PlatformPreferenceProvider.java   Source Code and License 5 votes vote down vote up
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);
		}
	}
}
 
Example 35
Project: com.onpositive.prefeditor   File: PlatformPreferenceProvider.java   Source Code and License 5 votes vote down vote up
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);
	}
}
 
Example 36
Project: com.onpositive.prefeditor   File: PlatformPreferenceProvider.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 37
Project: Hydrograph   File: ExportAction.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 38
Project: ec4e   File: NewEditorConfigWizard.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 39
Project: visuflow-plugin   File: ProjectPreferences.java   Source Code and License 5 votes vote down vote up
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();
		}
	}
 
Example 40
Project: visuflow-plugin   File: ProjectPreferences.java   Source Code and License 5 votes vote down vote up
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();
	}
}
 
Example 41
Project: visuflow-plugin   File: ProjectPreferences.java   Source Code and License 5 votes vote down vote up
public Map<String, Integer> getAllNodeColors() {
	HashMap<String, Integer> res = new HashMap<>();
	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()) {
		res.put(stmt, pref.getInt(stmt, 0));
	}
	return res;
}
 
Example 42
Project: eclipse-asciidoctools   File: AsciidocConfiguration.java   Source Code and License 5 votes vote down vote up
private static void createSettings(IProject project, String backend, String resourcesPath, String sourcesPath, String stylesheetPath,
		String targetPath) throws BackingStoreException {
	final IScopeContext projectScope = new ProjectScope(project);
	IEclipsePreferences preferences = projectScope.getNode(Activator.PLUGIN_ID);
	if (preferences.keys().length == 0) {
		preferences.put(BACKEND_PROPERTY, backend);
		preferences.put(RESOURCESPATH_PROPERTY, resourcesPath);
		preferences.put(SOURCESPATH_PROPERTY, sourcesPath);
		preferences.put(STYLESHEETPATH_PROPERTY, stylesheetPath);
		preferences.put(TARGETPATH_PROPERTY, targetPath);
		preferences.flush();
	}
}
 
Example 43
Project: eclipse   File: BazelProjectSupport.java   Source Code and License 5 votes vote down vote up
/**
 * List targets configure for <code>project</code>. Each project configured for Bazel is
 * configured to track certain targets and this function fetch this list from the project
 * preferences.
 */
public static List<String> getTargets(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("target")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 44
Project: eclipse   File: BazelProjectSupport.java   Source Code and License 5 votes vote down vote up
/**
 * List of build flags for <code>project</code>, taken from the project configuration
 */
public static List<String> getBuildFlags(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 45
Project: eclipse   File: BazelProjectSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Return the {@link BazelInstance} corresponding to the given <code>project</code>. It looks for
 * the instance that runs for the workspace root configured for that project.
 *
 * @throws BazelNotFoundException
 */
public static BazelCommand.BazelInstance getBazelCommandInstance(IProject project)
    throws BackingStoreException, IOException, InterruptedException, BazelNotFoundException {
  IScopeContext projectScope = new ProjectScope(project.getProject());
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  File workspaceRoot =
      new File(projectNode.get("workspaceRoot", project.getLocation().toFile().toString()));
  return Activator.getDefault().getCommand().getInstance(workspaceRoot);
}
 
Example 46
Project: eclipse   File: BazelProjectSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Convert an Eclipse JDT project into an IntelliJ project view
 */
public static ProjectView getProjectView(IProject project)
    throws BackingStoreException, JavaModelException {
  com.google.devtools.bazel.e4b.projectviews.Builder builder = ProjectView.builder();
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.addBuildFlag(projectNode.get(s, ""));
    } else if (s.startsWith("target")) {
      builder.addTarget(projectNode.get(s, ""));
    }
  }

  IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
  for (IClasspathEntry entry : ((IJavaProject) project).getRawClasspath()) {
    switch (entry.getEntryKind()) {
      case IClasspathEntry.CPE_SOURCE:
        IResource res = root.findMember(entry.getPath());
        if (res != null) {
          builder.addDirectory(res.getProjectRelativePath().removeFirstSegments(1).toOSString());
        }
        break;
      case IClasspathEntry.CPE_CONTAINER:
        String path = entry.getPath().toOSString();
        if (path.startsWith(STANDARD_VM_CONTAINER_PREFIX)) {
          builder.setJavaLanguageLevel(
              Integer.parseInt(path.substring(STANDARD_VM_CONTAINER_PREFIX.length())));
        }
        break;
    }
  }
  return builder.build();
}
 
Example 47
Project: google-cloud-eclipse   File: PreferenceResolver.java   Source Code and License 5 votes vote down vote up
/**
 * Resolve a path like <code>instance://org.example.bundle/path/to/boolean</code> to an
 * {@link IPreferenceStore}.
 * 
 * @param preferenceUri the preference path
 * @return the corresponding store
 * @throws IllegalArgumentException if unable to resolve the URI
 */
public static IPreferenceStore resolve(URI preferenceUri) throws IllegalArgumentException {
  IScopeContext context = resolveScopeContext(preferenceUri.getScheme());
  String path = preferenceUri.getHost();
  if (preferenceUri.getPath() != null) {
    path += preferenceUri.getPath();
  }
  return new ScopedPreferenceStore(context, path);
}
 
Example 48
Project: google-cloud-eclipse   File: PreferenceResolver.java   Source Code and License 5 votes vote down vote up
/**
 * Resolve the given scheme to a preference scope.
 * 
 * @param scheme the preference scheme
 * @return the corresponding preference scope
 * @throws IllegalArgumentException if unable to resolve the scheme to a preference scope
 */
private static IScopeContext resolveScopeContext(String scheme) throws IllegalArgumentException {
  switch (scheme) {
    case "instance":
      return InstanceScope.INSTANCE;
    case "configuration":
      return ConfigurationScope.INSTANCE;
    default:
      throw new IllegalArgumentException("Unknown scheme: " + scheme);
  }
}
 
Example 49
Project: SparkBuilderGenerator   File: PreferenceStoreProvider.java   Source Code and License 5 votes vote down vote up
public PreferenceStoreWrapper providePreferenceStore() {
    IPreferenceStore[] preferenceStores = new IPreferenceStore[2];
    preferenceStores[0] = Activator.getDefault().getPreferenceStore();

    ScopedPreferenceStore jdtCorePreferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.jdt.core");
    if (currentJavaProject.isPresent()) { // if we are in a project add to search scope
        jdtCorePreferenceStore.setSearchContexts(new IScopeContext[] { new ProjectScope(currentJavaProject.get().getProject()), InstanceScope.INSTANCE });
    }
    preferenceStores[1] = jdtCorePreferenceStore;

    return new PreferenceStoreWrapper(new ChainedPreferenceStore(preferenceStores));
}
 
Example 50
Project: hybris-commerce-eclipse-plugin   File: BuildUtils.java   Source Code and License 5 votes vote down vote up
protected static boolean isAutoBuildEnabled() {
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE };
	return service.getBoolean(qualifier, key, false, contexts);
}
 
Example 51
Project: hybris-commerce-eclipse-plugin   File: EclipseRefreshAndBuildHandler.java   Source Code and License 5 votes vote down vote up
protected boolean isAutoBuildEnabled()
{
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE };
	return service.getBoolean(qualifier, key, false, contexts);
}
 
Example 52
Project: hybris-commerce-eclipse-plugin   File: SynchronizePlatformWizard.java   Source Code and License 5 votes vote down vote up
protected boolean isAutoBuildEnabled()
{
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE};
	return service.getBoolean( qualifier, key, false, contexts );
}
 
Example 53
Project: hybris-commerce-eclipse-plugin   File: ImportPlatformWizard.java   Source Code and License 5 votes vote down vote up
protected boolean isAutoBuildEnabled()
{
	IPreferencesService service = Platform.getPreferencesService();
	String qualifier = ResourcesPlugin.getPlugin().getBundle().getSymbolicName();
	String key = "description.autobuilding";
	IScopeContext[] contexts = { InstanceScope.INSTANCE, ConfigurationScope.INSTANCE};
	return service.getBoolean( qualifier, key, false, contexts );
}
 
Example 54
Project: CodeCheckerEclipsePlugin   File: CcConfiguration.java   Source Code and License 5 votes vote down vote up
public CcConfiguration(IProject project) {
    super();
    init();
    this.project = project;

    try {
        if (project.hasNature(CodeCheckerNature.NATURE_ID)) {
            IScopeContext context = new ProjectScope(project);
            projectPreferences = context.getNode(CodeCheckerNature.NATURE_ID);
        }
    } catch (CoreException e) {
        Logger.log(IStatus.ERROR, "" + e);
        Logger.log(IStatus.INFO, "" + e.getStackTrace());
    }
}
 
Example 55
Project: dsl-devkit   File: CheckConfigurationStore.java   Source Code and License 5 votes vote down vote up
/** {@inheritDoc} */
public boolean getBoolean(final String key, final boolean defaultValue) {
  IScopeContext scope = getProjectScope();
  if (scope != null) {
    for (final String node : nodes) {
      boolean result = scope.getNode(node).getBoolean(key, defaultValue);
      if (result != defaultValue) {
        return result;
      }
    }
  }
  return defaultValue;
}
 
Example 56
Project: dsl-devkit   File: CheckConfigurationStore.java   Source Code and License 5 votes vote down vote up
/** {@inheritDoc} */
public int getInt(final String key, final int defaultValue) {
  IScopeContext scope = getProjectScope();
  if (scope != null) {
    for (final String node : nodes) {
      int result = scope.getNode(node).getInt(key, defaultValue);
      if (result != defaultValue) {
        return result;
      }
    }
  }
  return defaultValue;
}
 
Example 57
Project: dsl-devkit   File: CheckConfigurationStore.java   Source Code and License 5 votes vote down vote up
/** {@inheritDoc} */
public String getString(final String key, final String defaultValue) {
  IScopeContext scope = getProjectScope();
  if (scope != null) {
    for (final String node : nodes) {
      String result = scope.getNode(node).get(key, null);
      if (result != null) {
        return result;
      }
    }
  }
  return defaultValue;
}
 
Example 58
Project: fluentmark   File: FluentMkEditor.java   Source Code and License 5 votes vote down vote up
public String getLineDelimiter(IDocument doc) {
	try {
		if (doc != null) return doc.getLineDelimiter(0);
	} catch (BadLocationException e) {}

	// workspace preference
	IScopeContext[] scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
	return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR,
			Strings.EOL, scopeContext);
}
 
Example 59
Project: typescript.java   File: OptionsConfigurationBlock.java   Source Code and License 5 votes vote down vote up
private IEclipsePreferences getNode(IScopeContext context, IWorkingCopyManager manager) {
	IEclipsePreferences node = context.getNode(fQualifier);
	if (manager != null) {
		return manager.getWorkingCopy(node);
	}
	return node;
}
 
Example 60
Project: typescript.java   File: OptionsConfigurationBlock.java   Source Code and License 5 votes vote down vote up
public String getStoredValue(IScopeContext[] lookupOrder, boolean ignoreTopScope, IWorkingCopyManager manager) {
	for (int i = ignoreTopScope ? 1 : 0; i < lookupOrder.length; i++) {
		String value = getStoredValue(lookupOrder[i], manager);
		if (value != null) {
			return value;
		}
	}
	return null;
}