Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Dynamic menu pagination
Dynamic menu pagination [message #661353] Thu, 24 March 2011 11:01 Go to next message
Jaime  is currently offline 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 Go to previous messageGo to next message
Grant Gayed is currently offline Grant Gayed
Messages: 2151
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?
Re: Dynamic menu pagination [message #661892 is a reply to message #661353] Mon, 28 March 2011 13:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Grant has a good example of implementing something like that using SWT.
But if you are in an RCP app and using ContributionItems, please don't
do that, the protocol doesn't support it (and in Eclipse 4 or Eclipse
SDK 4.x it won't work reliably/at all).

From a UX point of view, the menu is the wrong place to provide
pagination. List a few items (like you mention) and then the More...
menu item should open a small dialog. The pattern is used all over
eclipse: Show view.., Open perspective..., The "New" menu Other..., etc

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Dynamic menu pagination [message #662095 is a reply to message #661892] Tue, 29 March 2011 09:39 Go to previous message
Jaime  is currently offline Jaime
Messages: 2
Registered: March 2011
Junior Member
Grant, that's exactly the SWT behavior I'd like to reproduce in Eclipse RCP, but I guess I'll have to use a dialog as Paul suggests.

Thanks you both for your quick replies.
Jaime

[Updated on: Tue, 29 March 2011 09:40]

Report message to a moderator

Previous Topic:Missing Constraint: Require-Bundle: org.eclipse.equinox.common; bundle-version="[3.5.0,4.0.0)
Next Topic:Exception when unlocking windows' screensaver
Goto Forum:
  


Current Time: Sat Oct 25 03:04:37 GMT 2014

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

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