/** * Goes through all the resource-dependent preferences associated with currentProject & key and * updates the preference keys if needed based on projectDelta * * @param currentProject current project of the preferences to be looked at * @param key current key/subcategory of the preferences to be looked at * @param projectDelta the changes to process the preference keys against * @param projectsToSave the projects that need to be updated/saved * @return true if currentProject's preferences were modified */ private boolean processPreferences( IProject currentProject, String key, IResourceDelta projectDelta, Set projectsToSave) { boolean resourceChanges = false; // get the project-key preference node Preferences projectPrefs = CSSContentProperties.getPreferences(currentProject, key, false); if (projectPrefs == null) // no preferences for this project-key, just bail return false; String[] affectedResources; try { affectedResources = projectPrefs.keys(); } catch (BackingStoreException e) { // problems with the project scope... we gonna miss the // changes (but will log) Logger.log( Logger.WARNING_DEBUG, "Problem retreiving JSP Fragment preferences", e); // $NON-NLS-1$ return false; } // go through each preference key (which is really a file name) for (int i = 0; i < affectedResources.length; i++) { // see if preference key/file name was file that was changed IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i])); // no changes for the given resource if (memberDelta == null) continue; if (memberDelta.getKind() == IResourceDelta.REMOVED) { resourceChanges = true; // remove the setting for the original location String currentValue = projectPrefs.get(affectedResources[i], null); projectPrefs.remove(affectedResources[i]); if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) { // if moving, copy the setting for the new location IProject targetProject = ResourcesPlugin.getWorkspace() .getRoot() .getProject(memberDelta.getMovedToPath().segment(0)); Preferences targetPrefs = CSSContentProperties.getPreferences(targetProject, key, true); targetPrefs.put( CSSContentProperties.getKeyFor(memberDelta.getMovedToPath()), currentValue); if (targetProject != currentProject) projectsToSave.add(targetProject); } } } return resourceChanges; }
protected IStatus run(IProgressMonitor monitor) { MultiStatus result = new MultiStatus( CSSContentProperties.CSSCORE_ID, IResourceStatus.FAILED_SETTING_CHARSET, CSSCoreMessages.CSSContentPropertiesManager_Updating, null); monitor = monitor == null ? new NullProgressMonitor() : monitor; try { monitor.beginTask( CSSCoreMessages.CSSContentPropertiesManager_Updating, asyncChanges.size()); try { IProject next; while ((next = getNextChange()) != null) { // just exit if the system is shutting down or has // been shut down // it is too late to change the workspace at this // point anyway if (Platform.getBundle("org.eclipse.osgi").getState() != Bundle.ACTIVE) // $NON-NLS-1$ return Status.OK_STATUS; try { // save the preferences nodes if (next.isAccessible()) { // save css profile preferences Preferences projectPrefs = CSSContentProperties.getPreferences( next, CSSContentProperties.CSS_PROFILE, false); if (projectPrefs != null) projectPrefs.flush(); } } catch (BackingStoreException e) { // we got an error saving String detailMessage = NLS.bind( CSSCoreMessages.CSSContentPropertiesManager_Problems_Updating, next.getFullPath()); result.add( new Status( 1 << (IResourceStatus.FAILED_SETTING_CHARSET % 100 / 33), ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_SETTING_CHARSET, detailMessage, e)); } } monitor.worked(1); } catch (OperationCanceledException e) { throw e; } } finally { monitor.done(); } return result; }