Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » [Oxygen] Enabling/Disable Menus when Form is already open
[Oxygen] Enabling/Disable Menus when Form is already open [message #1781678] Mon, 12 February 2018 06:00 Go to next message
Peter Pfeifer is currently offline Peter PfeiferFriend
Messages: 213
Registered: November 2014
Senior Member

Hello there,

I was wondering if and how it is possible to change the enabled and/or visible state of a menu when a form is already opened?

When opening the form setting these states works wonderfully.

But in my use case the user can only print an invoice to an order, when the order is finished and in "Closed"-State. The user can put the order in closed state, when all requirements are met by pressing a "Close Order" button. And in the "execAction" method I'd like to enable the print invoice menu immediately. But unfortunately invoking "setEnabled(true)/setVisible(true)" doesn't do the trick.

Is there a way to tell a menu to refresh it's enabled/visible state other than in the execFormActivated() method?

My menu structure looks like this:
Print Menu
 - Print Invoice
 - Print Bil Of Delivery
 - Print Credit Voucher



Thanks

Peter



[Updated on: Mon, 12 February 2018 06:01]

Report message to a moderator

Re: [Oxygen] Enabling/Disable Menus when Form is already open [message #1781685 is a reply to message #1781678] Mon, 12 February 2018 08:06 Go to previous messageGo to next message
Stephan Merkli is currently offline Stephan MerkliFriend
Messages: 40
Registered: April 2012
Member
Hi Peter

Enable/visible state of menus can be changed by setEnabled/setVisible even if the menu is already rendered.

If the menu is set as "visibleGranted"=false when the form is initialized, it can never be set to visible again (because it won't exist in the UI). If you disable a menu initially by "enabledGranted"=false, you must not enable if afterwards, just use "enable"=false initially in such a szenario.
The actual visibility or enabled state is determined by the regular property, its granted analogue and the property of the parents.

How do you disable the menu initially and how do you enable it afterwards?

Kind regards
Stephan
Re: [Oxygen] Enabling/Disable Menus when Form is already open [message #1781686 is a reply to message #1781678] Mon, 12 February 2018 08:14 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
In one of our products we have menu items that should only be active (or even visible) when a specific outline or a specific page within an outline is active. We solved this by adding corresponding listeners to the menu item itself, so it is informed if the outline and page change and can then do setVisible() and setEnabled() on itself. We also have other, custom events that have an impact on menu availability. We solved this by creating listeners for these events which are implemented by the menu items and triggered by the changes. You could probably do something like this as well:

public interface IOrderChangeListener {
  void orderStateChanged(OrderState state);
}

public class PrintInvoiceMenu extends AbstractMenu implements IOrderChangeListener {
    @Override
    protected void execInitAction() throws ProcessingException {
        super.execInitAction();
        BEANS.get(OrderManager.class).addListener(this);
    }
    @Override
    public void orderStateChange(OrderState state) {
        setEnabled(state == OrderState.CLOSED);
    }
}

@ApplicationScoped
public class OrderManager {
    List<IOrderChangeListener> listeners = new ArrayList<>();
    public addListener(IOrderCompletionListener listener) {
        listners.add(listener);
    }
    public void orderStateChanged (OrderState state) {
        for(IOrderChangeListener listener: listeneres) {
            listener.orderStateChanged(state);
        }
    }
}

....
    public void loadOrder(....) {
       // code to load order
      BEAN.get(OrderManager.class).orderStateChanged(order.state);
    }

    public void closeOrder(....) {
       // code to close order
      order.state = OrderState.CLOSED;
      BEAN.get(OrderManager.class).orderStateChanged(order.state);
    }
...

[Updated on: Mon, 12 February 2018 08:16]

Report message to a moderator

Re: [Oxygen] Enabling/Disable Menus when Form is already open [message #1781734 is a reply to message #1781686] Mon, 12 February 2018 16:55 Go to previous message
Peter Pfeifer is currently offline Peter PfeiferFriend
Messages: 213
Registered: November 2014
Senior Member

Thank you very much. In the meanwhile I found my bug. But I must admit I like the OrderChangeListener a much nicer solution :)

Thanks Peter
Previous Topic:[Neon] Scout Thread management in a Java EE container
Next Topic:Load Test with JMeter
Goto Forum:
  


Current Time: Fri Apr 26 11:00:03 GMT 2024

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

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

Back to the top