From 1d3584e26ea8f56e8347013dcd06f69a09e64ef2 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 12 Jan 2023 20:26:54 -0500 Subject: [PATCH] fix nasty sync problem w/ contrib list; other cleaning while debugging --- .../app/contrib/ContributionListing.java | 45 ++++++++++++++++++- .../app/contrib/ContributionTab.java | 12 ++--- app/src/processing/app/contrib/ListPanel.java | 21 +++------ .../processing/app/contrib/ManagerFrame.java | 4 ++ 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/app/src/processing/app/contrib/ContributionListing.java b/app/src/processing/app/contrib/ContributionListing.java index b1684d1f1..f0ad7656e 100644 --- a/app/src/processing/app/contrib/ContributionListing.java +++ b/app/src/processing/app/contrib/ContributionListing.java @@ -26,6 +26,7 @@ import java.io.*; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; import processing.app.Base; @@ -62,7 +63,7 @@ public class ContributionListing { listPanels = new HashSet<>(); advertisedContributions = new ArrayList<>(); librariesByImportHeader = new HashMap<>(); - allContributions = new LinkedHashSet<>(); + allContributions = ConcurrentHashMap.newKeySet(); downloadingLock = new ReentrantLock(); listingFile = Base.getSettingsFile(LOCAL_FILENAME); @@ -97,6 +98,48 @@ public class ContributionListing { } + /** + * Adds the installed libraries to the listing of libraries, replacing + * any pre-existing libraries by the same name as one in the list. + */ + protected void updateInstalled(Set installed) { +// Map replacements = new HashMap<>(); +// Set additions = new HashSet<>(); + + for (Contribution contribution : installed) { + Contribution existingContribution = findContribution(contribution); + if (existingContribution != null) { + if (existingContribution != contribution) { + // don't replace contrib with itself + replaceContribution(existingContribution, contribution); +// replacements.put(existingContribution, contribution); + } + } else { + addContribution(contribution); +// additions.add(contribution); + } + } + +// for (Contribution existing : replacements.keySet()) { +// replaceContribution(existing, replacements.get(existing)); +// } +// for (Contribution adding : additions) { +// addContribution(adding); +// } + } + + + private Contribution findContribution(Contribution contribution) { + for (Contribution c : allContributions) { + if (c.getName().equals(contribution.getName()) && + c.getType() == contribution.getType()) { + return c; + } + } + return null; + } + + protected void replaceContribution(Contribution oldLib, Contribution newLib) { if (oldLib != null && newLib != null) { if (oldLib.getImports() != null) { diff --git a/app/src/processing/app/contrib/ContributionTab.java b/app/src/processing/app/contrib/ContributionTab.java index 54331c980..56caf7f51 100644 --- a/app/src/processing/app/contrib/ContributionTab.java +++ b/app/src/processing/app/contrib/ContributionTab.java @@ -216,7 +216,7 @@ public class ContributionTab extends JPanel { category = null; } //filterLibraries(category, filterField.filterWords); - filterLibraries(); + updateFilter(); }); filterField = new FilterField(); @@ -316,9 +316,11 @@ public class ContributionTab extends JPanel { } - //protected void filterLibraries(String category, List filters) { - protected void filterLibraries() { - listPanel.filterLibraries(category, filterField.filterWords); + /** + * Filter the libraries based on category and filter words. + */ + protected void updateFilter() { + listPanel.updateFilter(category, filterField.filterWords); } @@ -475,7 +477,7 @@ public class ContributionTab extends JPanel { filterWords = Arrays.asList(filter.split(" ")); //filterLibraries(category, filterWords); - filterLibraries(); + updateFilter(); } protected void updateTheme() { diff --git a/app/src/processing/app/contrib/ListPanel.java b/app/src/processing/app/contrib/ListPanel.java index 8a397f1c1..cc86643cf 100644 --- a/app/src/processing/app/contrib/ListPanel.java +++ b/app/src/processing/app/contrib/ListPanel.java @@ -704,28 +704,19 @@ public class ListPanel extends JPanel implements Scrollable { // Thread: EDT protected void contributionChanged(final Contribution oldContrib, - final Contribution newContrib) { + final Contribution newContrib) { if (filter.matches(oldContrib)) { -// if (true || filter.matches(oldContrib)) { -// System.out.println(contributionTab.contribType + " tab: " + -// "changed " + oldContrib + " -> " + newContrib); -// new Exception().printStackTrace(System.out); StatusDetail detail = detailForContrib.get(oldContrib); -// if (panel == null) { -//// System.out.println("panel null for " + newContrib); -// contributionAdded(newContrib); -// } else { - detailForContrib.remove(oldContrib); - detail.setContrib(newContrib); - detailForContrib.put(newContrib, detail); - model.fireTableDataChanged(); -// } + detailForContrib.remove(oldContrib); + detail.setContrib(newContrib); + detailForContrib.put(newContrib, detail); + model.fireTableDataChanged(); } } // Thread: EDT - protected void filterLibraries(String category, List filters) { + protected void updateFilter(String category, List filters) { rowFilter.setCategoryFilter(category); rowFilter.setStringFilters(filters); model.fireTableDataChanged(); diff --git a/app/src/processing/app/contrib/ManagerFrame.java b/app/src/processing/app/contrib/ManagerFrame.java index 7ceb00406..2cb75272a 100644 --- a/app/src/processing/app/contrib/ManagerFrame.java +++ b/app/src/processing/app/contrib/ManagerFrame.java @@ -96,8 +96,12 @@ public class ManagerFrame { // ContributionListing.updateInstalled(base); // showTab.activate(); // } else { + ContributionListing.getInstance().updateInstalled(base.getInstalledContribs()); } tabs.setPanel(showTab); +// if (contributionType == null) { +// showTab.listPanel.model.fireTableDataChanged(); +// System.out.println("rows: " + showTab.listPanel.model.getRowCount()); // } frame.setVisible(true); // Avoid the search box taking focus and hiding the 'search' text