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

Getting full state of a custom attribute

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,

0 votes



3 answers

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

0 votes


Permanent link
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();

0 votes


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

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,938

Question asked: Feb 28 '11, 2:58 a.m.

Question was seen: 6,669 times

Last updated: Feb 28 '11, 2:58 a.m.

Confirmation Cancel Confirm