|
From: Eric B. <el...@gm...> - 2006-11-30 15:55:05
|
> Here's the code for a macro I want to run. How can I modify it to run
> "creation.sql" (which is open), instead of the current view?
>
> I have two or three SQL scripts to run and I want to automate it.
>
> sql.SqlTextPublisher.publishBuffer(
> view, sql.SqlUtils.getSelectedServerName(sql.SqlUtils.getProject(view))
> );
The SQL plugin's "Publish Buffer" functionality is dependent on the
current buffer. So all you need to do is bring that buffer to the
front before calling the method.
Here's 2 ways of doing what you want, though seems like a lot of work
if the file is already open in jEdit. Why not just go to the file and
click the "Execute Buffer" button in the SQL plugin tool bar?
First way - I recommend this way because if the sql plugin code
changes but the action name does not, then your macro will still work.
[code]
String sqlFilePath = "/some/path/to/creation.sql";
jEdit.openFile(view, sqlFilePath);
EditPlugin sqlPlugin = jEdit.getPlugin("sql.SqlPlugin", true);
PluginJAR sqlPluginJar = sqlPlugin.getPluginJAR();
ActionSet sqlPluginActionSet = sqlPluginJar.getActionSet();
sqlPluginActionSet.getAction("sql.publishBuffer").invoke(view);
[/code]
Second way - Shorter, but is dependent on the sql plugin code to
publish a buffer.
[code]
String sqlFilePath = "/some/path/to/creation.sql";
jEdit.openFile(view, sqlFilePath);
sql.SqlTextPublisher.publishBuffer(
view, sql.SqlUtils.getSelectedServerName(sql.SqlUtils.getProject(view))
);
[/code]
Hope this helps,
Eric
--
Learn from the past. Live in the present. Plan for the future.
|