Skip to content

Commit 0042a30

Browse files
committed
Simplified version display logic in Library Manager
- replaced the logic to check if an installed-library is a builtin library by reusing the same method available in ContributedLibraryReleases - renamed some local vars to better reflect their contents: uninstalledLibraries -> notInstalled uninstalledNewerReleases -> notInstalledNewer uninstalledPreviousReleases -> notInstalledPrevious
1 parent ac6d3c1 commit 0042a30

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java

+17-25
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@
3737
import java.util.LinkedList;
3838
import java.util.List;
3939
import java.util.Optional;
40-
import java.util.stream.Collectors;
4140

4241
import javax.swing.JComboBox;
4342
import javax.swing.JTable;
4443

4544
import cc.arduino.contributions.DownloadableContributionVersionComparator;
4645
import cc.arduino.contributions.VersionComparator;
47-
import cc.arduino.contributions.filters.BuiltInPredicate;
4846
import cc.arduino.contributions.libraries.ContributedLibrary;
4947
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
5048
import cc.arduino.contributions.ui.InstallerTableCell;
@@ -88,50 +86,44 @@ public Component getTableCellEditorComponent(JTable table, Object value,
8886
final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
8987

9088
List<ContributedLibrary> releases = editorValue.getReleases();
91-
List<ContributedLibrary> uninstalledReleases = releases.stream()
92-
.filter(l -> !l.isLibraryInstalled()).collect(Collectors.toList());
93-
94-
List<ContributedLibrary> installedBuiltIn = releases.stream()
95-
.filter(l -> !l.isLibraryInstalled()).filter(new BuiltInPredicate())
96-
.collect(Collectors.toList());
97-
98-
if (mayInstalled.isPresent() && !installedBuiltIn.contains(mayInstalled.get())) {
99-
uninstalledReleases.addAll(installedBuiltIn);
89+
List<ContributedLibrary> notInstalled = new LinkedList<>(releases);
90+
if (mayInstalled.isPresent()) {
91+
notInstalled.remove(editorValue.getInstalled().get());
10092
}
10193

102-
Collections.sort(uninstalledReleases, new ReverseComparator<>(
94+
Collections.sort(notInstalled, new ReverseComparator<>(
10395
new DownloadableContributionVersionComparator()));
10496

10597
editorCell.downgradeChooser.removeAllItems();
10698
editorCell.downgradeChooser.addItem(tr("Select version"));
10799

108-
final List<ContributedLibrary> uninstalledPreviousReleases = new LinkedList<>();
109-
final List<ContributedLibrary> uninstalledNewerReleases = new LinkedList<>();
100+
final List<ContributedLibrary> notInstalledPrevious = new LinkedList<>();
101+
final List<ContributedLibrary> notIInstalledNewer = new LinkedList<>();
110102

111-
uninstalledReleases.stream().forEach(input -> {
103+
notInstalled.stream().forEach(input -> {
112104
if (!mayInstalled.isPresent()
113105
|| VersionComparator.greaterThan(mayInstalled.get(), input)) {
114-
uninstalledPreviousReleases.add(input);
106+
notInstalledPrevious.add(input);
115107
} else {
116-
uninstalledNewerReleases.add(input);
108+
notIInstalledNewer.add(input);
117109
}
118110
});
119-
uninstalledNewerReleases.forEach(editorCell.downgradeChooser::addItem);
120-
uninstalledPreviousReleases.forEach(editorCell.downgradeChooser::addItem);
111+
notIInstalledNewer.forEach(editorCell.downgradeChooser::addItem);
112+
notInstalledPrevious.forEach(editorCell.downgradeChooser::addItem);
121113

122114
editorCell.downgradeChooser
123115
.setVisible(mayInstalled.isPresent()
124-
&& (!uninstalledPreviousReleases.isEmpty()
125-
|| uninstalledNewerReleases.size() > 1));
116+
&& (!notInstalledPrevious.isEmpty()
117+
|| notIInstalledNewer.size() > 1));
126118
editorCell.downgradeButton
127119
.setVisible(mayInstalled.isPresent()
128-
&& (!uninstalledPreviousReleases.isEmpty()
129-
|| uninstalledNewerReleases.size() > 1));
120+
&& (!notInstalledPrevious.isEmpty()
121+
|| notIInstalledNewer.size() > 1));
130122

131123
editorCell.versionToInstallChooser.removeAllItems();
132-
uninstalledReleases.forEach(editorCell.versionToInstallChooser::addItem);
124+
notInstalled.forEach(editorCell.versionToInstallChooser::addItem);
133125
editorCell.versionToInstallChooser
134-
.setVisible(!mayInstalled.isPresent() && uninstalledReleases.size() > 1);
126+
.setVisible(!mayInstalled.isPresent() && notInstalled.size() > 1);
135127

136128
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
137129
return editorCell;

0 commit comments

Comments
 (0)