By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Dynamic popup menu item events

P: 19
Hi,
I used SWT to develop an windows application. In the application there is a dynamic created popup menu. The dynamic part is that i will pass a list of name to be a submenu of one menu item. However, when I code selection event, i cannot access to the list i pass in. Anybody got idea? Below is the code.


Expand|Select|Wrap|Line Numbers
  1.  
  2.     public static void setUpMenu(final Shell shell, Menu popUpMenu, final String clientId) {
  3.         myShell = shell;
  4.         myClientId = clientId;
  5.  
  6.         MenuItem clientProfileItem = new MenuItem(popUpMenu,SWT.CASCADE);
  7.         clientProfileItem.setText("Client Profile");
  8.         // submenu for client profile menu item
  9.         int i = ClickFlowSession.getInstance().getPublicMemoryList().size();
  10.         if (i > 0) {
  11.             ArrayList list = ClickFlowSession.getInstance().getPublicMemoryList();
  12.             Menu ClientProfileMenu = new Menu(popUpMenu);
  13.             clientProfileItem.setMenu(ClientProfileMenu);
  14.             for ( int j = 0; j < i; j++) {
  15.                 MenuItem clientNameItem = new MenuItem(ClientProfileMenu,SWT.CHECK);
  16.                 clientNameItem.addSelectionListener(new SelectionAdapter() {
  17.                     public void widgetSelected(SelectionEvent arg0) {
  18. // this is the part i get stuck                
  19.         ((Pub_Main)ClickFlowSession.getInstance().getPublicMainComposite()).refresh((String)list.get(j), isBusiness((String)list.get(j)));
  20.                     }
  21.                 });
  22.                 clientNameItem.setText(ClickFlowSession.getInstance().getPublicClientName((String)list.get(j)));
  23.  
  24.             }
  25.         }
  26.  
  27.  
  28.         MenuItem needsItem = new MenuItem(popUpMenu,SWT.CASCADE);
  29.         needsItem.addSelectionListener(new SelectionAdapter() {
  30.             public void widgetSelected(SelectionEvent arg0) {
  31.                 jumpToFlash(myShell, "Needs", myClientId);
  32.             }
  33.         });
  34.         needsItem.setText("Needs");
  35.  
  36.         MenuItem calculationsItem = new MenuItem(popUpMenu,SWT.CASCADE);
  37.         calculationsItem.setText("Calculations");
  38.  
  39.         MenuItem productListItem = new MenuItem(popUpMenu,SWT.CASCADE);
  40.         productListItem.setText("Product List");
  41.  
  42.         MenuItem reviewItem = new MenuItem(popUpMenu,SWT.CASCADE);
  43.         reviewItem.setText("Review");
  44.  
  45.         MenuItem privacyItem = new MenuItem(popUpMenu,SWT.CASCADE);
  46.         privacyItem.setText("Privacy");
  47.  
  48.         new MenuItem(popUpMenu, SWT.SEPARATOR);
  49.  
  50.         MenuItem findClientItem = new MenuItem(popUpMenu,SWT.CASCADE);
  51.         findClientItem.addSelectionListener(new SelectionAdapter() {
  52.             public void widgetSelected(SelectionEvent arg0) {
  53.                 PopupShell newShell = new PopupShell(Display.getDefault(), SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
  54.                 newShell.setSize(770,500);
  55.                 Pri_Search searchPage = new Pri_Search(newShell, SWT.NONE, true, true); 
  56.                 searchPage.setBounds(0,0,770,500); 
  57.                 newShell.setText("Search");
  58.                 newShell.open();
  59.             }
  60.         });
  61.  
  62.         findClientItem.setText("Find Client");
  63.  
  64.         MenuItem notesItem = new MenuItem(popUpMenu,SWT.CASCADE);
  65.         notesItem.addSelectionListener(new SelectionAdapter() {
  66.             public void widgetSelected(SelectionEvent arg0) {
  67.                 PopupShell newShell = new PopupShell(Display.getDefault(), SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
  68.                 newShell.setSize(320,300);
  69.                 newShell.setText("Add Notes");
  70.                 Pub_AddNotes PublicAddNotesPage = new Pub_AddNotes(newShell, SWT.NONE);
  71.                 PublicAddNotesPage.setBounds(0,0,320,300);
  72.                 newShell.open();
  73.             }
  74.         });
  75.         notesItem.setText("Notes");
  76.  
  77.         MenuItem ratesItem = new MenuItem(popUpMenu,SWT.CASCADE);
  78.         ratesItem.setText("Rates");
  79.  
  80.         // sub menu for popup menu item "Rates"
  81.         Menu ratesMenu = new Menu(popUpMenu);
  82.         ratesItem.setMenu(ratesMenu);
  83.         MenuItem ratesRatesItem = new MenuItem(ratesMenu,SWT.NONE);
  84.         ratesRatesItem.addSelectionListener(new SelectionAdapter() {
  85.             public void widgetSelected(SelectionEvent arg0) {
  86.                 PopupShell newShell = new PopupShell(Display.getDefault(), SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
  87.                 newShell.setSize(492,570);
  88.                 Pri_Menu_Rates MenuRatesPage = new Pri_Menu_Rates(newShell, SWT.NONE);
  89.                 MenuRatesPage.setBounds(0,0,492,570);
  90.                 newShell.open();
  91.             }
  92.         });
  93.         ratesRatesItem.setText("Rates");
  94.  
  95.         MenuItem ratesMutualFundReturnsItem = new MenuItem(ratesMenu,SWT.CHECK);
  96.         ratesMutualFundReturnsItem.addSelectionListener(new SelectionAdapter() {
  97.             public void widgetSelected(SelectionEvent arg0) {
  98.                 PopupShell newShell = new PopupShell(Display.getDefault(), SWT.SHELL_TRIM | SWT.APPLICATION_MODAL);
  99.                 newShell.setSize(798,570);
  100.                 Pri_Menu_MutualFund MenuMutualFundsPage = new Pri_Menu_MutualFund(newShell, SWT.NONE);
  101.                 MenuMutualFundsPage.setBounds(0,0,798,570);
  102.                 newShell.open();
  103.             }
  104.         });
  105.         ratesMutualFundReturnsItem.setText("Mutual Funds Returns");
  106.  
  107.         MenuItem exitItem = new MenuItem(popUpMenu,SWT.CASCADE);
  108.         exitItem.setText("Exit");
  109.         exitItem.addSelectionListener(new SelectionAdapter() {
  110.             public void widgetSelected(SelectionEvent arg0) {
  111.                 shell.close();
  112.             }
  113.         });
  114.     }
  115.  
  116.  
Aug 18 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.