From 3daca6067d6f2aa7d41a00bf8b9d15a64867dc03 Mon Sep 17 00:00:00 2001 From: Matt Nash Date: Thu, 2 Feb 2012 15:31:38 -0600 Subject: [PATCH] Issue #26 radio buttons hopefully gerrit doesn't screw this up Change-Id: I5ebc3356f83b3f5eb213cb659badd5ae93694d11 Former-commit-id: e4034f0fa53d2763a4cc9f6f260af3e0a3dd18d3 [formerly eead5c9a7e35cfb2e64ccc55f42717ca3dd2cbd0] [formerly c966b7d8fd27814fdae0e3b36df872c5548cb203] [formerly b236733537566f5077dde7e854ca3fc7c2a71a30 [formerly c966b7d8fd27814fdae0e3b36df872c5548cb203 [formerly c03b20a3c52a7570133a972a8c915bffd167f733]]] Former-commit-id: b236733537566f5077dde7e854ca3fc7c2a71a30 Former-commit-id: 08d0111c6d1158bd9b704f1e9f629300df408cfe [formerly 6a23c2537f7319626dbb01120a864a2d5aecba37] Former-commit-id: c6183ff3a3921d04c3d3f2eba599e89feeec815f --- .../widgets/tearoff/MenuItemComposite.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/widgets/tearoff/MenuItemComposite.java b/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/widgets/tearoff/MenuItemComposite.java index db6cb6d027..5b2920956d 100644 --- a/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/widgets/tearoff/MenuItemComposite.java +++ b/cave/com.raytheon.uf.viz.ui.menus/src/com/raytheon/uf/viz/ui/menus/widgets/tearoff/MenuItemComposite.java @@ -134,6 +134,31 @@ public class MenuItemComposite extends Composite { ((Label) secondItem).setText(labels[0]); gd = new GridData(SWT.LEFT, SWT.CENTER, true, true); secondItem.setLayoutData(gd); + item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (e.widget instanceof MenuItem) { + // check that the radio groups match + for (Control comp : firstItem.getParent() + .getParent().getChildren()) { + MenuItemComposite composite = (MenuItemComposite) comp; + if (composite.item.getText().equals( + ((MenuItem) e.widget).getText())) { + if (composite.firstItem instanceof Button) { + ((Button) composite.firstItem) + .setSelection(composite.item + .getSelection()); + } + } else { + if (composite.firstItem instanceof Button) { + ((Button) composite.firstItem) + .setSelection(false); + } + } + } + } + } + }); } // check boxes // else if (item.getStyle() == SWT.CHECK) { @@ -181,9 +206,15 @@ public class MenuItemComposite extends Composite { @Override public IStatus runInUIThread(IProgressMonitor monitor) { + if (parent == null || parent.isDisposed() + || parent.getShell() == null + || parent.getShell().isDisposed()) { + return Status.CANCEL_STATUS; + } if (menu == null || menu.isDisposed()) { for (MenuItem item : topLevelMenu.getItems()) { if (item.getMenu() != null) { + ; for (Listener list : item.getMenu() .getListeners(SWT.Show)) { Event event = new Event(); @@ -424,6 +455,7 @@ public class MenuItemComposite extends Composite { // if the menu has been opened, then the items need to // be regenerated if there is a submenu, then add the // ability to show it + // TODO, actually need to keep them in sync if (item == null || item.isDisposed()) { int start = 0; if (menu.getItemCount() != parent.getChildren().length) { @@ -507,9 +539,11 @@ public class MenuItemComposite extends Composite { if (mic.getData("radioGroup").equals( parent.getData("radioGroup"))) { if (!parent.equals(mic)) { + item.setSelection(false); ((Button) mic.firstItem) .setSelection(false); } else { + item.setSelection(true); ((Button) mic.firstItem).setSelection(true); } } @@ -541,7 +575,9 @@ public class MenuItemComposite extends Composite { item.getParent().removeListener(SWT.Show, showListener); topLevelMenu.removeListener(SWT.Show, showListener); } - firstItem.dispose(); + if (firstItem != null) { + firstItem.dispose(); + } if (secondItem != null) { secondItem.dispose(); }