Issue #26 tear off menu changes to fix issues

Former-commit-id: 0ff3ef8d72 [formerly 542049e455 [formerly 30c43cbcd4500c5754261b420f5c9b031bd63014]]
Former-commit-id: 542049e455
Former-commit-id: 0ea872be36
This commit is contained in:
Matt Nash 2012-02-03 13:13:15 -06:00
parent 1cde213e67
commit 41d93a82a1
6 changed files with 114 additions and 17 deletions

View file

@ -130,7 +130,7 @@ public class SubmenuContributionItem extends MenuManager {
@Override
public boolean isVisible() {
return true;
return visible;
}
// call getContributionItems using the getContributionItems JobPool.

View file

@ -213,17 +213,22 @@ public class MenuItemComposite extends Composite {
}
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();
event.widget = item;
event.type = SWT.Show;
list.handleEvent(event);
try {
Event event = new Event();
event.widget = topLevelMenu;
event.type = SWT.Show;
list.handleEvent(event);
} catch (Exception e) {
// do nothing
}
}
if (getShell().getText().equals(
item.getText())) {
item.getText().replaceAll("&",
""))) {
menu = item.getMenu();
break;
}
@ -232,6 +237,11 @@ public class MenuItemComposite extends Composite {
}
int start = 0;
if (menu == null || menu.isDisposed()
|| parent == null || parent.isDisposed()
|| parent.getChildren() == null) {
return Status.CANCEL_STATUS;
}
if (menu.getItemCount() != parent.getChildren().length) {
start = (menu.getItemCount() - parent
.getChildren().length);
@ -254,6 +264,28 @@ public class MenuItemComposite extends Composite {
list.handleEvent(e);
}
}
mic.item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(
SelectionEvent e) {
if (e.widget instanceof MenuItem) {
if (mic.item.getText().equals(
((MenuItem) e.widget)
.getText())) {
if (mic.firstItem instanceof Button) {
((Button) mic.firstItem)
.setSelection(mic.item
.getSelection());
} else {
if (mic.firstItem instanceof Button) {
((Button) mic.firstItem)
.setSelection(false);
}
}
}
}
}
});
}
}
@ -445,7 +477,8 @@ public class MenuItemComposite extends Composite {
event.type = SWT.Show;
list.handleEvent(event);
}
if (getShell().getText().equals(item.getText())) {
if (getShell().getText().equals(
item.getText().replaceAll("&", ""))) {
menu = item.getMenu();
break;
}
@ -538,12 +571,16 @@ public class MenuItemComposite extends Composite {
// check that the radio groups match
if (mic.getData("radioGroup").equals(
parent.getData("radioGroup"))) {
if (!parent.equals(mic)) {
item.setSelection(false);
if (!parent.item
.getText()
.replaceAll("&", "")
.equals(mic.item.getText().replaceAll(
"&", ""))) {
mic.item.setSelection(false);
((Button) mic.firstItem)
.setSelection(false);
} else {
item.setSelection(true);
mic.item.setSelection(true);
((Button) mic.firstItem).setSelection(true);
}
}

View file

@ -28,6 +28,9 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.viz.ui.EditorUtil;
import com.raytheon.viz.ui.editor.AbstractEditor;
/**
* The popup menu for when items are populated out of the TearOffMenuDialog
*
@ -82,6 +85,13 @@ public class PopupMenu {
mItem.addListener(SWT.Selection, list);
}
mItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
((AbstractEditor) EditorUtil.getActiveEditor()).refresh();
}
});
// a show listener, so when the menu is shown (in cave) it updates
// the time in the tear off submenu
// this tries to update all the times when the menu is opened
@ -205,10 +215,14 @@ public class PopupMenu {
// showing the menu in cave (won't actually show), but executes all the
// listeners to build the menus (since they are built on-demand)
for (Listener list : item.getMenu().getListeners(SWT.Show)) {
Event event = new Event();
event.widget = item;
event.type = SWT.Show;
list.handleEvent(event);
try {
Event event = new Event();
event.widget = item;
event.type = SWT.Show;
list.handleEvent(event);
} catch (Exception e) {
// do nothing
}
}
addPopupMenu(item, shell, y);

View file

@ -147,6 +147,14 @@ public class TearOffMenuListener implements IMenuListener2 {
String filled = "- - - - - - TEAR-OFF : "
+ parent.getParentItem().getText() + " - - - - - -";
// String filled = "-" * bytes.length
// safety, not wanting to be permanent, making sure only one shows
// up
for (MenuItem item : menu.getItems()) {
if (item.getText().contains("TEAR-OFF")) {
return;
}
}
new ActionContributionItem(new TearOffAction(filled, manager,
items, menu)).fill(parent, 0);
}

View file

@ -392,6 +392,10 @@
name="size"
value="7">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="miniscule">
</parameter>
</command>
<command
commandId="com.raytheon.viz.hydro.actions.setfont"
@ -402,6 +406,10 @@
name="size"
value="8">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="verysmall">
</parameter>
</command>
<command
commandId="com.raytheon.viz.hydro.actions.setfont"
@ -412,6 +420,10 @@
name="size"
value="9">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="small">
</parameter>
</command>
<command
commandId="com.raytheon.viz.hydro.actions.setfont"
@ -422,6 +434,10 @@
name="size"
value="10">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="normal">
</parameter>
</command>
<command
commandId="com.raytheon.viz.hydro.actions.setfont"
@ -432,6 +448,10 @@
name="size"
value="12">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="large">
</parameter>
</command>
<command
commandId="com.raytheon.viz.hydro.actions.setfont"
@ -442,6 +462,10 @@
name="size"
value="16">
</parameter>
<parameter
name="org.eclipse.ui.commands.radioStateParameter"
value="verylarge">
</parameter>
</command>
</menu>
</menuContribution>
@ -625,8 +649,17 @@
<commandParameter
id="size"
name="size"
optional="true">
</commandParameter>
optional="false">
</commandParameter>
<commandParameter
id="org.eclipse.ui.commands.radioStateParameter"
name="State"
optional="false">
</commandParameter>
<state
class="org.eclipse.ui.handlers.RadioState:normal"
id="org.eclipse.ui.commands.radioState">
</state>
</command>
<command
id="com.raytheon.viz.hydro.actions.EditLocationShiftAction"

View file

@ -22,6 +22,8 @@ package com.raytheon.viz.hydrocommon.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.handlers.RadioState;
import com.raytheon.viz.hydrocommon.HydroDisplayManager;
@ -48,6 +50,9 @@ public class FontAction extends AbstractHandler {
HydroDisplayManager manager = HydroDisplayManager.getInstance();
manager.setFontSize(Integer.parseInt(event.getParameter("size")));
String newVal = event.getParameter(RadioState.PARAMETER_ID);
HandlerUtil.updateRadioState(event.getCommand(), newVal);
return null;
}