It's all about the answers!

Ask a question

Getting Work Item Icons


Andy Meneely (26132) | asked Oct 20 '09, 2:53 p.m.
I've been working on a plugin for the Jazz 2.0 client and I wanted to show the icon associated with a work item (based on its type). Based on some of the other posts in this forum, I put together this piece of code to put a work item into a Table inside of a UIJob:


@Override

public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkItemClient workItemClient = (IWorkItemClient) repository
.getClientLibrary(IWorkItemClient.class);
try {
//Query for the type
IWorkItemType type = workItemClient.findWorkItemType(workItem
.getProjectArea(), workItem.getWorkItemType(), monitor);

//Obtain the actual image from its URL - this line seems to be the slow one
Image image = new Image(PlatformUI.getWorkbench().getDisplay(),
type.getIconURL().openStream());

//Put the image in the first column of the table.
tableItem.setImage(new Image[]{image});
} catch (TeamRepositoryException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return Status.OK_STATUS;
}



However, this code tends to be pretty slow. It's making a call to the server every time it needs this icon. So as a workaround for the performance hit, I'm caching the icons in a global hash table after that first call - doesn't seem like a good permanent solution, though.

I'm wondering, is there a faster way to get icons? Maybe a global icon registry on the client or something?

One answer



permanent link
Patrick Streule (4.9k21) | answered Oct 21 '09, 3:45 a.m.
JAZZ DEVELOPER
However, this code tends to be pretty slow. It's making a call to the
server every time it needs this icon. So as a workaround for the
performance hit, I'm caching the icons in a global hash table after
that first call - doesn't seem like a good permanent solution,
though.

I'm wondering, is there a faster way to get icons? Maybe a global icon
registry on the client or something?

Your code doesn't seem to go to the server on every call as there is some
caching involved on lower levels. But you are right that creating the
image every time is not efficient.

This is what we use in our code:

resourceManager= new LocalResourceManager(JFaceResources.getResources(),
table);
....
imageDescriptor= WorkItemUI.getImageDescriptor(type.getIconURL());
image= JazzResources.getImageWithDefault(resourceManager, imageDescriptor)

Images will be managed by the resource manager, which takes care of
reuse/dispose. You could attach it to your table, so all image resources
will be disposed when the table is disposed.

--
Regards,
Patrick
Jazz Work Item Team

Your answer


Register or to post your answer.