Dynamic menu pagination [message #661353] |
Thu, 24 March 2011 11:01 |
Jaime Messages: 2 Registered: March 2011 |
Junior Member |
|
|
Hi,
I want to build a menu with dynamic items coming from a list of strings of variable size. The menu should show the first 5 items in the list and then a 'More...' item that would refresh the list of items showing the next 5.
Menu - New Item
- Recent item 1
- Recent item 2
- Recent item 3
- Recent item 4
- Recent item 5
- More ...
after clicking on 'More...'
Menu - New Item
- Recent item 6
- Recent item 7
- Recent item 8
- Recent item 9
- More ...
Is that possible? I'm using CompoundContributionItem for building the meny but I don't know how to do the pagination part. Any ideas?
[Updated on: Thu, 24 March 2011 11:30] Report message to a moderator
|
|
|
Re: Dynamic menu pagination [message #661580 is a reply to message #661353] |
Fri, 25 March 2011 13:45 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
I don't know if it's possible to do this up at the level of
ContributionItems, etc. FWIW the snippet below shows two approaches for
doing this in a plain SWT pop-up menu (a drop-down menu would be no
different). Its default behaviour updates the items when the More... item
is armed. If you change its UPDATE_ON_ARM variable to false then the items
will update when the More... item is selected, but this is not as smooth and
necessitates showing a new menu with the updated items.
public static void main (String [] args) {
final boolean UPDATE_ON_ARM = true;
Display display = new Display ();
Shell shell = new Shell (display);
final Menu menu = new Menu (shell, SWT.POP_UP);
for (int i = 0; i < 5; i++) {
new MenuItem(menu, SWT.NONE).setText("item " + i);
}
MenuItem moreItem = new MenuItem(menu, SWT.NONE);
moreItem.setText("More...");
moreItem.addListener(UPDATE_ON_ARM ? SWT.Arm : SWT.Selection, new
Listener() {
public void handleEvent(Event event) {
MenuItem[] items = menu.getItems();
for (int i = 0; i < items.length - 1; i++) {
MenuItem item = items[i];
item.setText(item.getText() + "0");
}
if (!UPDATE_ON_ARM) {
menu.setVisible(true);
}
}
});
shell.setMenu (menu);
shell.setSize (200, 200);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
HTH,
Grant
"Jaime" <jaimelop@gmail.com> wrote in message
news:imf7sb$1gd$1@news.eclipse.org...
> Hi,
> I want to build a menu with dynamic items coming from a list of strings of
> variable size. The menu should show the first 5 items in the list and then
> a 'More...' item that would refresh the list of items showing the next 5.
>
> Menu - New Item
> - Recent item 1
> - Recent item 2
> - Recent item 3
> - Recent item 4
> - Recent item 5
> - More ...
>
> after clicking on 'More...'
> Menu - New Item
> - Recent item 6
> - Recent item 7
> - Recent item 8
> - Recent item 9
> - More ...
>
> Is that possible? I'm using CompoundContributionItem for building the meny
> but I don't know how to do the pagination part. Any ideas?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02967 seconds