在 swt 中无法从 table 中删除 table 项
Unable to remove tableitem from table in swt
当我从 left_group_table(List) select List5 时,所有属于 List5 的项目都应该从 middle_group_table(Contact) 中删除。如果列表包含多个项目,则应删除联系人 table 中的所有项目。请在下面找到应用程序的屏幕截图和代码片段。提前致谢!
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;
}
}
您的 table 应该有 removeAll() 方法供您使用。
middle_group_table.removeAll();
编辑:
要删除一行,您需要获取要删除的元素的正确索引,没有任何 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);
}
当我从 left_group_table(List) select List5 时,所有属于 List5 的项目都应该从 middle_group_table(Contact) 中删除。如果列表包含多个项目,则应删除联系人 table 中的所有项目。请在下面找到应用程序的屏幕截图和代码片段。提前致谢!
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;
}
}
您的 table 应该有 removeAll() 方法供您使用。
middle_group_table.removeAll();
编辑: 要删除一行,您需要获取要删除的元素的正确索引,没有任何 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);
}