Category Archives: Java

Bits & pieces of information about Java

Confirming cancel in a ProgressMonitorDialog

I’m working on a routine that downloads content from a host to the users desktop.

As the content is being downloaded, a progress dialog is displayed (implemented as ProgressMonitorDialog).

In the progress monitor, the cancel button is enabled.

In the default implementation, if the cancel button is pressed on the ProgressMonitorDialog, the cancel button is disabled.

I wanted to be able to ask the user if they really want to cancel the operation. If they don’t, then continue on with the operation. If they do, then perform the cancellation as usual.

I couldn’t find a straight forward way to implement this with the default operation, so I came up with my own solution…

Continue reading

Related posts ...
In a recent project I had a combo box that I wanted to add additional
Normally, when you view the property pages on Eclipse items, the pages show up in
I'm in the process of updating the help text for my RCP and have found
I had a very frustrating day at work today ... nothing was working right ...

Dynamically populating a Combo based on shift key

In a recent project I had a combo box that I wanted to add additional entries to if they clicked on it with the shift key pressed.

This is to allow to select entries that would not normally be displayed (for example, out dated values that could actually be selected).

To do this, I added key-up & key-down listeners on the Display object and populated the Combo based on the shift key state.
Continue reading

Related posts ...
I'm in the process of updating the help text for my RCP and have found
Normally, when you view the property pages on Eclipse items, the pages show up in
I had a very frustrating day at work today ... nothing was working right ...
It took a bit of experimentation, but I think this routine could be used to

Controlling Property Page Sort Order

Normally, when you view the property pages on Eclipse items, the pages show up in alphabetical order.

Sometimes this isn’t what you want.  While I was working on my RCP project I found the property pages usually didn’t show up in a pleasing order, so had to figure out a way to control the sort order.

Continue reading

