DZone Forums
Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
Reload this Page Contributing ToggleState menu items or ViewFilter(Action) contributions.. (3.3)
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Mar 2008
Default Contributing ToggleState menu items or ViewFilter(Action) contributions.. (3.3) - 07-01-2008, 03:41 AM

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. toggleGlobalVariables"
description="%showGlobalVarsCommand.name"
name="%showGlobalVarsCommand.description" />
</extension>

then the menu:

<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="menurg.eclipse.debug.ui.VariableVie w">
<menu
label="%variablesViewMenu.name"
id="org.eclipse.dltk.javascript.debug.ui.menu.Vari ableView" />
</menuContribution>
<menuContribution locationURI="menurg.eclipse.dltk.javascript.debu g.ui.menu.VariableView">
<command
commandId="org.eclipse.dltk.javascript.debug.ui.co mmands.toggleGlobalVariables"
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.co mmands.toggleGlobalVariables"
class="org.eclipse.dltk.javascript.internal.debug. ui.handlers.ToggleGlobalVariablesHandler" />
</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.consol e.ui.actions.ShowFunctionsAction"
helpContextId="show_functions_context"
icon="icons/javascript.gif"
id="org.eclipse.jdt.debug.ui.variableViewActions.S howFunctionsAction"
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get paid for contributing in open source projects othmanelmoulat Open Source 0 09-24-2008 01:03 AM
how to disable an action on some other action sandeepp Eclipse 0 08-28-2008 06:29 AM
Problem with deleting Items from the Context Menu of my RCP App. alwin74 Eclipse 0 07-30-2008 08:09 AM
How can i add action to Popup menu of Project Explorer? rajeshgubba Eclipse 0 06-22-2008 10:55 PM
Plugin menu items arthur_dent.42 Eclipse 1 03-27-2008 04:14 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com