Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Dumais2015-04-13 11:02:14 -0400
committerGerrit Code Review @ Eclipse.org2015-04-17 14:59:36 -0400
commit9cc312e1fef3e8db9e818a6002eeca25b587a5bd (patch)
tree2608431ba72b5213b408a2072fb9497c8b2b0a87
parentd071e969b73264b7b54242a1c38ee7786453c087 (diff)
downloadorg.eclipse.cdt-9cc312e1fef3e8db9e818a6002eeca25b587a5bd.tar.gz
org.eclipse.cdt-9cc312e1fef3e8db9e818a6002eeca25b587a5bd.tar.xz
org.eclipse.cdt-9cc312e1fef3e8db9e818a6002eeca25b587a5bd.zip
Bug 462353 - [visualizer] Add support for persistent List<T> and
Map<String,T> parameters in PersistentSettingsManager Change-Id: I77fc411e7484e41a9b66bf388a4120bc51a78549
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.classpath7
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.project28
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.settings/org.eclipse.jdt.core.prefs70
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/META-INF/MANIFEST.MF9
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/about.html24
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/build.properties16
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/pom.xml66
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/AllTests.java27
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/PersistentSettingsManagerTest.java436
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/MementoUtils.java41
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/PersistentSettingsManager.java387
-rw-r--r--pom.xml1
12 files changed, 1053 insertions, 59 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.classpath b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.classpath
new file mode 100644
index 0000000000..098194ca4b
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.project b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.project
new file mode 100644
index 0000000000..8eadc1d468
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.settings/org.eclipse.jdt.core.prefs b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..0cabaef07c
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,70 @@
+#Tue Jun 24 11:05:41 PDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=error
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=error
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..8ee578d9b3
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: DSF-GDB test fragment
+Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.junit
+
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/about.html b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/about.html
new file mode 100644
index 0000000000..04492dd7e1
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>May 14, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ No newline at end of file
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/build.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/build.properties
new file mode 100644
index 0000000000..6e32543e0e
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 2015 Ericsson AB and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Marc Dumais (Ericsson) - initial Version
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html
+src.includes = about.html
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/pom.xml b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/pom.xml
new file mode 100644
index 0000000000..fadc0e810e
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.cdt</groupId>
+ <artifactId>cdt-parent</artifactId>
+ <version>8.6.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <version>1.0.0-SNAPSHOT</version>
+ <artifactId>org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+
+ <!-- Uncommenting this is useful when the repo is built first then you want to run tests on this plugin only -->
+ <!--
+ <repositories>
+ <repository>
+ <id>cdt.repo</id>
+ <url>file:/${basedir}/../../releng/org.eclipse.cdt.repo/target/repository</url>
+ <layout>p2</layout>
+ </repository>
+ </repositories>
+ -->
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <useUIHarness>true</useUIHarness>
+ <argLine>${tycho.testArgLine} ${base.ui.test.vmargs}</argLine>
+ <includes>
+ <include>**/AllTests.*</include>
+ </includes>
+ <testFailureIgnore>true</testFailureIgnore>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>target-platform-configuration</artifactId>
+ <configuration>
+ <dependency-resolution>
+ <extraRequirements>
+ <requirement>
+ <type>eclipse-feature</type>
+ <id>org.eclipse.platform</id>
+ <versionRange>0.0.0</versionRange>
+ </requirement>
+ <requirement>
+ <type>eclipse-feature</type>
+ <id>org.eclipse.cdt</id>
+ <versionRange>0.0.0</versionRange>
+ </requirement>
+ </extraRequirements>
+ </dependency-resolution>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/AllTests.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/AllTests.java
new file mode 100644
index 0000000000..73e2be2278
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/AllTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson AB and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc Dumais (Ericsson) - Initial Implementation
+ *******************************************************************************/
+package org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.test;
+
+import org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.test.PersistentSettingsManagerTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+
+@RunWith(Suite.class)
+
+// Add additional test case classes below
+@SuiteClasses({
+ PersistentSettingsManagerTest.class,
+})
+public class AllTests {
+ // Often overriding BeforeClass method here
+}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/PersistentSettingsManagerTest.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/PersistentSettingsManagerTest.java
new file mode 100644
index 0000000000..d008846e71
--- /dev/null
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/ui/test/PersistentSettingsManagerTest.java
@@ -0,0 +1,436 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc Dumais (Ericsson) - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.utils.PersistentSettingsManager;
+import org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.utils.PersistentSettingsManager.PersistentListParameter;
+import org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.utils.PersistentSettingsManager.PersistentMapParameter;
+import org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.utils.PersistentSettingsManager.PersistentParameter;
+import org.junit.Test;
+
+public class PersistentSettingsManagerTest {
+
+ // ---- variables ----
+
+ /** persistent settings manager */
+ private PersistentSettingsManager m_persistentSettingsManager1;
+ private PersistentSettingsManager m_persistentSettingsManager2;
+ private PersistentSettingsManager m_persistentSettingsManager3;
+
+ // set of persistent parameters
+ private PersistentParameter<String> m_stringParam;
+ private PersistentParameter<Boolean> m_booleanParam;
+ private PersistentParameter<Integer> m_integerParam;
+ private PersistentListParameter<String> m_listOfStringParam;
+ private PersistentListParameter<Boolean> m_listOfBooleanParam;
+ private PersistentListParameter<Integer> m_listOfIntegerParam;
+ private PersistentMapParameter<String> m_mapOfStringParam;
+ private PersistentMapParameter<Boolean> m_mapOfBooleanParam;
+ private PersistentMapParameter<Integer> m_mapOfIntegerParam;
+
+ // set of per-instance parameters
+ private PersistentParameter<String> m_stringParamInstance1;
+ private PersistentParameter<String> m_stringParamInstance2;
+ private PersistentParameter<String> m_stringParamInstance3;
+
+ // set of global parameters
+ private PersistentParameter<String> m_stringGlobalParamInstance1;
+ private PersistentParameter<String> m_stringGlobalParamInstance2;
+ private PersistentParameter<String> m_stringGlobalParamInstance3;
+
+ // random number generator
+ private Random m_random = new Random();
+
+
+ // ---- constants ----
+ private final static int NUM_LIST_ELEMENTS = 10;
+
+ private final static String INSTANCE_ID_1 = "instance1";
+ private final static String INSTANCE_ID_2 = "instance2";
+ private final static String INSTANCE_ID_3 = "instance3";
+
+ private final static String DEFAULT_STRING = "Default String";
+ private final static Boolean DEFAULT_BOOLEAN = false;
+ private final static Integer DEFAULT_INTEGER = 1234321;
+
+ private final static String DEFAULT_STRING_VAL_INSTANCE1 = "Default String Instance 1";
+ private final static String DEFAULT_STRING_VAL_INSTANCE2 = "Default String Instance 2";
+ private final static String DEFAULT_STRING_VAL_INSTANCE3 = "Default String Instance 3";
+ private final static String DEFAULT_STRING_VAL_SHARED = "Default String Shared Instance";
+
+
+ public PersistentSettingsManagerTest() {
+ // 3 instances of managers - to simulate, for example, 3 views each having one manager
+ m_persistentSettingsManager1 = new PersistentSettingsManager("PersistentSettingsManagerTest", INSTANCE_ID_1);
+ m_persistentSettingsManager2 = new PersistentSettingsManager("PersistentSettingsManagerTest", INSTANCE_ID_2);
+ m_persistentSettingsManager3 = new PersistentSettingsManager("PersistentSettingsManagerTest", INSTANCE_ID_3);
+
+ // one persistent parameter for each supported type:
+ // simple types
+ m_stringParam = m_persistentSettingsManager1.getNewParameter(String.class, "String Parameter", false, DEFAULT_STRING);
+ m_booleanParam = m_persistentSettingsManager1.getNewParameter(Boolean.class, "Boolean Parameter", false, DEFAULT_BOOLEAN);
+ m_integerParam = m_persistentSettingsManager1.getNewParameter(Integer.class, "Integer Parameter", false, DEFAULT_INTEGER);
+ // List<T>
+ m_listOfStringParam = m_persistentSettingsManager1.getNewListParameter(String.class, "List of String Parameter", false, new ArrayList<String>());
+ m_listOfBooleanParam = m_persistentSettingsManager1.getNewListParameter(Boolean.class, "List of Boolean Parameter", false, new ArrayList<Boolean>());
+ m_listOfIntegerParam = m_persistentSettingsManager1.getNewListParameter(Integer.class, "List of Integer Parameter", false, new ArrayList<Integer>());
+ // Map<String,T>
+ m_mapOfStringParam = m_persistentSettingsManager1.getNewMapParameter(String.class, "Map of String Parameter", true, new HashMap<String,String>());
+ m_mapOfBooleanParam = m_persistentSettingsManager1.getNewMapParameter(Boolean.class, "Map of Boolean Parameter", true, new HashMap<String,Boolean>());
+ m_mapOfIntegerParam = m_persistentSettingsManager1.getNewMapParameter(Integer.class, "Map of Integer Parameter", true, new HashMap<String,Integer>());
+
+ // simulate 3 instances using the same parameter, using "per instance" persistence (i.e. they'll be persisted independently)
+ m_stringParamInstance1 = m_persistentSettingsManager1.getNewParameter(String.class, "Per-instance String Parameter", true, DEFAULT_STRING_VAL_INSTANCE1);
+ m_stringParamInstance2 = m_persistentSettingsManager2.getNewParameter(String.class, "Per-instance String Parameter", true, DEFAULT_STRING_VAL_INSTANCE2);
+ m_stringParamInstance3 = m_persistentSettingsManager3.getNewParameter(String.class, "Per-instance String Parameter", true, DEFAULT_STRING_VAL_INSTANCE3);
+
+ // This is to simulate a persistent parameter, being "shared" by 3 instances (e.g. views). So, the 3 instances are persisted as a single parameter.
+ m_stringGlobalParamInstance1 = m_persistentSettingsManager1.getNewParameter(String.class, "Global String Parameter", false, DEFAULT_STRING_VAL_SHARED);
+ m_stringGlobalParamInstance2 = m_persistentSettingsManager2.getNewParameter(String.class, "Global String Parameter", false, DEFAULT_STRING_VAL_SHARED);
+ m_stringGlobalParamInstance3 = m_persistentSettingsManager3.getNewParameter(String.class, "Global String Parameter", false, DEFAULT_STRING_VAL_SHARED);
+ }
+
+ // testcases
+
+ /** Test Un-supported base type - we expect an Exception */
+ @Test(expected = Exception.class)
+ public void testUnsupportedBaseType() throws Exception {
+ m_persistentSettingsManager1.getNewParameter(Float.class, "Float Parameter", false, 1.0f);
+ }
+
+ /** Test Un-supported List type - we expect an Exception */
+ @Test(expected = Exception.class)
+ public void testUnsupportedListType() throws Exception {
+ m_persistentSettingsManager1.getNewListParameter(Float.class, "List of Float Parameter", false, new ArrayList<Float>());
+ }
+
+ /** Test Un-supported Map type - we expect an Exception */
+ @Test(expected = Exception.class)
+ public void testUnsupportedMapType() throws Exception {
+ m_persistentSettingsManager1.getNewMapParameter(Float.class, "Map of Float Parameter", false, new HashMap<String,Float>());
+ }
+
+ /** Test persisting one String value */
+ @Test
+ public void testPersistentParamString() throws Exception {
+ // no value persisted yet - should return default
+ assertEquals(DEFAULT_STRING, m_stringParam.value());
+
+ // set a value
+ String randomString = getRandomString();
+ m_stringParam.set(randomString);
+ // get cached value
+ assertEquals(randomString, m_stringParam.value());
+ // force re-read from storage
+ assertEquals(randomString, m_stringParam.value(true));
+
+ // set a different value
+ randomString = getRandomString();
+ m_stringParam.set(randomString);
+ // get cached value
+ assertEquals(randomString, m_stringParam.value());
+ // force re-read from storage
+ assertEquals(randomString, m_stringParam.value(true));
+ }
+
+ /** Test persisting one Boolean value */
+ @Test
+ public void testPersistentParamBoolean() throws Exception {
+ // no value persisted yet - should return default
+ assertEquals(DEFAULT_BOOLEAN, m_booleanParam.value());
+
+ // set a value
+ m_booleanParam.set(!DEFAULT_BOOLEAN);
+ // get cached value
+ assertEquals(!DEFAULT_BOOLEAN, m_booleanParam.value());
+ // force re-read from storage
+ assertEquals(!DEFAULT_BOOLEAN, m_booleanParam.value(true));
+ }
+
+ /** Test persisting one Integer value */
+ @Test
+ public void testPersistentParamInteger() throws Exception {
+ // no value persisted yet - should return default
+ assertEquals(DEFAULT_INTEGER, m_integerParam.value());
+
+ // set a value
+ Integer randomInt = getRandomInt();
+ m_integerParam.set(randomInt);
+ // get cached value
+ assertEquals(randomInt, m_integerParam.value());
+ // force re-read from storage
+ assertEquals(randomInt, m_integerParam.value(true));
+
+ // set a different value
+ randomInt = getRandomInt();
+ m_integerParam.set(randomInt);
+ // get cached value
+ assertEquals(randomInt, m_integerParam.value());
+ // force re-read from storage
+ assertEquals(randomInt, m_integerParam.value(true));
+ }
+
+ /** Test persisting a List of String */
+ @Test
+ public void testPersistentParamListOfString() throws Exception {
+ // no value persisted yet - should return default (empty list)
+ List<String> list = m_listOfStringParam.value();
+ assertEquals(0,list.size());
+ // generate list of random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ list.add(getRandomString());
+ }
+ m_listOfStringParam.set(list);
+
+ // get cached value
+ List<String> list2 = m_listOfStringParam.value();
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ // force re-read from storage
+ list2 = m_listOfStringParam.value(true);
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ }
+
+ /** Test persisting a List of Boolean */
+ @Test
+ public void testPersistentParamListOfBoolean() throws Exception {
+ // no value persisted yet - should return default (empty list)
+ List<Boolean> list = m_listOfBooleanParam.value();
+ assertEquals(0,list.size());
+ // generate list of random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ list.add(getRandomBoolean());
+ }
+ m_listOfBooleanParam.set(list);
+
+ // get cached value
+ List<Boolean> list2 = m_listOfBooleanParam.value();
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ // force re-read from storage
+ list2 = m_listOfBooleanParam.value(true);
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ }
+
+ /** Test persisting a List of Integer */
+ @Test
+ public void testPersistentParamListofInteger() throws Exception {
+ // no value persisted yet - should return default (empty list)
+ List<Integer> list = m_listOfIntegerParam.value();
+ assertEquals(0,list.size());
+ // generate list of random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ list.add(getRandomInt());
+ }
+ m_listOfIntegerParam.set(list);
+
+ List<Integer> list2;
+ // get cached value
+ list2 = m_listOfIntegerParam.value();
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ // force re-read from storage
+ list2 = m_listOfIntegerParam.value(true);
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ assertEquals(list.get(i), list2.get(i));
+ }
+ }
+
+
+ /** Test persisting a Map of String */
+ @Test
+ public void testPersistentParamMapOfString() throws Exception {
+ // no value persisted yet - should return default (empty Map)
+ Map<String,String> map = m_mapOfStringParam.value();
+ assertEquals(0,map.size());
+
+ // generate random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ map.put(getRandomString(), getRandomString());
+ }
+ m_mapOfStringParam.set(map);
+
+ // get cached value
+ Map<String,String> map2 = m_mapOfStringParam.value();
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+
+ // force re-read from storage
+ map2 = m_mapOfStringParam.value(true);
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+ }
+
+ /** Test persisting a Map of Boolean*/
+ @Test
+ public void testPersistentParamMapOfBoolean() throws Exception {
+ // no value persisted yet - should return default (empty Map)
+ Map<String,Boolean> map = m_mapOfBooleanParam.value();
+ assertEquals(0,map.size());
+
+ // generate random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ map.put(getRandomString(), getRandomBoolean());
+ }
+ m_mapOfBooleanParam.set(map);
+
+ // get cached value
+ Map<String,Boolean> map2 = m_mapOfBooleanParam.value();
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+
+ // force re-read from storage
+ map2 = m_mapOfBooleanParam.value(true);
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+ }
+
+ /** Test persisting a List of Integer */
+ @Test
+ public void testPersistentParamMapOfInteger() throws Exception {
+ // no value persisted yet - should return default (empty Map)
+ Map<String,Integer> map = m_mapOfIntegerParam.value();
+ assertEquals(0,map.size());
+
+ // generate random elements
+ for(int i = 0; i < NUM_LIST_ELEMENTS; i++) {
+ map.put(getRandomString(), getRandomInt());
+ }
+ m_mapOfIntegerParam.set(map);
+
+ // get cached value
+ Map<String,Integer> map2 = m_mapOfIntegerParam.value();
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+
+ // force re-read from storage
+ map2 = m_mapOfIntegerParam.value(true);
+ assertEquals(map.size(), map2.size());
+ for(String key : map2.keySet()) {
+ assertEquals(map2.get(key), map.get(key));
+ }
+ }
+
+ /** This test simulates 3 different instances (e.g. views) writing and reading the same persistent
+ * parameter. In this case the parameter is defined as "per-instance" (vs "global"), so each
+ * instance has it's own independent copy of the persistent parameter. */
+ @Test
+ public void testMultipleInstances() throws Exception {
+ // no values persisted yet - should return defaults
+ assertEquals(DEFAULT_STRING_VAL_INSTANCE1, m_stringParamInstance1.value());
+ assertEquals(DEFAULT_STRING_VAL_INSTANCE2, m_stringParamInstance2.value());
+ assertEquals(DEFAULT_STRING_VAL_INSTANCE3, m_stringParamInstance3.value());
+
+ // set values - since the parameters were defined to save values per-instance, they should be
+ // persisted independently (i.e. not overwrite each other)
+ String randomString1 = getRandomString();
+ String randomString2 = getRandomString();
+ String randomString3 = getRandomString();
+ m_stringParamInstance1.set(randomString1);
+ m_stringParamInstance2.set(randomString2);
+ m_stringParamInstance3.set(randomString3);
+ assertEquals(randomString1, m_stringParamInstance1.value(true));
+ assertEquals(randomString2, m_stringParamInstance2.value(true));
+ assertEquals(randomString3, m_stringParamInstance3.value(true));
+
+ // set different values
+ randomString1 = getRandomString();
+ randomString2 = getRandomString();
+ randomString3 = getRandomString();
+ m_stringParamInstance1.set(randomString1);
+ m_stringParamInstance2.set(randomString2);
+ m_stringParamInstance3.set(randomString3);
+ assertEquals(randomString1, m_stringParamInstance1.value(true));
+ assertEquals(randomString2, m_stringParamInstance2.value(true));
+ assertEquals(randomString3, m_stringParamInstance3.value(true));
+ }
+
+
+ /** This test simulates 3 different instances (e.g. views) writing and reading the same persistent
+ * parameter. In this case the parameter is defined as "global" (vs "per-instance"), so only one
+ * copy is shared between the instances. */
+ @Test
+ public void testGlobalParamsWithMultipleInstances() throws Exception {
+ // no values persisted yet - should return defaults
+ assertEquals(DEFAULT_STRING_VAL_SHARED, m_stringGlobalParamInstance1.value());
+ assertEquals(DEFAULT_STRING_VAL_SHARED, m_stringGlobalParamInstance2.value());
+ assertEquals(DEFAULT_STRING_VAL_SHARED, m_stringGlobalParamInstance3.value());
+
+ // set values - since the parameters were defined to save values per-instance, they should be
+ // persisted independently
+ String randomString1 = getRandomString();
+ String randomString2 = getRandomString();
+ String randomString3 = getRandomString();
+ m_stringGlobalParamInstance1.set(randomString1);
+ m_stringGlobalParamInstance2.set(randomString2);
+ m_stringGlobalParamInstance3.set(randomString3);
+ // since the parameters are global, they share the same storage... So the last value written
+ // will be persisted
+ assertEquals(randomString3, m_stringGlobalParamInstance1.value(true));
+ assertEquals(randomString3, m_stringGlobalParamInstance2.value(true));
+ assertEquals(randomString3, m_stringGlobalParamInstance3.value(true));
+
+ // set different values
+ randomString1 = getRandomString();
+ randomString2 = getRandomString();
+ randomString3 = getRandomString();
+ m_stringGlobalParamInstance1.set(randomString1);
+ m_stringGlobalParamInstance2.set(randomString2);
+ m_stringGlobalParamInstance3.set(randomString3);
+ // since the parameters are global, they share the same storage... So the last value written
+ // will be persisted
+ assertEquals(randomString3, m_stringGlobalParamInstance1.value(true));
+ assertEquals(randomString3, m_stringGlobalParamInstance2.value(true));
+ assertEquals(randomString3, m_stringGlobalParamInstance3.value(true));
+ }
+
+ // utility methods
+
+ private int getRandomInt() {
+ return m_random.nextInt();
+ }
+
+ private String getRandomString() {
+ return Integer.toString(getRandomInt(), 16) + Integer.toString(getRandomInt(), 16);
+ }
+
+ private boolean getRandomBoolean() {
+ return getRandomInt() % 2 == 0;
+ }
+
+}
+
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/MementoUtils.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/MementoUtils.java
index 806665a651..c30b054e14 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/MementoUtils.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/MementoUtils.java
@@ -37,20 +37,19 @@ import org.xml.sax.helpers.DefaultHandler;
/** encodes and decodes memento to and from different data types; list, map, String*/
public class MementoUtils {
-
protected static final String ROOT_ELEMENT_TAGNAME = "root_element"; //$NON-NLS-1$
protected static final String ELEMENT_TAGNAME = "elem"; //$NON-NLS-1$
- protected static final String ATTRIBUTE_NAME = "value"; //$NON-NLS-1$
-
+ protected static final String ATTRIBUTE_KEY = "key"; //$NON-NLS-1$
+ protected static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
+
/** Returns a XML memento, that encodes a single String parameter */
public static String encodeStringIntoMemento(String str) {
- List<String> list = new ArrayList<String>();
+ List<String> list = new ArrayList<>();
list.add(str);
return encodeListIntoMemento(list);
}
-
-
+
/** Returns a single String parameter, decoded from a XML memento */
public static String decodeStringFromMemento(String memento) {
return decodeListFromMemento(memento).get(0);
@@ -71,7 +70,9 @@ public class MementoUtils {
// create one XML element per map entry
for (String key : keyPairValues.keySet()) {
Element elem = doc.createElement(ELEMENT_TAGNAME);
- elem.setAttribute(key, keyPairValues.get(key));
+ // store key and value as values of 2 attributes
+ elem.setAttribute(ATTRIBUTE_KEY, key);
+ elem.setAttribute(ATTRIBUTE_VALUE, keyPairValues.get(key));
rootElement.appendChild(elem);
}
@@ -96,7 +97,7 @@ public class MementoUtils {
/** Returns a Map of Strings, decoded from a XML memento */
public static Map<String, String> decodeMapFromMemento(String memento) {
- Map<String, String> keyPairValues = new HashMap<String, String>();
+ Map<String, String> keyPairValues = new HashMap<>();
Element root = null;
DocumentBuilder parser;
@@ -110,20 +111,26 @@ public class MementoUtils {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) node;
NamedNodeMap nodeMap = elem.getAttributes();
+ String key = null;
+ String value = null;
for(int idx = 0; idx < nodeMap.getLength(); idx++) {
Node attrNode = nodeMap.item(idx);
if (attrNode.getNodeType() == Node.ATTRIBUTE_NODE) {
Attr attr = (Attr) attrNode;
- String key = attr.getName();
- String value = attr.getValue();
- if (key != null && value != null) {
- keyPairValues.put(key, value);
+ if (attr.getName().equals(ATTRIBUTE_KEY)) {
+ key = attr.getValue();
}
- else {
- throw new Exception();
+ else if (attr.getName().equals(ATTRIBUTE_VALUE)) {
+ value = attr.getValue();
}
}
}
+ if (key != null && value != null) {
+ keyPairValues.put(key, value);
+ }
+ else {
+ throw new Exception();
+ }
}
}
} catch (Exception e) {
@@ -148,7 +155,7 @@ public class MementoUtils {
// create one XML element per list entry to save
for (String lbl : labels) {
Element elem = doc.createElement(ELEMENT_TAGNAME);
- elem.setAttribute(ATTRIBUTE_NAME, lbl);
+ elem.setAttribute(ATTRIBUTE_VALUE, lbl);
rootElement.appendChild(elem);
}
@@ -172,7 +179,7 @@ public class MementoUtils {
/** Returns a List of Strings, decoded from a XML memento */
public static List<String> decodeListFromMemento(String memento) {
- List<String> list = new ArrayList<String>();
+ List<String> list = new ArrayList<>();
Element root = null;
DocumentBuilder parser;
@@ -185,7 +192,7 @@ public class MementoUtils {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elem = (Element) node;
- String value = elem.getAttribute(ATTRIBUTE_NAME);
+ String value = elem.getAttribute(ATTRIBUTE_VALUE);
if (value != null) {
list.add(value);
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/PersistentSettingsManager.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/PersistentSettingsManager.java
index f7a9364ed7..168f884e1d 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/PersistentSettingsManager.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui/src/org/eclipse/cdt/dsf/gdb/multicorevisualizer/internal/utils/PersistentSettingsManager.java
@@ -7,30 +7,100 @@
*
* Contributors:
* Marc Dumais (Ericsson) - initial API and implementation (bug 460837)
+ * Marc Dumais (Ericsson) - Bug 462353
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.utils;
+
import java.security.InvalidParameterException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.cdt.dsf.gdb.multicorevisualizer.internal.ui.MulticoreVisualizerUIPlugin;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.osgi.service.prefs.BackingStoreException;
-/** This class manages one or more PersistentSetting objects, using a commmon
- * name-space and optionally an instance id so that multiple instances can
- * each have their own version of the parameter persisted */
+
+/**
+ * This class manages one or more PersistentParameter, PersistentListParameter,
+ * PersistentMapParameter objects, using a common name-space and optionally an
+ * instance id so that multiple instances can each have their own version of
+ * the parameter persisted
+ */
public class PersistentSettingsManager {
- // TODO: add a way to notify clients that the value of a global (shared) parameter
- // has been updated, and that they should re-read it.
- /** Class for a specific persistent parameter */
- public class PersistentParameter<T> {
- private String m_storeKey;
+ /** Base class for a persistent parameter */
+ private abstract class AbstractPersistentParameter<T> {
+ protected final Class<T> myClazz;
+ protected final boolean m_perInstance;
+ protected final String m_storeKey;
+
+ /** Constructor */
+ public AbstractPersistentParameter(Class<T> clazz, boolean perInstance, String storeKey) {
+ myClazz = clazz;
+ m_perInstance = perInstance;
+ m_storeKey = storeKey;
+ }
+
+ // accessors
+
+ /** Returns whether this parameter is persisted independently for each client instance */
+ public boolean isPerInstance() {
+ return m_perInstance;
+ }
+
+ /** Returns the class of the parameter */
+ public Class<T> getClazz() {
+ return myClazz;
+ }
+
+ protected String getStoreKey() {
+ return m_storeKey;
+ }
+
+ // misc
+
+ @SuppressWarnings("unchecked")
+ /** Converts a value from a String to its expected generic type. This is a base
+ * implementation that converts some base types - Use/Override as needed for more complex
+ * types, such as List or Map of these types */
+ protected T convertToT(String val) {
+ // TODO: Add other types? Float, etc
+ if (String.class.isAssignableFrom(getClazz())) {
+ return (T) val;
+ }
+ else if (Integer.class.isAssignableFrom(getClazz())) {
+ return (T) Integer.valueOf(val);
+ }
+ else if (Boolean.class.isAssignableFrom(getClazz())) {
+ return (T) Boolean.valueOf(val);
+ }
+ return null;
+ }
+
+ /** Returns whether the wanted Class type is supported, to use as a persistent parameter */
+ protected boolean isTypeSupported(Class<T> clazz) {
+ // TODO: Add other types? Float, etc
+ if (String.class.isAssignableFrom(clazz) ||
+ Integer.class.isAssignableFrom(clazz) ||
+ Boolean.class.isAssignableFrom(clazz))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ // TODO: add a way to notify clients that the value of a global (shared) parameter
+ // has been updated, and that they should re-read it.
+ }
+
+ /** Class for a persistent parameter */
+ public class PersistentParameter<T> extends AbstractPersistentParameter<T> {
private T m_value;
private T m_defaultValue;
- private Class<T> myClazz;
- private boolean m_perInstance;
/**
* Constructor
@@ -40,9 +110,7 @@ public class PersistentSettingsManager {
* @param storeKey : The key used to store the parameter in the store
*/
public PersistentParameter(Class<T> clazz, boolean perInstance, String storeKey) {
- myClazz = clazz;
- m_perInstance = perInstance;
- m_storeKey = storeKey;
+ super(clazz, perInstance, storeKey);
}
/** Sets the default value to use if no persistent
@@ -51,36 +119,46 @@ public class PersistentSettingsManager {
m_defaultValue = defaultValue;
}
- /** Sets the persistent value to set */
+ /** Sets the value to persist */
public void set(T value) {
m_value = value;
// save value in preference store
persistParameter(value);
}
- /** Gets the persistent value, if found, else the default value */
+ /** Returns the persistent value, if found, else the default value */
public T value() {
if (m_value == null) {
// attempt to get the value from the preference store
m_value = restoreParameter();
}
// parameter has one value for any/all instances
- else if(!m_perInstance) {
+ else if(!isPerInstance()) {
// do not rely on cached value, since another instance might have
// changed it - reread from data store
m_value = restoreParameter();
}
- return (m_value!=null)? m_value : m_defaultValue;
+ return (m_value == null)? m_defaultValue : m_value;
+ }
+
+ /**
+ * Gets the persistent value, optionally forcing re-reading stored value
+ * @param forceRefresh whether to force to re-read memento in case value changed
+ */
+ public T value(boolean forceRefresh) {
+ if (forceRefresh) {
+ m_value = null;
+ }
+ return value();
}
/** Attempts to find the parameter in the preference store. Returns null if not found */
private T restoreParameter() {
IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
- String memento = store.get(m_storeKey, null);
+ String memento = store.get(getStoreKey(), null);
if (memento == null) return null;
String val = MementoUtils.decodeStringFromMemento(memento);
-
T convertedVal = convertToT(val);
return convertedVal;
}
@@ -93,7 +171,7 @@ public class PersistentSettingsManager {
// save memento in store
if (memento != null) {
IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
- store.put(m_storeKey, memento);
+ store.put(getStoreKey(), memento);
try {
store.flush();
} catch (BackingStoreException e) {
@@ -101,22 +179,208 @@ public class PersistentSettingsManager {
}
}
}
+ }
+
+ /** Class for a persistent {@literal List<T>} parameter */
+ public class PersistentListParameter<T> extends AbstractPersistentParameter<T> {
+ private List<T> m_value;
+ private List<T> m_defaultValue;
- @SuppressWarnings("unchecked")
- /** Converts the stored value from a String to its expected type */
- private T convertToT(String val) {
- // TODO: Add other types? Float, etc
- if (String.class.isAssignableFrom(myClazz)) {
- return (T) val;
+ public PersistentListParameter(Class<T> clazz, boolean perInstance, String storeKey) {
+ super(clazz, perInstance, storeKey);
+ }
+
+ /** Sets the default value to use if no persistent
+ * value is found for this parameter */
+ public void setDefault(List<T> defaultValues) {
+ m_defaultValue = defaultValues;
+ }
+
+ /** Sets the value to persist */
+ public void set(List<T> values) {
+ m_value = values;
+ // save value in preference store
+ persistParameter(values);
+ }
+
+ /** Returns the persistent value, if found, else the default value */
+ public List<T> value() {
+ if (m_value == null) {
+ // attempt to get the value from the preference store
+ m_value = restoreParameter();
}
- else if (Integer.class.isAssignableFrom(myClazz)) {
- return (T) Integer.valueOf(val);
+ // parameter has one value for any/all instances
+ else if(!isPerInstance()) {
+ // do not rely on cached value, since another instance might have
+ // changed it - reread from data store
+ m_value = restoreParameter();
}
- else if (Boolean.class.isAssignableFrom(myClazz)) {
- return (T) Boolean.valueOf(val);
+ return (m_value == null)? m_defaultValue : m_value ;
+ }
+
+ /**
+ * Gets the persistent value, optionally forcing re-reading stored value
+ * @param forceRefresh whether to force to re-read memento in case value changed
+ */
+ public List<T> value(boolean forceRefresh) {
+ if (forceRefresh) {
+ m_value = null;
}
+ return value();
+ }
+
+ /** Attempts to find the parameter in the preference store. Returns null if not found */
+ private List<T> restoreParameter() {
+ IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
+ String memento = store.get(getStoreKey(), null);
+ if (memento == null) return null;
- return null;
+ List<String> vals = MementoUtils.decodeListFromMemento(memento);
+ // convert from List<String> to List<T>
+ List<T> convertedVal = convertToT(vals);
+ return convertedVal;
+ }
+
+ /** Saves parameter's value in preference store */
+ private void persistParameter(List<T> values) {
+ // Convert List<T> to List<String>
+ List<String> strList = convertTListToStringList(values);
+ // create memento from List<String>
+ String memento = MementoUtils.encodeListIntoMemento(strList);
+
+ // save memento in store
+ if (memento != null) {
+ IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
+ store.put(getStoreKey(), memento);
+ try {
+ store.flush();
+ } catch (BackingStoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /** For list parameters, converts the restored values from String
+ * to its expected generic type */
+ private List<T> convertToT(List<String> vals) {
+ List<T> convertedList = new ArrayList<>();
+
+ for(String val : vals) {
+ convertedList.add(convertToT(val));
+ }
+ return convertedList;
+ }
+
+ /** Converts a list of generic type to a list of String */
+ private List<String> convertTListToStringList(List<T> tList) {
+ List<String> strList = new ArrayList<>();
+ // convert list to list of String
+ for(T elem : tList) {
+ strList.add(elem.toString());
+ }
+ return strList;
+ }
+ }
+
+
+ /** Class for a persistent {@literal Map<String,T>} parameter */
+ public class PersistentMapParameter<T> extends AbstractPersistentParameter<T> {
+ private Map<String,T> m_value;
+ private Map<String,T> m_defaultValue;
+
+ public PersistentMapParameter(Class<T> clazz, boolean perInstance, String storeKey) {
+ super(clazz, perInstance, storeKey);
+ }
+
+ /** Sets the default value to use if no persistent
+ * value is found for this parameter */
+ public void setDefault(Map<String,T> defaultValues) {
+ m_defaultValue = defaultValues;
+ }
+
+ /** Sets the value to persist */
+ public void set(Map<String,T> values) {
+ m_value = values;
+ // save value in preference store
+ persistParameter(values);
+ }
+
+ /** Returns the persistent value, if found, else the default value */
+ public Map<String,T> value() {
+ if (m_value == null) {
+ // attempt to get the value from the preference store
+ m_value = restoreParameter();
+ }
+ // parameter has one value for any/all instances
+ else if(!isPerInstance()) {
+ // do not rely on cached value, since another instance might have
+ // changed it - reread from data store
+ m_value = restoreParameter();
+ }
+ return (m_value == null)? m_defaultValue : m_value ;
+ }
+
+ /**
+ * Gets the persistent value, optionally forcing re-reading stored value
+ * @param forceRefresh whether to force to re-read memento in case value changed
+ */
+ public Map<String,T> value(boolean forceRefresh) {
+ if (forceRefresh) {
+ m_value = null;
+ }
+ return value();
+ }
+
+ /** Attempts to find the parameter in the preference store. Returns null if not found */
+ private Map<String,T> restoreParameter() {
+ IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
+ String memento = store.get(getStoreKey(), null);
+ if (memento == null) return null;
+
+ Map<String,String> vals = MementoUtils.decodeMapFromMemento(memento);
+ // convert from Map<String,String> to Map<String,T>
+ Map<String,T> convertedVal = convertToT(vals);
+ return convertedVal;
+ }
+
+ /** Saves parameter's value in preference store */
+ private void persistParameter(Map<String,T> values) {
+ // Convert Map<String,T> to Map<String,String>
+ Map<String,String> strMap = convertTMapToStringMap(values);
+ // create memento from Map
+ String memento = MementoUtils.encodeMapIntoMemento(strMap);
+
+ // save memento in store
+ if (memento != null) {
+ IEclipsePreferences store = MulticoreVisualizerUIPlugin.getEclipsePreferenceStore();
+ store.put(getStoreKey(), memento);
+ try {
+ store.flush();
+ } catch (BackingStoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /** For Map parameters, converts the restored values from {@literal Map<String,String>}
+ * to {@literal Map<String, T>} */
+ private Map<String,T> convertToT(Map<String,String> vals) {
+ Map<String,T> convertedMap = new HashMap<>();
+
+ for(String key : vals.keySet()) {
+ convertedMap.put(key, convertToT(vals.get(key)));
+ }
+ return convertedMap;
+ }
+
+ /** Converts a {@literal Map<String,T>} to a {@literal Map<String,String>} */
+ private Map<String,String> convertTMapToStringMap(Map<String,T> map) {
+ Map<String,String> strMap = new HashMap<>();
+ // convert each entry
+ for(String key : map.keySet()) {
+ strMap.put(key, map.get(key).toString());
+ }
+ return strMap;
}
}
@@ -165,17 +429,56 @@ public class PersistentSettingsManager {
* @param defaultValue: default value to use (mandatory)
*/
public <T> PersistentParameter<T> getNewParameter(Class<T> clazz, String label, boolean perInstance, T defaultValue) {
+ PersistentParameter<T> setting;
+ // build the final store key with category, parameter label and specific instance, if applicable
+ setting = new PersistentParameter<T>(clazz, perInstance, getStorageKey(perInstance) + "." + label); //$NON-NLS-1$
// check that we're dealing with one of a few supported types
- // TODO: Add other types? Float, etc
- if (String.class.isAssignableFrom(clazz) ||
- Integer.class.isAssignableFrom(clazz) ||
- Boolean.class.isAssignableFrom(clazz))
- {
- PersistentParameter<T> setting;
- // build the final store key with category, parameter label and specific instance, if applicable
- setting = new PersistentParameter<T>(clazz, perInstance, getStorageKey(perInstance) + "." + label); //$NON-NLS-1$
+ if (setting.isTypeSupported(clazz)) {
+ setting.setDefault(defaultValue);
+ return setting;
+ }
+ else {
+ throw new InvalidParameterException("Unsupported class type: " + clazz.toString()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates a new persistent {@literal List<T>} parameter, using the namespace and instance id of this manager.
+ * @param clazz: the class of the persistent parameter List (e.g. List of that type). Supported types: String, Integer, Boolean
+ * @param label: unique label that identifies this parameter.
+ * @param perInstance: whether the parameter's value should be persisted per client instance or
+ * globally (one common shared stored value for all instances)
+ * @param defaultValue: default value to use (mandatory).
+ */
+ public <T> PersistentListParameter<T> getNewListParameter(Class<T> clazz, String label, boolean perInstance, List<T> defaultValue) {
+ PersistentListParameter<T> setting;
+ // build the final store key with category, parameter label and specific instance, if applicable
+ setting = new PersistentListParameter<T>(clazz, perInstance, getStorageKey(perInstance) + "." + label); //$NON-NLS-1$
+ // check that we're dealing with one of a few supported types
+ if (setting.isTypeSupported(clazz)) {
+ setting.setDefault(defaultValue);
+ return setting;
+ }
+ else {
+ throw new InvalidParameterException("Unsupported class type: " + clazz.toString()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates a new persistent {@literal Map<String,T>} parameter, using the namespace and instance id of this manager.
+ * @param clazz: the class of the persistent parameter List (e.g. List of that type). Supported types: String, Integer, Boolean
+ * @param label: unique label that identifies this parameter.
+ * @param perInstance: whether the parameter's value should be persisted per client instance or
+ * globally (one common shared stored value for all instances)
+ * @param defaultValue: default value to use (mandatory).
+ */
+ public <T> PersistentMapParameter<T> getNewMapParameter(Class<T> clazz, String label, boolean perInstance, Map<String,T> defaultValue) {
+ PersistentMapParameter<T> setting;
+ // build the final store key with category, parameter label and specific instance, if applicable
+ setting = new PersistentMapParameter<T>(clazz, perInstance, getStorageKey(perInstance) + "." + label); //$NON-NLS-1$
+ // check that we're dealing with one of a few supported types
+ if (setting.isTypeSupported(clazz)) {
setting.setDefault(defaultValue);
-
return setting;
}
else {
@@ -183,11 +486,11 @@ public class PersistentSettingsManager {
}
}
+ // ---- misc ----
/** Returns the key to be used to save parameter, taking into account the
* instance id, if applicable */
private String getStorageKey(boolean perInstance) {
return (perInstance ? m_instance : "") + (!m_category.equals("") ? "." + m_category : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
-
-}
+} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3eef02c47d..dac1be87d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -184,6 +184,7 @@
<module>dsf-gdb/org.eclipse.cdt.dsf.gdb.tests</module>
<module>dsf-gdb/org.eclipse.cdt.tests.dsf.gdb</module>
<module>dsf-gdb/org.eclipse.cdt.examples.dsf.gdb</module>
+ <module>dsf-gdb/org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui.tests</module>
<module>build/org.eclipse.cdt.autotools.core</module>
<module>build/org.eclipse.cdt.autotools.docs</module>

Back to the top