Java Code Examples for org.osgi.service.prefs.BackingStoreException

The following examples show how to use org.osgi.service.prefs.BackingStoreException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sarl   Source File: IssueInformationPage.java    License: Apache License 2.0 6 votes vote down vote up
/** Invoked when the wizard is closed with the "Finish" button.
 *
 * @return {@code true} for closing the wizard; {@code false} for keeping it open.
 */
public boolean performFinish() {
	final IEclipsePreferences prefs = SARLEclipsePlugin.getDefault().getPreferences();
	final String login = this.trackerLogin.getText();
	if (Strings.isEmpty(login)) {
		prefs.remove(PREFERENCE_LOGIN);
	} else {
		prefs.put(PREFERENCE_LOGIN, login);
	}
	try {
		prefs.sync();
		return true;
	} catch (BackingStoreException e) {
		ErrorDialog.openError(getShell(), e.getLocalizedMessage(), e.getLocalizedMessage(),
				SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, e));
		return false;
	}
}
 
Example 2
public static String getStartupUrl(Shell shell, IProject project,
    Map<String, Set<String>> hostPagesByModule, boolean isExternal) {
  LegacyGWTHostPageSelectionDialog dialog = new LegacyGWTHostPageSelectionDialog(
      shell, project, hostPagesByModule, isExternal);

  if (dialog.open() == Window.OK) {
    try {
      WebAppProjectProperties.setLaunchConfigExternalUrlPrefix(project,
          dialog.getExternalUrlPrefix());
    } catch (BackingStoreException e) {
      GWTPluginLog.logError(e);
    }
    return dialog.getUrl();
  }

  // User clicked Cancel
  return null;
}
 
Example 3
/**
 * Creates a populated project via the {@link IWebAppProjectCreator}.
 *
 * @throws FileNotFoundException
 * @throws UnsupportedEncodingException
 * @throws MalformedURLException
 * @throws BackingStoreException
 * @throws ClassNotFoundException
 * @throws SdkException
 * @throws CoreException
 * @throws IOException
 */
