mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-18 13:45:45 +02:00
Bug 480579 - Put platform libs into proper categories.
I had created a category for platform libraries, but some of those libraries actually belong to real categories. So, let's just use them instead. Change-Id: Ie94b546e4c21b2d6b545becc781ca0dc02f5379d
This commit is contained in:
parent
cf05b210bd
commit
e61edf0d66
1 changed files with 25 additions and 32 deletions
|
@ -2,7 +2,9 @@ package org.eclipse.cdt.arduino.ui.internal.project;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
|
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
|
||||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
||||||
|
@ -50,16 +52,9 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
@Override
|
@Override
|
||||||
public boolean hasChildren(Object element) {
|
public boolean hasChildren(Object element) {
|
||||||
if (element instanceof LibraryIndex) {
|
if (element instanceof LibraryIndex) {
|
||||||
return !index.getCategories().isEmpty();
|
return true;
|
||||||
} else if (element instanceof String) { // category
|
} else if (element instanceof String) { // category
|
||||||
return !index.getLibraries((String) element).isEmpty();
|
return true;
|
||||||
} else if (element instanceof ArduinoPlatform) {
|
|
||||||
try {
|
|
||||||
return !((ArduinoPlatform) element).getLibraries().isEmpty();
|
|
||||||
} catch (CoreException e) {
|
|
||||||
Activator.log(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (element instanceof ArduinoLibrary) {
|
} else if (element instanceof ArduinoLibrary) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,19 +67,7 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
if (element instanceof ArduinoLibrary) {
|
if (element instanceof ArduinoLibrary) {
|
||||||
ArduinoLibrary lib = (ArduinoLibrary) element;
|
ArduinoLibrary lib = (ArduinoLibrary) element;
|
||||||
String category = lib.getCategory();
|
String category = lib.getCategory();
|
||||||
if (category != null) {
|
return category != null ? category : LibraryIndex.UNCATEGORIZED;
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ArduinoPlatform platform = getPlatform();
|
|
||||||
if (platform.getLibrary(lib.getName()) != null) {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
Activator.log(e);
|
|
||||||
}
|
|
||||||
return LibraryIndex.UNCATEGORIZED;
|
|
||||||
} else if (element instanceof String || element instanceof ArduinoPlatform) {
|
} else if (element instanceof String || element instanceof ArduinoPlatform) {
|
||||||
return index;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,30 +77,42 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
List<Object> categories = new ArrayList<>();
|
Set<String> categories = new HashSet<>();
|
||||||
|
categories.addAll(((LibraryIndex) inputElement).getCategories());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ArduinoPlatform platform = getPlatform();
|
for (ArduinoLibrary lib : getPlatform().getLibraries()) {
|
||||||
categories.add(platform);
|
String category = lib.getCategory();
|
||||||
|
categories.add(category != null ? category : LibraryIndex.UNCATEGORIZED);
|
||||||
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
categories.addAll(((LibraryIndex) inputElement).getCategories());
|
|
||||||
return categories.toArray();
|
return categories.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getChildren(Object parentElement) {
|
public Object[] getChildren(Object parentElement) {
|
||||||
if (parentElement instanceof String) {
|
if (parentElement instanceof String) {
|
||||||
return index.getLibraries((String) parentElement).toArray(new ArduinoLibrary[0]);
|
String category = (String) parentElement;
|
||||||
} else if (parentElement instanceof ArduinoPlatform) {
|
List<ArduinoLibrary> libs = new ArrayList<>();
|
||||||
|
libs.addAll(index.getLibraries(category));
|
||||||
try {
|
try {
|
||||||
return ((ArduinoPlatform) parentElement).getLibraries().toArray();
|
for (ArduinoLibrary lib : getPlatform().getLibraries()) {
|
||||||
|
String cat = lib.getCategory();
|
||||||
|
if (cat != null) {
|
||||||
|
if (cat.equals(category)) {
|
||||||
|
libs.add(lib);
|
||||||
|
}
|
||||||
|
} else if (category.equals(LibraryIndex.UNCATEGORIZED)) { // cat == null
|
||||||
|
libs.add(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
return new Object[0];
|
|
||||||
}
|
}
|
||||||
|
return libs.toArray();
|
||||||
} else {
|
} else {
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
|
@ -134,8 +129,6 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
public String getColumnText(Object element, int columnIndex) {
|
public String getColumnText(Object element, int columnIndex) {
|
||||||
if (element instanceof String) {
|
if (element instanceof String) {
|
||||||
return columnIndex == 0 ? (String) element : null;
|
return columnIndex == 0 ? (String) element : null;
|
||||||
} else if (element instanceof ArduinoPlatform) {
|
|
||||||
return columnIndex == 0 ? ((ArduinoPlatform) element).getName() : null;
|
|
||||||
} else if (element instanceof ArduinoLibrary) {
|
} else if (element instanceof ArduinoLibrary) {
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
Loading…
Add table
Reference in a new issue