Search in sources :

Example 11 with Preferences

use of org.osgi.service.prefs.Preferences in project azure-tools-for-java by Microsoft.

the class PreferenceUtil method unsetPreference.

public static void unsetPreference(String name) {
    Preferences prefs = PluginUtil.getPrefs(com.microsoft.azuretools.core.utils.Messages.prefFileName);
    prefs.remove(name);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        Activator.getDefault().log("Error", e);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 12 with Preferences

use of org.osgi.service.prefs.Preferences in project azure-tools-for-java by Microsoft.

the class PreferenceUtil method loadPreferences.

public static String[] loadPreferences(String name) {
    Preferences prefs = PluginUtil.getPrefs(com.microsoft.azuretools.core.utils.Messages.prefFileName);
    String pref = prefs.get(name, null);
    return pref == null ? null : convertFromPreference(pref);
}
Also used : Preferences(org.osgi.service.prefs.Preferences)

Example 13 with Preferences

use of org.osgi.service.prefs.Preferences in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsPreferences method loadPreferences.

/**
	 * Read and load preference file data.
	 * Converts byte array format data to list of application insights resources.
	 */
private void loadPreferences() {
    Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
    try {
        byte[] data = prefs.getByteArray(PREF_KEY, null);
        if (data != null) {
            ByteArrayInputStream buffer = new ByteArrayInputStream(data);
            ObjectInput input = new ObjectInputStream(buffer);
            try {
                ApplicationInsightsResource[] resources = (ApplicationInsightsResource[]) input.readObject();
                for (ApplicationInsightsResource resource : resources) {
                    if (!ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
                        ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
                    }
                }
            } finally {
                input.close();
            }
        }
    } catch (IOException e) {
        Activator.getDefault().log(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        Activator.getDefault().log(e.getMessage(), e);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ObjectInputStream(java.io.ObjectInputStream)

Example 14 with Preferences

use of org.osgi.service.prefs.Preferences in project tdi-studio-se by Talend.

the class Log4jPrefsSettingManager method createTalendLog4jPrefs.

public Preferences createTalendLog4jPrefs(String prefNode, String value) {
    Preferences log4jSettings = null;
    try {
        log4jSettings = getLog4jPreferences(prefNode, true);
        if (log4jSettings != null) {
            log4jSettings.put(prefNode, value);
        }
        // create log4j prefs file
        log4jSettings.flush();
    } catch (BackingStoreException e) {
        e.printStackTrace();
    }
    return log4jSettings;
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 15 with Preferences

use of org.osgi.service.prefs.Preferences in project tdi-studio-se by Talend.

the class Log4jPrefsSettingManager method getLog4jPreferences.

public Preferences getLog4jPreferences(String log4jPrefsNode, boolean create) {
    try {
        IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        if (create) {
            return new ProjectScope(project).getNode(Log4jPrefsConstants.LOG4J_RESOURCES).node(log4jPrefsNode);
        }
        Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
        if (!node.nodeExists(project.getName())) {
            return null;
        }
        node = node.node(project.getName());
        if (!node.nodeExists(Log4jPrefsConstants.LOG4J_RESOURCES)) {
            return null;
        }
        node = node.node(Log4jPrefsConstants.LOG4J_RESOURCES);
        if (!node.nodeExists(log4jPrefsNode)) {
            return null;
        }
        return node.node(log4jPrefsNode);
    } catch (BackingStoreException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) BackingStoreException(org.osgi.service.prefs.BackingStoreException) PersistenceException(org.talend.commons.exception.PersistenceException) Preferences(org.osgi.service.prefs.Preferences) IProject(org.eclipse.core.resources.IProject)

Aggregations

Preferences (org.osgi.service.prefs.Preferences)15 BackingStoreException (org.osgi.service.prefs.BackingStoreException)8 ProjectScope (org.eclipse.core.resources.ProjectScope)5 IProject (org.eclipse.core.resources.IProject)4 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)4 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)2 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutput (java.io.ObjectOutput)1 ObjectOutputStream (java.io.ObjectOutputStream)1 IPath (org.eclipse.core.runtime.IPath)1 PersistenceException (org.talend.commons.exception.PersistenceException)1