public void setPaletteCustomization(PaletteCustomization prefs) { try { JSONObject jsonObject = null; if (prefs != null) { jsonObject = new JSONObject(); if (prefs.drawers != null) { jsonObject.put(PaletteCustomization.DRAWERS, prefs.drawers); } if (prefs.drawerEntries != null && prefs.drawerEntries.size() > 0) { jsonObject.put(PaletteCustomization.DRAWER_ENTRIES, prefs.drawerEntries); } if (prefs.entryProperties != null && prefs.entryProperties.size() > 0) { jsonObject.put(PaletteCustomization.ENTRY_PROPERTIES, prefs.entryProperties); } } if (jsonObject != null && jsonObject.keys().hasNext()) { setProperty( PALETTE_CUSTOMIZATION_SETTING, ServoyJSONObject.toString(jsonObject, false, false, false)); } else { removeProperty(PALETTE_CUSTOMIZATION_SETTING); } } catch (JSONException e) { ServoyLog.logError("Could not save palette preferences", e); } }
public PaletteCustomization getPaletteCustomization() { String property = getProperty(PALETTE_CUSTOMIZATION_SETTING, null); if (property != null) { try { Map map = (Map) ServoyJSONObject.toJava(new ServoyJSONObject(property, false)); return new PaletteCustomization( (List<String>) map.get(PaletteCustomization.DRAWERS), (Map<String, List<String>>) map.get(PaletteCustomization.DRAWER_ENTRIES), (Map<String, Object>) map.get(PaletteCustomization.ENTRY_PROPERTIES)); } catch (JSONException e) { ServoyLog.logError("Could not read palette preferences", e); } } return null; }