From: Timo Mueller <timo.muel...@bmw-carit.de>

If a target profile is modified, renamed or deleted globally the
projects using this profile are updated accordingly.
On deletion of a target profile the affected projects will set use the
standard target profile.

Signed-off-by: Timo Mueller <timo.muel...@bmw-carit.de>
---
 .../org/yocto/sdk/ide/YoctoSDKMessages.properties  |  2 +-
 .../ide/preferences/YoctoSDKPreferencePage.java    | 91 +++++++++++++++++++++-
 2 files changed, 89 insertions(+), 4 deletions(-)

diff --git 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
index bfdde41..e779f7d 100644
--- 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
+++ 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/YoctoSDKMessages.properties
@@ -60,7 +60,7 @@ Preferences.Profile.Rename.Dialog.Title = Rename target 
profile
 Preferences.Profile.Rename.Dialog.Message = Please input a new profile name.
 Preferences.Profile.Remove.Title = Remove
 Preferences.Profile.Remove.Dialog.Title = Remove target profile
-Preferences.Profile.Remove.Dialog.Message = Do you really want to the remove 
the target profile "{0}"?
+Preferences.Profile.Remove.Dialog.Message = Do you really want to the remove 
the target profile "{0}"?\nProjects using this target profile will be 
reconfigured to use the standard profile.
 Preferences.Profile.Standard.Modification.Title = Modify standard target 
profile
 Preferences.Profile.Standard.Modification.Message = Standard target profile 
cannot be removed or renamed.
 
diff --git 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java
 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java
index fb015ab..b5963cf 100644
--- 
a/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java
+++ 
b/plugins/org.yocto.sdk.ide/src/org/yocto/sdk/ide/preferences/YoctoSDKPreferencePage.java
@@ -10,6 +10,11 @@
  
*******************************************************************************/
 package org.yocto.sdk.ide.preferences;
 
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.InputDialog;
@@ -25,6 +30,7 @@ import org.yocto.sdk.ide.YoctoProfileElement;
 import org.yocto.sdk.ide.YoctoProfileSetting;
 import org.yocto.sdk.ide.YoctoSDKMessages;
 import org.yocto.sdk.ide.YoctoSDKPlugin;
+import org.yocto.sdk.ide.YoctoSDKProjectNature;
 import org.yocto.sdk.ide.YoctoSDKUtils;
 import org.yocto.sdk.ide.YoctoSDKUtils.SDKCheckRequestFrom;
 import org.yocto.sdk.ide.YoctoUIElement;
@@ -80,8 +86,8 @@ public class YoctoSDKPreferencePage extends PreferencePage 
implements IWorkbench
                        System.out.println(e.getMessage());
                        return result;
                }
-
        }
+
        /*
         * @see IPreferencePage#performOk()
         */
@@ -95,6 +101,8 @@ public class YoctoSDKPreferencePage extends PreferencePage 
implements IWorkbench
                        YoctoProfileElement profileElement = 
yoctoProfileSetting.getCurrentInput();
                        
YoctoSDKUtils.saveProfilesToDefaultStore(profileElement);
 
+                       
updateAffectedProjects(profileElement.getSelectedProfile(), elem);
+
                        return super.performOk();
                } catch (YoctoGeneralException e) {
                        // TODO Auto-generated catch block
@@ -151,9 +159,86 @@ public class YoctoSDKPreferencePage extends PreferencePage 
implements IWorkbench
        public void renameProfile(String oldProfileName, String newProfileName) 
{
                YoctoUIElement oldProfileElement = 
YoctoSDKUtils.getElemFromStore(YoctoSDKPlugin.getProfilePreferenceStore(oldProfileName));
                YoctoSDKUtils.saveElemToStore(oldProfileElement, 
YoctoSDKPlugin.getProfilePreferenceStore(newProfileName));
+
+               renameProfileInAffectedProjects(oldProfileName, newProfileName);
+       }
+
+       public void deleteProfile(String selectedProfile)
+       {
+               resetProfileInAffectedProjects(selectedProfile);
        }
 
-       public void deleteProfile(String selectedProfile) {
-               // do nothing
+       private void resetProfileInAffectedProjects(String usedProfile)
+       {
+               HashSet<IProject> yoctoProjects = 
getAffectedProjects(usedProfile);
+               YoctoProfileElement profileElement = 
YoctoSDKUtils.getProfilesFromDefaultStore();
+               
profileElement.setSelectedProfile(PreferenceConstants.STANDARD_PROFILE_NAME);
+
+               for (IProject project : yoctoProjects)
+               {
+                       
YoctoSDKUtils.saveProfilesToProjectPreferences(profileElement, project);
+                       YoctoUIElement elem = YoctoSDKUtils.getElemFromStore(
+                                                                               
        
YoctoSDKPlugin.getProfilePreferenceStore(PreferenceConstants.STANDARD_PROFILE_NAME));
+                       YoctoSDKUtils.saveElemToProjectEnv(elem, project);
+               }
+       }
+
+       private void renameProfileInAffectedProjects(String oldProfileName, 
String newProfileName) {
+               HashSet<IProject> yoctoProjects = 
getAffectedProjects(oldProfileName);
+               YoctoProfileElement profileElement = 
YoctoSDKUtils.getProfilesFromDefaultStore();
+               profileElement.setSelectedProfile(newProfileName);
+
+               for (IProject project : yoctoProjects)
+               {
+                       
YoctoSDKUtils.saveProfilesToProjectPreferences(profileElement, project);
+               }
+       }
+
+       private void updateAffectedProjects(String usedProfile, YoctoUIElement 
elem) {
+               HashSet<IProject> yoctoProjects = 
getAffectedProjects(usedProfile);
+
+               for (IProject project : yoctoProjects)
+               {
+                       YoctoSDKUtils.saveElemToProjectEnv(elem, project);
+               }
+       }
+
+       private HashSet<IProject> getAffectedProjects(String usedProfile)
+       {
+               HashSet<IProject> yoctoProjects = new HashSet<IProject>();
+
+               IProject[] projects = 
ResourcesPlugin.getWorkspace().getRoot().getProjects();
+
+               for (IProject project : projects)
+               {
+                       try
+                       {
+                               if 
(!project.hasNature(YoctoSDKProjectNature.YoctoSDK_NATURE_ID)) {
+                                       continue;
+                               }
+                       } catch (CoreException e)
+                       {
+                               // project is closed or does not exist so don't 
update
+                               continue;
+                       }
+
+                       if (!projectUsesProfile(project, usedProfile)) {
+                               continue;
+                       }
+
+                       yoctoProjects.add(project);
+               }
+               return yoctoProjects;
+       }
+
+       private boolean projectUsesProfile(IProject project, String profile)
+       {
+               YoctoProfileElement profileElement = 
YoctoSDKUtils.getProfilesFromProjectPreferences(project);
+
+               if (!profileElement.getSelectedProfile().equals(profile)) {
+                       return false;
+               }
+
+               return true;
        }
 }
-- 
1.7.11.7

_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Reply via email to