Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2014-04-09 09:35:56 -0400
committerTobias Schwarz2014-04-09 09:35:56 -0400
commit87d617e8fb906aabfebc268bb0a65fca5111f393 (patch)
tree3d29ceba3ec2eb39dc89544738f09b84c54a521c /target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence
parentac3614fec55fd49e54d58da00492b21f1f35460a (diff)
downloadorg.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.tar.gz
org.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.tar.xz
org.eclipse.tcf-87d617e8fb906aabfebc268bb0a65fca5111f393.zip
Target Explorer: rework action history
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java109
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java95
3 files changed, 176 insertions, 32 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
index a6c685fca..d9b673608 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/delegates/GsonMapPersistenceDelegate.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.TreeMap;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
@@ -187,7 +188,8 @@ public class GsonMapPersistenceDelegate extends ExecutableExtension implements I
data.put(VARIABLES, variables);
}
}
- return data;
+ Map<String, Object> sorted = new TreeMap<String, Object>(data);
+ return sorted;
}
catch (Exception e) {
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java
index b44ab4a69..3e29fe54c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/history/HistoryManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2012 - 2014 Wind River Systems, Inc. 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
@@ -103,23 +103,41 @@ public class HistoryManager {
/**
* Get the history for a given history id.
* @param historyId The history id.
- * @return The list of ids within the history ids list or an empty list.
+ * @return The list of entries within the history ids list or an empty list.
*/
public String[] getHistory(String historyId) {
Assert.isNotNull(historyId);
- List<String> ids = history.get(historyId);
- if (ids == null) {
- ids = new ArrayList<String>();
+ List<String> entries = history.get(historyId);
+ if (entries == null) {
+ entries = new ArrayList<String>();
}
- return ids.toArray(new String[ids.size()]);
+ return entries.toArray(new String[entries.size()]);
+ }
+
+ /**
+ * Get all history ids matching the given id pattern.
+ * @param historyIdPattern The history id regex pattern.
+ * @return The list of history ids matching the given pattern or an empty list.
+ */
+ public String[] getMatchingHistoryIds(String historyIdPattern) {
+ Assert.isNotNull(historyIdPattern);
+
+ List<String> historyIds = new ArrayList<String>();
+ for (String historyId : history.keySet()) {
+ if (historyId.matches(historyIdPattern)) {
+ historyIds.add(historyId);
+ }
+ }
+
+ return historyIds.toArray(new String[historyIds.size()]);
}
/**
* Get the fist entry of a history ids list.
* @param historyId The history id.
- * @return The first entry of the history ids list or null if no history is available for that id.
+ * @return The first entry for the given history ids or null if no history is available for that id.
*/
public String getFirst(String historyId) {
String[] history = getHistory(historyId);
@@ -130,26 +148,39 @@ public class HistoryManager {
* Add a new history entry to the top of the history ids list.
* If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed.
* @param historyId The history id.
- * @param id The id to be added to the top of history ids list.
+ * @param entry The entry to be added to the top of history ids list.
* @return <code>true</code> if the id
*/
- public boolean add(String historyId, String id) {
+ public boolean add(String historyId, String entry) {
+ return add(historyId, entry, HISTORY_LENGTH);
+ }
+
+ /**
+ * Add a new history entry to the top of the history ids list.
+ * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed.
+ * @param historyId The history id.
+ * @param entry The id to be added to the top of history ids list.
+ * @param historyLength The maximum length of the history.
+ * @return <code>true</code> if the entry was added
+ */
+ public boolean add(String historyId, String entry, int historyLength) {
Assert.isNotNull(historyId);
- Assert.isNotNull(id);
+ Assert.isNotNull(entry);
+ Assert.isTrue(historyLength > 0);
List<String> ids = history.get(historyId);
if (ids == null) {
ids = new ArrayList<String>();
history.put(historyId, ids);
}
- if (ids.contains(id)) {
- ids.remove(id);
+ if (ids.contains(entry)) {
+ ids.remove(entry);
}
- ids.add(0, id);
+ ids.add(0, entry);
- while (ids.size() > HISTORY_LENGTH) {
- ids.remove(HISTORY_LENGTH);
+ while (ids.size() > historyLength) {
+ ids.remove(historyLength);
}
flush();
@@ -163,18 +194,30 @@ public class HistoryManager {
* Set a new list of history entries to the history ids list.
* If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed.
* @param historyId The history id.
- * @param ids The ids to be set to the history ids list.
- * @return <code>true</code> if the id
+ * @param entries The entries to be set to the history ids list.
+ * @return <code>true</code> if the entries were added
+ */
+ public void set(String historyId, String[] entries) {
+ set(historyId, entries, HISTORY_LENGTH);
+ }
+
+ /**
+ * Set a new list of history entries to the history ids list.
+ * If the list size exceeds the HISTORY_LENGTH, the last element of the list will be removed.
+ * @param historyId The history id.
+ * @param entries The entries to be set to the history ids list.
+ * @param historyLength The maximum length of the history.
+ * @return <code>true</code> if the entries were set
*/
- public void set(String historyId, String[] ids) {
+ public void set(String historyId, String[] entries, int historyLength) {
Assert.isNotNull(historyId);
- Assert.isNotNull(ids);
+ Assert.isNotNull(entries);
- history.put(historyId, Arrays.asList(ids));
+ history.put(historyId, Arrays.asList(entries));
List<String> newIds = history.get(historyId);
- while (newIds.size() > HISTORY_LENGTH) {
- newIds.remove(HISTORY_LENGTH);
+ while (newIds.size() > historyLength) {
+ newIds.remove(historyLength);
}
flush();
@@ -185,18 +228,18 @@ public class HistoryManager {
/**
* Remove a id from the history ids list.
* @param historyId The history id.
- * @param id The id to be removed from the history ids list.
- * @return <code>true</code> if the id was removed from the history ids list.
+ * @param entry The entry to be removed from the history ids list.
+ * @return <code>true</code> if the entry was removed from the history ids list.
*/
- public boolean remove(String historyId, String id) {
+ public boolean remove(String historyId, String entry) {
Assert.isNotNull(historyId);
- Assert.isNotNull(id);
+ Assert.isNotNull(entry);
boolean removed = false;
List<String> ids = history.get(historyId);
if (ids != null) {
- removed |= ids.remove(id);
+ removed |= ids.remove(entry);
if (ids.isEmpty()) {
history.remove(historyId);
}
@@ -215,11 +258,15 @@ public class HistoryManager {
* @param historyId The history id.
**/
public void clear(String historyId) {
- Assert.isNotNull(historyId);
-
- List<String> ids = history.remove(historyId);
+ List<String> entries = null;
+ if (historyId == null) {
+ history.clear();
+ }
+ else {
+ entries = history.remove(historyId);
+ }
- if (ids != null) {
+ if (entries != null || historyId == null) {
flush();
EventManager.getInstance().fireEvent(new ChangeEvent(this, ChangeEvent.ID_REMOVED, historyId, historyId));
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java
new file mode 100644
index 000000000..d1c4f418d
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.runtime.persistence/src/org/eclipse/tcf/te/runtime/persistence/utils/DataHelper.java
@@ -0,0 +1,95 @@
+/**
+ * DataHelper.java
+ * Created on Aug 21, 2013
+ *
+ * Copyright (c) 2013 Wind River Systems, Inc.
+ *
+ * The right to copy, distribute, modify, or otherwise make use
+ * of this software may be licensed only pursuant to the terms
+ * of an applicable Wind River license agreement.
+ */
+package org.eclipse.tcf.te.runtime.persistence.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.persistence.PersistenceManager;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+
+/**
+ * Data helper for de/encoding.
+ */
+public class DataHelper {
+
+ /**
+ * Encode a properties container to a string.
+ * @param data The properties container.
+ * @return String representing the properties container.
+ */
+ public static final String encodePropertiesContainer(IPropertiesContainer data) {
+ try {
+ if (data != null && !data.isEmpty()) {
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, String.class);
+ return (String)delegate.write(data, String.class);
+ }
+ }
+ catch (Exception e) {
+ }
+ return null;
+ }
+
+ /**
+ * Decode a string encoded properties container.
+ * @param encoded The string encoded properties container.
+ * @return Properties container.
+ */
+ public static final IPropertiesContainer decodePropertiesContainer(String encoded) {
+ if (encoded != null && encoded.trim().length() > 0) {
+ try {
+ IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, String.class);
+ return (IPropertiesContainer)delegate.read(IPropertiesContainer.class, encoded);
+ }
+ catch (Exception e) {
+ }
+ }
+ return new PropertiesContainer();
+ }
+
+ /**
+ * Convert all keys of the map to lower case.
+ * @param list The list of maps to convert.
+ * @return List with new maps with lowercase keys.
+ */
+ public static List<Map<String,Object>> keysToLowerCase(List<Map<String,Object>> list) {
+ List<Map<String, Object>> paramListLowerCase = new ArrayList<Map<String,Object>>();
+ for (Map<String, Object> map : list) {
+ paramListLowerCase.add(keysToLowerCase(map));
+ }
+ return paramListLowerCase;
+ }
+
+ /**
+ * Convert all keys of the map to lower case.
+ * @param map The map to convert.
+ * @return New map with lowercase keys.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String,Object> keysToLowerCase(Map<String,Object> map) {
+ Map<String, Object> mapLowerCase = new HashMap<String, Object>();
+ for (String key : map.keySet()) {
+ Object value = map.get(key);
+ if (value instanceof Map) {
+ value = keysToLowerCase((Map<String,Object>)value);
+ }
+ else if (value instanceof List) {
+ value = keysToLowerCase((List<Map<String,Object>>)value);
+ }
+ mapLowerCase.put(key.toLowerCase(), value);
+ }
+ return mapLowerCase;
+ }
+}

Back to the top