简体   繁体   English

无法从swt中的表中删除tableitem

[英]Unable to remove tableitem from table in swt

When i select List5 from left_group_table(List), all the items that belong to List5 should be removed from the middle_group_table(Contact). 当我从left_group_table(List)中选择List5时,应从middle_group_table(Contact)中删除所有属于List5的项。 If the list contains mulitple items, all the items in the contact table should be removed. 如果列表中包含多个项目,则应删除联系表中的所有项目。 Please find the screenshot of the application and code snippet below. 请在下面找到该应用程序的屏幕截图和代码段。 Thanks in advance! 提前致谢!

在此处输入图片说明

public static ArrayList<String> allEmailsFortheSelectedList = new ArrayList<String>();
HashMap<Integer, ArrayList<String>> allEmailsForALLSelectedList;

tableCursor.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent arg0) {
            final int selectionIndex = left_group_table.getSelectionIndex();

            if(left_group_table.getItem(selectionIndex).getChecked()) {
                int tempCount = 0;
                left_group_table.getItem(selectionIndex).setChecked(false);
                TableItem[] items = middle_group_table.getItems();

                if(allEmailsForALLSelectedList.containsKey(selectionIndex)) {
                    allEmailsForALLSelectedList.remove(selectionIndex);
                }

                Set<Entry<Integer, ArrayList<String>>>  set = allEmailsForALLSelectedList.entrySet();
                Iterator<Entry<Integer, ArrayList<String>>> itr = set.iterator(); 
                while(itr.hasNext()) 
                { 
                    HashMap.Entry<Integer, ArrayList<String>> entry = itr.next(); 
                    for(int i=0; i< entry.getValue().size(); i++) {
                        new TableItem(middle_group_table, SWT.NONE);
                        items[tempCount].setText(1, entry.getValue().get(i));
                        tempCount++;
                    }
                }

                tempCount = items.length;
                middle_group_table.setRedraw(true);

            }else {
                int middleGroupTableItemCount = 0;
                left_group_table.getItem(selectionIndex).setChecked(true);
                sendEmailslistName = left_group_table.getItem(selectionIndex).getText(1);

                int listId = SelectionDb.getUserContactListId(sendEmailslistName);

                allEmailsForALLSelectedList.put(selectionIndex, SelectionDb.getAllContactEmail(listId));

                for (int i = 0; i < SelectionDb.getAllContactEmail(listId).size(); i++) {
                    new TableItem(middle_group_table, SWT.NONE);
                }

                middle_group_table.setRedraw(true);

                TableItem[] items = middle_group_table.getItems();
                Set<Entry<Integer, ArrayList<String>>>  set = allEmailsForALLSelectedList.entrySet();
                Iterator<Entry<Integer, ArrayList<String>>> itr = set.iterator(); 
                while(itr.hasNext()) 
                { 
                    HashMap.Entry<Integer, ArrayList<String>> entry = itr.next(); 
                    for(int i=0; i< entry.getValue().size(); i++) {
                        items[middleGroupTableItemCount].setText(1, entry.getValue().get(i));
                        middleGroupTableItemCount++;
                    }
                }
                middleGroupTableItemCount = items.length;
            }

        }

There should be removeAll() method for your table, that you can use. 您的表应该有removeAll()方法可供使用。

middle_group_table.removeAll(); middle_group_table.removeAll();

EDIT: To remove a single row you need to get the right index of the element you want to remove, the simplest method without any LINQis this: 编辑:要删除一行,您需要获取要删除的元素的正确索引,而没有任何LINQ的最简单方法是:

First get the right list you need:
List<String> itemsToRemove = ...getting the list5, from your code I don't understand how the list is holding.

Then you can just iterate in reverse way and remove.
for (int i = middle_group_table.getItemCount() - 1; i <= 0; i--)
{
    if (itemsToRemove.contains(items[i].getText()))
        middle_group_table.remove(i);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM