fix nasty sync problem w/ contrib list; other cleaning while debugging

This commit is contained in:
Ben Fry
2023-01-12 20:26:54 -05:00
parent 6a80624eaa
commit 1d3584e26e
4 changed files with 61 additions and 21 deletions

View File

@@ -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<Contribution> installed) {
// Map<Contribution, Contribution> replacements = new HashMap<>();
// Set<Contribution> 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) {

View File

@@ -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<String> 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() {

View File

@@ -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<String> filters) {
protected void updateFilter(String category, List<String> filters) {
rowFilter.setCategoryFilter(category);
rowFilter.setStringFilters(filters);
model.fireTableDataChanged();

View File

@@ -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