Bugzilla

Does anyone have anything to say about whether upgrading Bugzilla 2.x to the latest version is a major pain in the ass or totally worth it? We’re still using that “dinosaur” version at work, and I’m sure we’re missing out on all kinds of improvements and cool features and usability improvements, but the question remains, is it worth the headaches of upgrading?

JList that can be selected by keyboard entry

The default behavior of a JList is that when you use the keyboard to press the first character of a list item, the selection will jump to the first item starting with that letter. Additional presses of the same letter will cycle through all the items starting with the same letter.

For a small list, this functionality works great. For a larger list with hundreds of items however, you may not want to press a single key thirty times to get to the item you are looking for.

So I did a little research about how to make the list work more like windows, where if you type quickly, it will navigate to the item in the list that starts with the prefix selected. So you could type the first few characters of the item to jump much closer to or exactly on the item you are trying to reach.

It turns out this is not difficult but it requires a bit of boilerplate code. My example code here is a modified version of some example code released under the GNU license.

One of the keys to making this work is you need to define how long between key-presses should the system interpret the new keypress as a starting a new search vs. adding additional characters to the original search. CHAR_DELTA in this example code defines how long the system will wait between keypresses before presuming you’re starting a new search, here we are saying you have to type at least one key per second (1000ms) to add additional letters to your search. m_key is needed to track what key sequence has been typed so far, and m_time tracks the time of the last key-press in order to identify whether the threshold of time has elapsed to make this a new search.

     //elsewhere: jList1 = new javax.swing.JList();

    private static int CHAR_DELTA = 1000; 
    private String m_key; 
    private long m_time;

    private void keyPressHandler(java.awt.event.KeyEvent evt) {
        char ch = evt.getKeyChar();

        //ignore searches for non alpha-numeric characters
        if (!Character.isLetterOrDigit(ch)) {
            return;
        }

        // reset string if too much time has elapsed
        if (m_time+CHAR_DELTA < System.currentTimeMillis()) {
            m_key = "";
        }

        m_time = System.currentTimeMillis();
        m_key += Character.toLowerCase(ch);

        // Iterate through items in the list until a matching prefix is found.
        // This technique is fine for small lists, however, doing a linear
        // search over a very large list with additional string manipulation
        // (eg: toLowerCase) within the tight loop would be quite slow.
        // In that case, pre-processing the case-conversions, and storing the
        // strings in a more search-efficient data structure such as a Trie
        // or a Ternary Search Tree would lead to much faster find.
        for (int i=0; i < jList1.getModel().getSize(); i++) {
            String str = ((String)jList1.getModel().getElementAt(i)).toLowerCase();
            if (str.startsWith(m_key)) {
                jList1.setSelectedIndex(i);     //change selected item in list
                jList1.ensureIndexIsVisible(i); //change listbox scroll-position
                break;
            }

        }
    }

Hallelujah moment

I’m sure it will be short-lived rejoicing, and most of the people reading this have not a clue what any of this means, but I got my IE plugin to run on the “normal user” using “Run as administrator” in Vista rather than having to log into the special “Administrator” account. What does that mean? Likely that I can stop switching back and forth between two logins on Vista and just stay as the normal user.

You know what gets me though? The whole time it turns out the problem was apparently the plugin was disabled using the IE plugins manager (some time ago by me), and Netbeans isn’t quite smart enough to detect that the plugin is disabled and tell you you’re trying to do something stupid that you shouldn’t expect to work.

HTTP Monitor

You know what’s fun about writing an HTTP monitor? Testing it basically requires surfing the internet. (c’mon that’s got to be a major plus, right?)

You know what’s not as fun? Creating an infinite loop in your internet explorer plugin that causes your system to go completely erratic and unstable without completely crashing. I ended up with three task-managers one of which was completely erratic and not actually showing correct performance. Needless to say, reboot was quite necessary at that point.

I’m actually making quite a bit of progress. Earlier this week with Q.’s help I figured out why my faked headers weren’t showing up in Netbeans (apparently there was one more spot the feature had to be enabled for IE). And since then I’ve been working on getting real headers into Netbeans rather than fake ones, and that basically means writing code to parse strings in C++. Parsing strings in C++ is not fun, its not nearly as easy as in Java. And its a lot more difficult to do in a non-MFC project where you can’t use CString, it requires going back to the <string.h> library functions, except there’s a bunch of quirks like the function that would seem obvious to use doesn’t really do what you need so you have to do it a different way. But every time I get a new header to show up in Netbeans correctly its great fun, and for some reason IE doesn’t put all the headers in one place so I’ve been getting them added in little chunks and it just looks closer and closer to working properly, at least for the general case with no bad data or anything.

A Breakthrough

Do you have any idea what this means?

It means I am 9/10 of the way there on finding a solution to my impossible problem 🙂

And here yesterday I left the office feeling frustrated, in over my head, like I was trying to solve an impossible problem, and there was no way I was going to figure this out on my own.

