Sampleplugin

Hi

I’m new to java and Agilian plugin development. Are there any resources beside the user guide documentation? (
http://www.visual-paradigm.com/support/documents/vpumluserguide/124/254/7040_implementing.html
)

I would love to see a working sample. Right now I’m struggling with the basics - e.g. creating the sampleplugin.jar out of eclipse.

Can the following code work?:

Thanks,
Milan

plugin xml:


<plugin 
id="sample.plugin"
name="Sample Plugin"
description="Sample Plugin"
provider="Visual Paradigm"
class="sample.plugin.SamplePlugin">
<runtime> 
<library path="lib/sampleplugin.jar" relativePath="true"/>
</runtime>
<!-- to be continued -->


<actionSet id="sample.plugin.actions.ActionSet1"> 
<toolbar 
id="sample.plugin.actions.Toolbar1"
orientation="north"
index="last"/>
<menu 
id="sample.plugin.actions.Menu1"
label="Sample Menu 1"
mnemonic="M"
menuPath="Tools/Report"/>
<action 
id="sample.plugin.actions.Action1"
actionType="generalAction"
label="Sample Action 1"
tooltip="Sample Action 1"
icon="icons/red.png"
style="normal"
menuPath="Tools/Report"
toolbarPath="sample.plugin.actions.Toolbar1/#">
<actionController class="sample.plugin.actions.ActionController"/>
</action>
<separator 
id="sample.plugin.actions.Separator1"
menuPath="Tools/sample.plugin.actions.Action1"
toolbarPath="sample.plugin.actions.Toolbar1/sample.plugin.action.Action1"/>
</actionSet>

</plugin>

SamplePlugin.java:


package sample.plugin;

import java.util.Iterator;

import com.vp.plugin.ApplicationManager;
import com.vp.plugin.ViewManager;
import com.vp.plugin.model.IModelElement;
import com.vp.plugin.model.IProject;

public class SamplePlugin implements com.vp.plugin.VPPlugin { 
// make sure there is a constructor without any parameters

public void loaded(com.vp.plugin.VPPluginInfo info) { 

	
	IProject project = ApplicationManager.instance().getProjectManager().getProject();
	Iterator iter = project.modelElementIterator();
	int modelElementCount = 0;
	while (iter.hasNext()) { 
	IModelElement modelElement = (IModelElement) iter.next();
	modelElementCount++;
	}
	
	ViewManager viewManager = ApplicationManager.instance().getViewManager();
	viewManager.showMessage("hello plugin! there are currently "+modelElementCount+" models in this project.");

	
	
}
public void unloaded() { 

}
}

Hi Milan,

The code have no problem. However, it CANNOT print the model element count. This is due to a wrong timing on reading the model elements from project.

interface:
VPPlugin
operation:
public void loaded(com.vp.plugin.VPPluginInfo info);

This operation will be called when VP-UML started. The project MAY NOT be opened at this time. Therefore, no model elements can be get from project.

If you want to get modelelements count when project is opened, you should add listener to listen ProjectOpened and print again.

A sample plugin is attached.

Best regards,
Jick Yeung
com.vp.plugin.sample.projectopened.zip