package org.reldb.relui.dbui;

import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.ResourceManager;
import org.reldb.relui.tools.ModeTab;
import org.reldb.relui.tools.ModeTabContent;
import org.reldb.relui.tools.TopPanel;

public class DbTab extends ModeTab {
	
	private LocationPanel locationPanel;
	
	public void addMode(String iconImageFilename, String toolTipText, ModeTabContent content) {
		addMode(ResourceManager.getPluginImage("RelUI", "icons/" + iconImageFilename), toolTipText, content);
	}
	
	public DbTab() {
		super(DbMain.getMainPanel().getTabFolder(), SWT.None);
		
		setImage(ResourceManager.getPluginImage("RelUI", "icons/plusIcon.png"));
		setToolTipText("New tab");
	}
	
	public void setText(String s) {
		super.setText(s);
		if (countModes() == 0) {
			setImage(ResourceManager.getPluginImage("RelUI", "icons/DatabaseIcon.png"));
			setToolTipText(s);
			addMode("ModeRelIcon.png", "Rel", new DbTabContentRel());
			addMode("ModeRevIcon.png", "Rev", new DbTabContentRev());
			addMode("ModeCmdIcon.png", "Command line", new DbTabContentCmd());
			setMode(0);
		}
	}
	
	public void buildLocationPanel(TopPanel parent) {
		locationPanel = new LocationPanel(parent, SWT.None) {
			@Override
			public void notifyDatabaseURIModified() {
				System.out.println("DbTab: new URI");
			}
		};
	}

	public void newDatabase(String string) {
		setMode(0);
		locationPanel.setDatabaseURI("db://file:" + string);
		System.out.println("DbTab: attempt to create database at " + locationPanel.getDatabaseURI());
	}

	public void openLocalDatabase(String string) {
		setMode(0);
		locationPanel.setDatabaseURI("db://file:" + string);
		System.out.println("DbTab: attempt to open database at " + locationPanel.getDatabaseURI());
	}

	public void openRemoteDatabase(String string) {
		setMode(0);
		locationPanel.setDatabaseURI(string);
		System.out.println("DbTab: attempt to open database at " + locationPanel.getDatabaseURI());		
	}

}

@@ -1081,16 +1081,500 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09public void openDatabaseAtURI(String uri, boolean canCreate) %7B%0A%09%09System.out.println(%22DbTab: attempt to open database at %22 + locationPanel.getDatabaseURI() + %22 with create==%22 + canCreate);%0A%09%09if (countModes() == 0)%0A%09%09%09new DbTab();%0A%09%09setText(uri);%0A%09%09setShowClose(true);%0A%09%7D%0A%0A%09private void createDatabaseAtLocation() %7B%0A%09%09openDatabaseAtURI(locationPanel.getDatabaseURI(), true);%0A%09%7D%0A%09%0A%09private void openDatabaseAtLocation() %7B%0A%09%09openDatabaseAtURI(locationPanel.getDatabaseURI(), false);%0A%09%7D
 %0A%09%0A%09publ
@@ -1741,43 +1741,31 @@
 %09%09%09%09
-System.out.println(%22DbTab: new URI%22
+openDatabaseAtLocation(
 );%0A%09
@@ -1894,99 +1894,33 @@
 ;%0A%09%09
-System.out.println(%22DbTab: attempt to 
 create
- d
+D
 atabase
- at %22 + locationPanel.getDatabaseURI()
+AtLocation(
 );%0A%09
@@ -2045,97 +2045,31 @@
 ;%0A%09%09
-System.out.println(%22DbTab: attempt to 
 open
- d
+D
 atabase
- at %22 + locationPanel.getDatabaseURI()
+AtLocation(
 );%0A%09
@@ -2180,101 +2180,33 @@
 ;%0A%09%09
-System.out.println(%22DbTab: attempt to 
 open
- d
+D
 atabase
- at %22 + locationPanel.getDatabaseURI());%09%09
+AtLocation();
 %0A%09%7D%0A

Work on RelUI