Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Dynamic menu items in menu bar
Dynamic menu items in menu bar [message #1479620] Wed, 19 November 2014 15:37 Go to next message
Thomas Schär is currently offline Thomas SchärFriend
Messages: 4
Registered: February 2014
Junior Member
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 #1481709 is a reply to message #1479620] Fri, 21 November 2014 06:51 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
There was a menu refactoring with Luna.

Can you check if execOwnerValueChanged(Object value) is working for you?
Can you check if this thread is helping: https://www.eclipse.org/forums/index.php/t/816782/

If not, feel free to continue the discussion. I will try to look into it more deeply or to find something that know about Menu and MenuBar.

.
Re: Dynamic menu items in menu bar [message #1485370 is a reply to message #1481709] Mon, 24 November 2014 07:25 Go to previous messageGo to next message
Thomas Schär is currently offline Thomas SchärFriend
Messages: 4
Registered: February 2014
Junior Member
Hi Jeremie! As far as I understand it, the execOwnerValueChanged method does not fix it in this case, because we don't want a context menu on a certain element. We want a dynamic menu item in the menu bar, which depends on the state of the outline tree form, but the tree is not the owner of the menu, so the execOwnerValueChanged method is not triggered.
Re: Dynamic menu items in menu bar [message #1503702 is a reply to message #1485370] Mon, 08 December 2014 18:03 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
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.
Previous Topic:New Eclipse Scout Homepage
Next Topic:Table with custom edit field
Goto Forum:
  


Current Time: Fri Apr 19 01:29:52 GMT 2024

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

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

Back to the top