Difference: MyFirstJavaTask (1 vs. 14)

Revision 1416 Feb 2012 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"
<-- 
  • Set TOPICTITLE = My first Java HIPE task
-->
Deleted:
<
<
PDF Version Portrait Landscape

help Did you spot something wrong or missing on this page? If you have an account on this TWiki, you can fix it yourself by editing the page. If you don't have an account, you can send a message to the Editorial Board to tell us about it. Thank you in advance!

 

My first Java HIPE task

Changed:
<
<
This tutorial will teach you the following:

  1. How to write a simple Java task using Eclipse.
  2. How to add the task to HIPE as a plug-in.

Requisites:

  • You know at least the basics of Java and are familiar with concepts such as package, class and superclass.
  • You have set up Eclipse for HIPE development. To learn how to do so, read the Getting started with HIPE development tutorial to the end of the Creating an Eclipse project section.

Writing the task in Eclipse

This tutorial has been tested with Eclipse 3.7 "Indigo". Steps may differ for other versions of Eclipse.

The following is a simple Java task that takes a table dataset as input and outputs an array with the averages of each row of the table dataset. For more information about table datasets, see the Scripting and Data Mining guide.

Start Eclipse. Choose File --> New --> Java Project. Enter TableAverageTask in the Project name field. Click Next.

In the next window, click on the Libraries tab. Click Add Library. The Add Library dialogue window appears. Select HCSS Project Container from the list and click Next. If you do not see HCSS Project Container among the available libraries, you need to install the HCSS Project plugin as described in the Getting started with HIPE development tutorial.

In the configuration dialogue window for the HCSS Project Container library, enter hcss.dp.core in the Project field, the major version number of your HIPE installation in the Track field (8.0 for HIPE 8.x, and so on), and click Fetch latest to get the latest build. These settings work for the simple example in this tutorial; if you are developing instrument-specific software, set the Project field as hcss.dp.hifi, hcss.dp.pacs or hcss.dp.spire.

Click Finish, then Finish again in the New Java Project dialogue window.

Right click on the project name in the Package Explorer view, and choose New --> Class from the context menu. The New Java Class dialogue window appears. Write herschel.ia.tableaverage in the Package field, and TableAverageTask in the Name field. In the Superclass field, change java.lang.Object to herschel.ia.task.Task.

Click Finish. Eclipse creates the class and opens the source file with the skeleton code:

package herschel.ia.tableaverage;

import herschel.ia.task.Task;

public class TableAverageTask extends Task {

}

Complete the source code as follows:

package herschel.ia.tableaveragejava;  // 1

import herschel.ia.task.Task;  // 2
import herschel.ia.task.TaskParameter;
import herschel.ia.dataset.TableDataset;
import herschel.ia.numeric.Double1d;

public class TableAverageJavaTask extends Task {  // 3

    public TableAverageJavaTask() {
        super("tableAverageJava");
        setDescription("Computes the average of each row of a table dataset");  // 4
        TaskParameter parameter = new TaskParameter("table", TableDataset.class);  // 5
        parameter.setType(TaskParameter.IN);
        parameter.setMandatory(true);
        parameter.setDescription("The table of whose rows to compute the average"); //6
        addTaskParameter(parameter);

        parameter = new TaskParameter("average", Double1d.class);  // 7
        parameter.setType(TaskParameter.OUT);
        parameter.setDescription("The array of averages of the table's rows");
        addTaskParameter(parameter);
    }

    public void execute() {  // 8
        TableDataset table = (TableDataset) getParameter("table").getValue();
        if (table == null) {
            throw (new NullPointerException("Missing table value"));
        }

        int columns = table.getColumnCount();
        double divider = 1.0 / columns;
        Double1d average = new Double1d(table.getRowCount());
        for (int column = 0; column < columns; column++) {
            average.add((Double1d) table.getColumn(column).getData());
        }

            setValue("average", average.multiply(divider));

        }
    }
}

Let us examine some lines of the script.

  1. This line sets the package as herschel.ia.tableaveragejava. You can set whatever suits your project or organisation. It does not need to be a subpackage of herschel.ia.
  2. This line and the following import the needed classes: Task and TaskParameter are needed for any task, while TableDataset and Double1d are needed for the specific computations done in this task.
  3. This line declares the TableAverageJavaTask class. The class, like any task, inherits from Task.
  4. This line sets the description of the task. It is what you see in the tooltip that appears when you hover on the task name in the Tasks view of HIPE. Every task must have a description.
  5. This line defines a task parameter. This parameter is called table and is of type TableDataset. The next two lines state that table is an input parameter and is mandatory.
  6. This line defines the description of the table parameter. Task parameters, like the task itself, must always have a description.
  7. This line defines the output parameter, called average. It is better to avoid vague parameter names such as result.
  8. This line defines the execute method. This is the heart of any task: it is the function that does the actual data processing.

