import static org.junit.Assert.assertNotEquals;
+import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.junit.Test;
@Test
public void loadPackagesTest() throws Exception {
- assertNotEquals(0, ArduinoManager.instance.getPackageIndices().size());
+ assertNotEquals(0, Activator.getService(ArduinoManager.class).getPackageIndices().size());
}
}
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal;
+import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtension;
public void start(BundleContext bundleContext) throws Exception {
plugin = this;
+ bundleContext.registerService(ArduinoManager.class, new ArduinoManager(), null);
}
public void stop(BundleContext bundleContext) throws Exception {
public static String ArduinoLaunchConfigurationDelegate_0;
public static String ArduinoLaunchConfigurationDelegate_1;
public static String ArduinoLaunchConfigurationDelegate_2;
+ public static String ArduinoManager_0;
+ public static String ArduinoManager_1;
+ public static String ArduinoManager_2;
+ public static String ArduinoPlatform_0;
+ public static String ArduinoPlatform_1;
public static String ArduinoProjectGenerator_0;
static {
import java.lang.reflect.Type;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Collection;
public class ArduinoManager {
- public static final ArduinoManager instance = new ArduinoManager();
-
// Build tool ids
public static final String BOARD_OPTION_ID = "org.eclipse.cdt.arduino.option.board"; //$NON-NLS-1$
public static final String PLATFORM_OPTION_ID = "org.eclipse.cdt.arduino.option.platform"; //$NON-NLS-1$
return null;
}
- public List<ArduinoBoard> getBoards() throws CoreException {
- List<ArduinoBoard> boards = new ArrayList<>();
- for (PackageIndex index : getPackageIndices()) {
- for (ArduinoPackage pkg : index.getPackages()) {
- for (ArduinoPlatform platform : pkg.getLatestPlatforms()) {
- boards.addAll(platform.getBoards());
- }
- }
- }
- return boards;
- }
-
public List<ArduinoBoard> getInstalledBoards() throws CoreException {
List<ArduinoBoard> boards = new ArrayList<>();
for (PackageIndex index : getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) {
- for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) {
+ for (ArduinoPlatform platform : pkg.getInstalledPlatforms().values()) {
boards.addAll(platform.getBoards());
}
}
Type stringSet = new TypeToken<Set<String>>() {
}.getType();
Set<String> libraryNames = new Gson().fromJson(librarySetting, stringSet);
- LibraryIndex index = ArduinoManager.instance.getLibraryIndex();
+ LibraryIndex index = Activator.getService(ArduinoManager.class).getLibraryIndex();
ArduinoPlatform platform = project.getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard()
.getPlatform();
Activator.log(e);
}
- new Job("Install libraries") {
+ new Job(Messages.ArduinoManager_0) {
protected IStatus run(IProgressMonitor monitor) {
- MultiStatus mstatus = new MultiStatus(Activator.getId(), 0, "Installing libraries", null);
+ MultiStatus mstatus = new MultiStatus(Activator.getId(), 0, Messages.ArduinoManager_1, null);
for (ArduinoLibrary library : libraries) {
IStatus status = library.install(monitor);
if (!status.isOK()) {
}
}
// out of retries
- return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", error);
+ return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoManager_2, error);
+ }
+
+ public static int compareVersions(String version1, String version2) {
+ if (version1 == null) {
+ return version2 == null ? 0 : -1;
+ }
+
+ if (version2 == null) {
+ return 1;
+ }
+
+ String[] v1 = version1.split("\\."); //$NON-NLS-1$
+ String[] v2 = version2.split("\\."); //$NON-NLS-1$
+ for (int i = 0; i < Math.max(v1.length, v2.length); ++i) {
+ if (v1.length <= i) {
+ return v2.length < i ? 0 : -1;
+ }
+
+ if (v2.length <= i) {
+ return 1;
+ }
+
+ try {
+ int vi1 = Integer.parseInt(v1[i]);
+ int vi2 = Integer.parseInt(v2[i]);
+ if (vi1 < vi2) {
+ return -1;
+ }
+
+ if (vi1 > vi2) {
+ return 1;
+ }
+ } catch (NumberFormatException e) {
+ // not numbers, do string compares
+ int c = v1[i].compareTo(v2[i]);
+ if (c < 0) {
+ return -1;
+ }
+ if (c > 0) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
}
private static Set<PosixFilePermission> toPerms(int mode) {
return perms;
}
+ public static void recursiveDelete(Path directory) throws IOException {
+ Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+
+ });
+ }
}
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
+
public class ArduinoPackage {
private String name;
return Collections.unmodifiableCollection(platforms);
}
+ public Path getInstallPath() {
+ return ArduinoPreferences.getArduinoHome().resolve("packages").resolve(getName()); //$NON-NLS-1$
+ }
+
/**
* Only the latest versions of the platforms.
*
* @return latest platforms
*/
- public Collection<ArduinoPlatform> getLatestPlatforms() {
+ public Map<String, ArduinoPlatform> getAvailablePlatforms() {
Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) {
ArduinoPlatform p = platformMap.get(platform.getName());
- if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) {
+ if (p == null || ArduinoManager.compareVersions(platform.getVersion(), p.getVersion()) > 0) {
platformMap.put(platform.getName(), platform);
}
}
- return Collections.unmodifiableCollection(platformMap.values());
+ return platformMap;
}
- public Collection<ArduinoPlatform> getInstalledPlatforms() {
+ public Map<String, ArduinoPlatform> getInstalledPlatforms() {
Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) {
if (platform.isInstalled()) {
- ArduinoPlatform p = platformMap.get(platform.getName());
- if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) {
- platformMap.put(platform.getName(), platform);
- }
- }
- }
- return Collections.unmodifiableCollection(platformMap.values());
- }
-
- // TODO move somewhere.
- public static int compareVersions(String version1, String version2) {
- if (version1 == null) {
- return version2 == null ? 0 : -1;
- }
-
- if (version2 == null) {
- return 1;
- }
-
- String[] v1 = version1.split("\\."); //$NON-NLS-1$
- String[] v2 = version2.split("\\."); //$NON-NLS-1$
- for (int i = 0; i < Math.max(v1.length, v2.length); ++i) {
- if (v1.length <= i) {
- return v2.length < i ? 0 : -1;
- }
-
- if (v2.length <= i) {
- return 1;
- }
-
- try {
- int vi1 = Integer.parseInt(v1[i]);
- int vi2 = Integer.parseInt(v2[i]);
- if (vi1 < vi2) {
- return -1;
- }
-
- if (vi1 > vi2) {
- return 1;
- }
- } catch (NumberFormatException e) {
- // not numbers, do string compares
- int c = v1[i].compareTo(v2[i]);
- if (c < 0) {
- return -1;
- }
- if (c > 0) {
- return 1;
- }
+ platformMap.put(platform.getName(), platform);
}
}
-
- return 0;
+ return platformMap;
}
public ArduinoPlatform getPlatform(String name) {
foundPlatform = platform;
} else {
if (platform.isInstalled()
- && compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) {
+ && ArduinoManager.compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) {
foundPlatform = platform;
}
}
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
+import org.eclipse.cdt.arduino.core.internal.Messages;
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
return size;
}
- public List<ArduinoBoard> getBoards() throws CoreException {
+ public List<ArduinoBoard> getBoards() {
if (isInstalled() && boardsProperties == null) {
Properties boardProps = new Properties();
-
- try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile());
+
+ try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile()); //$NON-NLS-1$
Reader reader = new InputStreamReader(is, "UTF-8")) { //$NON-NLS-1$
boardProps.load(reader);
} catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading boards.txt", e)); //$NON-NLS-1$
+ Activator.log(e);
}
boardsProperties = new HierarchicalProperties(boardProps);
}
public Path getInstallPath() {
- return ArduinoPreferences.getArduinoHome().resolve("hardware").resolve(pkg.getName()).resolve(architecture) //$NON-NLS-1$
+ // TODO remove migration in Neon
+ Path oldPath = ArduinoPreferences.getArduinoHome().resolve("hardware").resolve(pkg.getName()) //$NON-NLS-1$
+ .resolve(architecture).resolve(version);
+ Path newPath = getPackage().getInstallPath().resolve("hardware").resolve(pkg.getName()).resolve(architecture) //$NON-NLS-1$
.resolve(version);
+ if (Files.exists(oldPath)) {
+ try {
+ Files.createDirectories(newPath.getParent());
+ Files.move(oldPath, newPath);
+ for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
+ if (Files.newDirectoryStream(parent).iterator().hasNext()) {
+ break;
+ } else {
+ Files.delete(parent);
+ }
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+ return newPath;
}
public List<Path> getIncludePath() {
public IStatus install(IProgressMonitor monitor) {
// Check if we're installed already
if (isInstalled()) {
- return Status.OK_STATUS;
+ try {
+ ArduinoManager.recursiveDelete(getInstallPath());
+ } catch (IOException e) {
+ // just log it, shouldn't break the install
+ Activator.log(e);
+ }
}
// Install the tools
// On Windows install make from bintray
if (Platform.getOS().equals(Platform.OS_WIN32)) {
try {
- Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe"); //$NON-NLS-1$
+ Path makePath = ArduinoPreferences.getArduinoHome().resolve("make.exe"); //$NON-NLS-1$
if (!makePath.toFile().exists()) {
Files.createDirectories(makePath.getParent());
URL makeUrl = new URL("https://bintray.com/artifact/download/cdtdoug/tools/make.exe"); //$NON-NLS-1$
makePath.toFile().setExecutable(true, false);
}
} catch (IOException e) {
- return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", e);
+ return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_0, e);
}
}
return Status.OK_STATUS;
}
+ public IStatus uninstall(IProgressMonitor monitor) {
+ try {
+ ArduinoManager.recursiveDelete(getInstallPath());
+ // TODO delete tools that aren't needed any more
+ return Status.OK_STATUS;
+ } catch (IOException e) {
+ return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_1, e);
+ }
+ }
+
@Override
public int hashCode() {
final int prime = 31;
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
}
public Path getInstallPath() {
- return ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$
+ // TODO remove migration in Neon
+ Path oldPath = ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$
.resolve(version);
+ Path newPath = getPackage().getInstallPath().resolve("tools").resolve(name).resolve(version); //$NON-NLS-1$
+ if (Files.exists(oldPath)) {
+ try {
+ Files.createDirectories(newPath.getParent());
+ Files.move(oldPath, newPath);
+ for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
+ if (Files.newDirectoryStream(parent).iterator().hasNext()) {
+ break;
+ } else {
+ Files.delete(parent);
+ }
+ }
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ }
+ return newPath;
}
public boolean isInstalled() {
ArduinoLibrary current = latestLibs.get(name);
if (current != null) {
- if (ArduinoPackage.compareVersions(library.getVersion(), current.getVersion()) > 0) {
+ if (ArduinoManager.compareVersions(library.getVersion(), current.getVersion()) > 0) {
latestLibs.put(name, library);
}
} else {
private final IBuildConfiguration config;
+ private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
+
private ArduinoBoard board;
private Properties properties;
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$
- board = ArduinoManager.instance.getBoard(boardName, platformName, packageName);
+ board = manager.getBoard(boardName, platformName, packageName);
if (board == null) {
// Default to Uno or first one we find
- board = ArduinoManager.instance.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ board = manager.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (board == null) {
- List<ArduinoBoard> boards = ArduinoManager.instance.getInstalledBoards();
+ List<ArduinoBoard> boards = manager.getInstalledBoards();
if (!boards.isEmpty()) {
board = boards.get(0);
}
// The list of library sources
List<String> librarySources = new ArrayList<>();
- for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
+ for (ArduinoLibrary lib : manager.getLibraries(project)) {
librarySources.addAll(lib.getSources());
}
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
}
includes += '"' + pathString(include) + '"';
}
- for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
+ for (ArduinoLibrary lib : manager.getLibraries(project)) {
for (Path include : lib.getIncludePath()) {
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
}
for (Path include : platform.getIncludePath()) {
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
}
- Collection<ArduinoLibrary> libs = ArduinoManager.instance.getLibraries(config.getProject());
+ Collection<ArduinoLibrary> libs = manager.getLibraries(config.getProject());
for (ArduinoLibrary lib : libs) {
for (Path path : lib.getIncludePath()) {
includes += " -I\"" + pathString(path) + '"'; //$NON-NLS-1$
################################################################################
ArduinoLaunchConfigurationDelegate_0=Arduino Launch
ArduinoLaunchConfigurationDelegate_2=Target has not been selected for Launch Configuration
+ArduinoManager_0=Install libraries
+ArduinoManager_1=Installing libraries
+ArduinoManager_2=Download failed, please try again.
+ArduinoPlatform_0=Download failed, please try again.
+ArduinoPlatform_1=Uninstall failed.
ArduinoProjectGenerator_0=Write Arduino project file
}
public ArduinoBoard getBoard() throws CoreException {
- return ArduinoManager.instance.getBoard(remoteConnection.getAttribute(BOARD_NAME),
+ return Activator.getService(ArduinoManager.class).getBoard(remoteConnection.getAttribute(BOARD_NAME),
remoteConnection.getAttribute(PLATFORM_NAME), remoteConnection.getAttribute(PACKAGE_NAME));
}
id="org.eclipse.cdt.arduino.preference.page.boards"
name="Boards">
</page>
+ <page
+ category="org.eclipse.cdt.arduino.preference.page"
+ class="org.eclipse.cdt.arduino.ui.internal.preferences.ArduinoPlatformsPreferencePage"
+ id="org.eclipse.cdt.arduino.ui.page.platforms"
+ name="Platforms">
+ </page>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
super.start(context);
plugin = this;
// Load up the Arduino indices
- ArduinoManager.instance.loadIndices();
+ getService(ArduinoManager.class).loadIndices();
}
public void stop(BundleContext context) throws Exception {
public static String NewArduinoTargetWizardPage_4;
public static String NewArduinoTargetWizardPage_5;
public static String ArduinoBoardsPreferencePage_desc;
+ public static String LibrariesPropertyPage_0;
+ public static String LibrariesPropertyPage_1;
public static String LibrariesPropertyPage_desc;
+ public static String ArduinoPlatformsPreferencePage_0;
+ public static String ArduinoPlatformsPreferencePage_1;
+ public static String ArduinoPlatformsPreferencePage_10;
+ public static String ArduinoPlatformsPreferencePage_11;
+ public static String ArduinoPlatformsPreferencePage_12;
+ public static String ArduinoPlatformsPreferencePage_13;
+ public static String ArduinoPlatformsPreferencePage_14;
+ public static String ArduinoPlatformsPreferencePage_15;
+ public static String ArduinoPlatformsPreferencePage_2;
+ public static String ArduinoPlatformsPreferencePage_3;
+ public static String ArduinoPlatformsPreferencePage_4;
+ public static String ArduinoPlatformsPreferencePage_5;
+ public static String ArduinoPlatformsPreferencePage_6;
+ public static String ArduinoPlatformsPreferencePage_7;
+ public static String ArduinoPlatformsPreferencePage_8;
+ public static String ArduinoPlatformsPreferencePage_9;
public static String ArduinoPreferencePage_desc;
+ public static String PlatformDetailsDialog_0;
+ public static String PlatformDetailsDialog_1;
static {
// initialize resource bundle
NewArduinoTargetWizardPage_3=
NewArduinoTargetWizardPage_4=Serial port:
NewArduinoTargetWizardPage_5=Board type:
-ArduinoBoardsPreferencePage_desc=Select a board you would like to install and click Install and then \
-OK or Apply to install the SDK and Tools for that board. By doing so you agree to the licenses of the \
-libraries and tools. For more information, see http://arduino.cc.
+ArduinoBoardsPreferencePage_desc=NOTE: To install support for an Arduino board, please use the Arduino \
+Platforms preference page to install the platform support for that board.
+LibrariesPropertyPage_0=Name
+LibrariesPropertyPage_1=Description
LibrariesPropertyPage_desc=Select libraries to use in your project and click OK or Apply. \
If necessary the library will be installed. By adding libraries you agree to the licenses of those \
libraries. For more information, see http://arduino.cc
-ArduinoPreferencePage_desc=Enter URLs for package_index.json files one per line.
\ No newline at end of file
+ArduinoPlatformsPreferencePage_0=Select a platform then click a button to install, uninstall, or find more details about the platform.
+ArduinoPlatformsPreferencePage_1=Platform
+ArduinoPlatformsPreferencePage_10=Information on the licenses can be found at arduino.cc web site.
+ArduinoPlatformsPreferencePage_11=Arduino License
+ArduinoPlatformsPreferencePage_12=Accept
+ArduinoPlatformsPreferencePage_13=Decline
+ArduinoPlatformsPreferencePage_14=Installing Arduino Board Platforms
+ArduinoPlatformsPreferencePage_15=Installing Arduino Board Platforms
+ArduinoPlatformsPreferencePage_2=Installed
+ArduinoPlatformsPreferencePage_3=Available
+ArduinoPlatformsPreferencePage_4=Install
+ArduinoPlatformsPreferencePage_5=Upgrade
+ArduinoPlatformsPreferencePage_6=Details
+ArduinoPlatformsPreferencePage_7=Install
+ArduinoPlatformsPreferencePage_8=Uninstall
+ArduinoPlatformsPreferencePage_9=Do you accept the licenses for the Arduino SDK and libraries?
+ArduinoPreferencePage_desc=Enter URLs for package_index.json files one per line.
+PlatformDetailsDialog_0=Platform:
+PlatformDetailsDialog_1=Supports boards:\n
*******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.preferences;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
-import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
-import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
-import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
-import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class ArduinoBoardsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
- private Table table;
- private Button installButton;
- private Set<ArduinoBoard> toInstall = new HashSet<>();
-
@Override
public void init(IWorkbench workbench) {
}
desc.setBackground(parent.getBackground());
desc.setText(Messages.ArduinoBoardsPreferencePage_desc);
- Composite comp = new Composite(control, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- layout.marginWidth = 0;
- comp.setLayout(layout);
- comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- Composite tableComp = new Composite(comp, SWT.NONE);
- tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- table = new Table(tableComp, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
-
- TableColumn packageColumn = new TableColumn(table, SWT.LEAD);
- packageColumn.setText("Board");
-
- TableColumn platformColumn = new TableColumn(table, SWT.LEAD);
- platformColumn.setText("Platform");
-
- TableColumn installedColumn = new TableColumn(table, SWT.LEAD);
- installedColumn.setText("Installed");
-
- TableColumnLayout tableLayout = new TableColumnLayout();
- tableLayout.setColumnData(packageColumn, new ColumnWeightData(5, 150, true));
- tableLayout.setColumnData(platformColumn, new ColumnWeightData(5, 150, true));
- tableLayout.setColumnData(installedColumn, new ColumnWeightData(2, 75, true));
- tableComp.setLayout(tableLayout);
-
- table.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- updateButtons();
- }
- });
-
- Composite buttonComp = new Composite(comp, SWT.NONE);
- buttonComp.setLayout(new GridLayout());
- buttonComp.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
-
- installButton = new Button(buttonComp, SWT.PUSH);
- installButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
- installButton.setText("Install");
- installButton.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- for (TableItem item : table.getSelection()) {
- ArduinoBoard board = (ArduinoBoard) item.getData();
- toInstall.add(board);
- item.setText(2, "selected");
- updateButtons();
- }
- }
- });
-
- updateTable();
- updateButtons();
-
return control;
}
- private void updateTable() {
- if (table == null || table.isDisposed()) {
- return;
- }
-
- table.removeAll();
-
- try {
- List<ArduinoBoard> boards = ArduinoManager.instance.getBoards();
- Collections.sort(boards, new Comparator<ArduinoBoard>() {
- public int compare(ArduinoBoard o1, ArduinoBoard o2) {
- return o1.getName().compareTo(o2.getName());
- }
- });
-
- for (ArduinoBoard board : boards) {
- TableItem item = new TableItem(table, SWT.NONE);
- item.setData(board);
- item.setText(0, board.getName());
- item.setText(1, board.getPlatform().getName());
- String msg;
- if (toInstall.contains(board)) {
- msg = "selected";
- } else {
- msg = board.getPlatform().isInstalled() ? "yes" : "no";
- }
- item.setText(2, msg);
- }
- } catch (CoreException e) {
- Activator.log(e);
- }
- }
-
- private void updateButtons() {
- if (table == null || table.isDisposed()) {
- return;
- }
-
- boolean enable = false;
- for (TableItem item : table.getSelection()) {
- ArduinoBoard board = (ArduinoBoard) item.getData();
- if (toInstall.contains(board)) {
- continue;
- }
- ArduinoPlatform platform = board.getPlatform();
- if (!platform.isInstalled()) {
- enable = true;
- }
- }
- installButton.setEnabled(enable);
- }
-
- @Override
- public boolean performOk() {
- File acceptedFile = ArduinoPreferences.getArduinoHome().resolve(".accepted").toFile(); //$NON-NLS-1$
- if (!acceptedFile.exists()) {
- String message = "Do you accept the licenses for the Arduino SDK and libraries? "
- + "Information on the licenses can be found at arduino.cc web site.";
- MessageDialog dialog = new MessageDialog(getShell(), "Arduino License", null, message,
- MessageDialog.QUESTION, new String[] { "Accept", "Decline" }, 0);
- int rc = dialog.open();
- if (rc == 0) {
- try {
- acceptedFile.createNewFile();
- } catch (IOException e) {
- Activator.log(e);
- }
- } else {
- return false;
- }
- }
-
- new Job("Installing Arduino Board Platforms") {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- Set<ArduinoPlatform> platforms = new HashSet<>();
- for (ArduinoBoard board : toInstall) {
- platforms.add(board.getPlatform());
- }
-
- MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 0, "Installing Arduino Board Platforms",
- null);
- for (ArduinoPlatform platform : platforms) {
- status.add(platform.install(monitor));
- }
-
- toInstall.clear();
-
- if (table != null && !table.isDisposed()) {
- table.getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- updateTable();
- }
- });
- }
-
- return status;
- }
- }.schedule();
- return true;
- }
-
}
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
+import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
@Override
public boolean performOk() {
ArduinoPreferences.setBoardUrls(urlsText.getText());
- ArduinoManager.instance.loadIndices();
+ Activator.getService(ArduinoManager.class).loadIndices();
return true;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.arduino.ui.internal.preferences;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
+import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
+import org.eclipse.cdt.arduino.ui.internal.Messages;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class PlatformDetailsDialog extends Dialog {
+
+ private final ArduinoPlatform platform;
+
+ protected PlatformDetailsDialog(Shell parentShell, ArduinoPlatform platform) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.platform = platform;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite control = (Composite) super.createDialogArea(parent);
+
+ Text text = new Text(control, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ StringBuilder str = new StringBuilder();
+
+ str.append(Messages.PlatformDetailsDialog_0);
+ str.append(platform.getName());
+ str.append('\n');
+
+ str.append(Messages.PlatformDetailsDialog_1);
+ List<ArduinoBoard> boards = platform.getBoards();
+ Collections.sort(boards, new Comparator<ArduinoBoard>() {
+ @Override
+ public int compare(ArduinoBoard o1, ArduinoBoard o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ for (ArduinoBoard board : platform.getBoards()) {
+ str.append(" "); //$NON-NLS-1$
+ str.append(board.getName());
+ str.append('\n');
+ }
+
+ text.setText(str.toString());
+ return control;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
+ }
+
+}
public class LibrariesPropertyPage extends PropertyPage {
+ private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
+
private class ContentProvider implements ITreeContentProvider {
private LibraryIndex index;
Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
- column1.setText("Name");
+ column1.setText(Messages.LibrariesPropertyPage_0);
column1.setWidth(200);
TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
- column2.setText("Description");
+ column2.setText(Messages.LibrariesPropertyPage_1);
column2.setWidth(200);
viewer.setContentProvider(new ContentProvider());
viewer.setLabelProvider(new LabelProvider());
try {
- viewer.setInput(ArduinoManager.instance.getLibraryIndex());
+ viewer.setInput(manager.getLibraryIndex());
// Set the check states for currently selected libraries
IProject project = getElement().getAdapter(IProject.class);
- Collection<ArduinoLibrary> libraries = ArduinoManager.instance.getLibraries(project);
+ Collection<ArduinoLibrary> libraries = manager.getLibraries(project);
for (ArduinoLibrary lib : libraries) {
viewer.setChecked(lib, true);
}
}
}
try {
- ArduinoManager.instance.setLibraries(getProject(), libs);
+ manager.setLibraries(getProject(), libs);
} catch (CoreException e) {
Activator.log(e);
}
try {
ArduinoBoard currentBoard = arduinoRemote.getBoard();
- Collection<ArduinoBoard> boardList = ArduinoManager.instance.getBoards();
+ Collection<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
boards = new ArduinoBoard[boardList.size()];
i = 0;
int boardSel = 0;
boardCombo = new Combo(this, SWT.READ_ONLY);
boardCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
try {
- List<ArduinoBoard> boardList = ArduinoManager.instance.getInstalledBoards();
+ List<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
Collections.sort(boardList, new Comparator<ArduinoBoard>() {
@Override
public int compare(ArduinoBoard o1, ArduinoBoard o2) {