Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to design for competing use of popup menu on StyledText?
How to design for competing use of popup menu on StyledText? [message #494066] Thu, 29 October 2009 05:22 Go to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 105
Registered: July 2009
Senior Member
Building a small UI component framework. One of the components is a
spellchecker. When associated with a StyledText it will add a a right
click/popup menu. Since this is a framework, I won't have exclusive
control over other components that might add popup menus to the
StyledText.

Is there a recommended, or at least practical way to manage the
potential conflict? Any way to do a contolled merge of popup menu
contributions?
Re: How to design for competing use of popup menu on StyledText? [message #494244 is a reply to message #494066] Thu, 29 October 2009 17:08 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Hi,

There isn't an automated way to merge menus at the swt level. The snippet
below demonstrates how to do it manually, and I think it should be fine for
your case unless someone else is also adding their menu items asynchronously
(seems unlikely).

public class Main0 {
static int counter = 0;
public static void main (String [] args) {
final String ID_SPELLCHECKER = "SPELLCHECKER";
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setBounds(10,10,200,250);
shell.setLayout(new FillLayout());
final StyledText st = new StyledText(shell, SWT.NONE);
Menu menu = new Menu(st);
new MenuItem(menu, SWT.NONE).setText("static item");
st.setMenu(menu);
st.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
/* asyncExec so that all other MenuDetects run first */
display.asyncExec(new Runnable() {
public void run() {
if (st.isDisposed()) return;
Menu menu = st.getMenu();
MenuItem item = (MenuItem)menu.getData(ID_SPELLCHECKER);
if (item != null) {
int index = menu.indexOf(item);
if (index != menu.getItemCount() - 1) {
/* move it to the bottom of the menu */
item.dispose();
item = null;
}
}
if (item == null) {
item = new MenuItem(menu, SWT.NONE);
item.setText("check spelling");
menu.setData(ID_SPELLCHECKER, item);
}
}
});
}
});
st.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
Menu menu = ((Control)event.widget).getMenu();
new MenuItem(menu, SWT.NONE).setText("dynamic menu item " +
counter++);
}
});

shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}

Grant


"Gerald Rosenberg" <no@dr.ess> wrote in message
news:MPG.2552c65e4116a36e9896c7@news.eclipse.org...
> Building a small UI component framework. One of the components is a
> spellchecker. When associated with a StyledText it will add a a right
> click/popup menu. Since this is a framework, I won't have exclusive
> control over other components that might add popup menus to the
> StyledText.
>
> Is there a recommended, or at least practical way to manage the
> potential conflict? Any way to do a contolled merge of popup menu
> contributions?
Re: How to design for competing use of popup menu on StyledText? [message #494454 is a reply to message #494244] Fri, 30 October 2009 16:56 Go to previous message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 105
Registered: July 2009
Senior Member
Thanks much.

In article <hcci74$3gt$1@build.eclipse.org>, grant_gayed@ca.ibm.com
says...
>
> Hi,
>
> There isn't an automated way to merge menus at the swt level. The snippet
> below demonstrates how to do it manually, and I think it should be fine for
> your case unless someone else is also adding their menu items asynchronously
> (seems unlikely).
>
Previous Topic:Dockable Widgets
Next Topic:Losing clicks and redraws on Ubuntu Karmic with Eclipse 3.5?
Goto Forum:
  


Current Time: Mon Aug 19 05:29:34 GMT 2019

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

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

Back to the top