Save the file. Right click on the project name, and choose Export from the context menu. Choose JAR File from the list and click Next. Write a name of your liking in the JAR file field (for example, TableAverageJavaTask.jar) and click Finish. Eclipse creates the JAR file.

Turning the task into a HIPE plug-in

Create a Jython file named plugin.py. Write the following in the file:

from herschel.ia.tableaveragejava import TableAverageJavaTask
tableAverageJava = TableAverageJavaTask()  # 1
toolRegistry = TaskToolRegistry.getInstance()
toolRegistry.register(tableAverageJava, [Category.GENERAL, Category.SPECTRUM])  # 2
del(toolRegistry)

  1. This line creates an instance of the task. Note that from the task name TableAverageJavaTask we obtained tableAverageJava as instance name. This is a general rule. The task name is made of words with capitalised initials and ends with Task. The instance name starts with a lower case letter and drops the Task part.
  2. The task is assigned to the GENERAL and SPECTRUM categories. This is not required, since the task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GENERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.

Now create a zip file (or download the one we made for you) containing the plugin.py file and the JAR file previously created by Eclipse, in a jars directory:

plugin.py
jars/TableAverageJavaTask.jar

The zip file name must be made by three parts:

    • The plug-in name, for example TableAverageJavaPlugin.
    • An underscore character.
    • The plug-in version number, which can be any combination of digits separated by dots. For example, 0.1, 1.0.0, 2.3.3 and so on.

The plug-in is now ready.

Installing, running and sharing the plug-in is done in the same way as described in the My first Jython task tutorial. The only difference is that we called the Java task class TableAverageJavaTask instead of TableAverageTask. Correspondingly, the task instance is tableAverageJava instead of tableAverage. This allows you to install the plug-ins from this tutorial and from the My first Jython task tutorial without name clashes.

Where to go from here

You are now ready to develop more complex tasks and plug-ins. You may find the following resources useful:

Your comments

<--/commentPlugin-->
* wrt Turning the task into a HIPE plug-in:
>
>
This page has moved!
 
Changed:
<
<
I'm not sure about plug-ins but the preferred way in init.py's to register tasks is:
>
>
The latest version of this tutorial is now hosted on the HIPE community website.
 
Changed:
<
<
toolRegistry.register(TableAverageJavaTask?(), [Category.GENERAL, Category.SPECTRUM])
>
>
Why have we moved? For these reasons, among others:
 
Changed:
<
<
Do not create a variable, just create the instance in the call to the registry. -- JavierDiaz - 29 Nov 2011 - 09:33
<--/commentPlugin-->
>
>
  • On the HIPE community wiki you can edit our pages even without an account.
  • There is a discussion forum associated with every page. You need just a free Wikispace account to be able to start and reply to discussions.
  • With the visual editor you can make most changes to a page without having to know the wiki language syntax.
 

Revision 1329 Nov 2011 - Main.JavierDiaz

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

Revision 1214 Oct 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"
Added:
>
>
META FILEATTACHMENT attachment="MyJavaAverage_0.1.zip" attr="" comment="Sample Java HIPE plugin" date="1318585397" name="MyJavaAverage_0.1.zip" path="MyJavaAverage_0.1.zip" size="2624" stream="MyJavaAverage_0.1.zip" user="Main.DavideRizzo" version="1"
 
META TOPICMOVED by="DavideRizzo" date="1316178511" from="Public.MyFirstHipeTask" to="Public.MyFirstJavaTask"

Revision 1127 Sep 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

Revision 1027 Sep 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

Revision 916 Sep 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"
Changed:
<
<
META TOPICMOVED by="DavideRizzo" date="1273652556" from="Sandbox.MyFirstHipeTask" to="Public.MyFirstHipeTask"
>
>
META TOPICMOVED by="DavideRizzo" date="1316178511" from="Public.MyFirstHipeTask" to="Public.MyFirstJavaTask"

