[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: Enabling and disabling actions according to user priviledges

Hi,

after some debuging, ... and digging around in the sources the situation is fairly easy if you control *all* Action-Delegates.

- do the privileges checks in selectionChanged(IAction action,
  ISelection selection) is called directly after the delegate is
  created.

- you simply have to implement the IActionDelegate2-Interface and when
  the delegate is created the first method called afterwards is
  init(IAction action) where you can check the privileges.

If you are interested in the code where I read the behaviour from it is: org.eclipse.ui.internal.PluginAction

The second solution is the save way if you ask me because IActionDelegate2#init(IAction)'s javadoc states that it is immediately called when the delegate is instantiated whereas solution one might be an implementation detail that can change.

Tom

Camilo Arango schrieb:
Thanks for the reply,

Hmm... as it appears, org.eclipse.ui.internal is not part of the RCP, so I can't find the WorkbenchPlugin class. Is there any other mechanism to do this?

Besides, I am not sure that removing the actions is the best choice, because they would appear behind the login dialog and then disappear.

Any other thoughts?

Thanks,

C. A.

Tom Schindl wrote:

Hi,

The trick is fairly simple. You can access the actions added by plugins
when the workbench starts up and removing those the user is not allowed
to see said enough you can disable them easily as it looks like.


http://www.richclient2.eu/2006_03_20/getting-rid-of-convert-line-delimiters-to/


Tom

Camilo Arango schrieb:
Hi,

I am building an Eclipse RCP application using Acegi Security. After
login, I need to show the actions allowed to the user in the coolbar and
menus. However, I am having some trouble figuring out how to enable and
disable actions.

First, I created my action as a subclass of
org.eclipse.jface.action.Action and added to the Coolbar manually in the
Application ActionBarAdvisor. However, I was not able to figure out the
correct way of handling the enable and disable behavior.

Later, I found that I could add actions using the ActionsSet extension
point. To do so, the action must implement
org.eclipse.ui.IWorkbenchWindowActionDelegate. By doing this, I could
define a way to enable and disable actions using the "enablement" and
"visibility" elements of the action set extension point in my
plugin.xml. However, this mechanism is oriented to handle enablement
driven by user selection. The only two options which do not depend on
user selection are "pluginState" and "systemProperty". The former does
not apply to this case, and the latter seems kind of awkward for
managing authorization.
I am a little bit confused on how to do this in an elegant way.

Can anyone give me some ideas?

Thanks.