package com.github.fengtan.solrgui;
import java.util.Arrays;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.swt.widgets.TableItem;

public class SolrGUICellModifier implements ICellModifier {
	private SolrGUI solrGUI;
	
	public SolrGUICellModifier(SolrGUI solrGUI) {
		super();
		this.solrGUI = solrGUI;
	}

	/**
	 * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
	 * 
	 * All Solr fields can be modified. The others cannot.
	 */
	public boolean canModify(Object element, String columnName) {
		return Arrays.asList(solrGUI.getServer().getFields()).contains(columnName);
	}

	/**
	 * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
	 */
	public Object getValue(Object element, String columnName) {
		SolrGUIDocument document = (SolrGUIDocument) element;
		return document.getFieldValue(columnName).toString();	
	}

	/**
	 * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
	 */
	public void modify(Object element, String columnName, Object value) {
		TableItem item = (TableItem) element;
		SolrGUIDocument document = (SolrGUIDocument) item.getData();
		document.setField(columnName, value.toString());
		solrGUI.getServer().documentChanged(document);
		// TODO do not mark as Modified if new value = old value
	}
}
@@ -53,16 +53,42 @@
 .Arrays;
+%0Aimport java.util.Objects;
 %0A%0Aimport
@@ -889,16 +889,33 @@
 %09return 
+Objects.toString(
 document
@@ -944,21 +944,14 @@
 ame)
-.toString(
+, %22%22
 );
-%09
 %0A%09%7D%0A

Fix NullPointException.