package com.github.fengtan.solrgui.viewers;

import java.util.Objects;

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

import com.github.fengtan.solrgui.beans.SolrGUIDocument;
import com.github.fengtan.solrgui.beans.SolrGUIServer;

public class SolrGUILabelProvider extends LabelProvider implements ITableLabelProvider {

	private String[] fields;
	
	public SolrGUILabelProvider(SolrGUIServer server) {
		this.fields = server.getFields();
	}
	
	/**
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
	public String getColumnText(Object element, int columnIndex) {
		SolrGUIDocument document = (SolrGUIDocument) element;
		switch (columnIndex) {
			case 0: // Change status.
				// TODO tooltips A/D/M
				switch(document.getChange()) {
					case ADDED:
						return "A";
					case DELETED:
						return "D";
					case NONE:
						return "";
					case UPDATED:
						return "M";
				}
			default: // Solr fields.
				int fieldIndex = columnIndex-1;
				if (fieldIndex < fields.length) {
					String field = fields[fieldIndex];
					return Objects.toString(document.getFieldValue(field), "");	
				} else {
					return "";
				}
		}
	}
	
	/**
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
	 */
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

}
@@ -61,24 +61,73 @@
 l.Objects;%0A%0A
+import org.eclipse.jface.viewers.IColorProvider;%0A
 import org.e
@@ -243,22 +243,129 @@
 swt.
-graphics.Image
+SWT;%0Aimport org.eclipse.swt.graphics.Color;%0Aimport org.eclipse.swt.graphics.Image;%0Aimport org.eclipse.swt.widgets.Display
 ;%0A%0Ai
@@ -562,19 +562,305 @@
 Provider
- %7B%0A
+, IColorProvider %7B%0A%0A%09private static final Color GREEN = Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);%0A%09private static final Color RED = Display.getCurrent().getSystemColor(SWT.COLOR_RED);%0A%09private static final Color YELLOW = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);%0A%09
 %0A%09privat
@@ -979,108 +979,17 @@
 %0A%09%0A%09
-/**%0A%09 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)%0A%09 */
+@Override
 %0A%09pu
@@ -1626,170 +1626,440 @@
 %0A%09%0A%09
-/**%0A%09 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)%0A%09 */%0A%09public Image getColumnImage(Object element, int columnIndex
+@Override%0A%09public Image getColumnImage(Object element, int columnIndex) %7B%0A%09%09return null;%0A%09%7D%0A%0A%09@Override%0A%09public Color getBackground(Object element) %7B%0A%09%09SolrGUIDocument document = (SolrGUIDocument) element;%0A%09%09switch (document.getChange()) %7B%0A%09%09%09case ADDED:%0A%09%09%09%09return GREEN;%0A%09%09%09case DELETED:%0A%09%09%09%09return RED;%0A%09%09%09case UPDATED:%0A%09%09%09%09return YELLOW;%0A%09%09%09default:%0A%09%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public Color getForeground(Object element
 ) %7B%0A

Add color provider.