mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Various improvements on library manager
This commit is contained in:
@ -29,10 +29,16 @@
|
|||||||
package cc.arduino.libraries.contributions.ui;
|
package cc.arduino.libraries.contributions.ui;
|
||||||
|
|
||||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||||
|
import cc.arduino.libraries.contributions.ContributedLibraryComparator;
|
||||||
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
||||||
|
import cc.arduino.libraries.contributions.ui.filters.InstalledPredicate;
|
||||||
import cc.arduino.ui.InstallerTableCell;
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
|
import cc.arduino.utils.ReverseComparator;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
|
|
||||||
|
import javax.sound.midi.Soundbank;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
@ -45,6 +51,9 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import static processing.app.I18n._;
|
||||||
import static processing.app.I18n.format;
|
import static processing.app.I18n.format;
|
||||||
@ -59,6 +68,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
private Component removeButtonPlaceholder;
|
private Component removeButtonPlaceholder;
|
||||||
private Component installButtonPlaceholder;
|
private Component installButtonPlaceholder;
|
||||||
private JComboBox downgradeChooser;
|
private JComboBox downgradeChooser;
|
||||||
|
private JComboBox versionToInstallChooser;
|
||||||
private JButton downgradeButton;
|
private JButton downgradeButton;
|
||||||
private JPanel buttonsPanel;
|
private JPanel buttonsPanel;
|
||||||
private Component removeButtonStrut;
|
private Component removeButtonStrut;
|
||||||
@ -121,8 +131,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
downgradeButton.addActionListener(new ActionListener() {
|
downgradeButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ContributedLibrary selected;
|
ContributedLibrary selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
||||||
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
|
||||||
onInstall(selected, editorValue.getInstalled());
|
onInstall(selected, editorValue.getInstalled());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -139,6 +148,16 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
versionToInstallChooser = new JComboBox();
|
||||||
|
versionToInstallChooser.addItem("-");
|
||||||
|
versionToInstallChooser.setMaximumSize(versionToInstallChooser.getPreferredSize());
|
||||||
|
versionToInstallChooser.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
editorValue.select((ContributedLibrary) versionToInstallChooser.getSelectedItem());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
@ -156,6 +175,8 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
|
|
||||||
buttonsPanel.add(Box.createHorizontalGlue());
|
buttonsPanel.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
|
buttonsPanel.add(versionToInstallChooser);
|
||||||
|
buttonsPanel.add(Box.createHorizontalStrut(5));
|
||||||
buttonsPanel.add(installButton);
|
buttonsPanel.add(installButton);
|
||||||
buttonsPanel.add(Box.createHorizontalStrut(5));
|
buttonsPanel.add(Box.createHorizontalStrut(5));
|
||||||
buttonsPanel.add(removeButton);
|
buttonsPanel.add(removeButton);
|
||||||
@ -227,17 +248,22 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
editorValue = (ContributedLibraryReleases) value;
|
editorValue = (ContributedLibraryReleases) value;
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
|
|
||||||
|
List<ContributedLibrary> uninstalledLibraries = new LinkedList<ContributedLibrary>(Collections2.filter(editorValue.releases, Predicates.not(new InstalledPredicate())));
|
||||||
|
Collections.sort(uninstalledLibraries, new ReverseComparator<ContributedLibrary>(new ContributedLibraryComparator()));
|
||||||
|
|
||||||
downgradeChooser.removeAllItems();
|
downgradeChooser.removeAllItems();
|
||||||
downgradeChooser.addItem(_("Select version"));
|
downgradeChooser.addItem(_("Select version"));
|
||||||
boolean visible = false;
|
for (ContributedLibrary release : uninstalledLibraries) {
|
||||||
for (ContributedLibrary release : editorValue.releases) {
|
|
||||||
if (release.isInstalled())
|
|
||||||
continue;
|
|
||||||
downgradeChooser.addItem(release);
|
downgradeChooser.addItem(release);
|
||||||
visible = true;
|
|
||||||
}
|
}
|
||||||
downgradeChooser.setVisible(visible && editorValue.releases.size() > 1);
|
downgradeChooser.setVisible(editorValue.getInstalled() != null && uninstalledLibraries.size() > 1);
|
||||||
downgradeButton.setVisible(visible && editorValue.releases.size() > 1);
|
downgradeButton.setVisible(editorValue.getInstalled() != null && uninstalledLibraries.size() > 1);
|
||||||
|
|
||||||
|
versionToInstallChooser.removeAllItems();
|
||||||
|
for (ContributedLibrary release : uninstalledLibraries) {
|
||||||
|
versionToInstallChooser.addItem(release);
|
||||||
|
}
|
||||||
|
versionToInstallChooser.setVisible(editorValue.getInstalled() == null && uninstalledLibraries.size() > 1);
|
||||||
|
|
||||||
Component component = getUpdatedCellComponent(value, true, row);
|
Component component = getUpdatedCellComponent(value, true, row);
|
||||||
component.setBackground(new Color(218, 227, 227)); //#dae3e3
|
component.setBackground(new Color(218, 227, 227)); //#dae3e3
|
||||||
@ -257,12 +283,14 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
} else {
|
} else {
|
||||||
installable = false;
|
installable = false;
|
||||||
removable = !installedLib.isReadOnly();
|
removable = !installedLib.isReadOnly();
|
||||||
upgradable = (selectedLib != installedLib);
|
upgradable = new ContributedLibraryComparator().compare(selectedLib, installedLib) > 0;
|
||||||
}
|
}
|
||||||
if (installable)
|
if (installable) {
|
||||||
installButton.setText(_("Install"));
|
installButton.setText(_("Install"));
|
||||||
if (upgradable)
|
}
|
||||||
installButton.setText(_("Upgrade"));
|
if (upgradable) {
|
||||||
|
installButton.setText(_("Update"));
|
||||||
|
}
|
||||||
installButton.setVisible(installable || upgradable);
|
installButton.setVisible(installable || upgradable);
|
||||||
installButtonPlaceholder.setVisible(!(installable || upgradable));
|
installButtonPlaceholder.setVisible(!(installable || upgradable));
|
||||||
removeButton.setVisible(removable);
|
removeButton.setVisible(removable);
|
||||||
@ -327,13 +355,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
description.setText(desc);
|
description.setText(desc);
|
||||||
description.setBackground(Color.WHITE);
|
description.setBackground(Color.WHITE);
|
||||||
|
|
||||||
// If the selected lib is available from repository...
|
|
||||||
if (url != null) {
|
|
||||||
removeButton.setText(_("Remove"));
|
|
||||||
} else {
|
|
||||||
removeButton.setText(_("Delete"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// for modelToView to work, the text area has to be sized. It doesn't
|
// for modelToView to work, the text area has to be sized. It doesn't
|
||||||
// matter if it's visible or not.
|
// matter if it's visible or not.
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class LibraryInstaller {
|
|||||||
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
|
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
|
||||||
try {
|
try {
|
||||||
downloader.download(url, tmpFile, progress,
|
downloader.download(url, tmpFile, progress,
|
||||||
_("Downloading libraries index..."));
|
_("Downloading libraries index..."));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// Download interrupted... just exit
|
// Download interrupted... just exit
|
||||||
return;
|
return;
|
||||||
@ -121,7 +121,7 @@ public class LibraryInstaller {
|
|||||||
|
|
||||||
// Step 3: Remove replaced library and move installed one to the correct location
|
// Step 3: Remove replaced library and move installed one to the correct location
|
||||||
// TODO: Fix progress bar...
|
// TODO: Fix progress bar...
|
||||||
if (replacedLib != null) {
|
if (replacedLib != null && !replacedLib.isReadOnly()) {
|
||||||
remove(replacedLib);
|
remove(replacedLib);
|
||||||
}
|
}
|
||||||
File destFolder = new File(libsFolder, lib.getName());
|
File destFolder = new File(libsFolder, lib.getName());
|
||||||
@ -133,6 +133,10 @@ public class LibraryInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(ContributedLibrary lib) throws IOException {
|
public void remove(ContributedLibrary lib) throws IOException {
|
||||||
|
if (lib.isReadOnly()) {
|
||||||
|
throw new IllegalArgumentException("Can't delete a built-in library");
|
||||||
|
}
|
||||||
|
|
||||||
final MultiStepProgress progress = new MultiStepProgress(2);
|
final MultiStepProgress progress = new MultiStepProgress(2);
|
||||||
|
|
||||||
// Step 1: Remove library
|
// Step 1: Remove library
|
||||||
|
@ -65,8 +65,8 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRemove(ContributedLibrary installedPlatform) {
|
protected void onRemove(ContributedLibrary library) {
|
||||||
onRemovePressed(installedPlatform);
|
onRemovePressed(library);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
if (installable)
|
if (installable)
|
||||||
installButton.setText(_("Install"));
|
installButton.setText(_("Install"));
|
||||||
if (upgradable)
|
if (upgradable)
|
||||||
installButton.setText(_("Upgrade"));
|
installButton.setText(_("Update"));
|
||||||
installButton.setVisible(installable || upgradable);
|
installButton.setVisible(installable || upgradable);
|
||||||
|
|
||||||
removeButton.setVisible(removable);
|
removeButton.setVisible(removable);
|
||||||
|
@ -32,6 +32,9 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cc.arduino.packages.contributions.DownloadableContribution;
|
import cc.arduino.packages.contributions.DownloadableContribution;
|
||||||
|
import processing.app.I18n;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
public abstract class ContributedLibrary extends DownloadableContribution {
|
public abstract class ContributedLibrary extends DownloadableContribution {
|
||||||
|
|
||||||
@ -109,9 +112,9 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getVersion();
|
return I18n.format(_("Version {0}"), getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String info() {
|
public String info() {
|
||||||
String res = "";
|
String res = "";
|
||||||
res += " ContributedLibrary : " + getName() + "\n";
|
res += " ContributedLibrary : " + getName() + "\n";
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package cc.arduino.libraries.contributions;
|
||||||
|
|
||||||
|
import cc.arduino.packages.contributions.VersionComparator;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class ContributedLibraryComparator implements Comparator<ContributedLibrary> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(ContributedLibrary lib1, ContributedLibrary lib2) {
|
||||||
|
return VersionComparator.VERSION_COMPARATOR.compare(lib1.getVersion(), lib2.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
17
arduino-core/src/cc/arduino/utils/ReverseComparator.java
Normal file
17
arduino-core/src/cc/arduino/utils/ReverseComparator.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package cc.arduino.utils;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class ReverseComparator<T> implements Comparator<T> {
|
||||||
|
|
||||||
|
private final Comparator<T> orig;
|
||||||
|
|
||||||
|
public ReverseComparator(Comparator<T> orig) {
|
||||||
|
this.orig = orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(T t, T t1) {
|
||||||
|
return -1 * orig.compare(t, t1);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user