Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Getting Work Item Icons

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?

0 votes



One answer

Permanent link
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

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941

Question asked: Oct 20 '09, 2:53 p.m.

Question was seen: 4,624 times

Last updated: Oct 20 '09, 2:53 p.m.

Confirmation Cancel Confirm