Today, I spent pretty much all day looking at Igor’s PassThruApp sample code, trying to get his example to build and then deciding that was sufficient for solving my problem without the “kitchen sink” thrown in, and only a handful of files to deal with, and tried to mangle that code into my code…and finally end of the day today I’m displaying pop-ups with the HTTP request and responses, now I just need to send the IDE those values instead of displaying them on testing pop-ups and do a bunch of renaming and other clean up.

Netbeans HTTP Monitor

I’m working on a somewhat difficult (as in hard to solve) problem at work. We want to add Internet Explorer to the HTTP monitor in Netbeans.

Netbeans is an “IDE” or “editor” for writing computer programs or web applications. The HTTP monitor feature shows you all the HTTP headers (not to be confused with HTML headers) that the broswer sends to websites you visit and the sites send back to your browser, before it sends the actual webpage. The headers include things like whether or not the page you’re trying to view really exists, whether it hasn’t changed since the last time you viewed it (so your browser can load it faster by using its cache) and what website you came to that website from and a bunch of other stuff…most normal people wouldn’t care about what’s in the HTTP headers, but if you’re a web-developer trying to debug a complex web-application, it could be helpful diagnostic information. Right now our HTTP monitor only supports Firefox. But now I’m working on trying to add that same feature for IE.

So basically…for me, that means, I have to figure out how to get the HTTP headers out of IE. That’s the hard part. We already have a “C++ COM DLL” that intercepts page requests to do javascript debugging, but this new part you have to go a bit deeper into the browser communication and get down to the level where IE sends HTTP requests, several layers down in the browser architecture slide.

I’ve been doing a lot of internet searching. And most of that searching has gone nowhere. Other than a few people have written expensive closed source programs that monitor IE’s HTTP headers, so theoretically *what* we want to do should be possible, but not a lot of help on the *how*. And being a closed source browser, its not as easy to “hack into” as firefox. Even just doing javascript debugging, where firefox requires some javascript, IE requires a DLL written in C++ with lots of COM calls (and if you don’t know what that means, just think…its hard to read and understand ugly stuff to code).

But finally, today I’ve come across something slightly promising, a full demo-app on CodeProject.com that includes HTTP monitoring as well as the kitchen sink of other unrelated features I don’t need. The important part for me is it includes the full source code including their “C++ COM DLL” (notice how this is the same type of DLL we have? ;-)) that intercepts the requests the browser sends and acts as a pass through, mangled in with some code to be a download helper app stuff I don’t need.

On the upside this is promising because if I could understand this code, I could probably figure out exactly what I need to do to to add my new feature to our app. But the downside is that even with a several page long article on CodeProject about that app, they actually don’t document almost anything about the part I’m interested in. And the source code is extremely cryptic because it uses all these obsure programming constructs/libraries/something? like ATL that I barely know what the acronym means, and I certainly haven’t read the 500 page book on it that my coworker left me…

Its kind of like a puzzle where I’m trying to crack this code of deciphering cryptic pages on MSDN like “How to get Protocol Headers in a Pluggable Protocol Handler” which might be a little more obvious if I were a Microsoft Programming Guru (course, if I were, I’d probably be working for Microsoft or as a consultant selling my knowledge about these cryptic technologies at an obscene hourly rate…one of the other reasons those who “understand this stuff” don’t just post lots of articles all over the internet about how to do what I want to do…) so that I can figure out how this stuff works to mangle it into something different…while not recycling any code that is not appropriately licensed to be reused in an open source app (eg: big no no to recycle GPL code because GPL license requires the resulting product to also be released as GPL, which is a different license than the one we’re using) according to the legal department 😉

Transfer of Responsibility

I’m not sure if I mentioned this on the blog before or not..but toward the end of last week, I found out I’d be taking over the project of one of the guys on our team who’s going on a long vacation starting Friday…

He wrote the internet explorer javascript debugger plugin for Netbeans, (a C++ COM project in Visual Studio)…that’s the part I’m going to be taking over.

And then it turns out, he’s not actually just going on vacation, he’s not coming back after his vacation either…so double the fun, “make sure to ask him lots of questions before he leaves” my boss says.

Its a lot to jump into, code-wise, a bunch of stuff I’ve never even looked at before, and such a short time to learn it and sometimes its difficult to even know where to start with questions, or what would be the most fruitful things to discuss or study in the couple days left before he leaves, especially with the double learning curve of not having the background on the Netbeans side of the script debugger either. Time to cross my fingers and pray all goes well…

Java’s GregorianCalendar

Who would have thought up a calendar where the month starts at 0-11 but the days of the month run 1-31 (or so)? Its nice having full featured calendar utilities…but they could be slightly more intuitive to use, or at least consistent.

My new favorite SVN command: blame

Aside from having an interesting name, it’s actually pretty useful… tells you who last edited (or created) each line of code (and when) in the file. So if you’re wondering where this [holds my mouth] code came from, there’s an easy way to tell.

Dumb Java Generics Error Message of the Day

Type mismatch: cannot convert from List<SignPage> to List<SignPage>

And why not might I ask?