Apama 10.2 | Apama Documentation | Building and Using Apama Dashboards | Building Dashboard Clients | Defining Dashboard Commands | Creating custom commands | Sample ICommandLibrary implementation
 
Sample ICommandLibrary implementation
Below is a sample implementation of ICommandLibrary, which you can find under samples\dashboard_studio\tutorial\src:
package com.apama.dashboard.sample;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import com.apama.dashboard.command.CommandDescriptorFactory;
import com.apama.dashboard.command.ICommandDescriptor;
import com.apama.dashboard.command.ICommandLibrary;
/**
* SampleCommandLibrary is an example of a custom command library for
* Dashboard Builder. Custom commands allow you to extend Dashboard Builder
* to run custom code in response to a user action such as a clicking on
* a button.
* <p>
* SampleCommandLibrary implements the commands:
* <ul>
* <li><b>Show Message</b>: Displays a message window showing the arguments
* passed to the command.
* </ul>
*
* $Copyright(c) 2013 Software AG, Darmstadt, Germany and/or its licensors$
*
* @version $Id: SampleCommandLibrary.java 84623 2008-06-25 22:41:10Z cr $
*/
public class SampleCommandLibrary implements ICommandLibrary {
private final static String CMD_ECHO = "Show Message";
/**
* Get the list of command descriptors for the commands implemented
* by this command library. Each command descriptor identifies one
* command.
*/
public List<ICommandDescriptor> getCommandDescriptors() {
List<ICommandDescriptor> v = new ArrayList<ICommandDescriptor> ();
v.add(CommandDescriptorFactory.createCommandDescriptor(CMD_ECHO));
// Add additional command descriptors here.
return v;
}
/**
* Run a command.
*
* @param command Command to run.
* @param parameters Parameters to command.
*/
public boolean invokeCommand(String command, Object parameters) {
if (command.equals(CMD_ECHO)) {
//Create and set up the window.
JFrame frame = new JFrame("Message");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel(parameters.toString());
label.setBorder(BorderFactory.createEmptyBorder(30,100,30,100));
frame.getContentPane().add(label);
frame.setLocation(100,100);
//Display the window.
frame.pack();
frame.setVisible(true);
} else {
// Add additional command handlers here.
}
return true;
}
}

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release