Skip to content

A Simple Plugin

Pulseway
Pulseway

Let's start by writing a plugin which shows you the current date and time from the plugin host. You can use your favourite IDE, but for this example we will use Eclipse.

Launch Eclipse then create a new Java project with the name "SimplePlugin". See Figure A. Press Next then using Add External JARs ... button add the pulseway-client.jar file located in the plugin directory at the pulseway installation location. See Figure B.

Pulseway Figure A
Pulseway Figure B

Create a new java class named "com.pulseway.demo.SimplePlugin" making sure that you use "com.mmsoftdesign.client.ClientPluginImpl" as Superclass. See Figure C. After clicking finish the class should be opened automatically.

Pulseway Figure C

Now we can start writing our plugin. Let's open "SimplePlugin.java" (if it's not already opened) and add the code that will identify our plugin. Make sure you add code so Pulseway Manager shows it's users the name and description of the plugin.

@Override
public String getPluginName()
{
        return "Simple Plugin";
}

@Override
public String getPluginDescription()
{
        return "This plugin shows the current date and time.";
}
The text between the brackets can be changed to match your plugin name and description. Now only one thing remains to be implemented, the part where we tell our Pulseway what to show to clients. We do this by adding the following code under the other two (Order doesn't matter).
@Override
public getAdditionalComputerDetails()
{
        Groups container = new Groups();
        Group mainGroup = new Group( "Simple Plugin");
        SimpleItem date = new SimpleItem( "Current Date: ", SimpleDateFormat.getDateInstance().format(new Date()));
        SimpleItem time = new SimpleItem( "Current Time: ", SimpleDateFormat.getTimeInstance().format(new Date()));
        NumberInputItem number = new NumberInputItem("1", "Change me", Integer.toString(changeMe));
        mainGroup.getItems().add(date);
        mainGroup.getItems().add(time);
        mainGroup.getItems().add(number);
        container.add(mainGroup);
        return container;
}
Don't worry, it's actually not as complicated as it seems. As you can see from the method (function) declaration we have to return a Groups type back to Pulseway which is actually a container of containers. A "Groups" type can have many "Group" containers which can have many "SimpleItem" / "CommandItem" / "PageItem". See Figure D.

Pulseway Figure D
package com.pulseway.demo;

import java.text.SimpleDateFormat;
import java.util.Date;
import com.mmsoftdesign.client.ClientPluginImpl;
import com.mmsoftdesign.client.model.*;

public class SimplePlugin extends ClientPluginImpl {

    /**
    *Defines the plugin name.
    *
    *@return Plugin name
    */
    @Override
    public String getPluginName()
    {
        return "Simple Plugin";
    }

    /**
    *A short description which will be displayed when the plugin is installed.
    *
    *@return Plugin description
    */
    @Override
    public String getPluginDescription()
    {
        return "This plugin shows the current date and time.";
    } 

    private int changeMe = 0;

    /**
    *Occurs whenever a Pulseway loads the computer details page.
    *
    *@return A group of items which contain the current date and time
    */
    @Override
    public Groups getAdditionalComputerDetails()
    {
        Groups container = new Groups();// Group of "Group" types.
        // Group of "SimpleItem" / "CommandItem" / "PageItem" with the title Simple Plugin.
        Group mainGroup = new Group( "Simple Plugin");
        // Simple Item with "Current Date: " title and current date as subtitle.
        SimpleItem date = new SimpleItem( "Current Date: ", SimpleDateFormat.getDateInstance().format(new Date()));
        // Simple Item with "Current Time: " title and current time as subtitle.
        SimpleItem time = new SimpleItem( "Current Time: ", SimpleDateFormat.getTimeInstance().format(new Date()));
        NumberInputItem number = new NumberInputItem("1", "Change me", Integer.toString(changeMe));
        mainGroup.getItems().add(date); // Adding the date SimpleItem to our Group container.
        mainGroup.getItems().add(time); // Adding the time SimpleItem to our Group container.
        mainGroup.getItems().add(number); // Adding the NumberInputItem to our Group container.
        container.add(mainGroup); // Adding the mainGroup Group to Groups container.
        return container; // Returning our Groups container to Pulseway.
    }

    /**
    *Occurs whenever a NumericInput's value has been changed.
    */
    @Override
    public onNumericInputValueChanged(String inputId, int inputValue)
    {
        changeMe = inputValue;
    } 
}
   
All the text after double ("//") or between ("/* */") is completely optional and its reason is for code comments. Now go ahead and right click on the project in the package explorer and choose Export ... . In the dialog that opens select JAR file then press Next to go to the JAR File Specifications dialog. Here fill in the desire path and name of the new jar and choose Finish. This file represents the plugin you just made and you need to install it into Pulseway for it to work.