Category: GUITools

MySQL Workbench Plugins

MySQL Workbench supports scripting and writing plugins to extend its functionality. Currently you can write them in the Lua language, although support for Python and others will be added.

Contents

[edit] Plugin Installation

[edit] Writing Plugins

Workbench plugins are implemented as GRT modules that follow certain conventions. They are implemented as a file (a .lua file, .py file, .class file etc depending on the language you write it in) that must contain at least 3 functions:

Plugin skeleton

[edit] Plugin Function

Plugin functions take one argument, which is a list of objects the plugin should act upon. Workbench passes the list of objects currently selected, but if there's no selection, all objects in the current view are given to the plugin. The objects in the list are figure objects, not database objects. For accessing the associated database objects, access the appropriate field (eg: tableFigure.table.columns). See the #Workbench Object Structure section for more information about what objects the Workbench uses to internally represent models.

[edit] Plugin Registration

To get the list of available plugins the Workbench checks all available modules at startup time that extend the PluginInfo interface.

The registration function getPluginInfo() must provide the following meta-information:

This information is stored in an object of type base.Plugin. A list of these objects (one for each plugin function) has to be returned by getPluginInfo().

See the section for each language for an example of how this function should look like.

[edit] Lua Plugins

Visit the quick Lua intro if you're not familiar with the language.

[edit] Registration

In a Lua module, the getModuleInfo() function would look like this.

function getModuleInfo()
  local moduleInfo= {
    name= "MyPlugins", 
    functions= {
      "getPluginInfo::",
      "myPlugin::"
    }, 
    extends= "PluginInfo"
  }
  return moduleInfo
end

For registering a Plugin, you must implement something like this:

function getPluginInfo(args)
  -- create list
  local pluginList= grtV.newList("dict", "base.Plugin")
  local plugin

  -- create a new base.Plugin object and set its values
  -- to provide information about the plugin and add it to the list
  plugin= grtV.newObj("base.Plugin", "myPlugin", 
    "plugin://com.mysql.grt.base.Plugin.myPlugin", "")
  plugin.caption= _("My New Plugin")
  plugin.description= _("A table plugin that changes the figure color " ..
    "if the table has a foreign key")
  plugin.groupPath= "Table/Utilites"
  plugin.moduleName= "myPlugins"
  plugin.moduleFunctionName= "myPluginSetTableColorOnFk"
  plugin.categories= {"database", "table", "foreign key"}
  plugin.objectStructNames= {"db.workbench.TableElement"}
  plugin.singleArgument= 1
  grtV.insert(pluginList, plugin)


  -- repeated for each plugin
  plugin= grtV.newObj("base.Plugin", ...
  grtV.insert(pluginList, plugin)
  ...

  -- return the list of plugin information
  return grt.success(pluginList)
end

After creating the object and setting the caption and description of the plugin the groupPath is set. It specifies where the plugin will appear in the Plugin Menus. Further, the moduleName and moduleFunctionName are set to where the actual implementation is located. The categories property holds a list of keywords that are used in e.g. search for plugins.

To define the object types the plugin can work with the objectStructNames list is set. For a plugin that can operate on tables and views this would be set to {"db.workbench.TableElement", "db.workbench.View"}.


[edit] Python Plugins

[edit] Workbench Object Structure

The best way to explore Workbench objects is from the Workbench GRT shell. Press F4 to bring it up. The main textview can be used to issue Lua (or Python) commands while the sidebar will display the application object tree, list of structures and list of modules available. For writing plugins, the object tree and list of structures are of interest.

[edit] Application Object Tree

The following is a description of the main nodes in the object tree:


[edit] Object Types

There are basically two types of relevant objects in Workbench for working with in plugins, figure objects and database objects. Figure objects are 1:1 related to graphic elements you place and manipulate on your model. Database objects are how information about database schema objects are represented internally.

Here is a partial list of standard figure object types supported in MySQL Workbench:

Retrieved from "http://forge.mysql.com/wiki/MySQL_Workbench_Plugins"

This page has been accessed 21,306 times. This page was last modified 23:05, 19 January 2008.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...