Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Contributing ToggleState menu items or ViewFilter(Action) contributions.. (using eclipse 3.3)
Contributing ToggleState menu items or ViewFilter(Action) contributions.. (using eclipse 3.3) [message #329668] Tue, 01 July 2008 08:38 Go to next message
Johan Compagner is currently offline Johan CompagnerFriend
Messages: 148
Registered: July 2009
Senior Member
Hi

in the DLTK project (javascript part) we have for example a Toggle Action contribution:

first the command:

<extension point="org.eclipse.ui.commands">
<command
id=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
description="%showGlobalVarsCommand.name"
name="%showGlobalVarsCommand.description" />
</extension>

then the menu:

<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menu:org.eclipse.debug.ui.VariableView">
<menu
label="%variablesViewMenu.name"
id="org.eclipse.dltk.javascript.debug.ui.menu.VariableView" />
</menuContribution>
<menuContribution locationURI="menu:org.eclipse.dltk.javascript.debug.ui.menu.VariableView ">
<command
commandId=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
tooltip="%showGlobalVarsCommand.tooltip"
style="toggle" />
</menuContribution>
</extension>

and the handler of that command:

<extension point="org.eclipse.ui.handlers">
<handler
commandId=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
class=" org.eclipse.dltk.javascript.internal.debug.ui.handlers.Toggl eGlobalVariablesHandler " />
</extension>


Biggest problem here is that it is a toggle menu item. That has state that we use internally to show some variables in the variable view or not.

But the menu doesnt reflect that state (its always off) because at the time the VariableView is created de Debug plugin of DLTK isnt loaded yet and
this code:

PluginAction.
protected boolean isOkToCreateDelegate() {
if (getStyle() == IAction.AS_DROP_DOWN_MENU
&& !WWinPluginPulldown.class.isInstance(this)) {
return true;
}

// test if the plugin has loaded
String bundleId = configElement.getNamespace();
return BundleUtility.isActive(bundleId);
}

return false so the real delegate is not created.
I tried everything using ToggleState using AbstractHandlerWithState nothing seems to work
Also when i use 1 of those 2 and it would work. Where is then the state stored? How do i get that selected state? (because it is stored in my own
preference)

Strange thing about that togglestate is that also that isnt created when started up. No it is created when closing down? Huh? Then i see
an instance created and the persistent value is read in.

I personally find that isOkToCreateDelegate() a bit weird. It is just a matter of luck.. Is the plugin activated befor that call then it works
If it isnt? GUI is not reflecting the right state and it very confusing for the user.

I did see this getStyle() == IAction.AS_DROP_DOWN_MENU in the code so i though aha.. i can make my own menu which is a drop down menu
and fill in the menu items my self then!. So i created a menu but in the plugin.xml DROP_DOWN_MENU isnt an option. No that is set by implementing
IMenuCreator. 1 problem my class does implement it but that class isnt loaded and checked if it does so the first time i open the variable view menu
i see my item as a normal item (not as a drop down menu item). If i click on it then suddenly stuff changes and it becomes i think eventually a drop down.
I could fake this. But just setting the DROP_DOWN value in the plugin.xml by hand. Then everything starts to work perfectly but the plugin.xml
constantly reports an error :(

Now all this is not that something really doesnt work, the only thing is that the gui doesnt reflect the state and that it is very confusing for users
because they see something not checked. So the click on it. But it was checked so now it is really not checked but the users thinks that it checked it
so it has to look at it again to really see what the state is..

But the bigger problem is that we also have another one thats: ShowFunctionsAction that class is a ViewFilter and an Action
JDT also has that class called ViewFilterAction for example a ShowStaticVariablesAction is one that works like that.

Now my plugin has the same thing. Just like ShowStaticVariablesAction. The problem is that ShowStaticVariablesAction is in the jdt Debug plugin
itself so the above isOkToCreateDelegate() just returns true all the time. But for my action this is not the case. So my filter isnt applied
to the VariablesView at all no matter what my preferences (selected or not) says.. That filter is only applied when i really click on my menu item
This is the plugin.xml part:

<extension point="org.eclipse.ui.viewActions">
<viewContribution
targetID="org.eclipse.debug.ui.VariableView"
id="org.eclipse.jdt.debug.ui.VariableViewActions">
<action
class=" org.eclipse.dltk.javascript.internal.console.ui.actions.Show FunctionsAction "
helpContextId="show_functions_context"
icon="icons/javascript.gif"
id=" org.eclipse.jdt.debug.ui.variableViewActions.ShowFunctionsAc tion "
label="%showFunctionsAction.label"
menubarPath="org.eclipse.dltk.javascript.debug.ui.menu.VariableView/js "
style="toggle"
tooltip="%showFunctionsAction.tooltip">
</action>
</viewContribution>
</extension>

So how can i force that my filter is applied?? Is there another extention that will force my Viewfilter on the variable view no matter what?
Or should i just start to hack and try to find the view in a plugin of mine and then try to add the filter through that?

I still think that eclipse tries to be to lazy. For this ShowFunctionsActions that is a ViewFilter my class/plugin must be loaded.
It should be possible to force eclipse to do that.
I am already very close to just hack the eclipse plugin so that PluginAction does this:

PluginAction.
protected boolean isOkToCreateDelegate() {
if ( (getStyle() == IAction.AS_DROP_DOWN_MENU || getStyle() == IAction.AS_CHECK_BOX)
&& !WWinPluginPulldown.class.isInstance(this)) {
return true;
}

// test if the plugin has loaded
String bundleId = configElement.getNamespace();
return BundleUtility.isActive(bundleId);
}

so that when it is a checkbox == toggle state the delegate will be created. Because i really want that i want my gui to reflect the right state
i want my ViewFilter to be applied instantly

johan
Re: Contributing ToggleState menu items or ViewFilter(Action) contributions.. (using eclipse 3.3) [message #330253 is a reply to message #329668] Wed, 23 July 2008 08:02 Go to previous message
Michael Szediwy is currently offline Michael SzediwyFriend
Messages: 23
Registered: July 2009
Junior Member
Hi,

I don't know whether this solves your problem, but have you tried to let
your handler implement the IElementUpdater interface?

Cheers

Michi


Johan Compagner wrote:
> Hi
>
> in the DLTK project (javascript part) we have for example a Toggle
> Action contribution:
>
> first the command:
>
> <extension point="org.eclipse.ui.commands">
> <command
>
> id=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
> description="%showGlobalVarsCommand.name"
> name="%showGlobalVarsCommand.description" />
> </extension>
>
> then the menu:
>
> <extension point="org.eclipse.ui.menus">
> <menuContribution locationURI="menu:org.eclipse.debug.ui.VariableView">
> <menu
> label="%variablesViewMenu.name"
> id="org.eclipse.dltk.javascript.debug.ui.menu.VariableView" />
> </menuContribution>
> <menuContribution
> locationURI="menu:org.eclipse.dltk.javascript.debug.ui.menu.VariableView ">
> <command
>
> commandId=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
>
> tooltip="%showGlobalVarsCommand.tooltip"
> style="toggle" />
> </menuContribution>
> </extension>
>
> and the handler of that command:
>
> <extension point="org.eclipse.ui.handlers">
> <handler
>
> commandId=" org.eclipse.dltk.javascript.debug.ui.commands.toggleGlobalVa riables "
>
>
> class=" org.eclipse.dltk.javascript.internal.debug.ui.handlers.Toggl eGlobalVariablesHandler "
> />
> </extension>
>
>
> Biggest problem here is that it is a toggle menu item. That has state
> that we use internally to show some variables in the variable view or not.
>
> But the menu doesnt reflect that state (its always off) because at the
> time the VariableView is created de Debug plugin of DLTK isnt loaded yet
> and this code:
>
> PluginAction.
> protected boolean isOkToCreateDelegate() {
> if (getStyle() == IAction.AS_DROP_DOWN_MENU
> && !WWinPluginPulldown.class.isInstance(this)) {
> return true;
> }
>
> // test if the plugin has loaded
> String bundleId = configElement.getNamespace();
> return BundleUtility.isActive(bundleId);
> }
>
> return false so the real delegate is not created.
> I tried everything using ToggleState using AbstractHandlerWithState
> nothing seems to work
> Also when i use 1 of those 2 and it would work. Where is then the state
> stored? How do i get that selected state? (because it is stored in my
> own preference)
>
> Strange thing about that togglestate is that also that isnt created when
> started up. No it is created when closing down? Huh? Then i see
> an instance created and the persistent value is read in.
>
> I personally find that isOkToCreateDelegate() a bit weird. It is just a
> matter of luck.. Is the plugin activated befor that call then it works
> If it isnt? GUI is not reflecting the right state and it very confusing
> for the user.
>
> I did see this getStyle() == IAction.AS_DROP_DOWN_MENU in the code so i
> though aha.. i can make my own menu which is a drop down menu
> and fill in the menu items my self then!. So i created a menu but in the
> plugin.xml DROP_DOWN_MENU isnt an option. No that is set by implementing
> IMenuCreator. 1 problem my class does implement it but that class isnt
> loaded and checked if it does so the first time i open the variable view
> menu
> i see my item as a normal item (not as a drop down menu item). If i
> click on it then suddenly stuff changes and it becomes i think
> eventually a drop down.
> I could fake this. But just setting the DROP_DOWN value in the
> plugin.xml by hand. Then everything starts to work perfectly but the
> plugin.xml constantly reports an error :(
>
> Now all this is not that something really doesnt work, the only thing is
> that the gui doesnt reflect the state and that it is very confusing for
> users
> because they see something not checked. So the click on it. But it was
> checked so now it is really not checked but the users thinks that it
> checked it so it has to look at it again to really see what the state is..
>
> But the bigger problem is that we also have another one thats:
> ShowFunctionsAction that class is a ViewFilter and an Action
> JDT also has that class called ViewFilterAction for example a
> ShowStaticVariablesAction is one that works like that.
>
> Now my plugin has the same thing. Just like ShowStaticVariablesAction.
> The problem is that ShowStaticVariablesAction is in the jdt Debug plugin
> itself so the above isOkToCreateDelegate() just returns true all the
> time. But for my action this is not the case. So my filter isnt applied
> to the VariablesView at all no matter what my preferences (selected or
> not) says.. That filter is only applied when i really click on my menu item
> This is the plugin.xml part:
>
> <extension point="org.eclipse.ui.viewActions">
> <viewContribution
> targetID="org.eclipse.debug.ui.VariableView"
> id="org.eclipse.jdt.debug.ui.VariableViewActions">
> <action
>
> class=" org.eclipse.dltk.javascript.internal.console.ui.actions.Show FunctionsAction "
>
> helpContextId="show_functions_context"
> icon="icons/javascript.gif"
>
> id=" org.eclipse.jdt.debug.ui.variableViewActions.ShowFunctionsAc tion "
> label="%showFunctionsAction.label"
>
> menubarPath="org.eclipse.dltk.javascript.debug.ui.menu.VariableView/js "
> style="toggle"
> tooltip="%showFunctionsAction.tooltip">
> </action>
> </viewContribution>
> </extension>
>
> So how can i force that my filter is applied?? Is there another
> extention that will force my Viewfilter on the variable view no matter
> what?
> Or should i just start to hack and try to find the view in a plugin of
> mine and then try to add the filter through that?
>
> I still think that eclipse tries to be to lazy. For this
> ShowFunctionsActions that is a ViewFilter my class/plugin must be loaded.
> It should be possible to force eclipse to do that.
> I am already very close to just hack the eclipse plugin so that
> PluginAction does this:
>
> PluginAction.
> protected boolean isOkToCreateDelegate() {
> if ( (getStyle() == IAction.AS_DROP_DOWN_MENU || getStyle() ==
> IAction.AS_CHECK_BOX)
> && !WWinPluginPulldown.class.isInstance(this)) {
> return true;
> }
>
> // test if the plugin has loaded
> String bundleId = configElement.getNamespace();
> return BundleUtility.isActive(bundleId);
> }
>
> so that when it is a checkbox == toggle state the delegate will be
> created. Because i really want that i want my gui to reflect the right
> state
> i want my ViewFilter to be applied instantly
>
> johan
Previous Topic:Plugins with different versions, one as project, one as jar
Next Topic:accessing preferences of another plugin
Goto Forum:
  


Current Time: Sat Nov 09 03:35:22 GMT 2024

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

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

Back to the top