Revision 815 Sep 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"
New --> Java Project. Enter DoesNotDoMuch in the Project name field. Click Next.
>
>
This tutorial has been tested with Eclipse 3.7 "Indigo". Steps may differ for other versions of Eclipse

The following is a simple Java task that takes a table dataset as input and outputs an array with the averages of each row of the table dataset. For more information about table datasets, see the Scripting and Data Mining guide.

Start Eclipse. Choose File --> New --> Java Project. Enter TableAverageTask in the Project name field. Click Next.

 In the next window, click on the Libraries tab. Click Add Library. The Add Library dialogue window appears. Select HCSS Project Container from the list and click Next. If you do not see HCSS Project Container among the available libraries, you need to install the HCSS Project plugin as described in the Getting started with HIPE development tutorial.
Changed:
<
<
In the configuration dialogue window for the HCSS Project Container library, enter hcss.dp.core in the Project field, the major version number of your HIPE installation in the Track field (3.0 for HIPE 3.x, and so on), and click Fetch latest to get the latest build. These settings work for the simple example in this tutorial; if you are developing instrument-specific software, set the Project field as hcss.dp.hifi, hcss.dp.pacs or hcss.dp.spire.
>
>
In the configuration dialogue window for the HCSS Project Container library, enter hcss.dp.core in the Project field, the major version number of your HIPE installation in the Track field (8.0 for HIPE 8.x, and so on), and click Fetch latest to get the latest build. These settings work for the simple example in this tutorial; if you are developing instrument-specific software, set the Project field as hcss.dp.hifi, hcss.dp.pacs or hcss.dp.spire.
 Click Finish, then Finish again in the New Java Project dialogue window.
Changed:
<
<
Right click on the project name in the Package Explorer view, and choose New --> Class from the context menu. The New Java Class dialogue window appears. Write herschel.ia.doesnotdomuch in the Package field, and DoesNotDoMuchTask in the Name field. In the Superclass field, change java.lang.Object to herschel.ia.task.Task.
>
>
Right click on the project name in the Package Explorer view, and choose New --> Class from the context menu. The New Java Class dialogue window appears. Write herschel.ia.tableaverage in the Package field, and TableAverageTask in the Name field. In the Superclass field, change java.lang.Object to herschel.ia.task.Task.
 Click Finish. Eclipse creates the class and opens the source file with the skeleton code:
Changed:
<
<
package herschel.ia.doesnotdomuch;
>
>
package herschel.ia.tableaverage;
 import herschel.ia.task.Task;
Changed:
<
<
public class DoesNotDoMuchTask? extends Task {
>
>
public class TableAverageTask? extends Task {
 }
Line: 49 to 53
 Complete the source code as follows:
Changed:
<
<
package herschel.ia.doesnotdomuch;
>
>
package herschel.ia.tableaverage; // 1
 
Changed:
<
<
import herschel.ia.gui.kernel.util.PopupDialog; import herschel.ia.task.Task;
>
>
import herschel.ia.task.Task; // 2
 import herschel.ia.task.TaskParameter;
Added:
>
>
import herschel.ia.dataset.TableDataset; import herschel.ia.numeric.Double1d;
 
Changed:
<
<
public class DoesNotDoMuchTask? extends Task { private static final long serialVersionUID = 1L;
>
>
public class TableAverageTask? extends Task { // 3
 
Changed:
<
<
public DoesNotDoMuchTask?() {
>
>
public TableAverageTask?() { super("tableAverage"); setDescription("Computes the average of each row of a table dataset"); // 4 TaskParameter? parameter = new TaskParameter?("table", TableDataset?.class); // 5 parameter.setType(TaskParameter?.IN); parameter.setMandatory(true); parameter.setDescription("The table of whose rows to compute the average"); //6 addTaskParameter(parameter);
 
Changed:
<
<
TaskParameter? parameter = new TaskParameter?("input", String.class); parameter.setDefaultValue("nothing"); parameter.setDescription("You can write anything.");
>
>
parameter = new TaskParameter?("average", Double1d.class); // 7 parameter.setType(TaskParameter.OUT); parameter.setDescription("The array of averages of the table's rows");
  addTaskParameter(parameter); }

Changed:
<
<
public void execute() { PopupDialog?.showInfo("You wrote \"" + getParameter("input").getValue() + "\".");
>
>
public void execute() { // 8 TableDataset? table = (TableDataset?) getParameter("table").getValue(); if (table == null) { throw (new NullPointerException?("Missing table value")); }

int columns = table.getColumnCount(); double divider = 1.0 / columns; Double1d average = new Double1d(table.getRowCount()); for (int column = 0; column < columns; column++) { average.add((Double1d) table.getColumn(column).getData());

  }
Added:
>
>
try { setValue("average", average.multiply(divider)); } catch (Exception e) { e.printStackTrace(); } }
 }
Changed:
<
<
Save the file. Right click on the project name, and choose Export from the context menu. Choose JAR File from the list and click Next. Write a name of your liking in the JAR file field and click Finish. Eclipse creates the JAR file.
>
>
Let us examine some lines of the script.
 
Changed:
<
<

Including the task in HIPE

>
>
  1. This line sets the package as herschel.ia.tableaverage. You can set whatever suits your project or organisation. It does not need to be a subpackage of herschel.ia.
  2. This line and the following import the needed classes: Task and TaskParameter are needed for any task, while TableDataset and Double1d are needed for the specific computations done in this task.
  3. This line declares the TableAverageJavaTask class. The class, like any task, inherits from Task.
  4. This line sets the description of the task. It is what you see in the tooltip that appears when you hover on the task name in the Tasks view of HIPE. Every task must have a description.
  5. This line defines a task parameter. This parameter is called table and is of type TableDataset. The next two lines state that table is an input parameter and is mandatory.
  6. This line defines the description of the table parameter. Task parameters, like the task itself, must always have a description.
  7. This line defines the output parameter, called average. It is better to avoid vague parameter names such as result.
  8. This line defines the execute method. This is the heart of any task: it is the function that does the actual data processing.
 
Added:
>
>
Save the file. Right click on the project name, and choose Export from the context menu. Choose JAR File from the list and click Next. Write a name of your liking in the JAR file field (for example, TableAverageJavaTask.jar) and click Finish. Eclipse creates the JAR file.
 
Added:
>
>

Turning the task into a HIPE plug-in

 
Changed:
<
<
Create a Jython file, named for example doesnotdomuch.py (but it can be any other name). It does not matter where you create the file. Write the following in the file:
>
>
Create a Jython file named plugin.py. Write the following in the file:
 
Changed:
<
<
from herschel.ia.doesnotdomuch import DoesNotDoMuchTask?

from herschel.ia.task.views import TaskToolRegistry? from herschel.ia.gui.kernel.Tool import Category

print "Importing DoesNotDoMuch?..."

doesNotDoMuch = DoesNotDoMuchTask?()

>
>
from herschel.ia.tableaverage import TableAverageJavaTask? tableAverageJava = TableAverageJavaTask?() # 1
 toolRegistry = TaskToolRegistry?.getInstance()
Changed:
<
<
toolRegistry.register(doesNotDoMuch, [Category.SPECTRUM, Category.GENERAL])
>
>
toolRegistry.register(tableAverageJava, [Category.GENERAL, Category.SPECTRUM]) # 2
 del(toolRegistry)
Changed:
<
<
This is the file HIPE is going to use to import the new task. Note these two points:

  • The print statement is not required, but it is useful to make sure that the task is being imported. It should be among the first statements written to the console when you start HIPE.
  • The task is assigned to the GENERAL and SPECTRUM categories. Again, this is not required. The task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GENERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.

Open the installed.userlibraries file in your HIPE installation directory. Add the following line as the first of the line beginning with <archive path:

<archive path="/path/to/jar/file/doesnotdomuch.jar"/>

Of course you have to substitute the correct path and name for the JAR file you created before.

>
>
  1. This line creates an instance of the task. Note that from the task name TableAverageJavaTask we obtained tableAverageJava as instance name. This is a general rule. The task name is made of words with capitalised initials and ends with Task. The instance name starts with a lower case letter and drops the Task part.
  2. The task is assigned to the GENERAL and SPECTRUM categories. This is not required, since the task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GENERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.
 
Changed:
<
<
Now go to the .hcss directory, which should be within your home directory. Open the file hipe.props, or create it if it does not exist. Add the following line:
>
>
Now create a zip file containing the plugin.py file and the JAR file previously created by Eclipse, in a jars directory:
 
Changed:
<
<
hcss.interpreter.imports = { /path/to/py/file/doesnotdomuch.py }
>
>
plugin.py jars/TableAverageJavaTask.jar
 
Changed:
<
<
Again, change the path and the file name to the correct values. If the hcss.interpreter.imports is already defined in hipe.props, or in another file such as hcss.props, add the new value after a comma within the braces:
>
>
The zip file name must be made by three parts:
    • The plug-in name, for example TableAverageJavaPlugin.
    • An underscore character.
    • The plug-in version number, which can be any combination of digits separated by dots. For example, 0.1, 1.0.0, 2.3.3 and so on.
 
Changed:
<
<
hcss.interpreter.imports = { /path/to/other/file/alreadythere.py, /path/to/py/file/doesnotdomuch.py }
>
>
The plug-in is now ready.
 
Changed:
<
<
Now start HIPE. You should see the Importing DoesNotDoMuch... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.
>
>
Installing, running and sharing the plug-in is done in the same way as described in the My first Jython task tutorial. The only difference is that we called the Java task class TableAverageJavaTask instead of TableAverageTask. Correspondingly, the task instance is tableAverageJava instead of tableAverage. This allows you to install the plug-ins from this tutorial and from the My first Jython task tutorial without name clashes.
 Please add your comments!
<--/commentPlugin-->

Revision 724 Jun 2011 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"
Added:
>
>
<-- 
  • Set TOPICTITLE = My first Java HIPE task
-->

PDF Version Portrait Landscape

help Did you spot something wrong or missing on this page? If you have an account on this TWiki, you can fix it yourself by editing the page. If you don't have an account, you can send a message to the Editorial Board to tell us about it. Thank you in advance!

 

My first Java HIPE task

Line: 115 to 123
 Now start HIPE. You should see the Importing DoesNotDoMuch... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.
Added:
>
>
Please add your comments!
<--/commentPlugin-->
 
<--  
-->

Revision 622 Jun 2011 - Main.JavierDiaz

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

My first Java HIPE task

Line: 91 to 91
 This is the file HIPE is going to use to import the new task. Note these two points:

  • The print statement is not required, but it is useful to make sure that the task is being imported. It should be among the first statements written to the console when you start HIPE.
Changed:
<
<
  • The task is assigned to the GENERAL and SPECTRUM categories. Again, this is not required. The task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GERNERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.
>
>
  • The task is assigned to the GENERAL and SPECTRUM categories. Again, this is not required. The task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GENERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.
 Open the installed.userlibraries file in your HIPE installation directory. Add the following line as the first of the line beginning with <archive path:

Revision 509 Jun 2010 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

My first Java HIPE task

Line: 113 to 113
 hcss.interpreter.imports = { /path/to/other/file/alreadythere.py, /path/to/py/file/doesnotdomuch.py }
Changed:
<
<
Now start HIPE. You should see the Importing DoesNotDoMuch?... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.
>
>
Now start HIPE. You should see the Importing DoesNotDoMuch... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.
 

Revision 417 May 2010 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DpHipe"

My first Java HIPE task

Line: 115 to 115
 Now start HIPE. You should see the Importing DoesNotDoMuch?... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.
Added:
>
>
<--  
-->
 
META TOPICMOVED by="DavideRizzo" date="1273652556" from="Sandbox.MyFirstHipeTask" to="Public.MyFirstHipeTask"

Revision 312 May 2010 - Main.DavideRizzo

Line: 1 to 1
Changed:
<
<
META TOPICPARENT name="DavideRizzoSandbox"
>
>
META TOPICPARENT name="DpHipe"
 

My first Java HIPE task

Added:
>
>
 This tutorial will teach you the following:
Changed:
<
<
  • How to write a simple Java task in Eclipse.
  • How to include the task in HIPE.
>
>
  1. How to write a simple Java task in Eclipse.
  2. How to include the task in HIPE.
 Requisites:
Line: 112 to 114
 

Now start HIPE. You should see the Importing DoesNotDoMuch?... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.

Added:
>
>
META TOPICMOVED by="DavideRizzo" date="1273652556" from="Sandbox.MyFirstHipeTask" to="Public.MyFirstHipeTask"

Revision 206 May 2010 - Main.DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="DavideRizzoSandbox"
Changed:
<
<

My first HIPE task

>
>

My first Java HIPE task

 
Changed:
<
<
To be written.
>
>
This tutorial will teach you the following:
 
Deleted:
<
<
-- DavideRizzo - 30 Apr 2010
 \ No newline at end of file
Added:
>
>
  • How to write a simple Java task in Eclipse.
  • How to include the task in HIPE.

Requisites:

Writing the task in Eclipse

Start Eclipse. Choose File --> New --> Java Project. Enter DoesNotDoMuch in the Project name field. Click Next.

In the next window, click on the Libraries tab. Click Add Library. The Add Library dialogue window appears. Select HCSS Project Container from the list and click Next. If you do not see HCSS Project Container among the available libraries, you need to install the HCSS Project plugin as described in the Getting started with HIPE development tutorial.

In the configuration dialogue window for the HCSS Project Container library, enter hcss.dp.core in the Project field, the major version number of your HIPE installation in the Track field (3.0 for HIPE 3.x, and so on), and click Fetch latest to get the latest build. These settings work for the simple example in this tutorial; if you are developing instrument-specific software, set the Project field as hcss.dp.hifi, hcss.dp.pacs or hcss.dp.spire.

Click Finish, then Finish again in the New Java Project dialogue window.

Right click on the project name in the Package Explorer view, and choose New --> Class from the context menu. The New Java Class dialogue window appears. Write herschel.ia.doesnotdomuch in the Package field, and DoesNotDoMuchTask in the Name field. In the Superclass field, change java.lang.Object to herschel.ia.task.Task.

Click Finish. Eclipse creates the class and opens the source file with the skeleton code:

package herschel.ia.doesnotdomuch;

import herschel.ia.task.Task;

public class DoesNotDoMuchTask extends Task {

}

Complete the source code as follows:

package herschel.ia.doesnotdomuch;

import herschel.ia.gui.kernel.util.PopupDialog;
import herschel.ia.task.Task;
import herschel.ia.task.TaskParameter;

public class DoesNotDoMuchTask extends Task {
    private static final long serialVersionUID = 1L;

    public DoesNotDoMuchTask() {
   
   TaskParameter parameter = new TaskParameter("input", String.class);
        parameter.setDefaultValue("nothing");
        parameter.setDescription("You can write anything.");
        addTaskParameter(parameter);
    }
    
    public void execute() {
   PopupDialog.showInfo("You wrote \"" + getParameter("input").getValue() + "\".");
    }

}

Save the file. Right click on the project name, and choose Export from the context menu. Choose JAR File from the list and click Next. Write a name of your liking in the JAR file field and click Finish. Eclipse creates the JAR file.

Including the task in HIPE

Create a Jython file, named for example doesnotdomuch.py (but it can be any other name). It does not matter where you create the file. Write the following in the file:

from herschel.ia.doesnotdomuch import DoesNotDoMuchTask

from herschel.ia.task.views import TaskToolRegistry
from herschel.ia.gui.kernel.Tool import Category

print "Importing DoesNotDoMuch..."

doesNotDoMuch = DoesNotDoMuchTask()

toolRegistry = TaskToolRegistry.getInstance()
toolRegistry.register(doesNotDoMuch, [Category.SPECTRUM, Category.GENERAL])
del(toolRegistry)

This is the file HIPE is going to use to import the new task. Note these two points:

  • The print statement is not required, but it is useful to make sure that the task is being imported. It should be among the first statements written to the console when you start HIPE.
  • The task is assigned to the GENERAL and SPECTRUM categories. Again, this is not required. The task would appear anyway in the All folder of the Tasks view in HIPE. The available categories are GERNERAL, CUBE, IMAGE, SPECTRUM, HIFI, PACS and SPIRE.

Open the installed.userlibraries file in your HIPE installation directory. Add the following line as the first of the line beginning with <archive path:

<archive path="/path/to/jar/file/doesnotdomuch.jar"/>

Of course you have to substitute the correct path and name for the JAR file you created before.

Now go to the .hcss directory, which should be within your home directory. Open the file hipe.props, or create it if it does not exist. Add the following line:

hcss.interpreter.imports = { /path/to/py/file/doesnotdomuch.py }

Again, change the path and the file name to the correct values. If the hcss.interpreter.imports is already defined in hipe.props, or in another file such as hcss.props, add the new value after a comma within the braces:

hcss.interpreter.imports = { /path/to/other/file/alreadythere.py, /path/to/py/file/doesnotdomuch.py }

Now start HIPE. You should see the Importing DoesNotDoMuch?... in the console, and the doesNotDoMuch task should appear in the All, General and Spectrum folders in the Tasks view.

Revision 130 Apr 2010 - Main.DavideRizzo

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="DavideRizzoSandbox"

My first HIPE task

To be written.

-- DavideRizzo - 30 Apr 2010