1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-01 03:47:23 +03:00

Removing previously installed platform on upgrade

This commit is contained in:
Federico Fissore
2015-02-23 12:47:48 +01:00
parent b1e0249a4f
commit fe6718ce4f
7 changed files with 49 additions and 35 deletions

View File

@ -98,7 +98,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
installButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onInstall(editorValue.getSelected());
onInstall(editorValue.getSelected(), editorValue.getInstalled());
}
});
@ -129,7 +129,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
// Empty
}
protected void onInstall(ContributedPlatform contributedPlatform) {
protected void onInstall(ContributedPlatform contributedPlatform, ContributedPlatform installed) {
// Empty
}

View File

@ -28,14 +28,17 @@
*/
package cc.arduino.packages.contributions.ui;
import java.util.ArrayList;
import java.util.List;
import cc.arduino.packages.contributions.ContributedPackage;
import cc.arduino.packages.contributions.ContributedPlatform;
import cc.arduino.packages.contributions.ContributionsIndex;
import cc.arduino.ui.FilteredAbstractTableModel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static processing.app.I18n._;
@SuppressWarnings("serial")
public class ContributionIndexTableModel extends FilteredAbstractTableModel {
@ -69,9 +72,21 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
}
public ContributedPlatform getInstalled() {
for (ContributedPlatform plat : releases)
if (plat.isInstalled())
return plat;
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>();
for (ContributedPlatform platform : releases) {
if (platform.isInstalled()) {
installedPlatforms.add(platform);
}
}
if (installedPlatforms.size() > 1) {
throw new IllegalStateException(_("More than one platform is currently installed! Only one can be installed at any given time"));
}
if (!installedPlatforms.isEmpty()) {
return installedPlatforms.get(0);
}
return null;
}
@ -112,9 +127,9 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
private List<ContributedPlatformReleases> contributions = new ArrayList<ContributedPlatformReleases>();
private String[] columnNames = { "Description" };
private String[] columnNames = {"Description"};
private Class<?>[] columnTypes = { ContributedPlatform.class };
private Class<?>[] columnTypes = {ContributedPlatform.class};
private ContributionsIndex index;
@ -141,11 +156,11 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
/**
* Check if <b>string</b> contains all the substrings in <b>set</b>. The
* compare is case insensitive.
*
*
* @param string
* @param set
* @return <b>true<b> if all the strings in <b>set</b> are contained in
* <b>string</b>.
* <b>string</b>.
*/
private boolean stringContainsAll(String string, String set[]) {
if (set == null)

View File

@ -63,8 +63,8 @@ public class ContributionManagerUI extends InstallerJDialog {
protected InstallerTableCell createCellEditor() {
return new ContributedPlatformTableCell() {
@Override
protected void onInstall(ContributedPlatform selectedPlatform) {
onInstallPressed(selectedPlatform);
protected void onInstall(ContributedPlatform selectedPlatform, ContributedPlatform installed) {
onInstallPressed(selectedPlatform, installed);
}
@Override
@ -146,13 +146,16 @@ public class ContributionManagerUI extends InstallerJDialog {
installerThread.start();
}
public void onInstallPressed(final ContributedPlatform platform) {
public void onInstallPressed(final ContributedPlatform platformToInstall, final ContributedPlatform platformToRemove) {
installerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
setProgressVisible(true);
installer.install(platform);
installer.install(platformToInstall);
if (platformToRemove != null) {
installer.remove(platformToRemove);
}
} catch (Exception e) {
// TODO Show ERROR
e.printStackTrace();

View File

@ -1123,7 +1123,7 @@ public class Base {
rebuildExamplesMenu(Editor.examplesMenu);
}
private void openInstallBoardDialog() {
private void openInstallBoardDialog() throws Exception {
// Create dialog for contribution manager
@SuppressWarnings("serial")
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
@ -1139,14 +1139,9 @@ public class Base {
// Installer dialog is modal, waits here until closed
// Reload all boards (that may have been installed/updated/removed)
try {
BaseNoGui.initPackages();
rebuildBoardsMenu();
onBoardOrPortChange();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BaseNoGui.initPackages();
rebuildBoardsMenu();
onBoardOrPortChange();
}
public void rebuildBoardsMenu() throws Exception {
@ -1158,7 +1153,12 @@ public class Base {
@SuppressWarnings("serial")
Action runInstaller = new AbstractAction("Install boards...") {
public void actionPerformed(ActionEvent actionevent) {
openInstallBoardDialog();
try {
openInstallBoardDialog();
} catch (Exception e) {
//TODO show error
e.printStackTrace();
}
}
};
boardMenu.add(new JMenuItem(runInstaller));