/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package de.naoth.rc.logmanager;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.xeoh.plugins.base.annotations.PluginImplementation;

/**
 *
 * @author thomas
 */
@PluginImplementation
public class LogFileEventManagerImpl implements LogFileEventManager {
    private final List<LogFrameListener> listeners = new ArrayList<>();
    private final BlackBoardImpl blackBoard = new BlackBoardImpl();
    
    private final ReadWriteLock lock = new ReentrantReadWriteLock();
    
    @Override
    public void addListener(LogFrameListener l) {
      lock.writeLock().lock();
      try
      {
        listeners.add(l);
      }
      finally
      {
        lock.writeLock().unlock();
      }
    }
    @Override
    public void removeListener(LogFrameListener l) {
      lock.writeLock().lock();
      try
      {
        listeners.remove(l);
      }
      finally
      {
        lock.writeLock().unlock();
      }
    }
    
    @Override
    public void fireLogFrameEvent(Collection<LogDataFrame> c) {
        
        if(c != null) {
            for(LogDataFrame f: c) {
                blackBoard.add(f);
            }
        }
        
        lock.readLock().lock();
        try
        {
          for(LogFrameListener l: listeners) {
              l.newFrame(blackBoard);
          }
        }
        finally
        {
          lock.readLock().unlock();
        }
    }
}

@@ -395,24 +395,59 @@
 dWriteLock;%0A
+import javax.swing.SwingUtilities;%0A
 import net.x
@@ -1333,16 +1333,22 @@
 meEvent(
+final 
 Collecti
@@ -1371,28 +1371,383 @@
  c) %7B%0A      
+%0A
   
-%0A
  
+   if(SwingUtilities.isEventDispatchThread()) %7B%0A        internalFire(c);%0A      %7D%0A      else %7B%0A        SwingUtilities.invokeLater(new Runnable()%0A        %7B%0A%0A          @Override%0A          public void run()%0A          %7B%0A            internalFire(c);%0A          %7D%0A        %7D);%0A      %7D%0A       %0A    %7D%0A    %0A    private void internalFire(Collection%3CLogDataFrame%3E c) %7B%0A
        if(c 

make sure logframe events are executed in the swing event dispatch thread