Skip to content

Creating a Custom Module

John edited this page Sep 5, 2019 · 4 revisions

Each module in PC2v9 is really a view (the "V" in the Model-View-Controller (MVC) architecture) that the controller (C) loads. (See the PC2V9 Architectural Overview wiki page for details on how PC2v9 uses the MVC architecture.)

This article describes how to write a quick and dirty new module that provides complete access without using the PC2v9 API.

The steps to implement a new module are:

  • Create a class that implements UIPlugin.
  • Use the controller to override/replace the default class with the new UIPlogin.
  • Login in the normal way.

One can create a console class or a GUI class. Every view class implements UIPlugin.

The edu.csus.ecs.pc2.core.InternalController class provides an override for the plugin that is loaded: see InternalController.setUiPlugin(plugin).

By default the plugin/View is determined by the login name; for example, logging in using account feeder1 starts the edu.csus.ecs.pc2.ui.eventfeed.ServicesView class.

The following snippet class provides all that is needed to create a custom PC2v9 module/program.

public class NewModule implements UIPlugin {

   public void setContestAndController(IInternalContest inContest, IInternalController inController) {
       contest = inContest;
       controller = inController;
       log = controller.getLog();

       // do whatever you like here, this module is logged into the server and
       // can perform any action that the login allows

       // in this example the program will print all runs in the contest.  

       Run[] runs = contest.getRuns(); 

       Arrays.sort(runs, new RunComparator());
       for (Run run : runs) {
         System.out.println(run);
       }
   }

   public static void main(String[] args) {
       IInternalContest model = new InternalContest();
       InternalController controller = new InternalController (model);
       NewModule plugin = new NewModule ();
       /**
        * Set this class as the plugin/class to run after logged in.
        */
       controller.setUiPlugin(plugin);
       
       /**
        * Start pc2, login if successful login, start plugin.
        */
       controller.start(args);
   }

}

Method LoadUIClass.getUIClassName() determines the GUI plugin class name; the non-gui class name is assigned in InternalController.

See Also

  • Uiname.properties - a file which can be used to override a view class based on login name.

PC2 Logo

Clone this wiki locally