Skip to content
Snippets Groups Projects
Commit e5f3ef58 authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

compatibility with controlPanel property, for better consistency with other applications

parent 0fbcd6a4
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package fr.soleil.salsa.client.preferences;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
......@@ -19,7 +20,6 @@ import fr.soleil.data.service.DataSourceProducerProvider;
import fr.soleil.data.service.IDataSourceProducer;
import fr.soleil.data.service.PolledRefreshingStrategy;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.lib.project.SystemUtils;
import fr.soleil.model.scanserver.ScanProperties;
import fr.soleil.salsa.client.preferences.UIPreferencesEvent.UIPreferenceEventType;
import fr.soleil.salsa.exception.SalsaPreferencesException;
......@@ -29,18 +29,31 @@ import fr.soleil.salsa.tool.SalsaUtils;
/**
* A class that represents Salsa's preferences
*
* @author Tarek
* @author Tarek, Raphaël GIRARDOT
*/
public class UIPreferences {
/** The logger for messages */
public static final Logger LOGGER = LoggingUtil.getLogger(UIPreferences.class);
/** Control panel property (to recover control panel when not set */
public static final String CONTROL_PANEL_PROPERTY = "ControlPanel";
private static final String CONTROL_PANEL_PROPERTY = "ControlPanel";
/** Control panel property, with first letter to lower case, (to recover control panel when not set */
private static final String ALTERNATE_CONTROL_PANEL_PROPERTY = "controlPanel";
/** Control panel recovered from properties */
public static final String DEFAULT_CONTROL_PANEL;
/** The singleton instance of preferences */
private static final UIPreferences PREFERENCES;
static {
String controlPanel;
try {
controlPanel = System.getProperty(CONTROL_PANEL_PROPERTY,
System.getProperty(ALTERNATE_CONTROL_PANEL_PROPERTY));
} catch (Exception e) {
LOGGER.error("Failed to recover device displaying application", e);
controlPanel = null;
}
DEFAULT_CONTROL_PANEL = controlPanel;
UIPreferences preferences = null;
try {
preferences = UIPreferencesPersistence.loadSystemPreferences();
......@@ -96,25 +109,17 @@ public class UIPreferences {
private String isSendSensor = "false";
private final Map<String, ScanProperties> currentScanPropertiesMap = new HashMap<>();
private final Map<String, ChartProperties> chartPropertiesMap = new HashMap<>();
private final Map<String, PlotProperties> plotPropertiesMap = new HashMap<>();
private final Map<String, ImageProperties> imagePropertiesMap = new HashMap<>();
private final Map<String, Map<String, String>> bookmarkMap = new HashMap<>();
private ArrayList<WeakReference<UIPreferencesListener>> listenerList = new ArrayList<>();
private Collection<WeakReference<UIPreferencesListener>> listeners = new ArrayList<>();
public static UIPreferences getInstance() {
return PREFERENCES;
}
private static String getDefaultControlPanel() {
return SystemUtils.getSystemProperty(CONTROL_PANEL_PROPERTY);
}
protected UIPreferences(String preferenceFile) {
lastPerspectiveName = ObjectUtils.EMPTY_STRING;
refreshTime = null;
......@@ -210,8 +215,8 @@ public class UIPreferences {
private void notifyListeners(UIPreferenceEventType eventType) {
ArrayList<WeakReference<UIPreferencesListener>> toRemove = new ArrayList<>();
UIPreferencesEvent event = new UIPreferencesEvent(this, eventType);
synchronized (listenerList) {
for (WeakReference<UIPreferencesListener> reference : listenerList) {
synchronized (listeners) {
for (WeakReference<UIPreferencesListener> reference : listeners) {
UIPreferencesListener tempListener = reference.get();
if (tempListener == null) {
toRemove.add(reference);
......@@ -219,7 +224,7 @@ public class UIPreferences {
tempListener.preferenceChanged(event);
}
}
listenerList.removeAll(toRemove);
listeners.removeAll(toRemove);
}
toRemove.clear();
}
......@@ -228,8 +233,8 @@ public class UIPreferences {
if (listener != null) {
boolean canAdd = true;
ArrayList<WeakReference<UIPreferencesListener>> toRemove = new ArrayList<>();
synchronized (listenerList) {
for (WeakReference<UIPreferencesListener> reference : listenerList) {
synchronized (listeners) {
for (WeakReference<UIPreferencesListener> reference : listeners) {
UIPreferencesListener tempListener = reference.get();
if (tempListener == null) {
toRemove.add(reference);
......@@ -238,9 +243,9 @@ public class UIPreferences {
}
}
if (canAdd) {
listenerList.add(new WeakReference<UIPreferencesListener>(listener));
listeners.add(new WeakReference<UIPreferencesListener>(listener));
}
listenerList.removeAll(toRemove);
listeners.removeAll(toRemove);
}
toRemove.clear();
}
......@@ -249,22 +254,22 @@ public class UIPreferences {
public void removePreferenceListener(UIPreferencesListener listener) {
if (listener != null) {
ArrayList<WeakReference<UIPreferencesListener>> toRemove = new ArrayList<>();
synchronized (listenerList) {
for (WeakReference<UIPreferencesListener> reference : listenerList) {
synchronized (listeners) {
for (WeakReference<UIPreferencesListener> reference : listeners) {
UIPreferencesListener tempListener = reference.get();
if ((tempListener == null) || (tempListener.equals(listener))) {
toRemove.add(reference);
}
}
listenerList.removeAll(toRemove);
listeners.removeAll(toRemove);
}
toRemove.clear();
}
}
public void removeAllPreferenceListeners() {
synchronized (listenerList) {
listenerList.clear();
synchronized (listeners) {
listeners.clear();
}
}
......@@ -406,7 +411,7 @@ public class UIPreferences {
* @param controlPanel
*/
public void setControlPanel(String controlPanel) {
this.controlPanel = SalsaUtils.isDefined(controlPanel) ? controlPanel : getDefaultControlPanel();
this.controlPanel = SalsaUtils.isDefined(controlPanel) ? controlPanel : DEFAULT_CONTROL_PANEL;
notifyListeners(UIPreferenceEventType.CONTROL_PANEL_CHANGED);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment