Adding Functionality To Other Plugins
Plugins have other ways of showing data and offering than creating full views. They can send tabs to be added to other views and dialogs they could also broadcast requests for functionality to see if the framework knows of a plugin that can process a certain feature.
if (PluginEntry.Framework.CanRunOperation("ProcessPostedStatement"))
{
PluginEntry.Framework.RunOperation("ProcessPostedStatement", null, new PluginOperationArguments(storeID, statement));
}
When the plugins are loaded the framework then asks what operations they can run. Using the GetOperations function.
public void GetOperations(IOperationList operations)
{
operations.AddOperation("", "ShowReportPrintPreview", false, true, PluginOperations.ShowReportPreview, Permission.ManageReports);
operations.AddOperation("", "ShowReportPrint", false, true, PluginOperations.ShowReportPrint, Permission.ManageReports);
}
After this plugin is loaded for instance the framework knows how to run the operations ShowReportPrintPreview and ShowReportPrint so if a plugin requests either the framwork can deliver.
Alternatively a plugin might add a link to the related window that is done through the AddContextBarItemConstructionHandler
that would then add links to views in other plugins
public static void TaskBarItemCallback(object sender, ContextBarItemConstructionArguments arguments)
{
const int priority = 100;
if (arguments.CategoryKey == "LSOne.ViewPlugins.RetailItems.Views.ItemView.Actions" && !arguments.View.MultiEditMode)
{
var item = new ContextBarItem(Properties.Resources.LabelPrinting, LabelsClickedFromContextBar);
item.Tag = new RecordIdentifier("Item", "");
arguments.Add(item, priority);
}
}
This will add a link to the RetailItems view for label printing. Where the handler LabelsClickedFromContextBar is the function run when the link is pressed
There are several examples of this functionality in the Development Package as well as other ways of extending functionality in the framework.
Sending a message to another plugin
Another way to control the functionality from another plugin directly from your plugin is by invoking the Message function from the IPlugin interface. To do this, you need to create a reference to the plugin as shown in the following example:
public partial class MyPluginPage
{
WeakReference retailItemPlugin;
public MyPluginPage()
{
IPlugin plugin = PluginEntry.Framework.FindImplementor(this, "CanViewRetailItem", null);
if(plugin != null)
{
retailItemPlugin = new WeakReference(plugin);
}
}
private void btnView_Click(object sender, EventArgs e)
{
if(retailItemPlugin.IsAlive)
{
((IPlugin)retailItemEditor.Target).Message(this, "ViewItem", item.RetailItemID);
}
}
}
In the above example we try to get a plugin that allows us to view a retail item. By calling the FindImplementor method, the framework invokes the ImplementsFeature method of all plugins and it will return the IPlugin instance of the corresponding plugin where it finds the feature.
The methods from the plugin that we try to reference should look like this:
public bool ImplementsFeature(object sender, string message, object parameters)
{
if (message == "CanViewRetailItem")
{
return PluginEntry.DataModel.HasPermission(LSOne.DataLayer.BusinessObjects.Permission.ItemsView);
}
return false;
}
public object Message(object sender, string message, object parameters)
{
if (message == "ViewItem")
{
if (parameters is RecordIdentifier)
{
RecordIdentifier itemID = (RecordIdentifier)parameters;
PluginOperations.ShowItemSheet(itemID, null);
}
}
return null;
}