Files
HeidiSQL/extra/jheidi/mainWindowEventsMySQL.ajl

250 lines
6.6 KiB
Plaintext

import javax.swing.tree.*;
import javax.swing.*;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
String event = arg("source");
WindowContext context = argObj("windowContext");
log.debug("Event received: " + event);
if (event == "New Connection")
{
script("jheidi");
}
else if (event == "Refresh")
{
DB db = context.get("db");
Panel tab = (Panel)((Tabs)context.get("/mainTabs")).getSelectedComponent();
if ( tab.getName() != "Host" )
{
db.flushCache();
}
Worker w = worker("initTreeMySQLWorker", args(), Worker.RunOption.LET_FINISH_IF_RUNNING);
if ( !w.isCancelled())
LongRunningTask.detect("initTreeMySQLWorker", "progressWaiter", args(), w , 250);
String script = tab.getProperty("refreshScript");
HashObject scriptArgs = (HashObject)tab.getProperty("refreshArgs");
if ( script != null )
{
if ( script.endsWith("Worker") )
{
w = worker(script, scriptArgs, Worker.RunOption.LET_FINISH_IF_RUNNING);
if ( scriptArgs.get("workerKey") != null)
script = scriptArgs.get("workerKey");
if (!w.isCancelled())
LongRunningTask.detect(script, "progressWaiter", scriptArgs, w , 250);
}
else
{
script(script, scriptArgs);
}
}
}
else if (event == "Cut" || event == "Copy" || event == "Paste" )
{
Component compFocusOwner =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
if ( compFocusOwner instanceof Editor)
{
Editor editor = (Editor)compFocusOwner;
if ( event == "Cut" )
{
editor.cut();
}
else if (event == "Copy")
{
editor.copy();
}
else if (event == "Paste")
{
editor.paste();
}
}
}
else if (event == "Drop Table")
{
Tree schemaTree = context.get("/schemaTree");
NodeInfo node = schemaTree.getSelectedNode();
if ( node != null && "table".equals(node.getType()) )
{
NodeInfo dbNode = node.getParent();
Frame f = context.get("/");
if (f.popupConfirm("Confirm Delete!", "Are you sure you want to drop table '" + dbNode.getText() + "." + node.getText() + "'?", "images/deletetable.gif"))
{
args().put("tableToDrop", node.getText());
script("dropTable$mysql", args());
node.remove();
//force the tabs to refresh and the db info to reload
//schema tree events will be called by the tree itself
context.put("currentDB", null);
schemaTree.select(dbNode);
}
}
}
else if (event == "Create Database")
{
if ( script("createDBDialog", args()) != null )
{
Tree schemaTree = context.get("/schemaTree");
Worker w = worker("initTreeMySQLWorker", args(), Worker.RunOption.LET_FINISH_IF_RUNNING);
if (!w.isCancelled())
{
LongRunningTask.detect("initTreeMySQLWorker", "progressWaiter", args(), w, 250);
}
}
}
else if (event == "Create Table")
{
if ( script("createTableDialogMySQL", args()) != null )
{
Tree schemaTree = context.get("/schemaTree");
Worker w = worker("initTreeMySQLWorker", args(), Worker.RunOption.LET_FINISH_IF_RUNNING);
if (!w.isCancelled())
{
LongRunningTask.detect("initTreeMySQLWorker", "progressWaiter", args(),w, 250);
}
}
}
else if (event == "Drop Database")
{
Tree schemaTree = context.get("/schemaTree");
NodeInfo node = schemaTree.getSelectedNode();
NodeInfo root = node.getParent();
if ( node != null && "db".equals(node.getType()) )
{
Frame f = context.get("/");
if (f.popupConfirm("Confirm Delete!", "Are you sure you want to drop db '" + node.getText() + "'?", "images/deletedb.gif"))
{
args().put("dbToDrop", node.getText());
DB db = context.get("db");
db.execute("drop database `" + node.getText() + "`");
node.remove();
schemaTree.select(root);
}
}
}
else if (event == "Print")
{
//this is total shit - but it does work if you try to print something that might fit on
//the page....omg this is bad.
Table table = null;
String selectedTab = ((Tabs)context.get("/mainTabs")).selected();
if ("Host" != selectedTab && "Query" != selectedTab)
{
table = context.get("/mainTabs/"+selectedTab+"/table");
}
else if ("Host" == selectedTab)
{
String subTab = ((Tabs)context.get("/mainTabs/Host/tabs")).selected();
table = context.get("/mainTabs/Host/tabs/"+subTab+"/table");
}
else if ("Query" == selectedTab)
{
table = context.get("/mainTabs/Query/results");
}
try
{
table.print();
} catch (Exception e) {e.printStackTrace();}
}
else if (event == "Import")
{
script("importCSVDialog",args());
}
else if (event == "Export")
{
script("exportDDLDialog",args());
}
else if (event == "User Manager")
{
script ("userManagerDialog", args());
}
else if (event == "Load SQL File")
{
Frame f = context.get("/");
Tabs tabs = context.get("/mainTabs");
tabs.select("Query");
String file = f.openFile(null, "SQL Script Files", "sql");
if (file != null)
{
Editor editor = context.get("/mainTabs/Query/editor");
editor.setText(FileUtil.toString(file));
editor.setProperty("filePath", file);
}
}
else if (event == "Import CSV File")
{
script("importCSVDialog",args());
}
else if (event == "Copy as CSV Data")
{
String csv = (String)script("resultsToCSV",args());
SystemUtil.copyToClipboard(csv);
}
else if (event == "Copy as HTML Data")
{
String html = (String)script("resultsToHTML",args());
SystemUtil.copyToClipboard(html);
}
else if (event == "Copy as XML Data")
{
String xml = (String)script("resultsToXML",args());
SystemUtil.copyToClipboard(xml);
}
else if (event == "Export Data...")
{
DB.Result results = context.get("lastQueryResults");
if ( results != null && !results.isEmpty())
{
Frame f = context.get("/");
args().put("source", "exportAsFile");
f.saveFileWithCallback("mainWindowEvents", args(), false, null, "CSV", "csv", "HTML", "html", "XML", "xml" );
}
}
else if (event == "exportAsFile")
{
String output = (String)script("resultsTo" + arg("fileType"), args());
FileUtil.fromString(arg("filePath"), output);
}
else if ( event == "Export Tables as SQL" )
{
script("exportDDLDialog",args());
}
else if ( event == "Import Files Into Blob Fields" )
{
script("filesToBlobsDialog",args());
}
else if ( event == "Maintenance" )
{
script("maintenanceDialog", args());
}
else if ( event == "Help" )
{
script("helpDialog$" + context.get("vendor"), args());
}
else if ( event == "Exit" )
{
System.exit(0);
}
else if ( event == "Close" )
{
Frame window = context.get("/");
script("removeFromWindowMenu", args());
window.dispose();
}
else {
((Frame)context.get("/")).popupMessage("Feature Unimplemented!");
}