It's all about the answers!

Ask a question

Getting full state of a custom attribute


Baris Erdemir (1812819) | asked Feb 28 '11, 2:58 a.m.
Hi,

I am extending com.ibm.team.workitem.ide.ui.internal.editor.presentations.AttributePart

Everything is fine when I am working on the attribute part I extend.

But now, I'd like to write to another existing custom attribute. In creation I can get Item handle of the custom attribute but after saving and reopenning the work item, I cannot get full state.

Here is the part that I am getting full state of the custom attribute successfully:

@Override

public void setInput(Object input) {
if (input instanceof WorkItemEditorInput && ((WorkItemEditorInput) input).isResolved() && getAttribute() != null) {
WorkItemEditorInput workItemEditorInput = ( WorkItemEditorInput) input;
fWorkingCopy = workItemEditorInput.getWorkingCopy();
List<IAttributeHandle> customAttributeHandleList = fWorkingCopy.getWorkItem().getCustomAttributes();
for (IAttributeHandle attrHandle : customAttributeHandleList) {
IItemHandle itemHandle = attrHandle.getFullState();


This code works in creation. But when I save and re-open the workitem, itemhandle is null. Can you please tell me a way to get item handle after saving the workitem?

Thanks,

3 answers



permanent link
Patrick Streule (4.9k21) | answered Mar 02 '11, 12:01 p.m.
JAZZ DEVELOPER
Hi,

I am extending com.ibm.team.workitem.ide.ui.internal.editor.presentations.AttributePart

Everything is fine when I am working on the attribute part I extend.

But now, I'd like to write to another existing custom attribute. In creation I can get Item handle of the custom attribute but after saving and reopenning the work item, I cannot get full state.

Here is the part that I am getting full state of the custom attribute successfully:

@Override

public void setInput(Object input) {
if (input instanceof WorkItemEditorInput && ((WorkItemEditorInput) input).isResolved() && getAttribute() != null) {
WorkItemEditorInput workItemEditorInput = ( WorkItemEditorInput) input;
fWorkingCopy = workItemEditorInput.getWorkingCopy();
List<IAttributeHandle> customAttributeHandleList = fWorkingCopy.getWorkItem().getCustomAttributes();
for (IAttributeHandle attrHandle : customAttributeHandleList) {
IItemHandle itemHandle = attrHandle.getFullState();


This code works in creation. But when I save and re-open the workitem, itemhandle is null. Can you please tell me a way to get item handle after saving the workitem?

Thanks,


The problem is this line:

IItemHandle itemHandle = attrHandle.getFullState();


There are two problems here:

a) If you want the full state of the item, getFullState() only works if the handle is actually an item already (items inherit from item handles). Never rely on this unless you are absolutely sure that you have a resolved item already.

You have to resolve the item handle either using the ItemManager or our IAuditableClient library:

IAuditableClient auditableClient= (IAuditableClient) getTeamRepository().getClientLibrary(IAuditableClient.class);

IAttribute attribute= auditableClient.resolveAuditable(attrHandle, IAttribute.SMALL_PROFILE, monitor);


b) If you need only an IItemHandle, as your assignment suggests, a simple assignment would be enough (IAttributeHandle inherits from IItemHandle)

permanent link
Baris Erdemir (1812819) | answered Mar 03 '11, 10:08 a.m.
Hi Patrick,
Thanks for your answer, I need some more clearifications in both a and b.
In a) you provided a code:

IAuditableClient auditableClient= (IAuditableClient) getTeamRepository().getClientLibrary(IAuditableClient.class);

IAttribute attribute= auditableClient.resolveAuditable(attrHandle, IAttribute.SMALL_PROFILE, monitor);

here, since I am extending com.ibm.team.workitem.ide.ui.internal.editor.presentations.AttributePart;
I do not have getTeamRepository() method. whose method is this?
And can you define attrHandle and monitor?

In b) I replaced IItemHandle with IAttributeHandle and I am still having null itemhandle:

//IItemHandle itemHandle = attrHandle.getFullState();
IAttributeHandle itemHandle = (IAttributeHandle)attrHandle.getFullState();


to be more spesific: here is what I do when I get the itemhandle:

if( itemHandle != null){

String identifier = null;
if(itemHandle instanceof AttributeImpl){
identifier = ((AttributeImpl)itemHandle).getIdentifier();
if( identifier.equals("java_deploy_request.exception_insertion_scripts")){
IItemHandle itemHandle2 = fWorkingCopy.getWorkItem().getFullState();
WorkItemImpl item = (WorkItemImpl)itemHandle2;
Identifier<IState> state = item.getState2();

permanent link
Andre Weinand (4811) | answered Mar 15 '11, 1:20 p.m.
Hi,

IAuditableClient has a getClientLibrary() method.

The monitor is a org.eclipse.core.runtime.ProgressMonitor. Please read the Java doc. There are lots of examples in the RTC source code. The monitor is necessary because resolveAuditable is a long running operation that talks to a server.

You can find the attrHandle for a custom attribute with a given ID through
IAttribute IWorkItemCommon.findAttribute(..., String identifier, ...).
A IWorkItemCommon can be obtained through the getClientLibrary() method.

hth,
--andre


Andre Weinand
Work Item Team

Your answer


Register or to post your answer.