diff --git a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java index 96e37ed0a..ebb26226f 100644 --- a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java +++ b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java @@ -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 } diff --git a/app/src/cc/arduino/packages/contributions/ui/ContributionIndexTableModel.java b/app/src/cc/arduino/packages/contributions/ui/ContributionIndexTableModel.java index e4332302c..d35f41fb6 100644 --- a/app/src/cc/arduino/packages/contributions/ui/ContributionIndexTableModel.java +++ b/app/src/cc/arduino/packages/contributions/ui/ContributionIndexTableModel.java @@ -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 installedPlatforms = new LinkedList(); + 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 contributions = new ArrayList(); - 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 string contains all the substrings in set. The * compare is case insensitive. - * + * * @param string * @param set * @return true if all the strings in set are contained in - * string. + * string. */ private boolean stringContainsAll(String string, String set[]) { if (set == null) diff --git a/app/src/cc/arduino/packages/contributions/ui/ContributionManagerUI.java b/app/src/cc/arduino/packages/contributions/ui/ContributionManagerUI.java index 9deebf651..d6c4f7570 100644 --- a/app/src/cc/arduino/packages/contributions/ui/ContributionManagerUI.java +++ b/app/src/cc/arduino/packages/contributions/ui/ContributionManagerUI.java @@ -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(); diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 03b8629a7..20b991143 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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)); diff --git a/arduino-core/src/cc/arduino/libraries/contributions/LibrariesIndexer.java b/arduino-core/src/cc/arduino/libraries/contributions/LibrariesIndexer.java index 5b34ae3f0..96cc38c15 100644 --- a/arduino-core/src/cc/arduino/libraries/contributions/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/libraries/contributions/LibrariesIndexer.java @@ -66,7 +66,6 @@ public class LibrariesIndexer { public void parseIndex() throws JsonParseException, IOException { parseIndex(indexFile); - System.out.println(index); index.fillCategories(); // TODO: resolve libraries inner references diff --git a/arduino-core/src/cc/arduino/packages/contributions/ContributionInstaller.java b/arduino-core/src/cc/arduino/packages/contributions/ContributionInstaller.java index 19d6cc2df..b46bea0eb 100644 --- a/arduino-core/src/cc/arduino/packages/contributions/ContributionInstaller.java +++ b/arduino-core/src/cc/arduino/packages/contributions/ContributionInstaller.java @@ -60,8 +60,9 @@ public class ContributionInstaller { } public void install(ContributedPlatform platform) throws Exception { - if (platform.isInstalled()) + if (platform.isInstalled()) { throw new Exception("Platform is already installed!"); + } // Do not download already installed tools List tools = new LinkedList(platform.getResolvedTools()); @@ -111,13 +112,11 @@ public class ContributionInstaller { File toolsFolder = new File(packageFolder, "tools"); int i = 1; for (ContributedTool tool : platform.getResolvedTools()) { - progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, - tools.size())); + progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size())); onProgress(progress); i++; DownloadableContribution toolContrib = tool.getDownloadableContribution(); - File destFolder = new File(toolsFolder, tool.getName() + File.separator + - tool.getVersion()); + File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion()); destFolder.mkdirs(); ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1); @@ -129,8 +128,7 @@ public class ContributionInstaller { // Unpack platform on the correct location progress.setStatus(_("Installing boards...")); onProgress(progress); - File platformFolder = new File(packageFolder, "hardware" + File.separator + - platform.getArchitecture()); + File platformFolder = new File(packageFolder, "hardware" + File.separator + platform.getArchitecture()); File destFolder = new File(platformFolder, platform.getVersion()); destFolder.mkdirs(); ArchiveExtractor.extract(platform.getDownloadedFile(), destFolder, 1); diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 36c0a90ef..83a2118c7 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -612,7 +612,6 @@ public class BaseNoGui { } indexer.parseIndex(); indexer.syncWithFilesystem(); - System.out.println(indexer); packages = new HashMap(); loadHardware(getHardwareFolder());