2121import java .util .Map ;
2222import java .util .Set ;
2323import java .util .StringTokenizer ;
24+ import java .util .stream .Collectors ;
2425
25- import com .vaadin .event . FieldEvents . TextChangeEvent ;
26- import com .vaadin .event . FieldEvents . TextChangeListener ;
26+ import com .vaadin .data . ValueProvider ;
27+ import com .vaadin .data . provider . ListDataProvider ;
2728import com .vaadin .graph .shared .ArcProxy ;
2829import com .vaadin .graph .shared .NodeProxy ;
2930import com .vaadin .graph .shared .NodeProxy .NodeKind ;
3031import com .vaadin .graph .shared .NodeProxy .NodeState ;
3132import com .vaadin .server .ResourceReference ;
32- import com .vaadin .ui .AbstractTextField .TextChangeEventMode ;
3333import com .vaadin .ui .CustomComponent ;
34- import com .vaadin .ui .Table ;
35- import com .vaadin .ui .Table .ColumnHeaderMode ;
34+ import com .vaadin .ui .Grid ;
35+ import com .vaadin .ui .Grid .Column ;
36+ import com .vaadin .ui .Grid .SelectionMode ;
3637import com .vaadin .ui .TextField ;
37- import com .vaadin .ui .VerticalLayout ;
38+ import com .vaadin .ui .components . grid . HeaderRow ;
3839
3940/**
4041 * Graph visualization controller component used to control/override graph construction and visualization.
@@ -162,66 +163,44 @@ public NodeSelector getMemberSelector(final String groupId, final GraphRepositor
162163 @ SuppressWarnings ("serial" )
163164 class SelectorUI extends CustomComponent implements NodeSelector {
164165
165- private static final String NODENAME = "nodename" ;
166- Table matchList = new Table ();
167- private final Map <String , String > members = new HashMap <String , String >();
166+ protected final Grid <N > matchList ;
167+ protected final ListDataProvider <N > members ;
168168
169169 public SelectorUI () {
170- VerticalLayout layout = new VerticalLayout ();
171-
170+ matchList = new Grid <>();
171+ matchList .setSizeFull ();
172+ matchList .setSelectionMode (SelectionMode .MULTI );
173+ Column <N , String > column = matchList .addColumn ((node ) -> getNodeLabel (node )).setCaption ("" );
174+
172175 TextField stringMatcher = new TextField ();
173- layout .addComponent (stringMatcher );
174176 stringMatcher .setWidth (100 , Unit .PERCENTAGE );
175177
176- layout .addComponent (matchList );
177- layout .setExpandRatio (matchList , 1.0f );
178- matchList .setSizeFull ();
179- matchList .setPageLength (40 );
180-
181- matchList .setSelectable (true );
182- matchList .setMultiSelect (true );
183- matchList .addContainerProperty (NODENAME , String .class , "" );
184- matchList .setColumnHeaderMode (ColumnHeaderMode .HIDDEN );
185-
186- stringMatcher .setTextChangeEventMode (TextChangeEventMode .LAZY );
178+ HeaderRow header = matchList .getHeaderRow (0 );
179+ header .getCell (column ).setComponent (stringMatcher );
187180
188181 StringTokenizer tokenizer = new StringTokenizer (groupId );
189182 String parentId = tokenizer .nextToken ();
190- N parent = repository .getNodeById (parentId );
191- for (A arc : groups .get (groupId ).values ()) {
192- N child = repository .getOpposite (parent , arc );
193- String id = child .getId ();
194- String label = getNodeLabel (child );
195- members .put (id , label );
196- matchList .addItem (id );
197- matchList .getContainerProperty (id , NODENAME ).setValue (label );
198- }
183+ final N parent = repository .getNodeById (parentId );
184+ members = new ListDataProvider <N >(
185+ groups .get (groupId ).values ().stream ().map ((arc ) -> repository .getOpposite (parent , arc )).collect (Collectors .toList ()));
186+ matchList .setDataProvider (members );
199187
200- stringMatcher .addTextChangeListener (new TextChangeListener () {
201- public void textChange (TextChangeEvent event ) {
202- String query = event .getText ().toLowerCase ().replaceAll ("\\ s" , "" );
203- matchList .removeAllItems ();
204- for (Map .Entry <String , String > entry : members .entrySet ()) {
205- String nodeId = entry .getKey ();
206- String value = entry .getValue ();
207- if (value .toLowerCase ().replaceAll ("\\ s" , "" ).contains (query )) {
208- matchList .addItem (nodeId );
209- matchList .getContainerProperty (nodeId , NODENAME ).setValue (value );
210- }
188+ stringMatcher .addValueChangeListener (event -> {
189+ members .setFilter (ValueProvider .identity (), node -> {
190+ if (node == null ) {
191+ return false ;
211192 }
212- }
193+ String nodeLabel = getNodeLabel (node ).toLowerCase ().replaceAll ("\\ s" , "" );
194+ String filter = event .getValue ().toLowerCase ().replaceAll ("\\ s" , "" );
195+ return nodeLabel .contains (filter );
196+ });
213197 });
214- layout .setSizeFull ();
215- setCompositionRoot (layout );
198+ setCompositionRoot (matchList );
216199 setSizeFull ();
217200 }
218201
219202 public Collection <String > getSelectedNodeIds () {
220- Collection <String > match = (Collection <String >) matchList .getValue ();
221- if (match .size () == 0 ) {
222- return (Collection <String >) matchList .getItemIds ();
223- }
224- return match ;
203+ return matchList .getSelectedItems ().stream ().map ((node ) -> node .getId ()).collect (Collectors .toList ());
225204 }
226205
227206 }
@@ -244,7 +223,7 @@ protected NodeProxy load(Node node, LayoutEngineModel model) {
244223 return p ;
245224 }
246225
247- public Collection <NodeProxy > loadMembers (String groupId , Collection <String > memberIds , GraphRepository <N , A > repository , LayoutEngineModel model ) {
226+ public Collection <NodeProxy > loadMembers (String groupId , Iterable <String > memberIds , GraphRepository <N , A > repository , LayoutEngineModel model ) {
248227 StringTokenizer tokenizer = new StringTokenizer (groupId );
249228 final String parentId = tokenizer .nextToken ();
250229 final N parent = repository .getNodeById (parentId );
0 commit comments