Menu

My first (Hello World) plug-in

2013-03-08
2014-08-28
  • André Olivera

    André Olivera - 2013-03-08

    Hi!

    I am just starting to learn about UnBBayes and I am trying to get in touch with the system to be able to extend it in the future.

    My first step was done. (set up the environment, check out the project from SVN, compile and execute).

    Now I am thinking in create a simple plugin as a start point. Unfortunately the page https://sourceforge.net/apps/mediawiki/unbbayes/index.php?title=My_first_plug-in
    is under construction.

    So, what should be my first steps to extend the UnBBayes tool? For example, I want to add a button that create a new window with a "Hello World message".

    I think I am able to change the source code to do this, but I guess that the right way to do that is create a plugin isn't?

    I read the architecture of the tool, but since I am beginner on Java/JPF/Eclipse/Maven etc.. I don't know what exactly to do.

    I suppose I need to create a new project on eclipse (what kind of project? what structure?) and try to connect in some way with the UnBBayes.

    Thanks,

    André.

     
  • Heitor VIeira

    Heitor VIeira - 2013-03-13

    Hi!!

    I have the same problem. I don't know how to start a new plugin. If you, Andre Oliveira, or anyone knows the first steps i would be grateful.

    Thanks,

    Heitor.

     

    Last edit: Heitor VIeira 2013-03-13
  • Rommel Novaes Carvalho

    Hello everyone!

    I have not found the time to actually create a Hello World plugin to share with you, so I decided to point you to some examples in order to help you out.

    So, the first plugin you should check out is the ProbabilisticNodePluginStub. This is just a stub that shows how to implement a new plugin in UnBBayes for the extension point which allows to include a new type of node in UnBBayes. This plugin can be found at https://sourceforge.net/p/unbbayes/code/2663/tree/trunk/UnBBayes/plugins/unbbayes.prs.extension.impl.ProbabilisticNodePluginStub/.

    There are three important things I want to show in this post in order to help you out. First, you need to understand the extension point. All extension points to UnBBayes core can be found in the following file: https://sourceforge.net/p/unbbayes/code/2663/tree/trunk/UnBBayes/plugins/unbbayes.core/plugin.xml. In it you will find the documentation on what you need to do in order to create a plugin for that specific extension point.

    Here is a snippet of the core plugin.xml file with the description for the PluginNode extension point:

    <?xml version="1.0" ?>
    <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
    
        <!-- 
             PluginNode extension point. 
             Hot plug is enabled.
             This extension point basically declares a new node type for BN module and a set of additional informations
             in order to show this node within GUI. Please note that I/O and/or inference algorithms must be implemented 
             separately (see PNIO and InferenceAlgorithm extension points) as a dependent plugin, in order to
             make it possible to compile or save a network containing these new node types.
    
             The arguments are basically:
                class: class of a node implementing unbbayes.prs.extension.IPluginNode. 
                       If so, the class must provide a default constructor with no arguments.
    
                       This parameter may also be a builder extending unbbayes.prs.builder.extension.PluginNodeBuilder
                       or implementing unbbayes.prs.builder.INodeBuilder. In such case, the builded node must be a instance
                       of unbbayes.prs.extension.IPluginNode. This approach is useful if the node class does not
                       provide a default constructor with no arguments. The builder itself must provide a default constructor
                       with no arguments.
    
                shapeClass: class implementing unbbayes.draw.extension.IPluginUShape, used in order to draw a node into canvas. 
                       In this case, it must provide a default constructor with no arguments.
    
                       This parameter may also be a builder implementing unbbayes.draw.extension.IPluginUShapeBuilder.
                       In this case, the builded node must be a instance
                       of unbbayes.draw.extension.IPluginUShape. This approach is useful if the shape class does not
                       provide a default constructor with no arguments. The builder itself must provide a default constructor
                       with no arguments.
    
                name: the name of the new node type. This is going to be used as a label.
    
                panelBuilder: class implementing unbbayes.gui.table.extension.IProbabilityFunctionPanelBuilder. This is basically
                      a class holding a swing JPanel, displayed to the user in order to edit this node's information, such as
                      probability distribution functions and other specific details.
    
                description: a brief description of a node type. This is going to be used a tool tip text.
    
                icon: an image (usually gif or png) to be used as an icon. This will be used for buttons.
                      if not set, a default icon will be used.
    
                cursor: an image (usually gif or png) to be used as a cursor when this new node type
                      is being selected by the user. The upper left corner (point x = 0, y = 0) will 
                      be marked as the active point. If not set, a default cursor will be used.
    
        -->
        <extension-point id="PluginNode">
            <parameter-def id="class"/>
            <parameter-def id="shapeClass"/>
            <parameter-def id="name"/>
            <parameter-def id="panelBuilder"/>
            <parameter-def id="description" multiplicity="none-or-one" />
            <parameter-def id="icon" multiplicity="none-or-one" />
            <parameter-def id="cursor" multiplicity="none-or-one" />
        </extension-point>
    

    I will leave all the explanations to the documentation above. The second important step in creating your plugin is the plugin.xml file for your plugin, which in this case is the ProbabilisticNodePluginStub at https://sourceforge.net/p/unbbayes/code/2663/tree/trunk/UnBBayes/plugins/unbbayes.prs.extension.impl.ProbabilisticNodePluginStub/plugin.xml:

    <?xml version="1.0" ?>
    <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
    <!-- This is a sample configuration for "new node type" plugin. By creating plugins like this, you can
         add new node types to core (PN module) -->
    <plugin id="unbbayes.prs.extension.impl.ProbabilisticNodePluginStub" version="1.0.0">
        <requires>
            <import plugin-id="unbbayes.util.extension.core"/>
        </requires>
        <runtime>
            <library id="ProbabilisticNodePluginStub" path="classes/" type="code">
                <export prefix="*" />
            </library>
            <library type="resources" path="icons/" id="ProbabilisticNodePluginStub_icons" />
        </runtime>
        <extension plugin-id="unbbayes.util.extension.core" point-id="PluginNode" id="ProbabilisticNodePluginStub">
            <parameter id="class" value="unbbayes.prs.extension.impl.ProbabilisticNodePluginStub" />
            <parameter id="shapeClass" value="unbbayes.draw.extension.impl.DefaultPluginUShape" />
            <parameter id="name" value="Boolean Node For Plugin Test" />
            <parameter id="panelBuilder" value= "unbbayes.gui.table.extension.StubPanelBuilder" />
            <parameter id="description" value="This is a stub in order to test plugins" />
        <parameter id="icon" value="icon_stub.gif" />
        <parameter id="cursor" value="cursor_stub.gif" />
        </extension>
    </plugin>
    

    In it you can see several important things necessary for this specific extension point. They are:

    <?xml version="1.0" ?>
    <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
    
            <parameter id="class" value="unbbayes.prs.extension.impl.ProbabilisticNodePluginStub" />
            <parameter id="shapeClass" value="unbbayes.draw.extension.impl.DefaultPluginUShape" />
            <parameter id="name" value="Boolean Node For Plugin Test" />
            <parameter id="panelBuilder" value= "unbbayes.gui.table.extension.StubPanelBuilder" />
            <parameter id="description" value="This is a stub in order to test plugins" />
            <parameter id="icon" value="icon_stub.gif" />
            <parameter id="cursor" value="cursor_stub.gif" />
    

    In it we define the class that represents the node we are adding to UnBBayes (parameter class), the class that defines the shape of our node (parameter shapeClass), the panel builder (parameter panelBuilder), and other simpler things (parameters name, description, icon and cursor).

    Since this post is getting too big, I will leave to you to open the corresponding classes (see atribute value for the class, shapeClass and panelBuilder parameters) and try to understand them by yourselves. If you have any questions, let me know!

    Finally, I want to just point out the extension plugin to create a new module inside UnBBayes with a panel that lets you do whatever you want with it. This is the most flexible extension point we have in UnBBayes core. It is the Module extension point at the core UnBBayes plugin.xml file (see url above). Here is the snippet:

    <?xml version="1.0" ?>
    <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
    
        <!-- Module extension point.
             UnBBayes' modules are basically new internal frames which are started when toolbars or menu are chosen.
             Hot plug is enabled.
             This extension point must extend unbbayes.util.extension.UnBBayesModule and provide the following informations:
                class: full class name. It must extend unbbayes.util.extension.UnBBayesModule and provide a default constructor
                                        (a constructor with no parameters) if factoryClass is not provided.
                builder: a class to instantiate the module. It must implement  unbbayes.util.extension.UnBBayesModuleBuilder.
                              Use this field if "class" cannot provide a plausible default constructor.
                name: name of the functionality. It must be unique. If null, unbbayes.util.extension.UnBBayesModule#getModuleName() 
                              or unbbayes.util.extension.UnBBayesModuleBuilder will be used.
                description: tool tip text. Currently, no localization is supported.
                icon: icon (image) to be used at the tool bar's button. 
                category: this is a name read by UnBBayes in order to categorize a module.
                          currently, the default values are: 
                                    - none (no definition or empty) or "plugins": the module's menu will be added to "plugin" menu; 
                                    - "bn": the button will be added into "new" tool bar and the module's menu will be added into "new" menu;
                                    - "tool": the module's menu will be added into "tool" menu; 
                                    - "sampling": the module's menu will be added into "sampling" menu;
                                    - user-defined (any category not listed above): the module's menu will be added into a new menu, but no localization support
                                                  will be availabe.
        -->
        <extension-point id="Module">
            <parameter-def id="class"/>
            <parameter-def id="builder" multiplicity="none-or-one" />
            <parameter-def id="name" multiplicity="none-or-one" />
            <parameter-def id="description" multiplicity="none-or-one" />
            <parameter-def id="icon" multiplicity="none-or-one" />
            <parameter-def id="category" multiplicity="none-or-one" />
        </extension-point>
    

    I hope this helps you all out!

    All the best,
    Rommel

     
  • Heitor VIeira

    Heitor VIeira - 2013-03-15

    OK, thanks!

    This was a great help. However, i can't run the unbbayes with this plugin, i mean this plugin don't appear in the window of UnBBayes, others plugins that i have downloaded from sourceforge like the simulation gibbs worked. How can i run the project to appear this stub plugin? Sorry about this dumb questions, can i just create the folder in plugin folder for my plug-in and create inside the plugin.xml or have i to create a new project in eclipse and after associate in some way to the UnBBayes project?

    Thank you so much!!!
    Sorry about something.

    Heitor.

     

    Last edit: Heitor VIeira 2013-03-15
    • Rommel Novaes Carvalho

      Hi,

      There are two ways of running a new plugin inside UnBBayes. If you download
      the source code of a specific plugin, like UnBMiner or Gibbs simulation,
      you only need to run the UnBBayesMainDelegator inside the test source
      folder. However, if you want to run it by downloading the zip file from SF,
      for instance (without Ecplise), you need to unzip the file inside UnBBayes
      core plugin folder. This works just like an Eclipse plugin. All you need to
      do is add the plugin folder (e.g., gibbs) inside the main plugins folder
      (this might sound confusing, but it is really simple). See
      http://sourceforge.net/p/unbbayes/discussion/156015/thread/cb2e0887/ to
      understand this second method better.

      Best,
      Rommel

      --
      Dr. Rommel N. Carvalho
      Postdoctoral Research Associate
      C4I Center / GMU
      http://mason.gmu.edu/~rcarvalh

      2013/3/15 Heitor VIeira hectoren@users.sf.net

      OK, thanks!
      This was a great help. However, i can't run the unbbayes with this plugin,
      i mean this plugin don't appear in the window of UnBBayes, others plugins
      that i have downloaded from sourceforge like the simulation gibbs worked.
      How i can run the project to appear this stub plugin? Sorry about this dumb
      questions, can i just create the folder in plugin folder for my plug-in and
      create inside the plugin.xml or have i to create a new project in eclipse
      and after associate in some way to the UnBBayes project?

      My first (Hello World) plug-inhttps://sourceforge.net/p/unbbayes/discussion/156015/thread/1cbf4a68/?limit=25#6989

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/unbbayes/discussion/156015/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/prefs/

       
  • Rommel Novaes Carvalho

    Hi Ben,

    It seems the mediawiki has been discontinued and I am pretty sure we lost all material we had inside it. :-(

    I have sent an e-mail to our team and are taking a look if we can recover the data somehow from our local archives. I will let you know ASAP.

    Cheers,
    Rommel

     

    Last edit: Rommel Novaes Carvalho 2014-08-28

Log in to post a comment.