Tuesday, June 17, 2008

[Harmless Hacks] Accessing Smart Client's Progress Bar


Servoy client's main application frame is comprised of the usual sorts of Swing components. Some of those swing components are accessible through scripting - via the solution object model (and/or the plugin API) - while others are not. For example the status text (JLabel) in the "statusbar" - the one that usually displays "Ready" - is accessible through scripting while the progress bar (JProgressBar) in the very same "statusbar" is not.

Awhile back I had posted a feature request asking for access to the main application frame's progress bar through the plugin API. Some time has gone by since that feature request so I started to look at how to gain access on my own; I had a particular need. Turns out there isn't much to it.

In the code below we are traversing through the layers of components that comprise the servoy client frame. When we get to the JProgressBar component, we set its "indeterminate" property to true - illustrating how to access it.

We could also script other properties of the JProgressBar and even create loops that update the meter for a particular purpose, but there are other examples out there that show you how to work with progress bars and the purpose of this post is really to show you how to gain access to the progress bar, not how to use it. If you read between the lines here a little I think you will realize that a lot more of the Servoy UI is scriptable then you realize.


// This code compatible with Servoy 4 only (b/c of the use of JavaImporter)
function accessSmartClientsProgressBar()
{
var SwingGui = new JavaImporter(java.awt);

with (SwingGui)
{
var parentframe = new Frame.getFrames();
}

var contentpane = parentframe[0].getContentPane();
var components = contentpane.getComponents();
var subcomponents = components[0].getComponents();
var statusbarcomponents = subcomponents[1].getComponents();

statusbarcomponents[7].indeterminate = true;
}

COMPATIBILITY: This code was tested in Servoy 4 RC1. It will most likely work in earlier 4 builds too. It could also be modified slightly to work in 3.x and maybe even 2.x.

IMPORTANT: Please be advised that you should always backup your Servoy solution before implementing or attempting any of the techniques described in this blog. None of the techniques described are guaranteed to work in any way shape or form, or for any specific purpose. Use them entirely at your own risk.

0 comments:

Post a Comment