Search in sources :

Example 6 with BackingStoreException

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

the class PreferenceUtil method savePreference.

public static void savePreference(String name, String value) {
    try {
        Preferences prefs = PluginUtil.getPrefs(com.microsoft.azuretools.core.utils.Messages.prefFileName);
        prefs.put(name, value);
        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 7 with BackingStoreException

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

the class PreferenceUtil method getPreferenceKeys.

public static String[] getPreferenceKeys() {
    String[] keys = null;
    try {
        Preferences prefs = PluginUtil.getPrefs(com.microsoft.azuretools.core.utils.Messages.prefFileName);
        keys = prefs.keys();
    } catch (BackingStoreException e) {
        Activator.getDefault().log("Error", e);
    }
    return keys;
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 8 with BackingStoreException

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

the class PreferenceUtil method savePreferences.

public static void savePreferences(String name, String[] values) {
    Preferences prefs = PluginUtil.getPrefs(com.microsoft.azuretools.core.utils.Messages.prefFileName);
    prefs.put(name, convertToPreference(values));
    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 9 with BackingStoreException

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

the class Log4jPrefsSettingManager method saveLog4jNodeIntoPref.

public void saveLog4jNodeIntoPref(final String prefNode, final String value) {
    try {
        Preferences log4jSettings = null;
        if (!isLog4jPrefsExist()) {
            // if not exist,create it
            log4jSettings = getLog4jPreferences(prefNode, true);
        } else {
            log4jSettings = getLog4jPreferences(prefNode, false);
        }
        if (log4jSettings != null) {
            log4jSettings.put(prefNode, value);
            // save log4j activate to prefs
            log4jSettings.flush();
        }
    } catch (BackingStoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences)

Example 10 with BackingStoreException

use of org.osgi.service.prefs.BackingStoreException in project cubrid-manager by CUBRID.

the class SelectWorkspaceDialog method okPressed.

/**
	 * Press ok
	 */
protected void okPressed() {
    String workspacePath = workspacePathCombo.getText();
    if (workspacePath.length() == 0) {
        setErrorMessage(Messages.errNoSelectWorkspace);
        return;
    }
    if (isSwitchWorkspace && workspacePath.equals(getLastSetWorkspaceDirectory())) {
        setErrorMessage(Messages.errWorkspaceUsed);
        return;
    }
    //now create
    String error = checkWorkspaceDirectory(workspacePath, true, productName, productVersion);
    if (error != null) {
        setErrorMessage(error);
        return;
    }
    if (!isSwitchWorkspace) {
        boolean isOk = false;
        try {
            Location instanceLoc = Platform.getInstanceLocation();
            isOk = instanceLoc.set(new URL("file", null, workspacePath), true);
        } catch (IllegalStateException e) {
            isOk = false;
        } catch (MalformedURLException e) {
            isOk = false;
        } catch (IOException e) {
            isOk = false;
        }
        if (!isOk) {
            setErrorMessage(Messages.errWorkspaceUsed);
            return;
        }
    }
    recentUsedWorkspaces.remove(workspacePath);
    if (!recentUsedWorkspaces.contains(workspacePath)) {
        recentUsedWorkspaces.add(0, workspacePath);
    }
    // deal with the max history
    if (recentUsedWorkspaces.size() > MAX_HISTORY) {
        List<String> remove = new ArrayList<String>();
        for (int i = MAX_HISTORY; i < recentUsedWorkspaces.size(); i++) {
            remove.add(recentUsedWorkspaces.get(i));
        }
        recentUsedWorkspaces.removeAll(remove);
    }
    // create a string concatenation of all our last used workspaces
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < recentUsedWorkspaces.size(); i++) {
        buf.append(recentUsedWorkspaces.get(i));
        if (i != recentUsedWorkspaces.size() - 1) {
            buf.append(WORKSPACE_SPLIT_CHAR);
        }
    }
    // save them into our preferences
    PREFERENCES.putBoolean(KEY_NOT_SHOW_WORKSPACE_SELECTION_DIALOG, rememberWorkspaceButton.getSelection());
    PREFERENCES.put(KEY_RECENT_WORKSPACES, buf.toString());
    PREFERENCES.put(KEY_LAST_WORKSPACE, workspacePath);
    try {
        PREFERENCES.flush();
    } catch (BackingStoreException e) {
    //NOPMD
    //ignore
    }
    super.okPressed();
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IOException(java.io.IOException) URL(java.net.URL) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

BackingStoreException (org.osgi.service.prefs.BackingStoreException)23 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)10 Preferences (org.osgi.service.prefs.Preferences)8 IOException (java.io.IOException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 ProjectScope (org.eclipse.core.resources.ProjectScope)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 JavaModelManager.getJavaModelManager (org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager)2 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ObjectOutput (java.io.ObjectOutput)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1