我想在多个表(SWT 表)上添加相同的菜单。当用户单击菜单项时,我想检测与该菜单关联的表。这是下面的代码。
private void setMenu(Table table) {
Listener popUpListener = new Listener() {
@Override
public void handleEvent(Event event) {
MenuItem item = (MenuItem)event.widget;
Menu pare = item.getParent();
Decorations fdf = pare.getParent();
//Code to get table name or instance of table.
}
};
Menu menu = new Menu(table); // where table1 is your table
MenuItem item1 = new MenuItem(menu, SWT.PUSH);
item1.setText("Copy cell");
item1.addListener(SWT.Selection, popUpListener);
MenuItem item2 = new MenuItem(menu, SWT.PUSH);
item2.setText("Copy row");
item2.addListener(SWT.Selection, popUpListener);
MenuItem item3 = new MenuItem(menu, SWT.PUSH);
item3.setText("Copy column");
item3.addListener(SWT.Selection, popUpListener);
MenuItem item4 = new MenuItem(menu, SWT.PUSH);
item4.setText("Copy all");
item4.addListener(SWT.Selection, popUpListener);
table.setMenu(menu);
}
多次调用 setMenu 方法发送表的实例。如何在弹出侦听器中检测与当前弹出菜单关联的表。