|
Hello , I am trying to implement an action that is enabled or disabled (in the application top menu) depending on the current user. All the tutorials about conditional actions are explaining how to deal with actions that handle the current selection.
But in this case I need that the action is enabled or disabled based on my own calculation : basically i want to write my own method that returns true or false and that is taken into account by the platform for disabling the action in the menu.
I have tried to extend the SystemAction class and override isEnabled: - when the application starts , the action appears enabled in the menu - i click on it
- after the first click, the action becomes disabled This is almost what I want , but it's important that the initial state of the action is "disabled" . So , how can I implement an action that I can be enabled/disabled programatically ? The action needs to be enabled if the current user has the rights to . I already have my own method that returns whether the action should be enabled or not, and just need to use it in the context of the netbeans platform.
Best regards, Adrian Maier |
|
How does the User change, more info is needed before this question can be answered. When/how does the user change? At the time the application starts or can it also be done at runtime? Gj On 02/19/2012 08:32 AM, Adrian Maier wrote: > Hello , > > I am trying to implement an action that is enabled or disabled (in the > application top menu) depending on the current user. > > All the tutorials about conditional actions are explaining how to deal > with actions that handle the current selection. > > But in this case I need that the action is enabled or disabled based > on my own calculation : > basically i want to write my own method that returns true or false > and that is taken into account by the platform for disabling the > action in the menu. > > > I have tried to extend the SystemAction class and override isEnabled: > - when the application starts , the action appears enabled in the menu > - i click on it > - after the first click, the action becomes disabled > This is almost what I want , but it's important that the initial > state of the action is "disabled" . > > > > > So , how can I implement an action that I can be enabled/disabled > programatically ? > > The action needs to be enabled if the current user has the rights to . > I already have my own method that returns whether the action should > be enabled or not, and just need to use it in the context of the > netbeans platform. > > > > > Best regards, > Adrian Maier |
|
On Sun, Feb 19, 2012 at 09:42, Geertjan Wielenga <[hidden email]> wrote:
Hello Geertjan , The user doesn't change. The login stuff happens during the Installer of one of the modules: at application start there is a login window where the user types his user and password. Then I create the database connection and create a connections pool that is available for data entry forms and reports.
Currently there is no plan to allow the user to logoff and re-login with another user without application restart . The current user and his access rights are available by calling a static methods of a singleton class. The class is available in the entire application : all modules have dependency for a core module.
-- Adrian
Adrian Maier |
|
Hi Adrian, Then I recommend this approach: https://blogs.oracle.com/geertjan/entry/injecting_a_layer_file_into Gj On 02/19/2012 09:34 AM, Adrian Maier wrote:
|
|
Ok, I'll give it a try with loading specific layer xml files depending on the user. I would have preferred to have all the menu items visible, and just disable some of them . But it's not a big issue - the important thing is to have a working user rights implemented.
Just curious : i saw that when using the conditional actions wizard there are a few cookies to choose from like OpenCookie, EditCookie, EditorCookie, Project. In principle , is this Project cookie intended to be used to store application-wide data like the current user ?
Thanks Geertjan ! Adrian On Sun, Feb 19, 2012 at 10:36, Geertjan Wielenga <[hidden email]> wrote:
Adrian Maier |
|
On 02/19/2012 10:11 AM, Adrian Maier wrote:
No, by "Project" is meant an implement of the NetBeans Project API. Gj
|
|
Hi Adrian,
> I would have preferred to have all the menu items visible, and just disable some of them . > But it's not a big issue - the important thing is to have a working user rights implemented. I just documented a possible way to hook into the action creation process. Whether it is a good idea is debatable, but it works. :) http://www.pellissier.co.za/hermien/?p=204 Best wishes, Hermien PELLISSIER |
|
On Wed, Feb 22, 2012 at 19:45, Hermien Pellissier <[hidden email]> wrote: Hi Adrian, Hello , It's been a long time since I posted the question. Only now did i manage to come back to this project and try it this way. I have been able to apply the example and instantiate the action in my own method, however I haven't been able to achieve the behavior that I need to implement : be able to programatically enable or disable the action (and consequently the menu item).
The interesting thing is that if I : - create an action that extends javax.swing.AbstractAction - override the isEnabled() method to return false by doing so I _almost_ get the effect that I want : * the corresponding menu item appears initially as enabled * if i click on it , the action is not executed . This indicates that the action is treated as disabled.
* if i open again the menu , now the menu item appears disabled (great !) So now I have only one visual glitch to solve : the menu item that initially is displayed as if it were enabled.
Does anyone have any suggestion for fixing the initial 'enabled' status of the menu items ? Is it possible to grab a reference to the actual JMenuItem object that corresponds to my action ?
Best regards, Adrian Maier |
|
Hi Adrian,
When you create the action (with the code as in my example), call setEnabled(false) on it. And then you don't need to override isEnabled() - the default implementation that is provided by the object returned by org.openide.awt.Actions.alwaysEnabled() will be sufficient.
Best wishes, Hermien On Thu, Mar 22, 2012 at 10:08 PM, Adrian Maier <[hidden email]> wrote:
|
| Powered by Nabble | See how NAML generates this page |
