Merge "Issue #206 radio buttons only select one at a time" into 10-Tech_Blocked
Former-commit-id:be5e7c3624
[formerlybe5e7c3624
[formerly 4b469b92a9c8f0b3ddc5023c1ed28eb1a50d78dc]] Former-commit-id:4353ae0f2a
Former-commit-id:b6efbfe56c
This commit is contained in:
commit
40e147867e
3 changed files with 109 additions and 86 deletions
|
@ -26,6 +26,8 @@ import org.eclipse.swt.SWT;
|
|||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseTrackAdapter;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
@ -134,18 +136,18 @@ public class MenuItemComposite extends Composite {
|
|||
secondItem.setLayoutData(gd);
|
||||
}
|
||||
// check boxes
|
||||
// else if (item.getStyle() == SWT.CHECK) {
|
||||
// // if (item.getStyle() == SWT.CHECK) {
|
||||
// firstItem = new Button(this, SWT.CHECK);
|
||||
// ((Button) firstItem).setSelection(item.getSelection());
|
||||
// GridData gd = new GridData(18, 18);
|
||||
// firstItem.setLayoutData(gd);
|
||||
//
|
||||
// secondItem = new Label(this, labelStyle);
|
||||
// ((Label) secondItem).setText(labels[0]);
|
||||
// gd = new GridData(SWT.LEFT, SWT.CENTER, true, true);
|
||||
// secondItem.setLayoutData(gd);
|
||||
// }
|
||||
// else if (item.getStyle() == SWT.CHECK) {
|
||||
// // if (item.getStyle() == SWT.CHECK) {
|
||||
// firstItem = new Button(this, SWT.CHECK);
|
||||
// ((Button) firstItem).setSelection(item.getSelection());
|
||||
// GridData gd = new GridData(18, 18);
|
||||
// firstItem.setLayoutData(gd);
|
||||
//
|
||||
// secondItem = new Label(this, labelStyle);
|
||||
// ((Label) secondItem).setText(labels[0]);
|
||||
// gd = new GridData(SWT.LEFT, SWT.CENTER, true, true);
|
||||
// secondItem.setLayoutData(gd);
|
||||
// }
|
||||
// submenus (with arrows)
|
||||
else if (item.getStyle() == SWT.CASCADE) {
|
||||
firstItem = new Label(this, SWT.PUSH);
|
||||
|
@ -170,7 +172,7 @@ public class MenuItemComposite extends Composite {
|
|||
|
||||
createUpdateListener(this);
|
||||
item.addListener(SWT.Modify, updateListener);
|
||||
|
||||
}
|
||||
showListener = new Listener() {
|
||||
@Override
|
||||
public void handleEvent(final Event event) {
|
||||
|
@ -178,11 +180,10 @@ public class MenuItemComposite extends Composite {
|
|||
"Regenerate Tear Off Menus") {
|
||||
|
||||
@Override
|
||||
public IStatus runInUIThread(
|
||||
IProgressMonitor monitor) {
|
||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||
System.out.println("runInUIThread");
|
||||
if (menu == null || menu.isDisposed()) {
|
||||
for (MenuItem item : topLevelMenu
|
||||
.getItems()) {
|
||||
for (MenuItem item : topLevelMenu.getItems()) {
|
||||
if (item.getMenu() != null) {
|
||||
for (Listener list : item.getMenu()
|
||||
.getListeners(SWT.Show)) {
|
||||
|
@ -191,6 +192,10 @@ public class MenuItemComposite extends Composite {
|
|||
event.type = SWT.Show;
|
||||
list.handleEvent(event);
|
||||
}
|
||||
System.out.println("getShell() : "
|
||||
+ getShell().getText());
|
||||
System.out.println("item : "
|
||||
+ item.getText());
|
||||
if (getShell().getText().equals(
|
||||
item.getText())) {
|
||||
menu = item.getMenu();
|
||||
|
@ -232,7 +237,6 @@ public class MenuItemComposite extends Composite {
|
|||
};
|
||||
item.getParent().addListener(SWT.Show, showListener);
|
||||
topLevelMenu.addListener(SWT.Show, showListener);
|
||||
}
|
||||
|
||||
if (item.isEnabled()) {
|
||||
// add the listeners to both the first and the second
|
||||
|
@ -480,7 +484,8 @@ public class MenuItemComposite extends Composite {
|
|||
// handles the check boxes, if clicking the check box
|
||||
// need to not do this (because SWT does it already)
|
||||
// otherwise do it
|
||||
if (firstItem instanceof Button) {
|
||||
if (firstItem instanceof Button
|
||||
&& firstItem.getStyle() == SWT.CHECK) {
|
||||
if (e.widget != firstItem) {
|
||||
((Button) firstItem).setSelection(!((Button) firstItem)
|
||||
.getSelection());
|
||||
|
@ -488,23 +493,40 @@ public class MenuItemComposite extends Composite {
|
|||
}
|
||||
|
||||
for (int i = 0; i < parent.getChildren().length; i++) {
|
||||
MenuItemComposite mic = (MenuItemComposite) parent
|
||||
final MenuItemComposite mic = (MenuItemComposite) parent
|
||||
.getChildren()[i];
|
||||
if (item.getStyle() == SWT.RADIO) {
|
||||
if (mic.item.getStyle() == SWT.RADIO) {
|
||||
try {
|
||||
if (((Control) e.widget).getParent()
|
||||
.getData("radioGroup")
|
||||
.equals(mic.getData("radioGroup"))) {
|
||||
if (!((Control) e.widget).getParent().equals(
|
||||
mic)) {
|
||||
MenuItemComposite parent = null;
|
||||
// check whether a Label is clicked or a
|
||||
// MenuItemComposite
|
||||
if (e.widget instanceof MenuItemComposite) {
|
||||
parent = (MenuItemComposite) e.widget;
|
||||
} else {
|
||||
parent = (MenuItemComposite) ((Control) e.widget)
|
||||
.getParent();
|
||||
}
|
||||
// check that the radio groups match
|
||||
if (mic.getData("radioGroup").equals(
|
||||
parent.getData("radioGroup"))) {
|
||||
if (!parent.equals(mic)) {
|
||||
((Button) mic.firstItem)
|
||||
.setSelection(false);
|
||||
parent.item.setSelection(false);
|
||||
} else {
|
||||
((Button) mic.firstItem).setSelection(true);
|
||||
parent.item.setSelection(true);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
mic.item.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
mic.item.setSelection(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class TearOffMenuDialog extends CaveSWTDialog {
|
|||
// go through menu items and build MenuItemComposite for each item,
|
||||
// which handles all the selection and color of the "MenuItem" in the
|
||||
// dialog
|
||||
int radioGroups = 0;
|
||||
int radioGroup = 0;
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
int labelStyle = SWT.NONE;
|
||||
if (items[i] == null) {
|
||||
|
@ -119,9 +119,9 @@ public class TearOffMenuDialog extends CaveSWTDialog {
|
|||
SWT.NONE);
|
||||
|
||||
if (items[i].getStyle() == SWT.RADIO) {
|
||||
comp.setData("radioGroup", radioGroups);
|
||||
comp.setData("radioGroup", radioGroup);
|
||||
} else {
|
||||
radioGroups++;
|
||||
radioGroup++;
|
||||
}
|
||||
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
|
@ -206,7 +207,7 @@ public abstract class AbstractVizPerspectiveManager implements
|
|||
public AbstractVizPerspectiveManager() {
|
||||
// new up a tool manager for the perspective
|
||||
toolManager = new ModalToolManager();
|
||||
perspectiveDialogs = new ArrayList<IPerspectiveSpecificDialog>();
|
||||
perspectiveDialogs = new CopyOnWriteArrayList<IPerspectiveSpecificDialog>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue