Search in sources :

Example 81 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.

the class ContentTypeMatcher method getMatchingRegexpAssociated.

public Collection<? extends ContentType> getMatchingRegexpAssociated(ContentTypeCatalog catalog, String fileName, final int typeMask) {
    if ((typeMask & IContentType.FILE_PATTERN_SPEC) == 0) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("This method only applies for FILE_REGEXP_SPEC.");
    }
    final IEclipsePreferences root = context.getNode(ContentTypeManager.CONTENT_TYPE_PREF_NODE);
    final Set<ContentType> result = new HashSet<>(3);
    try {
        root.accept(node -> {
            if (node == root)
                return true;
            String[] fileSpecs = ContentTypeSettings.getFileSpecs(node, typeMask);
            for (String fileSpecification : fileSpecs) if (Pattern.matches(catalog.toRegexp(fileSpecification), fileName)) {
                ContentType associated = catalog.getContentType(node.name());
                if (associated != null)
                    result.add(associated);
                break;
            }
            return false;
        });
    } catch (BackingStoreException bse) {
        ContentType.log(ContentMessages.content_errorLoadingSettings, bse);
    }
    return result == null ? Collections.EMPTY_SET : result;
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 82 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.

the class ContentTypeMatcher method getDirectlyAssociated.

/**
 * Enumerates all content types whose settings satisfy the given file spec type mask.
 */
public Collection<ContentType> getDirectlyAssociated(final ContentTypeCatalog catalog, final String fileSpec, final int typeMask) {
    if ((typeMask & (IContentType.FILE_EXTENSION_SPEC | IContentType.FILE_NAME_SPEC)) == 0) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("This method only apply to name or extension based associations");
    }
    // TODO: make sure we include built-in associations as well
    final IEclipsePreferences root = context.getNode(ContentTypeManager.CONTENT_TYPE_PREF_NODE);
    final Set<ContentType> result = new HashSet<>(3);
    try {
        root.accept(node -> {
            if (node == root)
                return true;
            String[] fileSpecs = ContentTypeSettings.getFileSpecs(node, typeMask);
            for (String fileSpecification : fileSpecs) if (fileSpecification.equalsIgnoreCase(fileSpec)) {
                ContentType associated = catalog.getContentType(node.name());
                if (associated != null)
                    result.add(associated);
                break;
            }
            return false;
        });
    } catch (BackingStoreException bse) {
        ContentType.log(ContentMessages.content_errorLoadingSettings, bse);
    }
    return result == null ? Collections.EMPTY_SET : result;
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 83 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.

the class PreferenceForwarderTest method testListenerOnRemove.

/* Comment this test out until we are able to use session tests
	 * with it. - ddw
	 * 	public void testPluginPrefs() {
	 IPluginRegistry registry = InternalPlatform.getPluginRegistry();
	 IPluginDescriptor resPlugin = registry.getPluginDescriptor("org.eclipse.core.resources");
	 Preferences perfs = null;
	 try {
	 perfs = resPlugin.getPlugin().getPluginPreferences();
	 } catch (CoreException ce) {
	 fail("0.1 core exception from getPlugin");
	 }
	 boolean oneBoolean = perfs.getBoolean("OneBoolean");
	 double oneDouble = perfs.getDouble("OneDouble");
	 float oneFloat = perfs.getFloat("OneFloat");
	 int oneInt = perfs.getInt("OneInt");
	 long oneLong = perfs.getLong("OneLong");
	 String oneString = perfs.getString("OneString");
	 assertTrue("1.0 boolean", oneBoolean);
	 assertTrue("2.0 double", oneDouble == 4);
	 assertTrue("3.0 float", oneFloat ==	4.3f);
	 assertTrue("4.0 int", oneInt == 5);
	 assertTrue("5.0 long", oneLong == 6);
	 assertTrue("6.0 string", oneString.equals("A string from the plugin root directory"));
	 int a = 4;
	 int b = 3;
	 }
	 */
/*
	 * Regression test for bug 178815.
	 */
