Re: mysql-workbench plugin data storage

"Michael G. Zinner" <[email protected]> Wed, 21 Jun 2006 15:18:56 +0200
Newsgroups gmane.comp.db.mysql.mycc
Organization MySQL AB
Message-ID <[email protected]>
Hi John,

John Yodsnukis wrote:
> Let's say I'm writing a plugin for workbench.  And let's say I want to 
> store
> some additional information in the data model .mwb file.  How do I do that?
> Is there an example somewhere in the existing lua code?  Thanks!

Good point. I have modified the following structs to hold plugin data in 
a "customData" member variable. The normal place to put workbench plugin 
data would now be /workbench/customData but you can choose the object to 
store your data yourself, depending of the functionality of your plugin.

These changes will be included in the next release.


You can access and use it like any other value in the Workbench. A small 
Example in the shell:

/ > data= grtV.getGlobal("/workbench/customData")

/ > data.myPluginSettings= {enabled= 1, prefix= 'test_'}

/ > print(data.myPluginSettings.enabled)
1

/ > print(data.myPluginSettings.prefix)
"test_"




The list of changes:

* structs.db.workbench.xml

   <gstruct name="db.workbench.Workbench" parent="GrtObject" 
caption="Workbench application object" desc="an object to store the 
workbench's data">
     <members>
       ...
+      <member name="customData" type="dict" desc="a generic dictionary 
to hold additional information used by e.g. plugins" />
     </members>
   </gstruct>


* structs.model.xml

   <gstruct name="model.Model" parent="GrtObject" caption="Model" 
desc="A model holding views">
     <members>
       ...
+      <member name="customData" type="dict" desc="a generic dictionary 
to hold additional information used by e.g. plugins" />
     </members>
   </gstruct>


* structs.db.xml

   <gstruct name="db.Catalog" parent="base.NamedGrtObject" 
caption="Catalog">
     <members>
       ...
+      <member name="customData" type="dict" desc="a generic dictionary 
to hold additional information used by e.g. plugins" />
     </members>
   </gstruct>


In the Workbench.lua file I have added the following line to initialize 
the dict and load it back from a stored Workbench model file.

function newDocument(args)
   ...

+  -- initialize workbench data dict
+  workbench.customData= grtV.newDict("", "")

   collectgarbage()

   return grt.success()
end

function loadDocumentData(args)
   ...

   -- set the catalog subtree to the loaded one
   wb.catalog= doc.catalog

+  -- set plugin data
+  if doc.customData ~= nil then
+    wb.customData= doc.customData
+  else
+    wb.customData= grtV.newDict("", "")
+  end

   -- set the rdbms subtree to the loaded one
   wb.rdbms= doc.rdbms

Mike
-- 
Michael Zinner, GUI Developer
MySQL AB, www.mysql.com
Office: +43 676 753 26 30

Are you MySQL certified?  www.mysql.com/certification

-- 
MySQL GUI Tools Mailing List
For list archives: http://lists.mysql.com/gui-tools
To unsubscribe:    http://lists.mysql.com/[email protected]