[Oxygen] Enabling/Disable Menus when Form is already open [message #1781678] |
Mon, 12 February 2018 06:00 |
|
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 #1781686 is a reply to message #1781678] |
Mon, 12 February 2018 08:14 |
Urs Beeli 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03627 seconds