Skip to content

Commit 840a2ea

Browse files
cmaglielmihalkovic
authored andcommitted
Extract ContributionIndexTableModel as outer class
1 parent c485c6b commit 840a2ea

File tree

4 files changed

+108
-65
lines changed

4 files changed

+108
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions.packages.ui;
31+
32+
import java.util.Collections;
33+
import java.util.LinkedList;
34+
import java.util.List;
35+
import java.util.stream.Collectors;
36+
37+
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
38+
import cc.arduino.contributions.filters.InstalledPredicate;
39+
import cc.arduino.contributions.packages.ContributedPackage;
40+
import cc.arduino.contributions.packages.ContributedPlatform;
41+
42+
public class ContributedPlatformReleases {
43+
44+
public final ContributedPackage packager;
45+
public final String arch;
46+
public final List<ContributedPlatform> releases;
47+
public final List<String> versions;
48+
public ContributedPlatform selected = null;
49+
50+
public ContributedPlatformReleases(ContributedPlatform platform) {
51+
packager = platform.getParentPackage();
52+
arch = platform.getArchitecture();
53+
releases = new LinkedList<>();
54+
versions = new LinkedList<>();
55+
add(platform);
56+
}
57+
58+
public boolean shouldContain(ContributedPlatform platform) {
59+
if (platform.getParentPackage() != packager)
60+
return false;
61+
return platform.getArchitecture().equals(arch);
62+
}
63+
64+
public void add(ContributedPlatform platform) {
65+
releases.add(platform);
66+
String version = platform.getParsedVersion();
67+
if (version != null) {
68+
versions.add(version);
69+
}
70+
selected = getLatest();
71+
}
72+
73+
public ContributedPlatform getInstalled() {
74+
List<ContributedPlatform> installedReleases = releases.stream()
75+
.filter(new InstalledPredicate()).collect(Collectors.toList());
76+
Collections
77+
.sort(installedReleases,
78+
new DownloadableContributionBuiltInAtTheBottomComparator());
79+
80+
if (installedReleases.isEmpty()) {
81+
return null;
82+
}
83+
84+
return installedReleases.get(0);
85+
}
86+
87+
public ContributedPlatform getLatest() {
88+
return ContributionIndexTableModel.getLatestOf(releases);
89+
}
90+
91+
public ContributedPlatform getSelected() {
92+
return selected;
93+
}
94+
95+
public void select(ContributedPlatform value) {
96+
for (ContributedPlatform plat : releases) {
97+
if (plat == value) {
98+
selected = plat;
99+
return;
100+
}
101+
}
102+
}
103+
}

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public ContributedPlatformTableCell() {
147147

148148
void update(JTable parentTable, Object value, boolean isSelected,
149149
boolean hasBuiltInRelease) {
150-
ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value;
150+
ContributedPlatformReleases releases = (ContributedPlatformReleases) value;
151151

152152
JTextPane description = makeNewDescription();
153153

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
5252

5353
private ContributedPlatformTableCell editorCell;
54-
private ContributionIndexTableModel.ContributedPlatformReleases editorValue;
54+
private ContributedPlatformReleases editorValue;
5555

5656
@Override
5757
public Object getCellEditorValue() {
@@ -77,7 +77,7 @@ public Component getTableCellEditorComponent(JTable table, Object value,
7777
.select((ContributedPlatform) editorCell.versionToInstallChooser
7878
.getSelectedItem()));
7979

80-
editorValue = (ContributionIndexTableModel.ContributedPlatformReleases) value;
80+
editorValue = (ContributedPlatformReleases) value;
8181
setEnabled(true);
8282

8383
final ContributedPlatform installed = editorValue.getInstalled();

app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

+2-62
Original file line numberDiff line numberDiff line change
@@ -38,74 +38,14 @@
3838
import processing.app.BaseNoGui;
3939

4040
import java.util.ArrayList;
41-
import java.util.Collections;
42-
import java.util.LinkedList;
4341
import java.util.List;
4442
import java.util.function.Predicate;
4543
import java.util.stream.Collectors;
4644
import java.util.stream.Stream;
4745

4846
@SuppressWarnings("serial")
49-
public class ContributionIndexTableModel extends FilteredAbstractTableModel<ContributedPlatform> {
50-
51-
public static class ContributedPlatformReleases {
52-
public final ContributedPackage packager;
53-
public final String arch;
54-
public final List<ContributedPlatform> releases;
55-
public final List<String> versions;
56-
public ContributedPlatform selected = null;
57-
58-
public ContributedPlatformReleases(ContributedPlatform platform) {
59-
this.packager = platform.getParentPackage();
60-
this.arch = platform.getArchitecture();
61-
this.releases = new LinkedList<>();
62-
this.versions = new LinkedList<>();
63-
add(platform);
64-
}
65-
66-
public boolean shouldContain(ContributedPlatform platform) {
67-
if (platform.getParentPackage() != packager)
68-
return false;
69-
return platform.getArchitecture().equals(arch);
70-
}
71-
72-
public void add(ContributedPlatform platform) {
73-
releases.add(platform);
74-
String version = platform.getParsedVersion();
75-
if (version != null) {
76-
versions.add(version);
77-
}
78-
selected = getLatest();
79-
}
80-
81-
public ContributedPlatform getInstalled() {
82-
List<ContributedPlatform> installedReleases = releases.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
83-
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
84-
85-
if (installedReleases.isEmpty()) {
86-
return null;
87-
}
88-
89-
return installedReleases.get(0);
90-
}
91-
92-
public ContributedPlatform getLatest() {
93-
return getLatestOf(releases);
94-
}
95-
96-
public ContributedPlatform getSelected() {
97-
return selected;
98-
}
99-
100-
public void select(ContributedPlatform value) {
101-
for (ContributedPlatform plat : releases) {
102-
if (plat == value) {
103-
selected = plat;
104-
return;
105-
}
106-
}
107-
}
108-
}
47+
public class ContributionIndexTableModel
48+
extends FilteredAbstractTableModel<ContributedPlatform> {
10949

11050
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
11151

0 commit comments

Comments
 (0)