0

I have a TreeViewer and a List inside the TreeViewer containing a list of items(String), for example :

Subtask one one \\first item in the TreeViewer

Subtask two one

Subtask three one

Subtask four two

Subtask four three

I want to remove the items from the TreeViewer with the suffix "one" and leave the rest of the items. How do I iterate over the items and remove the items whose name ends with the string "one"?

Sample code :

TreeViewer treeViewer = new TreeViewer(moverComposite, SWT.BORDER | SWT.MULTI);
treeViewer.setContentProvider(new TreeContentProvider());
treeViewer.setLabelProvider(new LabelProvider());
GridData gridData = new GridData(SWT.DEFAULT, SWT.FILL, false, true);
gridData.widthHint = 215;
treeViewer.getControl().setLayoutData(gridData);
List listItems = new ArrayList();
listItems.addAll(getItems());
//This line I would want to iterate through the list and remove the list items whose names end with the string "one".
treeViewer.setInput(listItems);

Someone please help me here at the earliest, Please.

Before setting the Tree Viewer's input I want to iterate over the List and remove only the items whose name ends with the string "one" (items with the suffix "one")? After removing the items from the list I would set the treeViewer's input.

Is there a way to remove the items whose name ends with the string "one"? How do I do this? I'm stuck here please someone please suggest how to proceed?

Thanks in advance.

Sangli
  • 373
  • 4
  • 20

1 Answers1

0

Assuming getItems() gives me list of Item object,

List<Item> listItems = new ArrayList<Item>();
foreach(Item item : getItems()){
  if(!item.getName().endsWith("one")){
     listItems.add(item);
   }
  }
treeViewer.setInput(listItems);
Subhankar
  • 487
  • 8
  • 25