package com.github.fengtan.solrgui.tabs;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.github.fengtan.solrgui.tables.SolrGUITable;

public class SolrGUITabItem extends CTabItem {

	private SolrGUITable table;
	private SolrServer server; // TODO move into SolrGUITable ? so we do not store both this.server and this.url
	private String url; // TODO needed ? should be gettable from this.server
	
	public SolrGUITabItem(CTabFolder tabFolder, String url) {
		super(tabFolder, SWT.NONE, tabFolder.getItemCount());
		this.url = url;
		setText(url);
		
		// Fill in tab.
		Composite tabComposite = new Composite(getParent(), SWT.NULL);
		tabComposite.setLayout(new GridLayout());
		server = new HttpSolrServer(url);
		table = new SolrGUITable(tabComposite, server);
		setControl(tabComposite); // TODO need composite ? TODO add status line ?
		
		// Set focus on this tab.
		tabFolder.setSelection(this);
		tabFolder.forceFocus();
	}
	
	@Override
	public void dispose() {
		server.shutdown();
		super.dispose();
	}
	
	public SolrGUITable getTable() {
		return table;
	}
	
	public String getURL() {
		return url;
	}
	
}

@@ -35,16 +35,77 @@
 .tabs;%0A%0A
+import java.net.MalformedURLException;%0Aimport java.net.URL;%0A%0A
 import o
@@ -858,20 +858,36 @@
 setText(
+formatTabTitle(
 url)
+)
 ;%0A%09%09%0A%09%09/
@@ -1266,16 +1266,273 @@
 );%0A%09%7D%0A%09%0A
+%09private String formatTabTitle(String url) %7B%0A%09%09try %7B%0A%09%09%09URL u = new URL(url);%0A%09%09%09return u.getPath()+%22@%22+u.getHost()+%22:%22+u.getPort();%0A%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%09return url;%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09@Overri

Format tab title.