Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2016-01-03 23:10:25 -0500
committerGerrit Code Review @ Eclipse.org2016-01-04 10:09:33 -0500
commit0ee5ad92f1e9f58fc005ecc75df876de46b4c9e1 (patch)
tree593f799e8f7aab4a65365ecf5dc2de3c7f70b28a /toolchains
parente9d5637ecaed1cee93df613d107360e7777cfc36 (diff)
downloadorg.eclipse.cdt-0ee5ad92f1e9f58fc005ecc75df876de46b4c9e1.tar.gz
org.eclipse.cdt-0ee5ad92f1e9f58fc005ecc75df876de46b4c9e1.tar.xz
org.eclipse.cdt-0ee5ad92f1e9f58fc005ecc75df876de46b4c9e1.zip
Bug 485100 - Fix Arduino Libraries Page.
Check behavior wasn't working correctly. Added check state provider and listeners instead of the hack I had. Also add a feature dependency from Arduino to the remote launch feature. This should have been done in the previous commit. Change-Id: If9957a35e90875aca7767dcab610316801c28aeb
Diffstat (limited to 'toolchains')
-rw-r--r--toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml1
-rw-r--r--toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java85
2 files changed, 63 insertions, 23 deletions
diff --git a/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml b/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml
index a8abff5329..f7e3e4a781 100644
--- a/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml
+++ b/toolchains/arduino/org.eclipse.cdt.arduino-feature/feature.xml
@@ -26,6 +26,7 @@
<import feature="org.eclipse.remote" version="2.0.0"/>
<import feature="org.eclipse.remote.console" version="2.0.0"/>
<import feature="org.eclipse.cdt" version="8.8.0"/>
+ <import feature="org.eclipse.launchbar.remote" version="1.0.0.qualifier"/>
</requires>
<plugin
diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java
index 4c0e2de75f..1a1a3a26dd 100644
--- a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java
+++ b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 QNX Software Systems and others.
+ * Copyright (c) 2015, 2016 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
@@ -8,7 +8,6 @@
package org.eclipse.cdt.arduino.ui.internal.project;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -23,6 +22,10 @@ import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
@@ -36,8 +39,6 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;
import org.eclipse.ui.dialogs.PropertyPage;
@@ -45,6 +46,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
public class LibrariesPropertyPage extends PropertyPage {
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
+ private Set<ArduinoLibrary> checkedLibs;
private class ContentProvider implements ITreeContentProvider {
private LibraryIndex index;
@@ -188,12 +190,62 @@ public class LibrariesPropertyPage extends PropertyPage {
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
- return new ContainerCheckedTreeViewer(parent, style);
+ CheckboxTreeViewer viewer = new CheckboxTreeViewer(parent, style);
+ viewer.setCheckStateProvider(new ICheckStateProvider() {
+ @Override
+ public boolean isGrayed(Object element) {
+ if (element instanceof String) {
+ for (ArduinoLibrary lib : checkedLibs) {
+ if (element.equals(lib.getCategory())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isChecked(Object element) {
+ if (element instanceof ArduinoLibrary) {
+ return checkedLibs.contains(element);
+ } else if (element instanceof String) {
+ for (ArduinoLibrary lib : checkedLibs) {
+ if (element.equals(lib.getCategory())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+ });
+ viewer.addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ Object element = event.getElement();
+ if (element instanceof ArduinoLibrary) {
+ if (event.getChecked()) {
+ checkedLibs.add((ArduinoLibrary) element);
+ } else {
+ checkedLibs.remove(element);
+ }
+ } else if (element instanceof String) {
+ if (!event.getChecked()) {
+ for (ArduinoLibrary lib : new ArrayList<>(checkedLibs)) {
+ if (element.equals(lib.getCategory())) {
+ checkedLibs.remove(lib);
+ }
+ }
+ }
+ }
+ }
+ });
+ return viewer;
}
};
filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) filteredTree.getViewer();
+ TreeViewer viewer = filteredTree.getViewer();
Tree tree = viewer.getTree();
tree.setHeaderVisible(true);
@@ -208,18 +260,14 @@ public class LibrariesPropertyPage extends PropertyPage {
viewer.setLabelProvider(new LabelProvider());
try {
- viewer.setInput(manager.getLibraryIndex());
- // Set the check states for currently selected libraries
IProject project = getElement().getAdapter(IProject.class);
- Collection<ArduinoLibrary> libraries = manager.getLibraries(project);
- for (ArduinoLibrary lib : libraries) {
- viewer.setChecked(lib, true);
- }
+ checkedLibs = new HashSet<>(manager.getLibraries(project));
+ viewer.setInput(manager.getLibraryIndex());
} catch (CoreException e) {
Activator.log(e);
}
- return comp;
+ return comp;
}
private IProject getProject() {
@@ -232,17 +280,8 @@ public class LibrariesPropertyPage extends PropertyPage {
@Override
public boolean performOk() {
- List<ArduinoLibrary> libs = new ArrayList<>();
- for (TreeItem categoryItem : filteredTree.getViewer().getTree().getItems()) {
- for (TreeItem libItem : categoryItem.getItems()) {
- ArduinoLibrary lib = (ArduinoLibrary) libItem.getData();
- if (libItem.getChecked()) {
- libs.add(lib);
- }
- }
- }
try {
- manager.setLibraries(getProject(), libs);
+ manager.setLibraries(getProject(), checkedLibs);
} catch (CoreException e) {
Activator.log(e);
}

Back to the top