It's all about the answers!

Ask a question

How do I add a WorkItemListener to WorkItemEditor?


Petcharat Viriyakattiyaporn (4113) | asked Jul 06 '08, 12:09 a.m.
Hi,

What is the right way to add an IWorkItemListener to a WorkItem that is currently opened in a WorkItemEditor? I have tried to cach the currently opened WorkItemEditor and do the following:

currentEditor = (WorkItemEditor) part;
IEditorInput input = currentEditor.getEditorInput();
if (input instanceof WorkItemEditorInput) {
WorkItemWorkingCopy workingCopy= ((WorkItemEditorInput) input).getWorkingCopy();
WorkItemUIWorkingCopy uiCopy= (WorkItemUIWorkingCopy) workingCopy.getAdapter(IWorkItemUIWorkingCopy.class);
uiCopy.getUIWorkItemListener().addListener(this);
}

However, this causes some strange behaviors. After I make changes to the WorkItem, the '*' sign doesn't appear on the editor tab as before and I can't directly save the changes. Only when I try to close the editor tab that there is a popup saying that there is another editor still opened and asking me if I want to save the changes.

Can anyone help me out on this, please?

Thanks,
Petcharat

2 answers



permanent link
Christof Marti (681) | answered Jul 07 '08, 11:45 a.m.
Hi Petcharat,

WorkItemEditorInput.getWorkingCopy() could cause some unexpected behavior if called before the input was fully resolved (you could check that with WorkItemEditorInput.isResolved()). Depending on what you want to do you could also register a listener with IWorkItemWorkingCopyManager.addWorkItemListener(...) which would then be notified independently of the kind of editor used to change the work item.

HTH,

Christof
Jazz Work Item team


petcharatv wrote:
Hi,

What is the right way to add an IWorkItemListener to a WorkItem that
is currently opened in a WorkItemEditor? I have tried to cach the
currently opened WorkItemEditor and do the following:

currentEditor = (WorkItemEditor) part;
IEditorInput input = currentEditor.getEditorInput();
if (input instanceof WorkItemEditorInput) {
WorkItemWorkingCopy workingCopy= ((WorkItemEditorInput)
input).getWorkingCopy();
WorkItemUIWorkingCopy uiCopy= (WorkItemUIWorkingCopy)
workingCopy.getAdapter(IWorkItemUIWorkingCopy.class);
uiCopy.getUIWorkItemListener().addListener(this);
}

However, this causes some strange behaviors. After I make changes to
the WorkItem, the '*' sign doesn't appear on the editor tab as before
and I can't directly save the changes. Only when I try to close the
editor tab that there is a popup saying that there is another editor
still opened and asking me if I want to save the changes.

Can anyone help me out on this, please?

Thanks,
Petcharat

permanent link
Petcharat Viriyakattiyaporn (4113) | answered Jul 07 '08, 3:18 p.m.
Thanks, Christof. I used IWorkItemWorkingCopyManager#addWorkItemListener(..) and things work properly now. :)

Your answer


Register or 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.