Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Adding menu to swt table(Adding same menu to multiple SWT tables)
Adding menu to swt table [message #1066207] Mon, 01 July 2013 14:41 Go to next message
Chandrayya Kumarswamimath is currently offline Chandrayya Kumarswamimath
Messages: 20
Registered: August 2010
Location: Bangalore
Junior Member
I want to add same menu on multiple tables(SWT table). When user clicks on menu items, I want to detect the table associated with that menu. See the code below.

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 method is called multiple times sending the instances of table. How I can detect the table associated with the currently popped up menu in pop-up listener.
Re: Adding menu to swt table [message #1066244 is a reply to message #1066207] Mon, 01 July 2013 17:12 Go to previous messageGo to next message
li ran is currently offline li ran
Messages: 11
Registered: June 2013
Junior Member
note sure if that is the currect way. but, try to add shownMenu listener
for each table, in the listener set the menu data to be your table reference
and all you got to do is:

MenuItem item = (MenuItem)event.widget;
Menu pare = item.getParent();
Table currTable = pare.getData();
Re: Adding menu to swt table [message #1066313 is a reply to message #1066244] Tue, 02 July 2013 06:53 Go to previous message
Chandrayya Kumarswamimath is currently offline Chandrayya Kumarswamimath
Messages: 20
Registered: August 2010
Location: Bangalore
Junior Member
Hello li ran,
Thanks it is working now.
Previous Topic:Using processing with WindowBuilder
Next Topic:verifyKey not working as printed in the Eclipse article
Goto Forum:
  


Current Time: Mon Sep 15 04:24:11 GMT 2014

Powered by FUDForum. Page generated in 0.02220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software