Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Adding Tools to HIPE | ||||||||
Deleted: | ||||||||
< < | ||||||||
![]() | ||||||||
Line: 19 to 17 | ||||||||
<-- summary -->Tools are processing units that operate on specific data elements. From the Java point of view, a tool is an implementation of the Tool interface. | ||||||||
Changed: | ||||||||
< < | The well-known Tasks are examples of tools within HIPE. In this case, TaskTool is used under the hood. | |||||||
> > | Tasks are examples of tools within HIPE. In this case, TaskTool is used under the hood. | |||||||
Changed: | ||||||||
< < | If a data element is selected, a list of tools that can operate on that data should appear. Double clicking on the tool will open an associated view (for non-task tools) or a dialog for settings parameters (for task tools). | |||||||
> > | If a data element is selected, a list of tools that can operate on that element should appear. Double clicking on the tool will open an associated view (for non-task tools) or a dialogue window for settings parameters (for task tools). | |||||||
Changed: | ||||||||
< < | This section explains:
| |||||||
> > | This section explains the following:
| |||||||
Deleted: | ||||||||
< < | ||||||||
Changed: | ||||||||
< < |
Adding a Tool as a Task | |||||||
> > | Adding a task as a HIPE tool | |||||||
Changed: | ||||||||
< < | Task Registry | |||||||
> > | Registering tasks | |||||||
Changed: | ||||||||
< < | Up to now you have made you task globally available to the system by specifying an instance of that task within the __init__.py file of your sub-system, e.g.: | |||||||
> > | You can made you task globally available to the system by specifying an instance of that task within a Jython file (usually called __init__.py for HIPE internal modules) that is read by HIPE at startup (see My first Java HIPE task). For example: | |||||||
# __init__.py file compute = ComputeTask() | ||||||||
Changed: | ||||||||
< < | To make your task appear in the "Tasks" view, you need to add the following lines: | |||||||
> > | To make your task appear in the Tasks view, you need to add the following lines to the Jython file: | |||||||
from herschel.ia.task.views import TaskToolRegistry toolRegistry = TaskToolRegistry.getInstance() toolRegistry.register(compute) | ||||||||
Deleted: | ||||||||
< < | For PACS users, this __init__.py file is located at $install_dir/data/toolbox/your_sub_system. | |||||||
You can also specify that your task belongs to one or more Category :
from herschel.ia.gui.kernel.Tool import Category toolRegistry.register(compute, [Category.IMAGE, Category.PACS])) | ||||||||
Deleted: | ||||||||
< < | Your task will now be enabled whenever a session variable is selected which matches the type of the first input parameter within your task! | |||||||
Changed: | ||||||||
< < | Within your task, you can control which parameter signs-up to be the prime parameter (the one which reacts on a selected data variable) by the Task API: | |||||||
> > | Your task is now enabled whenever the users selects a session variable of the same type as the first input parameter of your task. To define the prime parameter, modify your task constructor as follows: | |||||||
class ComputeTask extends Task { ComputeTask() { | ||||||||
Line: 79 to 72 | ||||||||
} | ||||||||
Changed: | ||||||||
< < | Naming conventions for task when to be registered in HIPE should follow this example assuming that the task will perform the functionality named "reduce" :
Name of the Class : ReduceTask Name of the Task (getName()) : reduce Name of the variable in Jython : reduce | |||||||
> > | Tasks registered in HIPE should follow the naming conventions shown in this example:
| |||||||
Changed: | ||||||||
< < | ![]() | |||||||
> > | ![]() reduceLight is valid, reduce_light is not. HIPE displays info log messages for invalid task names. Note that task names are used as variable names (of type Task ) automatically created when starting HIPE. | |||||||
Changed: | ||||||||
< < | Prime input validation | |||||||
> > | Validating prime input | |||||||
Changed: | ||||||||
< < | The mechanism above makes you task to become a tool within the system and it appears whenever a variable of type SpecificProduct (i.e. the type of the value of the Parameter) is selected. | |||||||
> > | If you followed the instructions in the previous section, your task now appears in the Applicable category of the Tasks view whenever a variable of the same type as the prime input is selected. | |||||||
Changed: | ||||||||
< < | Sometimes this may not be enough, e.g. in certain situations your task will only run on a SpecificProduct if it contains certain contents. A typical situation would be when a SPIRE reduction operates on an ObservationContext: such a task should not be listed whenever a HIFI observation is selected... | |||||||
> > | Sometimes this may not be enough. Your task may only run on a SpecificProduct if it contains certain contents: a typical example is a SPIRE task operating on an ObservationContext: clearly, such task should not be listed when a HIFI observation is selected. | |||||||
Changed: | ||||||||
< < | You can write a ParameterValidator to do just that: | |||||||
> > | To restrict a task to certain product contents, write a ParameterValidator : | |||||||
prime = new TaskParameter("spectrum", SpecificProduct.class) prime.setParameterValidator(new ParameterValidatorAdapter() { public void validate(Object value) throws ParameterValidationException { SpecificProduct s = (SpecificProduct)value; | ||||||||
Changed: | ||||||||
< < | if (! (logic that would validate the contents of the value...)) { throw new ParameterValidationException(reason); | |||||||
> > | if (! ( [logic that would validate the contents of the value] )) { throw new ParameterValidationException( [reason] ); | |||||||
} } }); | ||||||||
Changed: | ||||||||
< < | In other words, rather than writing this logic within the pre-amble or execution block of your task, we recommend you to move that logic into the parameter validation. This way we achieve two things:
| |||||||
> > | Note how the validation logic is now within the parameter validation block, rather than in the preamble or execution block of your task. One advantage is that the execution block of your task can concentrate on the core algorithm. | |||||||
Changed: | ||||||||
< < | Task DialogsDefault Task Dialog | |||||||
> > | Task dialogue windows | |||||||
Changed: | ||||||||
< < | The system generates a default input dialog for all registered tasks within the software. As the system does not know the intent of your task, it can only provide a dry-listing of all requested parameters; such a dialog may not be suitable for your purposes. | |||||||
> > | HIPE generates a default input dialog for all registered tasks. The dialog has three sections: Input, Output and Info, each of which can be collapsed. The following two figures show the interface of the crop task, with extended and collapsed sections: | |||||||
Deleted: | ||||||||
< < | The default dialog for the crop task: | |||||||
![]() | ||||||||
Deleted: | ||||||||
< < | As for instance you may want to have more control over how the input parameters are presented to the user:
![]() The default dialog for the crop task, with all sections opened: | |||||||
![]() | ||||||||
Changed: | ||||||||
< < | To adapt to these scenarios and more, the system provides three ways for customizing you Task dialogs:
| |||||||
> > | Parameters are listed in two columns. HIPE lists the parameters from left to right and top to bottom. If a single input or output parameter is present, this fills a whole line. | |||||||
Changed: | ||||||||
< < | ||||||||
> > | This automatic layout may not suit your task for several reasons:
| |||||||
Changed: | ||||||||
< < | Parameter Modifiers
The system provides a default dialog displaying an input area for setting the values of the parameter based on a composition of | |||||||
> > | ![]() | |||||||
Changed: | ||||||||
< < | The input area for the crop task: ![]() | |||||||
> > | The following sections explore three ways to customise your task dialogue windows:
| |||||||
Changed: | ||||||||
< < | The composition of Modifier objects is created based on the types of the values of the Task Parameters of the Task Signature. | |||||||
> > | ||||||||
Changed: | ||||||||
< < | The Modifier for the row1 Parameter of the crop task: ![]() | |||||||
> > | Parameter modifiersEach parameter field in the input area of a task dialogue window corresponds to a | |||||||
Changed: | ||||||||
< < | Currently the system contains basic implementation for the simple types Boolean , Integer , Float , Long , Double , String and few more, so there's still a lot of space for improvements and contribution. You can find the general available modifiers in package herschel.ia.gui.apps.modifier ; please consult the Javadoc of your HIPE installation. | |||||||
> > | For instance, the crop task displays five input parameters: image , row1 , column1 , row2 , column2 : | |||||||
Changed: | ||||||||
< < | If the default parameter doesn't fit for your Task Parameter, you can:
| |||||||
> > | ![]() Boolean , Integer , Float , Long , Double , String and few more, so there is still a lot of room for improvements and contributions. You can find the general available modifiers in the herschel.ia.gui.apps.modifier package; please consult the Javadoc of your HIPE installation. | |||||||
Changed: | ||||||||
< < | Alternatively, you could want to write your specific Modifier for one of the already available types. In that case, you could create your modifier in a custom Signature Component. | |||||||
> > | If no default modifier fits your task parameter, you can implement a custom Modifier and register it to the system. You can also write your specific Modifier for one of the already available types. In that case, you can create your modifier in a custom Signature Component. | |||||||
![]() The following behaviours and limitations are present in the provided modifiers: | ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
Changed: | ||||||||
< < | Implement a Modifier | |||||||
> > | Implementing a modifier | |||||||
Changed: | ||||||||
< < | The ia.gui.apps.Modifier interface consists of two explicit contracts:
| |||||||
> > | Your modifier should extend AbstractModifier , which in turn implements the Modifier interface. Both reside in the ia.gui.apps.modifier package. The Modifier interface consists of two explicit contracts:
| |||||||
Changed: | ||||||||
< < | Register a Modifier | |||||||
> > | Registering a modifier | |||||||
Changed: | ||||||||
< < | The registration of the Modifier is done again in the __init__.py via the Extension Registry with the usual syntax (please note the name of the factory: factory.modifier).
Be aware that the registration is system wise so the registration overrides any other registered modifier for that type. | |||||||
> > | You can register your modifier via the Extension Registry with the following syntax (please note the name of the factory: factory.modifier ): | |||||||
REGISTRY.register(COMPONENT,Extension( | ||||||||
Line: 195 to 171 | ||||||||
"herschel.ia.MyClass") | ||||||||
Changed: | ||||||||
< < | In case the Modifier you have created is only applicable to a specific task or even to a specific parameter of a specific task, you can simply assign it to the applicable Task Parameter: | |||||||
> > | Be aware that the registration is system-wise, so it overrides any other registered modifier for that type. In case the modifier you have created is only applicable to a specific task or even to a specific parameter of a specific task, you can simply assign it to the applicable task parameter: | |||||||
// YourTask constructor | ||||||||
Line: 204 to 182 | ||||||||
... } | ||||||||
Changed: | ||||||||
< < | // Customize your modifiers | |||||||
> > | // Customise your modifiers | |||||||
@Override![]() | ||||||||
Line: 213 to 191 | ||||||||
} | ||||||||
Deleted: | ||||||||
< < | ||||||||
Changed: | ||||||||
< < | Signature Components | |||||||
> > | Signature components | |||||||
Changed: | ||||||||
< < | In case the default input area based on Modifiers doesn't fit your needs you can just replace it by your own implementation.
Rotate Alternative Signature (old): ![]() ![]() | |||||||
> > | In case the default input area based on modifiers does not fit your needs, you can replace it by your own implementation, and register it to the system. The following sections show you how this is done. | |||||||
Changed: | ||||||||
< < | If this is the case you need to:
Implement a Task Signature Component | |||||||
> > | Implementing a task signature component | |||||||
| ||||||||
Changed: | ||||||||
< < | The ia.task.gui.dialog.TaskSignatureComponent interface consists of four explicit contracts: | |||||||
> > | You can create a task signature component by extending JTaskSignatureComponent in the ia.task.gui.dialog package, and providing your own implementation of the makeModifierMap() method.
The JTaskSignatureComponent class implements the TaskSignatureComponent interface, which consists of four explicit contracts: | |||||||
| ||||||||
Deleted: | ||||||||
< < | and the two implicit contracts inherited by the Extension Registry
| |||||||
Changed: | ||||||||
< < | Conventions for labels for input parameters: to construct the labels of your parameters you can use the static function of class JTaskSignatureComponent public static JLabel getDecoratedLabel(TaskParameter tp, boolean isPrimeInput, String altName)it provides a decorated label (including tooltip) that follows the standard style. For the function to work properly your task parameters should be fully configured (for example, the parameter description will be the tooltip of the label) if present. | |||||||
> > | Task signature components must also honour two implicit contracts:
| |||||||
Changed: | ||||||||
< < | An easy way of implementing TaskSignatureComponent is by extending ia.task.gui.dialog.JTaskSignatureComponent and providing your own implementation for the makeModifierMap() method. | |||||||
> > | Conventions for labels for input parameters: to construct the labels of your parameters you can use the static function of class JTaskSignatureComponent public static JLabel getDecoratedLabel(TaskParameter tp, boolean isPrimeInput, String altName)it provides a decorated label (including tooltip) that follows the standard style. For the function to work properly your task parameters should be fully configured (for example, the parameter description will be the tooltip of the label) if present. | |||||||
For example, if you want to use a custom Signature Component that just wants to use ia.gui.apps.modifier.JFilePathModifier for a parameter aimed for a file name, you could do it like this: | ||||||||
Line: 912 to 879 | ||||||||
} | ||||||||
Deleted: | ||||||||
< < | ||||||||
<-- Author: JorgoBakker - 21 Dec 2007 --> |