Thursday, 15 July 2010

java - How enable or disable correctly an Action -



java - How enable or disable correctly an Action -

i have little problem when seek disable action of netbeans platform project. when app starts, actions must disabled, , method:

callablesystemaction.get(buildprojectaction.class).setenabled(flag);

it works, because buildprojectaction disabled, corresponding items of menubar , toolbar remains enabled until click on 1 of it. later have clicked on it, comportament start work correctly. first question: why?

if want disable action, it's obvious want disable relative icon in menu , in toolbar, must automatic when phone call action.setenabled(false). doesn't have sense icons not refreshed if don't click on they.

same problem if seek utilize .gettoolbarpresenter().setenabled(false); , .getmenupresenter().setenabled(false);

for start application icons disabled, have tried set lazy attribute false , declare image programmatically method seticon(new imageicon(image)); sets same image menu , toolbar.

and works; there problem: menu , toolbar have icons of different size (16x16 , 24x24).

it doesn't have sense if set icon @actionregistration(iconbase = "image.png") right icon automatically selected, if utilize method .seticon(), doesn't.

i have read articles action, cookieaction, lookup, thing want disable graphic elements in same moment when disable action. sec question: how can that?

this illustration of action.

@actionid( category = "run", id = "buildprojectaction") @actionregistration( lazy = true, iconbase = "images/icons/compile.png", displayname = "#ctl_buildprojectaction") @actionreferences({ @actionreference( path = "menu/run", position = 3), @actionreference(path = "toolbars/run", position = 3), @actionreference( path = "shortcuts", name = "d-b") }) @messages("ctl_buildprojectaction=build project") public final class buildprojectaction extends callablesystemaction { @override public void actionperformed(actionevent e) {...} @override public void performaction() {} @override public string getname() { homecoming bundle.ctl_buildprojectaction(); } @override public helpctx gethelpctx() { homecoming helpctx.default_help; }

thanks

the easiest way create action disabled @ startup utilize platform’s new action wizard create action, , create 1 depends on "context" -- is, on finding specific object in global lookup. if no object available in lookup, @ startup, action disabled.

the menu , toolbar graphic elements bundled action via annotations. means enabled/disabled state of context-aware action automatically impact icons in menu , toolbar well.

this article geertjan wielenga has walkthrough on creating context-aware action:

http://netbeans.dzone.com/how-to-make-context-sensitive-actions

when want enable action, add together object on action depends global lookup, cause action (and graphic elements) enabled.

this entry in platform’s developer faq has examples of how add together object global context:

http://wiki.netbeans.org/devfaqaddglobalcontext

if need create action depends on more complex set of conditions there discussion, code sample illustrating how this, in platform developer list thread:

http://forums.netbeans.org/ptopic55295.html

the grayed-out versions of icons shown when action disabled created automatically platform. have provide "normal" non-grayed-out images.

as icons of different sizes, it’s matter of filename convention. if annotation declares icon @actionregistration(iconbase = "image.png”), provide 16x16 image called “image.png” , 24x24 version called “image24.png”. platform find , utilize appropriate size in menu , toolbar.

java action menuitem toolbar netbeans-platform

No comments:

Post a Comment