Plugin source code example

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Plugin source code example

Postby cuccuru » Wed Dec 07, 2005 4:37 am

Hi,
I'm currently evaluating MagicDraw v 10.0, and I'm trying to add
functionnalities via the openApi.
I have started to develop a plugin, but I'm not able to go further than
displaying a message box when MagicDraw opens or closes... (eventhough I
have tried to follow the example described in the user's guide
concerning browser actions).
Is there anybody who could give me a simple example of a plugin source
code, that shows for example who to add actions in menus,
toolbars,etc... or even how to react to events such as a model element
creation ?

Thank you.

Arnaud
cuccuru
 
Posts Rating:

Re: Plugin source code example

Postby Kristina Hildebrand » Wed Dec 07, 2005 2:15 pm

Hi Arnaud,

I found that there are some useful examples for Menu Configuration in
the MagicDraw_UML/openapi/examples/actiontypes directory in your
MagicDraw installation. There are probably lots of useful examples for
other purposes one directory up.

To create Menu Actions, you need to create classes that extend
com.nomagic.magicdraw.actions.MDAction. To add them to the menu system
in MagicDraw, create a new class that implements
com.nomagic.actions.AMConfigurator, then put something like the
following code inside it:

public void configure(ActionsManager mngr){
ActionsCategory category = (ActionsCategory)mngr.getActionFor("Your
New Menu Name");
if (category == null){
category = new MDActionsCategory("menu_id", "Your New Menu Name");
category.setNested(true);
mngr.addCategory(category);
}

//you can have as many of these as you want, each adding a different
menu action
category.addAction(new YourMenuAction());
}

Inside YourNewMenuAction (which as I said, extends MDAction), you need a
constructor something like:
YourNewMenuAction(){
super("id", "Menu Item");
}

Then, you'll need an actionPerformed(ActionEvent e) method which does
the actual work that is supposed to happen when someone clicks the menu
item.

Hope this helps. I don't know much about browser actions and toolbars,
because I don't need them for my application, but I think I've conquered
the regular menus. The initial learning curve for the OpenAPI may be a
little steep, but once you get into it, you can do some pretty neat things.
~Kristina (fellow OpenAPI user)

cuccuru wrote:
> Hi,
> I'm currently evaluating MagicDraw v 10.0, and I'm trying to add
> functionnalities via the openApi.
> I have started to develop a plugin, but I'm not able to go further than
> displaying a message box when MagicDraw opens or closes... (eventhough I
> have tried to follow the example described in the user's guide
> concerning browser actions).
> Is there anybody who could give me a simple example of a plugin source
> code, that shows for example who to add actions in menus,
> toolbars,etc... or even how to react to events such as a model element
> creation ?
>
> Thank you.
>
> Arnaud
Kristina Hildebrand
 
Posts Rating:

RE: Plugin source code example

Postby Tomas Pugzlys » Thu Dec 08, 2005 1:16 am

Hi Arnaud,

Kristina is right <MagicDraw install root>/openapi/examples/actiontypes is a
good example.

Also take a look at "<MagicDraw install
root>openapiexamplessimpleconfigurators" example.
This example plugin adds action to browser menu, main menu, main toolbar and
diagram toolbar.

Open API to listen for model events is introduced in MagicDraw 10.5 version
(which will be released soon).

Example how to listen for model element creation events in MagicDraw 10.5
version:

Element el = ...;
RepositoryListenerRegistry registry =
Application.getInstance().getProject().getRepositoryListenerRegistry();
PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt)
{
if (evt.getSource() instanceof Element)
{
Element source = (Element) evt.getSource();
///handle

}
}
};

registry.addPropertyChangeListener(listener,
UML2MetamodelConstants.INSTANCE_CREATED);

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com

Tomas Pugzlys
 
Posts Rating:

Re: Plugin source code example

Postby cuccuru » Thu Dec 08, 2005 7:32 am

Hi Kristina and Tomas,
you have solved my problems ;-)

Thank you for your help.
cuccuru
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests