summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-05-22 10:41:05 (EDT)
committerRemi Schnekenburger2014-05-23 05:01:48 (EDT)
commita8580b35d1ae50506e6969771b004d794470d57b (patch)
treee1607da7b62f34b283ce3e323833a400fb689183
parentc3a7ff13f29457d543a70e0500b9bfb11c2f254d (diff)
downloadorg.eclipse.papyrus-a8580b35d1ae50506e6969771b004d794470d57b.zip
org.eclipse.papyrus-a8580b35d1ae50506e6969771b004d794470d57b.tar.gz
org.eclipse.papyrus-a8580b35d1ae50506e6969771b004d794470d57b.tar.bz2
434956: [CSS] Exception in CSS Preference pagerefs/changes/17/27117/2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=434956 - Fix persisting action so avoid creation of broken preference file Change-Id: I96cdc3966fe8e31c47545875c9239cfcd7ed5d52 Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java34
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java11
2 files changed, 30 insertions, 15 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java
index 73be411..c0cb719 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/WorkspaceThemesHelper.java
@@ -94,7 +94,7 @@ public class WorkspaceThemesHelper {
// Get current resource of workspace theme preferences
Resource currentThemefile = findThemeFile();
- WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(currentThemefile.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES);
+ WorkspaceThemes workspaceThemes = getWorspaceThemesRoot(currentThemefile);
// Handle edited themes
for(Theme editedTheme : editedThemesArray) {
@@ -153,7 +153,7 @@ public class WorkspaceThemesHelper {
public void saveWorkspaceThemesPreferenceResource(Theme editedTheme) {
// Get current resource of workspace theme preferences
Resource currentThemefile = findThemeFile();
- WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(currentThemefile.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES);
+ WorkspaceThemes workspaceThemes = getWorspaceThemesRoot(currentThemefile);
updateWorkspaceTheme(editedTheme, workspaceThemes);
@@ -222,13 +222,7 @@ public class WorkspaceThemesHelper {
}
// Get workspace themes
- WorkspaceThemes workspaceThemes = (WorkspaceThemes)EcoreUtil.getObjectByType(themeFile.getContents(), StylesheetsPackage.eINSTANCE.getWorkspaceThemes());
-
- // Create a workspace themes root
- if(workspaceThemes == null) {
- workspaceThemes = StylesheetsFactory.eINSTANCE.createWorkspaceThemes();
- themeFile.getContents().add(workspaceThemes);
- }
+ WorkspaceThemes workspaceThemes = getWorspaceThemesRoot(themeFile);
// Add created theme
workspaceThemes.getThemes().add(theme);
@@ -299,4 +293,26 @@ public class WorkspaceThemesHelper {
IPath themeFilePath = pluginStatePath.append("theme.xmi");
return themeFilePath;
}
+
+ /**
+ * Get root element of an workspace themes resource.
+ *
+ * @param workspaceThemesResource
+ * The resource to inspect
+ * @return The existing root of type {@link WorkspaceThemes}, otherwise create and add to resource
+ */
+ private WorkspaceThemes getWorspaceThemesRoot(Resource workspaceThemesResource) {
+
+ //Verify if root element exit
+ WorkspaceThemes workspaceThemesRoot = (WorkspaceThemes)EcoreUtil.getObjectByType(workspaceThemesResource.getContents(), StylesheetsPackage.Literals.WORKSPACE_THEMES);
+
+ if(workspaceThemesRoot == null) {
+
+ // Create a root element if there is not
+ workspaceThemesRoot = StylesheetsFactory.eINSTANCE.createWorkspaceThemes();
+ workspaceThemesResource.getContents().add(workspaceThemesRoot);
+ }
+
+ return workspaceThemesRoot;
+ }
}
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java
index 24bf4c6..db41bcc 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/theme/ThemeManager.java
@@ -276,13 +276,13 @@ public class ThemeManager {
* @return <code>true</code> if theme can be edited, otherwise <code>false<code>
*/
public boolean isEditable(String id) {
- boolean isEditable = false;
- WorkspaceThemes workspacePreference = getWorkspaceThemesPreferences();
- if(workspacePreference != null) {
+ // Check if theme exist in temporary stack (edited or not saved)
+ boolean isEditable = temporaryThemesList.contains(allThemes.get(id));
- // Check if theme existing in temporary
- isEditable = temporaryThemesList.contains(allThemes.get(id));
+ // Check if theme is in persisted workspace themes
+ WorkspaceThemes workspacePreference = getWorkspaceThemesPreferences();
+ if(workspacePreference != null && !isEditable) {
//Check if theme comes from workspace preferences
Iterator<Theme> themesIterator = workspacePreference.getThemes().iterator();
@@ -290,7 +290,6 @@ public class ThemeManager {
isEditable = id.equals(themesIterator.next().getId());
}
-
}
return isEditable;