package com.github.fengtan.solrgui;

import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;


public class Dashboard {

	public void displayDocuments(SolrDocumentList list) {
	    Display display = new Display();
	    Shell shell = new Shell(display);
	    Table table = new Table(shell, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); // TODO
	    table.setLinesVisible(true);
	    table.setHeaderVisible(true);
	    String[] titles = { 
	    "id",
	    "index_id",
	    "item_id",
	    "hash",
	    "site",
	    "is_author",
	    "tm_body$value",
	    "spell",
	    "ds_changed",
	    "is_comment_count",
	    "ds_created",
	    "bs_promote",
	    "ss_search_api_language",
	    "bs_sticky",
	    "tm_title",
	    "ss_type",
	    "_version_",
	    "timestamp"};
	    	    
	    for (String title: titles) {
	      TableColumn column = new TableColumn(table, SWT.NONE);
	      column.setText(title);
	    }

	    for (SolrDocument document:list) {
	      TableItem item = new TableItem(table, SWT.NONE);
	      int count = 0;
	      for (Object value: document.values()) {
	    	  item.setText(count++, value.toString());
	      }
	    }
	    for (int i = 0; i < titles.length; i++) {
	      table.getColumn(i).pack();
	    }
	    table.setSize(table.computeSize(SWT.DEFAULT, 200));
	    shell.pack();
	    shell.open();
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())
	        display.sleep();
	    }
	    display.dispose();
	}
	
}

@@ -30,16 +30,90 @@
 lrgui;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 import o
@@ -754,16 +754,31 @@
     
+%09    %0A%09    List%3C
 String
-%5B%5D
+%3E
  tit
@@ -787,409 +787,341 @@
 s = 
-%7B %0A%09    %22id%22,%0A%09    %22index_id%22,%0A%09    %22item_id%22,%0A%09    %22hash%22,%0A%09    %22site%22,%0A%09    %22is_author%22,%0A%09    %22tm_body$value%22,%0A%09    %22spell%22,%0A%09    %22ds_changed%22,%0A%09    %22is_comment_count%22,%0A%09    %22ds_created%22,%0A%09    %22bs_promote%22,%0A%09    %22ss_search_api_language%22,%0A%09    %22bs_sticky%22,%0A%09    %22tm_title%22,%0A%09    %22ss_type%22,%0A%09    %22_version_%22,%0A%09    %22timestamp%22%7D;%0A%09    %09    %0A%09    for (String title: titles
+new ArrayList%3CString%3E(); // TODO hashed ? use of indexOf  %0A%09    for (SolrDocument document:list) %7B%0A%09    %09TableItem item = new TableItem(table, SWT.NONE);%0A%09    %09for (Map.Entry%3CString, Object%3E field:document.entrySet()) %7B // TODO is there a utility function to do that quikly%0A%09    %09%09if (!titles.contains(field.getKey())
 ) %7B%0A%09  
+%09%09
     
-TableColumn column = 
+  %09
 new 
@@ -1152,248 +1152,147 @@
 ONE)
-;%0A%09      column.setText(title);%0A%09    %7D%0A%0A%09    for (SolrDocument document:list) %7B%0A%09      TableItem item = new TableItem(table, SWT.NONE);%0A%09      int count = 0;%0A%09      for (Object value: document.values()) %7B%0A%09    %09  item.setText(count++, v
+.setText(field.getKey());%0A%09    %09%09%09titles.add(field.getKey());%0A%09    %09%09%7D%0A%09    %09%09item.setText(titles.indexOf(field.getKey()), field.getV
 alue
+()
 .toS
@@ -1306,16 +1306,22 @@
 );%0A%09    
+%09%7D%0A%09  
   %7D%0A%09   
@@ -1317,25 +1317,24 @@
 %09    %7D%0A%09    
-%7D
 %0A%09    for (i
@@ -1358,14 +1358,14 @@
 les.
-length
+size()
 ; i+

Make columns dynamic.