diff options
author | Wim Jongman | 2018-04-25 15:33:08 +0000 |
---|---|---|
committer | Wim Jongman | 2018-04-25 15:33:08 +0000 |
commit | ca27c513dfaff98bc5566b70d78d7637298b8736 (patch) | |
tree | be8a59e2a85237566214e984608d4405a64e34ec | |
parent | 2c9e972e29c5c4b8d9481dd6e724d3984fa16e4f (diff) | |
download | eclipse.platform.ua-ca27c513dfaff98bc5566b70d78d7637298b8736.tar.gz eclipse.platform.ua-ca27c513dfaff98bc5566b70d78d7637298b8736.tar.xz eclipse.platform.ua-ca27c513dfaff98bc5566b70d78d7637298b8736.zip |
Bug 534050: [Tips] Save read state to preferencesI20180426-2000I20180426-0500I20180425-2000I20180425-1705I20180425-1650I20180425-1455
* Removed unused tip constructor
* Added retrieval of provider id to save read state
* Saved state to preferences
Change-Id: Ifd7358f7c2e1687663954e9ef45e898f9765ccc1
Signed-off-by: Wim Jongman <wim.jongman@remainsoftware.com>
3 files changed, 40 insertions, 25 deletions
diff --git a/org.eclipse.tips.core/src/org/eclipse/tips/core/Tip.java b/org.eclipse.tips.core/src/org/eclipse/tips/core/Tip.java index 8d5cf112c..30c3831b0 100644 --- a/org.eclipse.tips.core/src/org/eclipse/tips/core/Tip.java +++ b/org.eclipse.tips.core/src/org/eclipse/tips/core/Tip.java @@ -20,9 +20,9 @@ import java.util.List; * */ public abstract class Tip { - + private String providerId; - + private final List<TipAction> fActions = new ArrayList<>(); /** @@ -35,15 +35,10 @@ public abstract class Tip { } /** - * For the sanity of the Framework, Tips should be created really fast. - * - * @param pProvider - * the associated {@link TipProvider} - * @param actions - * the list of actions which may not be null + * @return the id of the provider that created this tip. */ - public Tip(List<TipAction> actions) { - fActions.addAll(actions); + public String getProviderId() { + return providerId; } /** @@ -64,7 +59,6 @@ public abstract class Tip { */ public abstract Date getCreationDate(); - /** * @return the subject which may not be null. */ diff --git a/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/IDETipManager.java b/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/IDETipManager.java index 70267358c..728b10611 100644 --- a/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/IDETipManager.java +++ b/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/IDETipManager.java @@ -13,7 +13,9 @@ package org.eclipse.tips.ide.internal; import java.io.ByteArrayInputStream; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.xml.parsers.DocumentBuilderFactory; @@ -48,7 +50,7 @@ public class IDETipManager extends DefaultTipManager { private TipSourceProvider fSourceProvider = new TipSourceProvider(); - private List<Integer> fReadTips = new ArrayList<>(); + private Map<String, List<Integer>> fReadTips = new HashMap<>(); private boolean fNewTips; @@ -97,7 +99,7 @@ public class IDETipManager extends DefaultTipManager { evaluationService.addSourceProvider(fSourceProvider); fSourceProviderAdded = true; } - fReadTips.addAll(Preferences.loadReadState()); + fReadTips = Preferences.getReadState(); return super.open(startUp); } @@ -107,7 +109,7 @@ public class IDETipManager extends DefaultTipManager { * @param pReadTips the tips to save * */ - private void saveReadState(List<Integer> pReadTips) { + private void saveReadState(Map<String, List<Integer>> pReadTips) { Job job = new Job("Tips save read state..") { @Override protected IStatus run(IProgressMonitor monitor) { @@ -175,16 +177,22 @@ public class IDETipManager extends DefaultTipManager { @Override public boolean isRead(Tip tip) { - if (fReadTips.contains(Integer.valueOf(tip.hashCode()))) { + if (fReadTips.containsKey(tip.getProviderId()) + && fReadTips.get(tip.getProviderId()).contains(Integer.valueOf(tip.hashCode()))) { return true; } return false; } @Override - public TipManager setAsRead(Tip tip) { + public synchronized TipManager setAsRead(Tip tip) { if (!isRead(tip)) { - fReadTips.add(Integer.valueOf(tip.hashCode())); + List<Integer> readTips = fReadTips.get(tip.getProviderId()); + if (readTips == null) { + readTips = new ArrayList<>(); + fReadTips.put(tip.getProviderId(), readTips); + } + readTips.add(Integer.valueOf(tip.hashCode())); } return this; } @@ -201,7 +209,7 @@ public class IDETipManager extends DefaultTipManager { public void dispose() { try { refreshUI(); - saveReadState(Collections.unmodifiableList(fReadTips)); + saveReadState(Collections.unmodifiableMap(fReadTips)); } finally { super.dispose(); } diff --git a/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/Preferences.java b/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/Preferences.java index 5a08ae702..02fb09a00 100644 --- a/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/Preferences.java +++ b/org.eclipse.tips.ide/src/org/eclipse/tips/ide/internal/Preferences.java @@ -11,7 +11,9 @@ package org.eclipse.tips.ide.internal; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; @@ -57,14 +59,19 @@ public class Preferences extends AbstractPreferenceInitializer { /** * Loads the read tips from disk. * - * @return the integer array of read tips. + * @return a map that stores the read tip hashes per provider. */ - public static List<Integer> loadReadState() { - ArrayList<Integer> result = new ArrayList<>(); + public static Map<String, List<Integer>> getReadState() { + HashMap<String, List<Integer>> result = new HashMap<>(); IEclipsePreferences node = ConfigurationScope.INSTANCE.getNode("org.eclipse.tips.ide.read"); try { - for (String key : node.keys()) { - result.add(Integer.valueOf(node.getInt(key, 0))); + for (String key : node.childrenNames()) { + ArrayList<Integer> tips = new ArrayList<>(); + org.osgi.service.prefs.Preferences tipsNode = node.node(key); + for (String tipKey : tipsNode.keys()) { + tips.add(Integer.valueOf(tipsNode.getInt(tipKey, 0))); + } + result.put(key, tips); } } catch (BackingStoreException e) { Status status = new Status(IStatus.ERROR, "org.eclipse.tips.ide", e.getMessage(), e); @@ -79,11 +86,17 @@ public class Preferences extends AbstractPreferenceInitializer { * @param pReadTips the list with read tips * @return the status of the call */ - public static IStatus saveReadState(List<Integer> pReadTips) { + public static IStatus saveReadState(Map<String, List<Integer>> pReadTips) { try { IEclipsePreferences node = ConfigurationScope.INSTANCE.getNode("org.eclipse.tips.ide.read"); + for (String child : pReadTips.keySet()) { + if (node.nodeExists(child)) { + node.node(child).removeNode(); + } + } node.clear(); - pReadTips.forEach(value -> node.putInt(value.toString(), value.intValue())); + pReadTips.forEach( + (key, tips) -> tips.forEach(value -> node.node(key).putInt(value.toString(), value.intValue()))); node.flush(); return Status.OK_STATUS; } catch (BackingStoreException e) { |