Skip to content
Snippets Groups Projects
Commit bbe5695b authored by Hernan Ponce de Leon's avatar Hernan Ponce de Leon
Browse files

Merge branch '3545' into 'master'

selectAll(): make private and return empty list instead of null

See merge request !28
parents 18f0422e 8f349e70
No related branches found
No related tags found
1 merge request!28selectAll(): make private and return empty list instead of null
......@@ -7,7 +7,7 @@ EObjectSelectionUtils.java 128cf8f96c6b9478171dff3deda662d5934f5f44 GREEN
KernelUIUtils.java 46d3279ef3523b104f89a6c526109f72d36f72f2 GREEN
ObservableUtils.java 34abfd1dfaf9c0acbb31caf1f525e7b39416c116 GREEN
PropertiesConstantUtils.java 59b1a1e4d594bb98db3aa396f2ff6474ba405920 GREEN
SelectionUtils.java 3d20f87eaaee04173686ef62b09ca6971702cd00 GREEN
SelectionUtils.java 33aec7cccccb28e5568140cf8e5443ce0f9f59f7 GREEN
TutorialUIServiceUtils.java 093a8a3549c6952d44ea508e66691434b17a95b5 GREEN
UndoRedoImpl.java f218500875bda0ef52f4cc2ccdf452825e6751f7 GREEN
WidgetsFactory.java 5be121cc81e93731f4d0ab11e7707417fa950c2c GREEN
......@@ -15,9 +15,11 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.util;
import static java.util.Collections.emptyList;
import static org.conqat.ide.commons.ui.ui.WorkbenchUtils.getActiveEditor;
import static org.fortiss.tooling.common.util.LambdaUtils.filterByType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
......@@ -90,29 +92,24 @@ public class SelectionUtils {
}
/**
* Returns a list of all the selected elements that have the given type or
* null if selection is null or is not an IStructuredSelection.
* Returns a {@link Collection} of all the selected elements that have the given type (possibly
* an empty list, in particular if {@code selection} is {@code null} or is not an
* {@link IStructuredSelection}.
*
* @param selection
* the current selection
* @param type
* the type of elements to be returned
* @return the list of elements of the given type
* @return the {@link Collection} of elements of the given type
*/
@SuppressWarnings("unchecked")
public static <T> List<T> selectAll(ISelection selection, Class<T> type) {
private static <T> Collection<T> selectAll(ISelection selection, Class<T> type) {
if(selection == null || !(selection instanceof IStructuredSelection)) {
return null;
return emptyList();
}
IStructuredSelection structuredSelection = (IStructuredSelection)selection;
List<T> elements = new ArrayList<T>();
for(Object element : structuredSelection.toList()) {
if(type.isInstance(element)) {
elements.add((T)element);
}
}
return elements;
return filterByType(structuredSelection.toList(), type);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment