package org.reldb.relui.tools;

import java.util.HashMap;

import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.reldb.relui.tools.TabPanel;

public class ModeTab extends TabPanel {

	private Control displayed = null;
	private HashMap<String, ModeTabContent> modes = new HashMap<String, ModeTabContent>();
	private static int modeNumber = 0;
	
	public void addMode(Image iconImage, String toolTipText, ModeTabContent content) {
		String modeName = String.valueOf(modeNumber++);
		addMode(iconImage, toolTipText, modeName);
		modes.put(modeName, content);
	}
	
	public int countModes() {
		return modes.size();
	}
	
	public void clearModes() {
		super.clearModes();
		for (ModeTabContent content: modes.values())
			content.dispose();
		modes.clear();
	}
	
	public ModeTab(CTabFolder parent, int style) {
		super(parent, style);
	}
	
	public void buildLocationPanel(TopPanel parent) {}
	
	public String getStatus() {return "";}
	
	@Override
	public void notifyModeChange(String modeName) {
		ToolBar toolBar = getToolBar();
		
		for (ToolItem item: toolBar.getItems())
			item.dispose();

		ModeTabContent content = modes.get(modeName);
		displayed = content.getContent(getContentParent());
		setContent(displayed);

		content.getToolBarItems(toolBar);
		
		toolBar.pack();
	}

}

@@ -817,16 +817,34 @@
 odes();%0A
+%09%09clearToolBar();%0A
 %09%09for (M
@@ -882,16 +882,16 @@
 lues())%0A
-
 %09%09%09conte
@@ -996,24 +996,176 @@
 , style);%0A%09%7D
+%0A%0A%09private ToolBar clearToolBar() %7B%0A%09%09ToolBar toolBar = getToolBar();%0A%09%09for (ToolItem item: toolBar.getItems())%0A%09%09%09item.dispose();%09%0A%09%09return toolBar;%0A%09%7D
 %0A%09%0A%09public v
@@ -1335,82 +1335,20 @@
 r = 
-getToolBar();%0A%09%09%0A%09%09for (ToolItem item: toolBar.getItems())%0A%09%09%09item.dispose
+clearToolBar
 ();%0A

Fix toolbar visibility when failing to load a database.