mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
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
This commit is contained in:
parent
e9d5637eca
commit
0ee5ad92f1
2 changed files with 63 additions and 23 deletions
|
@ -26,6 +26,7 @@
|
||||||
<import feature="org.eclipse.remote" version="2.0.0"/>
|
<import feature="org.eclipse.remote" version="2.0.0"/>
|
||||||
<import feature="org.eclipse.remote.console" 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.cdt" version="8.8.0"/>
|
||||||
|
<import feature="org.eclipse.launchbar.remote" version="1.0.0.qualifier"/>
|
||||||
</requires>
|
</requires>
|
||||||
|
|
||||||
<plugin
|
<plugin
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,7 +8,6 @@
|
||||||
package org.eclipse.cdt.arduino.ui.internal.project;
|
package org.eclipse.cdt.arduino.ui.internal.project;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
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.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.viewers.BaseLabelProvider;
|
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.ITableLabelProvider;
|
||||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
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.Text;
|
||||||
import org.eclipse.swt.widgets.Tree;
|
import org.eclipse.swt.widgets.Tree;
|
||||||
import org.eclipse.swt.widgets.TreeColumn;
|
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.FilteredTree;
|
||||||
import org.eclipse.ui.dialogs.PatternFilter;
|
import org.eclipse.ui.dialogs.PatternFilter;
|
||||||
import org.eclipse.ui.dialogs.PropertyPage;
|
import org.eclipse.ui.dialogs.PropertyPage;
|
||||||
|
@ -45,6 +46,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
|
||||||
public class LibrariesPropertyPage extends PropertyPage {
|
public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
|
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
|
||||||
|
private Set<ArduinoLibrary> checkedLibs;
|
||||||
|
|
||||||
private class ContentProvider implements ITreeContentProvider {
|
private class ContentProvider implements ITreeContentProvider {
|
||||||
private LibraryIndex index;
|
private LibraryIndex index;
|
||||||
|
@ -188,12 +190,62 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
|
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));
|
filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||||
|
|
||||||
ContainerCheckedTreeViewer viewer = (ContainerCheckedTreeViewer) filteredTree.getViewer();
|
TreeViewer viewer = filteredTree.getViewer();
|
||||||
|
|
||||||
Tree tree = viewer.getTree();
|
Tree tree = viewer.getTree();
|
||||||
tree.setHeaderVisible(true);
|
tree.setHeaderVisible(true);
|
||||||
|
@ -208,18 +260,14 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
viewer.setLabelProvider(new LabelProvider());
|
viewer.setLabelProvider(new LabelProvider());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
viewer.setInput(manager.getLibraryIndex());
|
|
||||||
// Set the check states for currently selected libraries
|
|
||||||
IProject project = getElement().getAdapter(IProject.class);
|
IProject project = getElement().getAdapter(IProject.class);
|
||||||
Collection<ArduinoLibrary> libraries = manager.getLibraries(project);
|
checkedLibs = new HashSet<>(manager.getLibraries(project));
|
||||||
for (ArduinoLibrary lib : libraries) {
|
viewer.setInput(manager.getLibraryIndex());
|
||||||
viewer.setChecked(lib, true);
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
return comp;
|
|
||||||
|
|
||||||
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IProject getProject() {
|
private IProject getProject() {
|
||||||
|
@ -232,17 +280,8 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performOk() {
|
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 {
|
try {
|
||||||
manager.setLibraries(getProject(), libs);
|
manager.setLibraries(getProject(), checkedLibs);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue