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
This tutorial will teach you the following:
- 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 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.
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.
Please add your comments!