java - How to search TreeItem in SWT Tree? -


hi have made 1 program has produce correct output when single check box selected when multiple check box selected not produce correct output.plz me.

condition multiple checkbox: when multiple checkbox (checked == true)then child compare other parent , child same level,if name found other node output should match name list.
code single checkbox has working good.

public class treeclass {  public static void main(final string[] args) {     final display display = new display();     final shell shell = new shell(display);     final tree tree = new tree(shell, swt.border | swt.check | swt.v_scroll);     final string[] root_items = { "parent1", "parent2", "parent3",             "parent4", "test2", "test3" };     final string[] middle_items = { "test1", "test2", "test3" };     final string[] child_items = { "test", "test2", "test3" };      (int = 0; < root_items.length; i++) {         final treeitem item0 = new treeitem(tree, 0);         item0.settext(root_items[i]);          (int j = 0; j < middle_items.length; j++) {             final treeitem item1 = new treeitem(item0, 0);             item1.settext(middle_items[j]);             (int k = 0; k < child_items.length; k++) {                 final treeitem item2 = new treeitem(item1, 0);                 item2.settext(child_items[k]);             }         }     }     tree.setbounds(0, 0, 100, 100);     final menu menu = new menu(tree);     tree.setmenu(menu);     menu.addmenulistener(new menuadapter() {         public void menushown(final menuevent e) {             final menuitem[] items = menu.getitems();             (int = 0; < items.length; i++) {                 items[i].dispose();             }             final menuitem newitem = new menuitem(menu, swt.none);             newitem.settext("deleted menu " + tree.getselection()[0].gettext());             newitem.addselectionlistener(new selectionlistener() {                  @override                 public void widgetselected(final selectionevent e) {                     check_item(tree.getitems());                 }                  @override                 public void widgetdefaultselected(final selectionevent e) {                 }             });         }     });     tree.getitems()[0].setexpanded(true);     tree.setsize(300, 400);     shell.pack();     shell.open();     while (!shell.isdisposed()) {         if (!display.readanddispatch()) {             display.sleep();         }     }     display.dispose(); }  public static void check_item(final treeitem items[]) {     final arraylist<string> selecteditemchild = new arraylist<>();     try {         (final treeitem item : items) {             if (item.getchecked()) {                 treeitem[] parent_items;                 (final treeitem child_item : item.getitems()) {                     selecteditemchild.add(child_item.gettext());                      if (item.getparentitem() != null) {                         parent_items = item.getparentitem().getitems();                     } else {                         parent_items = item.getparent().getitems();                     }                     (final treeitem parent_item : parent_items) {                          if (child_item.gettext().equals(parent_item.gettext())) {                             system.out.println("no deleted bcz match found ::: " + child_item.gettext());                             break;                         }                     }                  }             }             check_item(item.getitems());         }     } catch (final exception e) {         e.printstacktrace();     }  } } 

input image:

input

output of above program:

output


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -