use of org.eclipse.core.runtime.preferences.IExportedPreferences in project knime-core by knime.
the class BatchExecutor method setPreferences.
/**
* Sets the workspace preferences using the given file.
*
* @param preferenceFile the preferences file
* @throws FileNotFoundException if the given file is not a file or does not exist
* @throws CoreException if applying the preferences fails
* @since 2.8
*/
public static void setPreferences(final File preferenceFile) throws FileNotFoundException, CoreException {
if (!preferenceFile.isFile()) {
throw new FileNotFoundException("Preference file '" + preferenceFile.getAbsolutePath() + "' does not exist");
}
InputStream in = new BufferedInputStream(new FileInputStream(preferenceFile));
IPreferencesService prefService = Platform.getPreferencesService();
IExportedPreferences prefs = prefService.readPreferences(in);
IPreferenceFilter filter = new IPreferenceFilter() {
@Override
public String[] getScopes() {
return new String[] { InstanceScope.SCOPE, ConfigurationScope.SCOPE, "profile" };
}
@Override
@SuppressWarnings("rawtypes")
public Map getMapping(final String scope) {
// this filter is applicable for all nodes
return null;
}
};
/*
* Calling this method with filters and not the applyPreferences without
* filters is very important! The other method does not merge the
* preferences but deletes all default values.
*/
prefService.applyPreferences(prefs, new IPreferenceFilter[] { filter });
}
use of org.eclipse.core.runtime.preferences.IExportedPreferences in project mdw-designer by CenturyLinkCloud.
the class WorkspaceConfigurator method loadPreferences.
/**
* Loads preferences from the workspace setup site.
*
* @return <code>true</code> if the load was successful
*/
protected boolean loadPreferences() {
// import all
IPreferenceFilter[] filters = new IPreferenceFilter[1];
filters[0] = new IPreferenceFilter() {
public String[] getScopes() {
return new String[] { InstanceScope.SCOPE, ConfigurationScope.SCOPE };
}
public Map<String, PreferenceFilterEntry[]> getMapping(String scope) {
return null;
}
};
String baseUrl = getWorkspaceConfig().getMdwSettings().getWorkspaceSetupUrl();
if (!baseUrl.endsWith("/"))
baseUrl += "/";
InputStream is = null;
try {
URL url = new URL(baseUrl + "MdwWorkspaceSetup.epf");
URLConnection connection = url.openConnection();
is = connection.getInputStream();
IPreferencesService service = Platform.getPreferencesService();
IExportedPreferences prefs = service.readPreferences(is);
service.applyPreferences(prefs, filters);
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Workspace Setup");
return false;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// do nothing
}
}
}
return true;
}
use of org.eclipse.core.runtime.preferences.IExportedPreferences in project polymap4-core by Polymap4.
the class ProjectPreferences method read.
private static void read(ProjectPreferences node, IFile file) throws BackingStoreException, CoreException {
if (file == null || !file.exists()) {
if (Policy.DEBUG_PREFERENCES)
// $NON-NLS-1$
Policy.debug("Unable to determine preference file or file does not exist for node: " + node.absolutePath());
return;
}
Properties fromDisk = loadProperties(file);
// no work to do
if (fromDisk.isEmpty())
return;
// create a new node to store the preferences in.
IExportedPreferences myNode = (IExportedPreferences) ExportedPreferences.newRoot().node(node.absolutePath());
convertFromProperties((EclipsePreferences) myNode, fromDisk, false);
// flag that we are currently reading, to avoid unnecessary writing
boolean oldIsReading = node.isReading;
node.isReading = true;
try {
Platform.getPreferencesService().applyPreferences(myNode);
} finally {
node.isReading = oldIsReading;
}
}
use of org.eclipse.core.runtime.preferences.IExportedPreferences in project knime-core by knime.
the class ImportPreferencesAction method run.
/**
* Invoke the Import wizards selection Wizard.
*/
@Override
public void run() {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow == null) {
// action has been disposed
return;
}
FileDialog fileDialog = new FileDialog(workbenchWindow.getShell(), SWT.OPEN);
fileDialog.setFilterExtensions(new String[] { "*.epf", "*.*" });
fileDialog.setText("Specify the preferences file to import.");
String filePath = fileDialog.open();
if (filePath == null || filePath.trim().length() == 0) {
return;
}
File inFile = new File(filePath);
if (!inFile.isFile() || !inFile.canRead()) {
MessageDialog.openError(workbenchWindow.getShell(), "File Selection Error", "Unable to read from specified location.");
return;
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(inFile));
IPreferencesService prefService = Platform.getPreferencesService();
LOGGER.info("Importing preferences from file " + inFile.getAbsolutePath() + " now ...");
IExportedPreferences prefs = prefService.readPreferences(in);
IPreferenceFilter filter = new IPreferenceFilter() {
@Override
public String[] getScopes() {
return new String[] { InstanceScope.SCOPE, ConfigurationScope.SCOPE, "profile" };
}
@Override
@SuppressWarnings("rawtypes")
public Map getMapping(final String scope) {
// this filter is applicable for all nodes
return null;
}
};
/* Calling this method with filters and not the applyPreferences
* without filters is very important! The other method does not
* merge the preferences but deletes all default values. */
prefService.applyPreferences(prefs, new IPreferenceFilter[] { filter });
LOGGER.info("Import of preferences successfully finished.");
} catch (Throwable t) {
String msg = "Unable to read preferences from selected file";
if (t.getMessage() != null && !t.getMessage().isEmpty()) {
msg = t.getMessage();
}
MessageDialog.openError(workbenchWindow.getShell(), "Error Importing Preferences", msg);
return;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
Aggregations