jkteater
asked on
adding a event listener only once
I am adding a event listener to the singlteton class. But I am only wanting to add the listener one time. Right now I have it in a add method.
I don't want to add the listener everything a object is added to the array. How would I only add the listener once?
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
String revMasterForm;
*** tcRevision.getSession().addAIFComponentEventListener(this); ***
try {
revMasterForm = tcRevision.getRelatedComponent("IMAN_master_form_rev").getUid();
RevDataset pp = new RevDataset(tcRevision, selectedDataset, revMasterForm);
if (!rds.contains(pp)) {
rds.add(pp);
}
}
catch (TCException e) {
e.printStackTrace();
}
fireTableDataChanged();
}// end add()
I don't want to add the listener everything a object is added to the array. How would I only add the listener once?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
where would you add the listener?
Ah well, that's just a guess based on instinct ;) Not knowing your setup, i couldn't begin to say. You should probably ignore that comment of mine ;)
ASKER
I basically just created a boolean to check
Seems to work
if(!addedListener){
tcRevision.getSession().addAIFComponentEventListener(this);
addedListener = true;
}
Seems to work
So only one listener is possible?
ASKER
Yes
Well if it can contain only one listener, then a boolean will suffice. However, that listener should be accessible to clients via a standard accessor method along the lines of getListener(). For that reason, no extra flag is necessary. In fact, an extra flag is error-prone as well as redundant. All you need is something like i posted in my last code illustration
:)
ASKER
Something like
If (Listener value == nul ) {
tcRevision.getSession().ad
}
not sure how to get the listener value