• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

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.

 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()

Open in new window


I don't want to add the listener everything a object is added to the array.  How would I only add the listener once?
0
jkteater
Asked:
jkteater
  • 5
  • 4
1 Solution
 
jkteaterAuthor Commented:
Maybe the  question should be how to do check and see if the listener is already running.

Something like

If (Listener value == nul ) {
tcRevision.getSession().addAIFComponentEventListener(this);
}

not sure how to get the listener value
0
 
CEHJCommented:
Not really sure why you'd be adding it there but the following sort of thing should do it if there's only one listener
if(tcRevision.getSession().getAIFComponentEventListener() != null) {
   // Add it
}

Open in new window

If there's a List<Listener> in some way, then you would have to search it for 'this'
0
 
jkteaterAuthor Commented:
where would you add the listener?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CEHJCommented:
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 ;)
0
 
jkteaterAuthor Commented:
I basically just created a boolean to check

if(!addedListener){
         tcRevision.getSession().addAIFComponentEventListener(this);
         addedListener = true;
      }

Open in new window


Seems to work
0
 
CEHJCommented:
So only one listener is possible?
0
 
jkteaterAuthor Commented:
Yes
0
 
CEHJCommented:
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
0
 
CEHJCommented:
:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now