aboutsummaryrefslogtreecommitdiffstats
path: root/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordSettingManager.java
blob: 21ff5885bb9bde28ec71c1d2116f418056a818fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package rba.tool.editor.ui.recordandplay;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences;


public class RBASimulationRecordSettingManager {

    public static final RBASimulationRecordSettingManager INSTANCE = new RBASimulationRecordSettingManager();

    public static final String ID_PREFERENCE_NODE = "rba.model.tool"; //$NON-NLS-1$

    private static final String ID_PREFERENCES = "rba.model.tool.recordAndPlay"; //$NON-NLS-1$

    private static final String ID_RECORD_PATH = "RecordFilePath"; //$NON-NLS-1$
    
    /**
     * Save record file path
     * @param path
     */
    public void saveRecordFilePath(final String path) {
        final String oldPath = RBASimulationRecordSettingManager.INSTANCE.getRecordFilePath();
        if (!equals(oldPath, path)) {
            IEclipsePreferences preferences = getPreferences();
            Preferences sub = preferences.node(ID_PREFERENCES);
            sub.put(ID_RECORD_PATH, path);
        }
    }

    /**
     * Get record file path
     * @return path
     */
    public String getRecordFilePath() {
        IEclipsePreferences preferences = getPreferences();
        Preferences sub = preferences.node(ID_PREFERENCES);
        return sub.get(ID_RECORD_PATH, "");
    }

    private IEclipsePreferences getPreferences() {
        return InstanceScope.INSTANCE.getNode(ID_PREFERENCE_NODE);
    }

    /**
     * String equality check
     * @param cs1
     * @param cs2
     * @return
     */
    private boolean equals(String cs1, String cs2) {

        boolean result = false;

        if (cs1 == cs2) {
            result = true;
        }
        if (cs1 == null || cs2 == null) {
            result = false;
        }
        if (cs1.length() != cs2.length()) {
            result = false;
        }
        if (cs1 instanceof String && cs2 instanceof String) {
            result = cs1.equals(cs2);
        }

        return result;
    }

}