public void testListenerOnRemove() {
    // create a new log listener that will fail if anything is written
    ILogListener logListener = new ILogListener() {

        @Override
        public void logging(IStatus status, String plugin) {
            CoreException ex = new CoreException(status);
            fail("0.99", ex);
        }
    };
    // set a preference value to get everything initialized
    String id = getUniqueString();
    Preferences ps = new PreferenceForwarder(id);
    ps.setValue("key", "value");
    // add a property change listener which will cause one to be
    // added at the preference node level
    IPropertyChangeListener listener = new Preferences.IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
        }
    };
    ps.addPropertyChangeListener(listener);
    ps.setValue("key2", "value2");
    IEclipsePreferences node = InstanceScope.INSTANCE.getNode(id);
    // add our log listener and remove the node. nothing should be logged.
    RuntimeLog.addLogListener(logListener);
    try {
        node.removeNode();
    } catch (BackingStoreException e) {
        fail("4.99", e);
    } catch (IllegalStateException e) {
        fail("5.00", e);
    } finally {
        RuntimeLog.removeLogListener(logListener);
    }
}
Also used : IPropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) PreferenceForwarder(org.eclipse.core.internal.preferences.legacy.PreferenceForwarder)

Example 84 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project webtools.servertools by eclipse.

the class ServerPreferenceModifyListener method preApply.

/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.preferences.PreferenceModifyListener#preApply(org.eclipse.core.runtime.preferences.IEclipsePreferences)
	 */
public IEclipsePreferences preApply(IEclipsePreferences node) {
    Preferences instance = node.node(InstanceScope.SCOPE);
    Preferences runtimes = instance.node(ServerPlugin.PLUGIN_ID);
    if (runtimes != null)
        // $NON-NLS-1$
        removeLockedServerRuntimePreference(runtimes);
    return super.preApply(node);
}
Also used : Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 85 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project mdw-designer by CenturyLinkCloud.

the class WorkspaceConfigurator method setFormatter.

protected void setFormatter() {
    IScopeContext instanceScope = InstanceScope.INSTANCE;
    IEclipsePreferences uiPrefs = instanceScope.getNode(JavaUI.ID_PLUGIN);
    if (getWorkspaceConfig().getCodeFormatter().equals(WorkspaceConfig.CODE_FORMATTERS[0]))
        uiPrefs.put("formatter_profile", "_CenturyLinkIT");
    else
        uiPrefs.put("formatter_profile", "_MDWCodeFormatter");
    try {
        uiPrefs.flush();
        uiPrefs.sync();
        IProfileVersioner profileVersioner = new ProfileVersioner();
        ProfileStore profileStore = new FormatterProfileStore(profileVersioner);
        List<ProfileManager.Profile> profiles = profileStore.readProfiles(instanceScope);
        if (profiles == null)
            profiles = profileStore.readProfiles(DefaultScope.INSTANCE);
        if (profiles == null)
            profiles = new ArrayList<>();
        WorkingCopyManager workingCopyManager = new WorkingCopyManager();
        PreferencesAccess access = PreferencesAccess.getWorkingCopyPreferences(workingCopyManager);
        ProfileManager profileManager = new FormatterProfileManager(profiles, instanceScope, access, profileVersioner);
        profileManager.commitChanges(instanceScope);
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Set Code Formatter");
    }
}
Also used : FormatterProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager) ProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ArrayList(java.util.ArrayList) PreferencesAccess(org.eclipse.jdt.internal.ui.preferences.PreferencesAccess) ProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) FormatterProfileStore(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) WorkingCopyManager(org.eclipse.ui.preferences.WorkingCopyManager) ProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersioner) IProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner) FormatterProfileManager(org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileManager) IProfileVersioner(org.eclipse.jdt.internal.ui.preferences.formatter.IProfileVersioner)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)339 BackingStoreException (org.osgi.service.prefs.BackingStoreException)81 Test (org.junit.Test)37 ProjectScope (org.eclipse.core.resources.ProjectScope)24 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)24 CoreException (org.eclipse.core.runtime.CoreException)22 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)17 IStatus (org.eclipse.core.runtime.IStatus)16 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)15 IOException (java.io.IOException)13 IProject (org.eclipse.core.resources.IProject)13 Status (org.eclipse.core.runtime.Status)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 ContentAssistProcessorTestBuilder (org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder)10 File (java.io.File)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 Job (org.eclipse.core.runtime.jobs.Job)8 Preferences (org.osgi.service.prefs.Preferences)8