Search in sources :

Example 61 with Preferences

use of org.osgi.service.prefs.Preferences in project jop by jop-devel.

the class JOPPropertyPage method performDefaults.

/* (non-Javadoc)
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performDefaults()
     */
@Override
public void performDefaults() {
    super.performDefaults();
    IProject project = getProject();
    IPath projectRoot = project.getLocation();
    IScopeContext scopeContext = new ProjectScope(project);
    Preferences projectPrefs = scopeContext.getNode(IJOPUIConstants.PLUGIN_ID);
    jopDirectoryEditor.setStringValue(projectPrefs.get(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME, projectRoot.toOSString()));
    IPath defaultQuartusProjectFile = projectRoot.append("quartus").append("cycmin").append("jop").addFileExtension("qpf");
    quartusProjectFileEditor.setStringValue(projectPrefs.get(IJOPLaunchConfigurationConstants.ATTR_QUARTUS_PROJECT, defaultQuartusProjectFile.toOSString()));
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IPath(org.eclipse.core.runtime.IPath) Preferences(org.osgi.service.prefs.Preferences) IProject(org.eclipse.core.resources.IProject)

Example 62 with Preferences

use of org.osgi.service.prefs.Preferences in project snow-owl by b2ihealthcare.

the class EclipsePreferencesTest method testFlushDeadlock.

@Test(timeout = 5000L)
public void testFlushDeadlock() {
    final IEclipsePreferences parent = InstanceScope.INSTANCE.getNode(RUNTIME_TESTS);
    final Preferences child = parent.node("testFlushDeadlock");
    class FlushJob extends Job {

        private final Preferences node;

        FlushJob(final Preferences node) {
            super("testFlushDeadlock");
            this.node = node;
        }

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                node.flush();
            } catch (final BackingStoreException e) {
                return new Status(IStatus.ERROR, RUNTIME_TESTS, "unexpected flush failure", e);
            }
            return Status.OK_STATUS;
        }
    }
    // make sure node is dirty
    child.putBoolean("testFlushDeadlock", true);
    // flush the parent of the load level, and the child
    final Job flushParent = new FlushJob(parent);
    final Job flushChild = new FlushJob(child);
    flushParent.schedule();
    flushChild.schedule();
    try {
        flushParent.join();
        flushChild.join();
    } catch (final InterruptedException e) {
        throw new RuntimeException("Interrupted while updating preferences store.", e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Example 63 with Preferences

use of org.osgi.service.prefs.Preferences in project hale by halestudio.

the class ContentTypeSettings method removeFileSpec.

static void removeFileSpec(IScopeContext context, String contentTypeId, String fileSpec, int type) throws CoreException {
    Preferences contentTypeNode = ContentTypeManager.getInstance().getPreferences(context).node(contentTypeId);
    String key = ContentType.getPreferenceKey(type);
    String existing = contentTypeNode.get(key, null);
    if (existing == null)
        // content type has no settings - nothing to do
        return;
    List existingValues = Util.parseItemsIntoList(contentTypeNode.get(key, null));
    int index = -1;
    int existingCount = existingValues.size();
    for (int i = 0; index == -1 && i < existingCount; i++) if (((String) existingValues.get(i)).equalsIgnoreCase(fileSpec))
        index = i;
    if (index == -1)
        // did not find the file spec to be removed - nothing to do
        return;
    existingValues.remove(index);
    // set new preference value
    String newValue = Util.toListString(existingValues.toArray());
    ContentType.setPreference(contentTypeNode, key, newValue);
    try {
        contentTypeNode.flush();
    } catch (BackingStoreException bse) {
        String message = NLS.bind(ContentMessages.content_errorSavingSettings, contentTypeId);
        IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
        throw new CoreException(status);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) List(java.util.List) Preferences(org.osgi.service.prefs.Preferences)

Example 64 with Preferences

use of org.osgi.service.prefs.Preferences in project hale by halestudio.

the class ContentTypeSettings method addFileSpec.

@SuppressWarnings("unchecked")
static void addFileSpec(IScopeContext context, String contentTypeId, String fileSpec, int type) throws CoreException {
    Preferences contentTypeNode = ContentTypeManager.getInstance().getPreferences(context).node(contentTypeId);
    String key = ContentType.getPreferenceKey(type);
    List existingValues = Util.parseItemsIntoList(contentTypeNode.get(key, null));
    for (int i = 0; i < existingValues.size(); i++) if (((String) existingValues.get(i)).equalsIgnoreCase(fileSpec))
        // don't do anything if already exists
        return;
    existingValues.add(fileSpec);
    // set new preference value
    String newValue = Util.toListString(existingValues.toArray());
    ContentType.setPreference(contentTypeNode, key, newValue);
    try {
        contentTypeNode.flush();
    } catch (BackingStoreException bse) {
        String message = NLS.bind(ContentMessages.content_errorSavingSettings, contentTypeId);
        IStatus status = new Status(IStatus.ERROR, ContentMessages.OWNER_NAME, 0, message, bse);
        throw new CoreException(status);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) List(java.util.List) Preferences(org.osgi.service.prefs.Preferences)

Example 65 with Preferences

use of org.osgi.service.prefs.Preferences in project hale by halestudio.

the class ContentTypeSettings method internalGetDefaultProperty.

public static String internalGetDefaultProperty(ContentType current, final Preferences contentTypePrefs, final QualifiedName key) throws BackingStoreException {
    String id = current.getId();
    if (contentTypePrefs.nodeExists(id)) {
        Preferences contentTypeNode = contentTypePrefs.node(id);
        String propertyValue = contentTypeNode.get(key.getLocalName(), null);
        if (propertyValue != null)
            return propertyValue;
    }
    // try built-in settings
    String propertyValue = current.basicGetDefaultProperty(key);
    if (propertyValue != null)
        return propertyValue;
    // try ancestor
    ContentType baseType = (ContentType) current.getBaseType();
    return baseType == null ? null : internalGetDefaultProperty(baseType, contentTypePrefs, key);
}
Also used : Preferences(org.osgi.service.prefs.Preferences)

Aggregations

Preferences (org.osgi.service.prefs.Preferences)157 BackingStoreException (org.osgi.service.prefs.BackingStoreException)82 EclipsePreferences (org.eclipse.core.internal.preferences.EclipsePreferences)41 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)37 ProjectScope (org.eclipse.core.resources.ProjectScope)18 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)14 IStatus (org.eclipse.core.runtime.IStatus)10 IOException (java.io.IOException)7 Test (org.junit.Test)7 IProject (org.eclipse.core.resources.IProject)6 Status (org.eclipse.core.runtime.Status)6 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)6 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)5 ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 ExportedPreferences (org.eclipse.core.internal.preferences.ExportedPreferences)4 IExportedPreferences (org.eclipse.core.runtime.preferences.IExportedPreferences)4 ContentTypeEncodingPreferences (org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences)4 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)4