Fix cast exception in UI (#816)
* check type before cast Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com> * use collection instead of set Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
fa6520a094
commit
3a5776a90d
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.ui.common.table;
|
package org.eclipse.hawkbit.ui.common.table;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -131,19 +132,26 @@ public abstract class AbstractTable<E extends NamedEntity> extends Table impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the selected item id or in multiselect mode a set of selected ids.
|
* Gets the selected item id or in multiselect mode the selected ids.
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* the table to retrieve the selected ID(s)
|
* the table to retrieve the selected ID(s)
|
||||||
* @return the ID(s) which are selected in the table
|
* @return the ID(s) which are selected in the table
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> Set<T> getTableValue(final Table table) {
|
public static <T> Set<T> getTableValue(final Table table) {
|
||||||
@SuppressWarnings("unchecked")
|
final Object value = table.getValue();
|
||||||
Set<T> values = (Set<T>) table.getValue();
|
Set<T> idsReturn;
|
||||||
if (values == null) {
|
if (value == null) {
|
||||||
values = Collections.emptySet();
|
idsReturn = Collections.emptySet();
|
||||||
|
} else if (value instanceof Collection) {
|
||||||
|
final Collection<T> ids = (Collection<T>) value;
|
||||||
|
idsReturn = ids.stream().filter(Objects::nonNull).collect(Collectors.toSet());
|
||||||
|
} else {
|
||||||
|
final T id = (T) value;
|
||||||
|
idsReturn = Collections.singleton(id);
|
||||||
}
|
}
|
||||||
return values.stream().filter(Objects::nonNull).collect(Collectors.toSet());
|
return idsReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onValueChange() {
|
private void onValueChange() {
|
||||||
|
|||||||
Reference in New Issue
Block a user