1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-17 11:54:33 +01:00

Various improvements on library manager

This commit is contained in:
Federico Fissore 2015-03-13 17:30:48 +01:00
parent e884789322
commit 8e5a04f6a9
7 changed files with 87 additions and 27 deletions

View File

@ -29,10 +29,16 @@
package cc.arduino.libraries.contributions.ui;
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.filters.InstalledPredicate;
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 javax.sound.midi.Soundbank;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.HyperlinkEvent;
@ -45,6 +51,9 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
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.format;
@ -59,6 +68,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
private Component removeButtonPlaceholder;
private Component installButtonPlaceholder;
private JComboBox downgradeChooser;
private JComboBox versionToInstallChooser;
private JButton downgradeButton;
private JPanel buttonsPanel;
private Component removeButtonStrut;
@ -121,8 +131,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
downgradeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ContributedLibrary selected;
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
ContributedLibrary selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
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.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
@ -156,6 +175,8 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
buttonsPanel.add(Box.createHorizontalGlue());
buttonsPanel.add(versionToInstallChooser);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(installButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(removeButton);
@ -227,17 +248,22 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
editorValue = (ContributedLibraryReleases) value;
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.addItem(_("Select version"));
boolean visible = false;
for (ContributedLibrary release : editorValue.releases) {
if (release.isInstalled())
continue;
for (ContributedLibrary release : uninstalledLibraries) {
downgradeChooser.addItem(release);
visible = true;
}
downgradeChooser.setVisible(visible && editorValue.releases.size() > 1);
downgradeButton.setVisible(visible && editorValue.releases.size() > 1);
downgradeChooser.setVisible(editorValue.getInstalled() != null && uninstalledLibraries.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.setBackground(new Color(218, 227, 227)); //#dae3e3
@ -257,12 +283,14 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
} else {
installable = false;
removable = !installedLib.isReadOnly();
upgradable = (selectedLib != installedLib);
upgradable = new ContributedLibraryComparator().compare(selectedLib, installedLib) > 0;
}
if (installable)
if (installable) {
installButton.setText(_("Install"));
if (upgradable)
installButton.setText(_("Upgrade"));
}
if (upgradable) {
installButton.setText(_("Update"));
}
installButton.setVisible(installable || upgradable);
installButtonPlaceholder.setVisible(!(installable || upgradable));
removeButton.setVisible(removable);
@ -327,13 +355,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
description.setText(desc);
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
// matter if it's visible or not.

View File

@ -68,7 +68,7 @@ public class LibraryInstaller {
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
try {
downloader.download(url, tmpFile, progress,
_("Downloading libraries index..."));
_("Downloading libraries index..."));
} catch (InterruptedException e) {
// Download interrupted... just exit
return;
@ -121,7 +121,7 @@ public class LibraryInstaller {
// Step 3: Remove replaced library and move installed one to the correct location
// TODO: Fix progress bar...
if (replacedLib != null) {
if (replacedLib != null && !replacedLib.isReadOnly()) {
remove(replacedLib);
}
File destFolder = new File(libsFolder, lib.getName());
@ -133,6 +133,10 @@ public class LibraryInstaller {
}
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);
// Step 1: Remove library

View File

@ -65,8 +65,8 @@ public class LibraryManagerUI extends InstallerJDialog {
}
@Override
protected void onRemove(ContributedLibrary installedPlatform) {
onRemovePressed(installedPlatform);
protected void onRemove(ContributedLibrary library) {
onRemovePressed(library);
}
};
}

View File

@ -254,7 +254,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
if (installable)
installButton.setText(_("Install"));
if (upgradable)
installButton.setText(_("Upgrade"));
installButton.setText(_("Update"));
installButton.setVisible(installable || upgradable);
removeButton.setVisible(removable);

View File

@ -32,6 +32,9 @@ import java.util.Comparator;
import java.util.List;
import cc.arduino.packages.contributions.DownloadableContribution;
import processing.app.I18n;
import static processing.app.I18n._;
public abstract class ContributedLibrary extends DownloadableContribution {
@ -109,9 +112,9 @@ public abstract class ContributedLibrary extends DownloadableContribution {
@Override
public String toString() {
return getVersion();
return I18n.format(_("Version {0}"), getVersion());
}
public String info() {
String res = "";
res += " ContributedLibrary : " + getName() + "\n";

View File

@ -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());
}
}

View 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);
}
}