Silly Flex trick of the day

Since "only top-level components in the application can have context menus", how would one make a different ContextMenu for every type of item in a tree? In particular, I want tree leaves to have different menu items enabled than the branches; e.g., the leaves should have "Properties" menu enabled, and the "Create new" menu disabled, and vice versa for the branches. Mac Martine mentions using rollovers, which is cute, but it looks like a more robust way is to use MOUSE_OVER (yeah, I tried both).

To do this, use the following TreeItemRenderer in the tree in question (obviously, you can choose to add/remove things from the ContextMenu.customItems rather than enabling/disabling them...):

    public class ServerTreeRenderer extends TreeItemRenderer {

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        if( {
            if (TreeListData(super.listData)) {
                    leaf:Boolean = !TreeListData(super.listData).hasChildren ;
                                 function(evt:MouseEvent):void {
                                       // This will disable all items in my context menu (it's declared somewhere 
                                       // else, this is not a TreeItemRenderer method, duh...
                                       if (leaf) {
                                           // propertiesItem is a ContextMenuItem...
                                           propertiesItem.enabled = true;
                                       } else {
                                           contextMenuContainer.createNewItem.enabled = true;

All of this is in anticipation of a promised exegesis on how a custom ContextMenu works anyway (I have no time for this at the moment), but works for now...

P.S. I just like the word "exegesis". The more exegeses, the merrier...

It's Friday...

Evaluating expressions in PyDev (Eclipse plug-in for Python)

I use PyDev because, probably like many, I am used to Eclipse for Java development. What I found useful is highlighting a snippet (expression) in a debug session and doing Ctrl+Shift+D to evaluate it, and I miss this in PyDev. A crude workaround is to add this expression to Watch list, but that grows the Watch list and is not convenient: I not only have to do right-click Watch and then look in the Watch list, but also may need to scroll that list, and remove things, etc. That's not what I am used to. So I threw together a crude implementation of it.Collapse )

How to waste a weekend

I spent half of Friday tracking down a GWT problem that caused problems in both Opera and IE. By trial and error I kind of isolated it to my use of syntactic sugar (yeah, I know...) Then I spent most of Saturday trying to come up with a pithy reproducible case. Here it is (posted to, reproducing here for my own reference): Collapse )

Now, should I spend Sunday trying to actually figure this out?

(no subject)

Boo-hoo! You had me, and then you lost me!
Frank Sinatra

При чем тут голубь?

Репортаж с Первых Весенних Олимпийских Игр

Yeah, yeah, we do want to "Just say 'No' to XML". Amen. And +1 to Mr.Holub for noting that "...many so-called programmers just don’t know how to build a compiler. I really don’t have much patience for this sort of thing." But it's all downhill from there:

  • -0.1 for describing Ant as a "scripting language" (it really is declarative...)

  • -0.4 for picking on Ant, of all things, in the first place. Some people can write a compiler and still manage to subject "every one of [their] users to many hours of needless grappling with", oh, I don't know... make???

  • -0.5 for plugging his book at the end

  • -10 for doing the above with an innocent "By the way". (+10 if this "innocence" is tongue-in-cheek, Lt.Columbo-"Oh, and just one more thing"-like. But "architects, consultants and instructors in C/C++, Java and OO design" don't do this kind of subtlety.)

In all, Mr.Holub is 10 in the hole for this round...

A classic case of how a perfectly defensible thesis is ruined by the examples...