Introduction
Tasks are functional units that accomplish a business operation in your application. The task framework provides an easy and systematic way of writing and executing custom tasks. A set of tasks are shipped with the Web ADF they are:
The above tasks are configurable from the Manager application when you create a new web application. The usage of these tasks does not require any programming knowledge.
The Web ADF provides a framework to write custom tasks. Some of the advantages of using the task framework are,
For information on how to configure and work with the pre-built task refer to documentation of the Manager application.
For information on how to write custom tasks refer to the section titled Writing a Custom Task
Task Framework
The task framework provides an easy way to write custom functionality in the form of tasks. Tasks are simple Java classes that follow conventions similar to JavaBean. The task framework introspects these classes and generates the necessary metadata information for providing the relevant html elements to interact with the task. It is possible to override the default introspection behavior by providing custom metadata information.
The framework is versatile enough to generate the metadata for your tasks that enables you to concentrate just on the functionality you are implementing. It also provides a way to specify custom metadata information to have control over fine grained details like using images for buttons and choosing different layouts for your task inputs.
Task Inputs
A task consists of three types of input elements parameters, commands and tools. The method signature in your java class determines the type of input.
public class Demo {
public void setParam1(String param1) {}
public String getParam1() {}
}
public class Demo {
public void myCommand(TaskEvent event) {}
}
public class Demo {
public void myTool(MapEvent event) {}
}
The methods for commands and parameters in the Java class have sufficient metadata information for the task framework to render their html represenation. With tools some additional information is needed, the framework has to know about the type of client side interaction the tool expects. These interactions could be dragging a rectangle, clicking a point, etc. The utility interface ClientActions provides the list of available client actions.
public class DemoTaskInfo extends SimpleTaskInfo {
public TaskToolDescriptorModel[ ] getToolDescriptors() {
return new TaskToolDescriptor[ ] {
new TaskToolDescriptor(Demo.class, "zoomIn", "Zoom In", ClientActions.EsriMapRectangle)};
}
}
Task Results
Most of the time the tasks generate some results. The results could be from a spatial query, geocoding, or results from a geo-processing operation. The task framework can work work with any arbitrary Java object as results. The task results support three types of information on them. They are
Task Visualization
The task framework by default, provides a simple html representation of the inputs in your tasks. More sophisticated html representation can be achieved by providing additional information in the TaskInfo class. You have already seen a TaskInfo class earlier that was used to describe the tool descriptors for a tool. The framework also supports three layout types: default, absolute, and tabular.
public class DemoTaskInfo extends SimpleTaskInfo {
private Class taskClass = DemoTask.class;
private TaskDescriptor taskDesc = null;
private TabularLayout[] taskLayout = null;
taskprivate TaskParamDescriptor[] taskParams = null;
private TaskToolDescriptor[] taskTools = null;
private TaskActionDescriptor[] taskActions = null;
public DemoTaskInfo() {
this.taskDesc = new TaskDescriptor(this.taskClass, "DemoTask", "Demo Task");
this.taskParams = new TaskParamDescriptor[1];
this.taskParams[0] = new TaskParamDescriptor(this.taskClass, "name", "City Name");
this.taskTools = new TaskToolDescriptor[1];
this.taskTools[0] = new TaskToolDescriptor(this.taskClass, "myTool", "Sample Tool", "EsriMapRectangle");
this.taskTools[0].setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);
this.taskActions = new TaskActionDescriptor[1];
taskActions[0] = new TaskActionDescriptor(this.taskClass, "myCommand", "Action");
toolDescs[0].setDefaultImage("images/box.gif");
toolDescs[0].setSelectedImage("images/boxD.gif");
toolDescs[0].setHoverImage("images/boxU.gif");
toolDescs[0].setDisabledImage("images/box.gif");
toolDescs[0].setToolTip("Select by Rectangle");
taskActions[0].setRendererType(TaskActionDescriptor.IMAGE_RENDERER_TYPE);
this.taskLayout = new TabularLayout[1];
this.taskLayout[0] = new TabularLayout();
this.taskLayout[0].setStyle("width:240px;");
this.taskLayout[0].setId("DemoTask");
this.taskLayout[0].addComponent(taskParams[0], new TabularLayout.TabularPosition(0, 0, 0, 4));
this.taskLayout[0].addComponent(taskParams[1], new TabularLayout.TabularPosition(1, 1, 0, 4));
this.taskLayout[0].addComponent(taskParams[2], new TabularLayout.TabularPosition(2, 2, 0, 4));
this.taskLayout[0].addComponent(taskParams[3], new TabularLayout.TabularPosition(3, 3, 0, 4));
this.taskLayout[0].addComponent(taskTools[0], new TabularLayout.TabularPosition(4, 0, 0, 0));
this.taskLayout[0].addComponent(taskActions[0], new TabularLayout.TabularPosition(4, 1, 0, 0));
this.taskLayout[0].addComponent(taskActions[1], new TabularLayout.TabularPosition(4, 2, 0, 0));
}
public TaskDescriptor getTaskDescriptor() {
return this.taskDesc;
}
public TaskLayout[] getTaskLayout() {
return this.taskLayout;
}
public TaskParamDescriptorModel[] getParamDescriptors() {
return this.taskParams;
}
public TaskToolDescriptorModel[] getToolDescriptors() {
return this.taskTools;
}
public TaskActionDescriptorModel[] getActionDescriptors() {
return this.taskActions;
}
}