public static IProject createPopulatedProject(String projectName,
    IWebAppProjectCreator.Participant... creationParticipants) throws MalformedURLException,
    ClassNotFoundException, UnsupportedEncodingException, FileNotFoundException, CoreException,
    SdkException, BackingStoreException, IOException {

  IWebAppProjectCreator projectCreator = ProjectUtilities.createWebAppProjectCreator();
  projectCreator.setProjectName(projectName);
  projectCreator.setPackageName(projectName.toLowerCase());

  for (IWebAppProjectCreator.Participant participant : creationParticipants) {
    participant.updateWebAppProjectCreator(projectCreator);
  }

  projectCreator.create(new NullProgressMonitor());

  return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
 
Example 4
/**
 * This method removes the spaces for tabs and tab width preferences from the default scope of the plugin preference
 * store.
 */
protected void removePluginDefaults()
{
	IEclipsePreferences store = getDefaultPluginPreferenceStore();
	if (store == null)
	{
		return;
	}

	store.remove(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
	store.remove(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);
	try
	{
		store.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
}
 
Example 5
public void clearPreferences(IProject project)
{
	if (project != null)
	{
		// Save to the project scope
		IEclipsePreferences preferences = new ProjectScope(project).getNode(CommonEditorPlugin.PLUGIN_ID);
		preferences.remove(IPreferenceConstants.USER_AGENT_PREFERENCE);
		try
		{
			preferences.flush();
		}
		catch (BackingStoreException e)
		{
			// ignore
		}
	}
}
 
Example 6
public IEclipsePreferences preApply(IEclipsePreferences node) {
	// the node does not need to be the root of the hierarchy
	Preferences root = node.node("/"); //$NON-NLS-1$
	try {
		// we must not create empty preference nodes, so first check if the node exists
		if (root.nodeExists(InstanceScope.SCOPE)) {
			Preferences instance = root.node(InstanceScope.SCOPE);
			// we must not create empty preference nodes, so first check if the node exists
			if (instance.nodeExists(JavaCore.PLUGIN_ID)) {
				cleanJavaCore(instance.node(JavaCore.PLUGIN_ID));
			}
		}
	} catch (BackingStoreException e) {
		// do nothing
	}
	return super.preApply(node);
}
 
Example 7
public boolean performOk() {
	MergeFileAssociation[] currentAssociations = getMergeFileAssociations();
	for (int i = 0; i < currentAssociations.length; i++) {
		currentAssociations[i].remove();
	}
	for (int i = 0; i < mergeFileAssociations.length; i++) {
		Preferences prefs = MergeFileAssociation.getParentPreferences().node(mergeFileAssociations[i].getFileType());
		if (mergeFileAssociations[i].getMergeProgram() == null) prefs.put("mergeProgram", ""); //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$
		else prefs.put("mergeProgram", mergeFileAssociations[i].getMergeProgram()); //$NON-NLS-1$
		if (mergeFileAssociations[i].getParameters() == null)prefs.put("parameters", ""); //$NON-NLS-1$ //$NON-NLS-1$ //$NON-NLS-2$ 
		else prefs.put("parameters", mergeFileAssociations[i].getParameters()); //$NON-NLS-1$
		prefs.putInt("type", mergeFileAssociations[i].getType()); //$NON-NLS-1$
		try {
			prefs.flush();
		} catch (BackingStoreException e) {}
	}
	return super.performOk();
}
 
Example 8
Source Project: CogniCrypt   Source File: Ruleset.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public Ruleset(Preferences subPrefs) throws BackingStoreException {
	String[] keys = subPrefs.keys();
	for (String key : keys) {
		switch (key) {
			case "SelectedVersion":
				this.selectedVersion = subPrefs.get(key, "");
				break;
			case "CheckboxState":
				this.isChecked = subPrefs.getBoolean(key, false);
				break;
			case "FolderName":
				this.folderName = subPrefs.get(key, "");
				break;
			case "Url":
				this.url = subPrefs.get(key, "");
				break;
			default:
				break;
		}
	}
}
 
Example 9
/**
 * Updates the persistent configuration.
 * @param config The new configuration to be saved.
 */
@Override
public void update(Map<ConfigTypes, String> config) {
    ConfigLogger configLogger = new ConfigLogger("Updated Project configuration with the following:");
    for (Map.Entry<ConfigTypes, String> entry : config.entrySet())
    {    
        preferences.put(entry.getKey().toString(), entry.getValue());
        this.config.put(entry.getKey(), entry.getValue());
        configLogger.append(entry);
    }
    configLogger.log();
    try {
        preferences.flush();
    } catch (BackingStoreException e) {
        Logger.log(IStatus.ERROR, e.getMessage());
        e.printStackTrace();
    }
    notifyListeners(config);
}
 
Example 10
Source Project: APICloud-Studio   Source File: EclipseUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Migrate the existing preferences from instance scope to configuration scope and then remove the preference key
 * from the instance scope.
 */
public static void migratePreference(String pluginId, String preferenceKey)
{
	IEclipsePreferences configNode = EclipseUtil.configurationScope().getNode(pluginId);
	if (StringUtil.isEmpty(configNode.get(preferenceKey, null))) // no value in config scope
	{
		IEclipsePreferences instanceNode = EclipseUtil.instanceScope().getNode(pluginId);
		String instancePrefValue = instanceNode.get(preferenceKey, null);
		if (!StringUtil.isEmpty(instancePrefValue))
		{
			// only migrate if there is a value!
			configNode.put(preferenceKey, instancePrefValue);
			instanceNode.remove(preferenceKey);
			try
			{
				configNode.flush();
				instanceNode.flush();
			}
			catch (BackingStoreException e)
			{
				IdeLog.logWarning(CorePlugin.getDefault(), e.getMessage(), e);
			}
		}
	}
}
 
Example 11
Source Project: APICloud-Studio   Source File: ThemeManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the FG, BG, selection and current line colors on our editors.
 * 
 * @param theme
 */
private void setAptanaEditorColorsToMatchTheme(Theme theme)
{
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("com.aptana.editor.common"); //$NON-NLS-1$
	prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT, false);
	prefs.put(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, toString(theme.getForeground()));

	prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, false);
	prefs.put(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, toString(theme.getBackground()));

	prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, false);
	prefs.put(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, toString(theme.getForeground()));

	prefs.put(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR,
			toString(theme.getLineHighlightAgainstBG()));
	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example 12
private void updatePreferences(IEclipsePreferences preferences) {

	 	IEclipsePreferences oldPreferences = loadPreferences();
	 	if (oldPreferences != null) {
			try {
		 		String[] propertyNames = oldPreferences.childrenNames();
				for (int i = 0; i < propertyNames.length; i++){
					String propertyName = propertyNames[i];
				    String propertyValue = oldPreferences.get(propertyName, ""); //$NON-NLS-1$
				    if (!"".equals(propertyValue)) { //$NON-NLS-1$
					    preferences.put(propertyName, propertyValue);
				    }
				}
				// save immediately new preferences
				preferences.flush();
			} catch (BackingStoreException e) {
				// fails silently
			}
		}
	 }
 
Example 13
Source Project: eclipse   Source File: BazelClasspathContainer.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isSourcePath(String path) throws JavaModelException, BackingStoreException {
  Path pp = new File(instance.getWorkspaceRoot().toString() + File.separator + path).toPath();
  IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
  for (IClasspathEntry entry : project.getRawClasspath()) {
    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
      IResource res = root.findMember(entry.getPath());
      if (res != null) {
        String file = res.getLocation().toOSString();
        if (!file.isEmpty() && pp.startsWith(file)) {
          IPath[] inclusionPatterns = entry.getInclusionPatterns();
          if (!matchPatterns(pp, entry.getExclusionPatterns()) && (inclusionPatterns == null
              || inclusionPatterns.length == 0 || matchPatterns(pp, inclusionPatterns))) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
Example 14
public static void setFileNamesCopiedToWebInfLib(IProject project,
    List<String> fileNamesCopiedToWebInfLib) throws BackingStoreException {
  IEclipsePreferences prefs = getProjectProperties(project);
  StringBuilder sb = new StringBuilder();
  boolean addPipe = false;
  for (String fileNameCopiedToWebInfLib : fileNamesCopiedToWebInfLib) {
    if (addPipe) {
      sb.append("|");
    } else {
      addPipe = true;
    }

    sb.append(fileNameCopiedToWebInfLib);
  }

  prefs.put(FILES_COPIED_TO_WEB_INF_LIB, sb.toString());
  prefs.flush();
}
 
Example 15
/**
 * Loads project level preferences from disk.
 */
@Override
public void load() {
    validate();
    config = new HashMap<>();
    try {
        for (String configKey : preferences.keys()) {
            ConfigTypes ct = ConfigTypes.getFromString(configKey);
            if (ct != null) {
                if (ConfigTypes.COMMON_TYPE.contains(ct)) {
                    config.put((ConfigTypes)ct, preferences.get(configKey, STR_EMPTY));
                }
            }
        }
    } catch (BackingStoreException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source Project: typescript.java   Source File: SaveProjectPreferencesJob.java    License: MIT License 6 votes vote down vote up
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
	if (monitor.isCanceled()) {
		return Status.CANCEL_STATUS;
	}
	monitor.beginTask(NLS.bind(TypeScriptCoreMessages.SaveProjectPreferencesJob_taskName, project.getName()), 1);

	try {
		preferences.flush();
	} catch (BackingStoreException e) {
		IStatus status = new Status(Status.ERROR, TypeScriptCorePlugin.PLUGIN_ID,
				"Error while saving  project preferences", e);
		throw new CoreException(status);
	}

	monitor.worked(1);
	monitor.done();

	return Status.OK_STATUS;
}
 
Example 17
Source Project: APICloud-Studio   Source File: UIPlugin.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void updateInitialPerspectiveVersion()
{
	// updates the initial stored version so that user won't get a prompt on a new workspace
	boolean hasStartedBefore = Platform.getPreferencesService().getBoolean(PLUGIN_ID,
			IPreferenceConstants.IDE_HAS_LAUNCHED_BEFORE, false, null);
	if (!hasStartedBefore)
	{
		IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(PLUGIN_ID);
		prefs.putInt(IPreferenceConstants.PERSPECTIVE_VERSION, WebPerspectiveFactory.VERSION);
		prefs.putBoolean(IPreferenceConstants.IDE_HAS_LAUNCHED_BEFORE, true);
		try
		{
			prefs.flush();
		}
		catch (BackingStoreException e)
		{
			IdeLog.logError(getDefault(), Messages.UIPlugin_ERR_FailToSetPref, e);
		}
	}
}
 
Example 18
/**
 * @param uiPrefs
 * @param allOptions
 */
private void addAll(IEclipsePreferences uiPrefs, Map allOptions) {
	try {
		String[] keys = uiPrefs.keys();
		for (int i = 0; i < keys.length; i++) {
			String key = keys[i];
			String val = uiPrefs.get(key, null);
			if (val != null) {
				allOptions.put(key, val);
			}
		}
	} catch (BackingStoreException e) {
		// ignore
	}

}
 
Example 19
@Override
protected void performDefaults()
{
	IEclipsePreferences store = getPluginPreferenceStore();

	store.remove(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
	store.remove(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH);

	setPluginDefaults();
	setTabSpaceCombo();
	super.performDefaults();
	try
	{
		store.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
}
 
Example 20
Source Project: hybris-commerce-eclipse-plugin   Source File: Activator.java    License: Apache License 2.0 6 votes vote down vote up
public void resetPlatform(String platformHome) {
	
	try {
		Preferences preferences = InstanceScope.INSTANCE.getNode("com.hybris.hyeclipse.preferences");
		preferences.put("platform_home", platformHome);
		preferences.flush();
	}
	catch (BackingStoreException e) {
		logError("Failed to persist platform_home", e);
	}
	
	getTypeSystemExporter().setPlatformHome(null);
	getTypeSystemExporter().nullifySystemConfig();
	getTypeSystemExporter().nullifyPlatformConfig();
	getTypeSystemExporter().nullifyTypeSystem();
	getTypeSystemExporter().nullifyAllTypes();
	getTypeSystemExporter().nullifyAllTypeNames();
}
 
Example 21
Source Project: n4js   Source File: WorkingSetManagerBrokerImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * (non-API)
 *
 * <p>
 * Resets the actual and the persistent state of the current broker instance and of all available working set
 * managers. This method does not remove any registered listeners. Also refreshes the common navigator view.
 *
 * <p>
 * This method is exposed only for testing and recovery purposes. It is highly discouraged to invoke from production
 * code.
 */
@VisibleForTesting
public void resetState() {

	for (final Resetable resetable : from(getWorkingSetManagers()).filter(Resetable.class)) {
		resetable.reset();
	}

	try {
		getPreferences().clear();
		getPreferences().flush();
		workingSetTopLevel.set(false);
		for (final TopLevelElementChangedListener listener : topLevelElementChangeListeners) {
			listener.topLevelElementChanged(workingSetTopLevel.get());
		}
		final Collection<WorkingSetManager> managers = getWorkingSetManagers();
		if (!managers.isEmpty()) {
			activeWorkingSetManager.set(managers.iterator().next());
		} else {
			activeWorkingSetManager.set(null);
		}

		refreshNavigator(true);
	} catch (final BackingStoreException e) {
		LOGGER.error("Error occurred while reseting persisted the state.", e);
	}

}
 
Example 22
private void removeFacet(IProject project) throws CoreException {
  GWTProjectPropertyPage projectProperty = new GWTProjectPropertyPage();
  try {
    projectProperty.removeGWTSdkForFacet(project);
  } catch (BackingStoreException e) {
    GwtWtpPlugin.logError("Could not uinstall the GWT facet.", e);
  }
}
 
Example 23
private static void savePreferences(final IScopeContext context) throws BackingStoreException {
	try {
		context.getNode(JavaUI.ID_PLUGIN).flush();
	} finally {
		context.getNode(JavaCore.PLUGIN_ID).flush();
	}
}
 
Example 24
Source Project: xds-ide   Source File: PreferenceCommons.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO : implement better architecture for storing preferences.
 * 
 * @param scope
 * @param qualifier
 * @see org.osgi.service.prefs.Preferences#flush
 */
public static void flush(IScopeContext scope, String qualifier) {
	try {
           IEclipsePreferences node = scope.getNode(qualifier);
           node.flush();
       } catch (BackingStoreException e) {
           LogHelper.logError(e);
       }
}
 
Example 25
Source Project: gwt-eclipse-plugin   Source File: GWTPreferences.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the port number to use for the SourceViewerServer.
 *
 * @param port the port number to save
 */
public static void setSourceViewerServerPort(int port) {
  IEclipsePreferences workspacePreferences = getEclipsePreferences();
  workspacePreferences.putInt(SOURCE_VIEWER_SERVER_PORT, port);
  try {
    workspacePreferences.flush();
  } catch (BackingStoreException e) {
    CorePluginLog.logError(e);
  }
}
 
Example 26
/**
 * Flushes the instance scope of this plug-in.
 * 
 * @since 3.7
 */
public static void flushInstanceScope() {
	try {
		InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).flush();
	} catch (BackingStoreException e) {
		log(e);
	}
}
 
Example 27
Source Project: tm4e   Source File: ThemeContribution.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private Action createAction(final String scopeName, final ITheme theme, boolean whenDark) {
	return new Action(theme.getName()) {
		@Override
		public void run() {
			IThemeManager manager = TMUIPlugin.getThemeManager();
			IThemeAssociation association = new ThemeAssociation(theme.getId(), scopeName, whenDark);
			manager.registerThemeAssociation(association);
			try {
				manager.save();
			} catch (BackingStoreException e) {
				e.printStackTrace();
			}
		}
	};
}
 
Example 28
Source Project: goclipse   Source File: PreferenceHelper.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected void flush(IProject project) throws CommonException {
	try {
		getProjectNode(project).flush();
	} catch(BackingStoreException e) {
		throwCommonException(e);
	}
}
 
Example 29
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * List of build flags for <code>project</code>, taken from the project configuration
 */
public static List<String> getBuildFlags(IProject project) throws BackingStoreException {
  // Get the list of targets from the preferences
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (String s : projectNode.keys()) {
    if (s.startsWith("buildArgs")) {
      builder.add(projectNode.get(s, ""));
    }
  }
  return builder.build();
}
 
Example 30
Source Project: eclipse   Source File: BazelProjectSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link BazelInstance} corresponding to the given <code>project</code>. It looks for
 * the instance that runs for the workspace root configured for that project.
 *
 * @throws BazelNotFoundException
 */
public static BazelCommand.BazelInstance getBazelCommandInstance(IProject project)
    throws BackingStoreException, IOException, InterruptedException, BazelNotFoundException {
  IScopeContext projectScope = new ProjectScope(project.getProject());
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  File workspaceRoot =
      new File(projectNode.get("workspaceRoot", project.getLocation().toFile().toString()));
  return Activator.getDefault().getCommand().getInstance(workspaceRoot);
}