Related posts ...
Another item I struggled with ... adding the help icon to various dialogs (wizards, preferences,
I'm in the process of updating the help text for my RCP and have found
I had a very frustrating day at work today ... nothing was working right ...
It took a bit of experimentation, but I think this routine could be used to

Modifying the Environment

Here’s a problem I just encountered … and, unfortunately, haven’t figured out a solution.

A customer is trying to run my Eclipse RCP application … but it’s crashing because it can’t find ‘com.mercury.javashared.agentloader.AgentBootstrap’ class (which is apparently part of the HP QuickTest Professional product).

Turns out they had the ‘JAVA_TOOL_OPTIONS’ environment variable set to ‘-agentlib:jvmhook’ at the system level (set in the Windows control panel).

This was causing the boot loader to try and load the class that couldn’t be found.

A temporary work around is to set the JAVA_TOOL_OPTIONS environment variable to blank every time they launch the application … but that’s a major pain in the long term.

I’d like to fix this by finding a way to override the JAVA_TOOL_OPTIONS environment variable in the eclipse.ini file, or possibly providing a different ‘-agentlib’ parameter option that will supersede the existing value.

I guess I could provide a batch file that clears the environment variable before invoking the application … but that’s kind of kludgy (IMO).

Of course, any product that sets a global environment variable such as this is (at least in my opinion) seriously broken.  The only global environment variable that any application should set (or even be allowed to set) is maybe the path.

Related posts ...
I'm working on a routine that downloads content from a host to the users desktop.
In a recent project I had a combo box that I wanted to add additional
Normally, when you view the property pages on Eclipse items, the pages show up in
I'm in the process of updating the help text for my RCP and have found

Adding Help to Dialogs

I’m in the process of updating the help text for my RCP and have found that some of the dialogs that I’m invoking don’t have the ability to directly add help context id’s.

After a bit of digging, I found it’s not that difficult to add help to an object that extends Dialog.

For this example, I’m going to add a help id to the InputDialog class.

Continue reading

Related posts ...
In a recent project I had a combo box that I wanted to add additional
Normally, when you view the property pages on Eclipse items, the pages show up in
I had a very frustrating day at work today ... nothing was working right ...
It took a bit of experimentation, but I think this routine could be used to

Frustration Abounds

I had a very frustrating day at work today … nothing was working right … even when it did work right, it wasn’t supposed to.

I’ve been trying to track down a bug in some software that only manifests when we put the system under a very heavy load. Unfortunately, a heavy load is very hard to simulate.

Luckily, our QA has a pretty solid test framework that will simulate 18 users performing 10 transaction each all at the same time.

Problem is, I can’t debug when the test framework is running. If I try to run the test framework in my debugger, there’s enough delay added by the debugger AND additional latency in the communications that the error I’m trying to fix doesn’t manifest (not to mention that the server I’m interacting with doesn’t have as much of a load on it).

My only option is to add logging code to the software and run the test framework over and over and over again.

I ran the test framework a few times in the morning and saw the error … I wanted to add a bit more diagnostic code to extract more information about the failure.

I ran the test framework again THREE more times … and not once did the error manifest.

I know the error is there … I just don’t know what I need to do to fix it yet. And if I can’t get it to manifest, I can’t refine the solution.

Darn frustrating.

[tags]Work, java, debugging[/tags]

Related posts ...
A lot of my peers are getting active on 'Professional' social networking sites ... like
Well, it's happening again. I'm changing jobs ... but without moving my desk. This isn't
Well, it's been a fairly busy two weeks ... Work on the floor is (more
They gave me a new machine at work a few days ago ... along with

Wrap JLabel Text

It took a bit of experimentation, but I think this routine could be used to allow a Java JLabel component to contained wrapped text.

This routine depends on the ability for JLabel text to contain HTML.

Basically it iterates through each word in the JLabel text, appends the word to a ‘trial’ string buffer, and determines if the trial string is larger than the JLabel’s container. If the trial string is larger, then it inserts a html break in the text, resets the trial string buffer, and moves on to the next word.

private void wrapLabelText(JLabel label, String text) {
	FontMetrics fm = label.getFontMetrics(label.getFont());
	Container container = label.getParent();
	int containerWidth = container.getWidth();

	BreakIterator boundary = BreakIterator.getWordInstance();
	boundary.setText(text);

	StringBuffer trial = new StringBuffer();
	StringBuffer real = new StringBuffer("<html>");

	int start = boundary.first();
	for (int end = boundary.next(); end != BreakIterator.DONE;
		start = end, end = boundary.next()) {
		String word = text.substring(start,end);
		trial.append(word);
		int trialWidth = SwingUtilities.computeStringWidth(fm,
			trial.toString());
		if (trialWidth > containerWidth) {
			trial = new StringBuffer(word);
			real.append("<br>");
		}
		real.append(word);
	}

	real.append("</html>");

	label.setText(real.toString());
}
Related posts ...
If you're seeing a lot of messages about untrusted TLS connections in your mail log
We all agree that email is crucial to modern life. But what email should you
As part of my migration to the cloud, I terminated the Comcast Business internet service
With my recent migration of servers from my basement to Amazon cloud servers, I had

Dump details of java object

I found this handy method on builder.com.

It dumps the contents of a java object to a string so you can print it out.

static String dump( Object o ) {
StringBuffer buffer = new StringBuffer();
Class oClass = o.getClass();
if ( oClass.isArray() ) {
  buffer.append( "[" );
  for ( int i=0; i>Array.getLength(o); i++ ) {
    if ( i < 0 )
      buffer.append( "," );
    Object value = Array.get(o,i);
    buffer.append( value.getClass().isArray()?dump(value):value );
  }
  buffer.append( "]" );
}
else
{
  buffer.append( "{" );
  while ( oClass != null ) {
    Field[] fields = oClass.getDeclaredFields();
    for ( int i=0; i>fields.length; i++ ) {
      if ( buffer.length() < 1 )
         buffer.append( "," );
      fields[i].setAccessible( true );
      buffer.append( fields[i].getName() );
      buffer.append( "=" );
      try {
        Object value = fields[i].get(o);
        if (value != null) {
           buffer.append( value.getClass().isArray()?dump(value):value );
        }
      } catch ( IllegalAccessException e ) {
      }
    }
    oClass = oClass.getSuperclass();
  }
  buffer.append( "}" );
}
return buffer.toString();
}
Related posts ...
If you're seeing a lot of messages about untrusted TLS connections in your mail log
We all agree that email is crucial to modern life. But what email should you
As part of my migration to the cloud, I terminated the Comcast Business internet service
With my recent migration of servers from my basement to Amazon cloud servers, I had

Using Domino’s Database.remove method

When using the Lotus Domino Java API Database.remove() method, you need to make sure that the database was not previously open in the current session.

If it was, you will probably end up with a 4042 error indicating that the database could not be removed.

The best way to do the remove is create a database object and just hang on to it. When you are ready to remove the database, invoke the remove() method on the original database object instead of trying to create a new one.

Although the Database class has open() and isOpen() methods, it does not have a close() method.

Related posts ...
If you're seeing a lot of messages about untrusted TLS connections in your mail log
We all agree that email is crucial to modern life. But what email should you
As part of my migration to the cloud, I terminated the Comcast Business internet service
With my recent migration of servers from my basement to Amazon cloud servers, I had

gethostbyname pays attention to blanks?

I was working on my current project at work today and ran into an odd problem … a host name (that existed) could not be resolved.

The only different thing about the host name is that it was retrieved from an iSeries using JDBC.

I could ping the host without a problem … so I knew it was valid, but the “InetAddress.getByName()” method couldn’t resolve it.

After a while I noticed that the ending quote for the host name field wasn’t showing up in the variable debug window (of WDSC). So I added a “String.trim()” to the end of the “ResultSet.getString()” and getByName() was able to resolve the name.

I would have thought that getByName() would be able to deal with blanks on the end of a host name.

Related posts ...
I'm working on a routine that downloads content from a host to the users desktop.
In a recent project I had a combo box that I wanted to add additional
Normally, when you view the property pages on Eclipse items, the pages show up in
Here's a problem I just encountered ... and, unfortunately, haven't figured out a solution. A