Dynamic menu items in menu bar [message #1479620] |
Wed, 19 November 2014 10:37  |
Eclipse User |
|
|
|
Hi!
For the effect of dynamic menu items in the menubar (visible if certain TablePage is active) we have added a tree listener onto our outline which sets the visibility of the EntityCopyMenu, defined in our Desktop or DesktopExtension:
@Order(20.0)
public class ToolsMenu extends AbstractMenu {
...
@Order(10.0)
public class CustomerCopyMenu extends AbstractMenu {
...
@Override
protected void execInitAction() throws ProcessingException {
List<IOutline> availableOutlines = getAvailableOutlines();
availableOutlines.get(0).addTreeListener(new TreeListener() {
@Override
public void treeChanged(TreeEvent e) {
if (e.getType() == TreeEvent.TYPE_NODE_CLICK) {
setVisible(getOutline().getActivePage() instanceof CustomerTablePage);
setEnabled(true);
}
}
@Override
public void treeChangedBatch(List<? extends TreeEvent> batch) {
}
});
}
}
}
This used to work perfectly in Scout Kepler (3.9) , but with Scout Luna the following occurs: The treeChanged() method is called on a switch to another TablePage, so are also the setVisible() and setEnabled() methods on the CustomerCopyMenu, but the menu item is still visible, even if CustomerTablePage is not the active page. The menu item can be clicked and the event comes from SWT, but no action is executed on the scout side, because the scout menu item's visibility property is set to false.
The menu item doesn't disappear even if another element in the tree is selected. It does disappear, though, if the table of any TablePage is clicked.
Is this a bug or is there any other way of having dynamic menu items in the menu bar?
|
|
|
|
|
Re: Dynamic menu items in menu bar [message #1503702 is a reply to message #1485370] |
Mon, 08 December 2014 13:03  |
Eclipse User |
|
|
|
The Scout Model element provides a setVisible(boolean) method (defined on the IAction interface), but the SWT Rendering engine is ignoring this property. See the implementation of SwtScoutMenuItem.updateVisibilityFromScout():
protected void updateVisibilityFromScout() {
// not supported on swt MenuItem
}
I do not know the reason behind this implementation.
The code in 3.9 might be different, but I cannot imagine that setVisble(false) was working on Menus with SWT.
The visible property is taken into account by the swing renderer. In Swing the menu item is made visible or not when the visible property changes.
---
Now for your question; I have tried to reproduce it. With this listener:
@Override
protected void execInitAction() throws ProcessingException {
List<IOutline> availableOutlines = getAvailableOutlines();
availableOutlines.get(0).addTreeListener(new TreeListener() {
@Override
public void treeChanged(TreeEvent e) {
if (e.getType() == TreeEvent.TYPE_NODE_CLICK) {
setEnabled(getOutline().getActivePage() instanceof MyTablePage);
}
else {
setEnabled(false);
}
}
@Override
public void treeChangedBatch(List<? extends TreeEvent> batch) {
}
});
}
The enablement is working for me.
That said I would not implement it with a Listener. In execPageActivated() I would call a method on the Desktop that enables the desired Menu.
|
|
|
Powered by
FUDForum. Page generated in 0.03660 seconds