Code Giveaway - Would it not be great to have an output console for Java AND LotusScript Agents?

Like many others I have worked my way thru Print and Msgbox statements in LotusScript Agents when debugging.

Why do that when we have a LS debugger?

Because it is a horrible arcane debugger. So many times it is just easier to do Print and Msgbox.
In Java agents you can at least open up a standard Java console and do a Println to it.
Still if you want to use the console to present information when running agents in the users Notes client, the Java debug console would have to be opened first

So a couple of years ago I thought I would create my own Console library.

Nothing fancy, I just wanted it to be:
- simple
- useful
- and work for both LotusScript and Java

Otherwise I knew I would not be using it.

So I came up with SimpleConsole.
It is a really simple no-nonsense console for both LotusScript and Java and it works down to at least version 6.5.

This is how you would use it:


The very simple version:

SimpleConsole console = new SimpleConsole();

console.addText("It is working!");

That is it! :-)

Add a different icon and a title:

Session session = getSession();

AgentContext agentContext = session.getAgentContext();
SimpleConsole console = new SimpleConsole();
String notesdata = session.getEnvironmentString("directory", true);
console.setConsoleIcon("file:///" + notesdata + "/domino/icons/actn151.gif");
for (int i = 0; i < 100; i++) {
Thread.currentThread().sleep(0, 0100);
console.addText("test" + i);

The icon can come from an URL as well:

If you want the console to close just add:



It is almost as easy to use it in LotusScript

You just use LS2J to call the java class

Option Public

Option Declare

UseLSX "*javacon"

Use "SimpleConsole"
Sub Initialize

Dim jSession As JavaSession
Dim SimpleConsole As JavaClass
Dim console As JavaObject
Dim jObj2 As JavaObject
Dim jMethod As JavaMethod
Dim jError As JavaError
Dim counter As Long

On Error GoTo errorHandler

Set jSession = New JavaSession()

Set SimpleConsole = jSession.GetClass("SimpleConsole")
Set console = SimpleConsole.CreateObject
console.setConsoleTitle("SimpleConsole...a simple console For LS too!")

For counter=1 To 1000
console.addText("test " + CStr(counter))

Call console.exitConsole()

Exit Sub

Set jError = jSession.getLastJavaError()

MessageBox jError.StackTrace,, Error

Exit Sub

End Sub


Lotus Notes (not talking about Eclipse) doesn't play well with Java Swing, anyone who has ever done any Swing GUI has had the experience that the Java GUI "disappears".
Or rather it is not moved to the front when created, but stays behind the Notes client, and nobody knows it is there.
Trial and error has helped me to fix this and the SimpleConsole should move to the front, when run from the Notes Client, ....but might not not when the agent is run from the Designer.
You will have to click on the icon on the taskbar to bring it to the front


I use SimpleConsole mainly in Agents, but you can of course use it anywhere you use Java or LS.
There is no Notes specifics in the library so you can use it in any other Java project too.
All I ask is to keep the reference to me and my company in the code :-)

SimpleConsole Demo Database

Posted on 01/05/2010 10:52:00 AM CET