package ru.taximaxim.pgsqlblocks.dbcdata;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

public class DbcDataListLabelProvider implements ITableLabelProvider {

    private List<ILabelProviderListener> listeners;

    private ConcurrentMap<String, Image> imagesMap = new ConcurrentHashMap<String, Image>();

    /**
     * Constructs a FileTreeLabelProvider
     */
    public DbcDataListLabelProvider() {
        listeners = new ArrayList<ILabelProviderListener>();
    }

    @Override
    public void addListener(ILabelProviderListener listener) {
        listeners.add(listener);
    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub
    }

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void removeListener(ILabelProviderListener listener) {
        // TODO Auto-generated method stub
    }

    @Override
    public Image getColumnImage(Object element, int columnIndex) {
        DbcData dbcData = (DbcData) element;
        switch (columnIndex) {
        case 0: return getImage(dbcData.getStatus().getImageAddr());
        }
        return null;
    }

    @Override
    public String getColumnText(Object element, int columnIndex) {
        DbcData dbcData = (DbcData) element;
        switch (columnIndex) {
        case 0: return (dbcData.hasBlockedProcess() ? "* " : "") + dbcData.getName(); // TODO: need to remake, after create new icons
        }
        return null;
    }

    private Image getImage(String path) {
        Image image = imagesMap.get(path);
        if (image == null) {
            image = new Image(null, getClass().getClassLoader().getResourceAsStream(path));
            imagesMap.put(path, image);
        }
        return image;
    }
}
@@ -1330,32 +1330,44 @@
 %0A        case 0:
+%0A           
  return getImage
@@ -1408,34 +1408,44 @@
 ));%0A        
-%7D%0A
+default:%0A   
         
 return null;
@@ -1424,32 +1424,33 @@
 ult:%0A           
+ 
 return null;%0A   
@@ -1438,32 +1438,42 @@
    return null;%0A
+        %7D%0A
     %7D%0A%0A    @Over
@@ -1635,16 +1635,28 @@
  case 0:
+%0A           
  return 
@@ -1770,34 +1770,44 @@
 ons%0A        
-%7D%0A
+default:%0A   
         
 return null;
@@ -1786,32 +1786,33 @@
 ult:%0A           
+ 
 return null;%0A   
@@ -1804,24 +1804,34 @@
 eturn null;%0A
+        %7D%0A
     %7D%0A%0A    p

fix sonar issues