summaryrefslogtreecommitdiffstats
path: root/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay
diff options
context:
space:
mode:
Diffstat (limited to 'rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay')
-rw-r--r--rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordPage.java50
-rw-r--r--rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordSettingManager.java71
2 files changed, 121 insertions, 0 deletions
diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordPage.java b/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordPage.java
new file mode 100644
index 0000000..c55581d
--- /dev/null
+++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordPage.java
@@ -0,0 +1,50 @@
+package rba.tool.editor.ui.recordandplay;
+
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.DirectoryFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.preferences.ScopedPreferenceStore;
+
+public class RBASimulationRecordPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ private DirectoryFieldEditor recordPathBrowser;
+
+ private IPreferenceStore preferenceStore;
+
+ private RBASimulationRecordSettingManager manager = RBASimulationRecordSettingManager.INSTANCE;
+
+ private static final String DESCRIPTION = "RBA Simulation Record Path"; //$NON-NLS-1$
+
+ public RBASimulationRecordPage() {
+ super(GRID);
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ recordPathBrowser = new DirectoryFieldEditor("RbaToolRecordPath", "", getFieldEditorParent());
+ addField(recordPathBrowser);
+ }
+
+ @Override
+ public boolean performOk() {
+ manager.saveRecordFilePath(recordPathBrowser.getStringValue());
+ return super.performOk();
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setDescription(DESCRIPTION);
+ }
+
+ @Override
+ public IPreferenceStore getPreferenceStore() {
+ if (preferenceStore == null) {
+ preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, manager.ID_PREFERENCE_NODE);
+ }
+ return preferenceStore;
+ }
+
+}
diff --git a/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordSettingManager.java b/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordSettingManager.java
new file mode 100644
index 0000000..21ff588
--- /dev/null
+++ b/rba.tool.editor.ui/src/rba/tool/editor/ui/recordandplay/RBASimulationRecordSettingManager.java
@@ -0,0 +1,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;
+ }
+
+}