Skip to content

Commit

Permalink
#1339 board manager board list and json list not sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
jantje committed Nov 25, 2021
1 parent 511110b commit 594a3b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -421,6 +422,8 @@ protected static synchronized void loadJsons(boolean forceDownload) {
if (!jsonUrl.trim().isEmpty()) // skip empty lines
loadJson(jsonUrl, forceDownload);
}
//sorting here so things look good in the gui
Collections.sort(packageIndices);
}

/**
Expand Down Expand Up @@ -799,6 +802,7 @@ static public List<ArduinoPackage> getPackages() {
for (ArduinoPlatformPackageIndex index : getPackageIndices()) {
packages.addAll(index.getPackages());
}

return packages;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import com.google.gson.annotations.JsonAdapter;

@JsonAdapter(ArduinoPlatformPackageIndex.class)
public class ArduinoPlatformPackageIndex extends Node implements JsonDeserializer<ArduinoPlatformPackageIndex> {
public class ArduinoPlatformPackageIndex extends Node
implements Comparable<ArduinoPlatformPackageIndex>, JsonDeserializer<ArduinoPlatformPackageIndex> {

private List<ArduinoPackage> myPackages = new ArrayList<>();

Expand Down Expand Up @@ -98,4 +99,9 @@ public String getName() {
return myJsonFile.getName();
}

@Override
public int compareTo(ArduinoPlatformPackageIndex o) {
return getID().compareTo(o.getID());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -50,7 +51,7 @@
public class PlatformSelectionPage extends PreferencePage implements IWorkbenchPreferencePage {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
// platform index json, package,platform,versions structure
private HashMap<String, HashMap<String, HashMap<String, InstallableVersion[]>>> myShownPlatforms = new HashMap<>();
private TreeMap<String, TreeMap<String, TreeMap<String, InstallableVersion[]>>> myShownPlatforms = new TreeMap<>();

private boolean mustBeInstalled(ArduinoPlatform platform) {
ArduinoPackage parentPkg = platform.getParent();
Expand All @@ -66,9 +67,9 @@ private boolean mustBeInstalled(ArduinoPlatform platform) {
}

private boolean mustBeInstalled(ArduinoPlatformPackageIndex packageIndex) {
HashMap<String, HashMap<String, InstallableVersion[]>> inScopeVersions = myShownPlatforms
TreeMap<String, TreeMap<String, InstallableVersion[]>> inScopeVersions = myShownPlatforms
.get(packageIndex.getID());
for (HashMap<String, InstallableVersion[]> platform : inScopeVersions.values()) {
for (TreeMap<String, InstallableVersion[]> platform : inScopeVersions.values()) {
for (InstallableVersion[] versions : platform.values()) {
for (InstallableVersion version : versions) {
if (version.mustBeInstalled()) {
Expand All @@ -82,7 +83,7 @@ private boolean mustBeInstalled(ArduinoPlatformPackageIndex packageIndex) {

private boolean mustBeInstalled(ArduinoPackage pkg) {
ArduinoPlatformPackageIndex parentIndex = pkg.getPackageIndex();
HashMap<String, InstallableVersion[]> inScopeVersions = myShownPlatforms.get(parentIndex.getID())
TreeMap<String, InstallableVersion[]> inScopeVersions = myShownPlatforms.get(parentIndex.getID())
.get(pkg.getID());
for (InstallableVersion[] versions : inScopeVersions.values()) {
for (InstallableVersion version : versions) {
Expand Down Expand Up @@ -133,9 +134,9 @@ public ArduinoPlatformVersion getPlatform() {
public PlatformSelectionPage() {
for (ArduinoPlatformPackageIndex curPackageIndex : BoardsManager.getPackageIndices()) {
String pkgIndexID = curPackageIndex.getID();
HashMap<String, HashMap<String, InstallableVersion[]>> packageMap = new HashMap<>();
TreeMap<String, TreeMap<String, InstallableVersion[]>> packageMap = new TreeMap<>();
for (ArduinoPackage curPackage : curPackageIndex.getPackages()) {
HashMap<String, InstallableVersion[]> platformMap = new HashMap<>();
TreeMap<String, InstallableVersion[]> platformMap = new TreeMap<>();
String pkgID = curPackage.getID();
for (ArduinoPlatform curPlatform : curPackage.getPlatforms()) {
String platformID = curPlatform.getID();
Expand Down Expand Up @@ -302,11 +303,11 @@ public void checkStateChanged(CheckStateChangedEvent event) {
public Object[] getElements(Object inputElement) {
if (PlatformSelectionPage.this.myHideJson) {
List<ArduinoPackage> packages = BoardsManager.getPackages();
Collections.sort(packages);
return packages.toArray(new Object[packages.size()]);
}
Collection<ArduinoPlatformPackageIndex> indexFiles = BoardsManager.getPackageIndices();
List<ArduinoPlatformPackageIndex> indexFiles = BoardsManager.getPackageIndices();
return indexFiles.toArray(new Object[indexFiles.size()]);

}

@Override
Expand All @@ -322,7 +323,8 @@ public void inputChanged(Viewer viewer11, Object oldInput, Object newInput) {
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof ArduinoPlatformPackageIndex) {
Collection<ArduinoPackage> packages = ((ArduinoPlatformPackageIndex) parentElement).getPackages();
Collection<ArduinoPackage> packages = ((ArduinoPlatformPackageIndex) parentElement)
.getPackages();
return packages.toArray(new Object[packages.size()]);
}
if (parentElement instanceof ArduinoPackage) {
Expand Down Expand Up @@ -440,8 +442,8 @@ public void update(ViewerCell cell) {
protected IStatus updateInstallation(IProgressMonitor monitor) {
List<ArduinoPlatformVersion> platformsToInstall = new LinkedList<>();
List<ArduinoPlatformVersion> platformsToRemove = new LinkedList<>();
for (HashMap<String, HashMap<String, InstallableVersion[]>> packageIndex : myShownPlatforms.values()) {
for (HashMap<String, InstallableVersion[]> arduinoPackage : packageIndex.values()) {
for (TreeMap<String, TreeMap<String, InstallableVersion[]>> packageIndex : myShownPlatforms.values()) {
for (TreeMap<String, InstallableVersion[]> arduinoPackage : packageIndex.values()) {
for (InstallableVersion[] versions : arduinoPackage.values()) {
for (InstallableVersion version : versions) {
if (version.isInstalled() != version.mustBeInstalled()) {
Expand Down

0 comments on commit 594a3b4

Please sign in to comment.