Skip to content

Commit afb3a08

Browse files
authored
Merge pull request #5742 from Sardtok/5524
Fixes #5524
2 parents 773b094 + 768c671 commit afb3a08

6 files changed

Lines changed: 409 additions & 572 deletions

File tree

app/src/processing/app/contrib/ContributionListing.java

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ public class ContributionListing {
5353
Map<String, Contribution> librariesByImportHeader;
5454
// TODO: Every contribution is getting added twice
5555
// and nothing is replaced ever.
56-
List<Contribution> allContributions;
56+
Set<Contribution> allContributions;
5757
boolean listDownloaded;
5858
boolean listDownloadFailed;
5959
ReentrantLock downloadingListingLock;
6060

6161

6262
private ContributionListing() {
63-
listeners = new ArrayList<ChangeListener>();
64-
advertisedContributions = new ArrayList<AvailableContribution>();
65-
librariesByCategory = new HashMap<String, List<Contribution>>();
66-
librariesByImportHeader = new HashMap<String, Contribution>();
67-
allContributions = new ArrayList<Contribution>();
63+
listeners = new ArrayList<>();
64+
advertisedContributions = new ArrayList<>();
65+
librariesByCategory = new HashMap<>();
66+
librariesByImportHeader = new HashMap<>();
67+
allContributions = new LinkedHashSet<>();
6868
downloadingListingLock = new ReentrantLock();
6969

7070
//listingFile = Base.getSettingsFile("contributions.txt");
@@ -96,7 +96,6 @@ private void setAdvertisedList(File file) {
9696
for (Contribution contribution : advertisedContributions) {
9797
addContribution(contribution);
9898
}
99-
Collections.sort(allContributions, COMPARATOR);
10099
}
101100

102101

@@ -139,11 +138,8 @@ protected void replaceContribution(Contribution oldLib, Contribution newLib) {
139138
}
140139
}
141140

142-
for (int i = 0; i < allContributions.size(); i++) {
143-
if (allContributions.get(i) == oldLib) {
144-
allContributions.set(i, newLib);
145-
}
146-
}
141+
allContributions.remove(oldLib);
142+
allContributions.add(newLib);
147143

148144
notifyChange(oldLib, newLib);
149145
}
@@ -169,7 +165,6 @@ private void addContribution(Contribution contribution) {
169165
}
170166
allContributions.add(contribution);
171167
notifyAdd(contribution);
172-
Collections.sort(allContributions, COMPARATOR);
173168
}
174169
}
175170

@@ -234,43 +229,7 @@ protected Set<String> getCategories(Contribution.Filter filter) {
234229
}
235230

236231

237-
// public List<Contribution> getAllContributions() {
238-
// return new ArrayList<Contribution>(allContributions);
239-
// }
240-
241-
242-
// public List<Contribution> getLibararies(String category) {
243-
// ArrayList<Contribution> libinfos =
244-
// new ArrayList<Contribution>(librariesByCategory.get(category));
245-
// Collections.sort(libinfos, nameComparator);
246-
// return libinfos;
247-
// }
248-
249-
250-
protected List<Contribution> getFilteredLibraryList(String category, List<String> filters) {
251-
ArrayList<Contribution> filteredList =
252-
new ArrayList<Contribution>(allContributions);
253-
254-
Iterator<Contribution> it = filteredList.iterator();
255-
while (it.hasNext()) {
256-
Contribution libInfo = it.next();
257-
//if (category != null && !category.equals(libInfo.getCategory())) {
258-
if (category != null && !libInfo.hasCategory(category)) {
259-
it.remove();
260-
} else {
261-
for (String filter : filters) {
262-
if (!matches(libInfo, filter)) {
263-
it.remove();
264-
break;
265-
}
266-
}
267-
}
268-
}
269-
return filteredList;
270-
}
271-
272-
273-
private boolean matches(Contribution contrib, String typed) {
232+
public boolean matches(Contribution contrib, String typed) {
274233
int colon = typed.indexOf(":");
275234
if (colon != -1) {
276235
String isText = typed.substring(0, colon);
@@ -601,11 +560,7 @@ public Map<String, Contribution> getLibrariesByImportHeader() {
601560
}
602561

603562

604-
static public Comparator<Contribution> COMPARATOR = new Comparator<Contribution>() {
605-
public int compare(Contribution o1, Contribution o2) {
606-
return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
607-
}
608-
};
563+
static public Comparator<Contribution> COMPARATOR = Comparator.comparing(o -> o.getName().toLowerCase());
609564

610565

611566
public interface ChangeListener {

app/src/processing/app/contrib/ContributionTab.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,14 @@ public ContributionTab(ManagerFrame dialog, ContributionType type) {
7373
this.contribDialog = dialog;
7474
this.contribType = type;
7575

76-
filter = new Contribution.Filter() {
77-
public boolean matches(Contribution contrib) {
78-
return contrib.getType() == contribType;
79-
}
80-
};
76+
filter = contrib -> contrib.getType() == contribType;
8177

8278
contribListing = ContributionListing.getInstance();
8379
statusPanel = new StatusPanel(this, 650);
84-
contributionListPanel = new ListPanel(this, filter);
80+
contributionListPanel = new ListPanel(this, filter, false);
8581
contribListing.addListener(contributionListPanel);
8682
}
8783

88-
89-
// public boolean hasUpdates(Base base) {
90-
// return contribListing.hasUpdates(base);
91-
// }
92-
93-
9484
public void showFrame(final Editor editor, boolean error, boolean loading) {
9585
this.editor = editor;
9686

@@ -277,9 +267,7 @@ protected void updateCategoryChooser() {
277267

278268

279269
protected void filterLibraries(String category, List<String> filters) {
280-
List<Contribution> filteredLibraries =
281-
contribListing.getFilteredLibraryList(category, filters);
282-
contributionListPanel.filterLibraries(filteredLibraries);
270+
contributionListPanel.filterLibraries(category, filters);
283271
}
284272

285273

@@ -449,15 +437,16 @@ protected void updateAll() {
449437
contributionListPanel.panelByContribution.values();
450438
for (DetailPanel detailPanel : collection) {
451439
detailPanel.update();
452-
453-
// Refreshing the ContributionUpdateTab's status icons
454-
contributionListPanel.updatePanelOrdering(contributionListPanel
455-
.panelByContribution.keySet());
456440
}
441+
contributionListPanel.model.fireTableDataChanged();
457442
}
458443

459444

460445
protected boolean hasUpdates() {
461446
return contributionListPanel.getRowCount() > 0;
462447
}
448+
449+
public boolean filterHasFocus() {
450+
return filterField != null && filterField.hasFocus();
451+
}
463452
}

0 commit comments

Comments
 (0)