Introduction to the task framework


In this topic


Web ADF tasks

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. The following tasks ship with the Web Application Developer Framework (ADF).
  • Navigation
  • Geoprocessing
  • Search by attributes
  • Predefined query
  • Editing
  • Find address
  • Find Place
These tasks can be configured from the Manager application when you create a Web application. No programming knowledge is required to use these tasks.
The Web ADF provides a framework to write custom tasks. Some of the advantages of using the task framework are as follows:
  • Tight integration with the ADF
  • Event handling with actions and tools
  • Automatic generation of user interface
  • Encapsulate related functionality
  • Implementation follows standard JavaBeans development
  • All tasks are Asynchronous JavaScript and XML (AJAX) enabled

Task framework

The task framework allows you to write custom functionality in the form of tasks. Tasks are simple Java classes that follow conventions similar to JavaBeans. The task framework introspects these classes and generates the necessary metadata information for providing the relevant Hypertext Markup Language (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 enabling you to concentrate solely on the functionality you are implementing. It also provides a way to specify custom metadata information for control over fine grained details such as using images for buttons and choosing different layouts for your task inputs.

Task inputs

A task consists of the following three types of input elements.
  • Parameters
  • Commands
  • Tools
The method signature in your Java class determines the type of input.
Parameters provide the textual inputs needed by the task, for example, layer name, zoom factor, and so on. These are usually represented as HTML input boxes and select boxes on the Web page. The setters and getters in the Java class are interpreted as parameters. A parameter is represented in the Java class as shown in the following code sample.
[Java]
public class Demo{
    public void setParam1(String param1){}
    public String getParam1(){}
}
Commands are actions that trigger the execution of a task—for example, zoom to full extent. Commands are represented as HTML buttons on the Web page. Methods that take TaskEvent as an argument are interpreted as commands. A command is represented in the Java class as shown in the following code sample.
[Java]
public class Demo{
    public void myCommand(TaskEvent event){}
}
Tools are actions that require interaction on the map to trigger the execution of a task, for example, identify, dynamic map navigation (zoom in and zoom out), and so on. On the Web page, these buttons require interactions such as drawing a rectangle, clicking a point, and so on. Methods that take MapEvent as an argument are interpreted as tools. A tool is represented in the Java class as shown in the following code sample.
[Java]
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 representation. With tools, additional information is needed—for example, the framework has to know the type of client side interaction the tool expects. Examples of these interactions are dragging a rectangle, clicking a point, and so on. The utility interface ClientActions provides the list of available client actions as shown in the following code sample.
[Java]
public class DemoTaskInfo extends SimpleTaskInfo{
    public TaskToolDescriptorModel[] getToolDescriptors(){
        return new TaskToolDescriptor[]{
            new TaskToolDescriptor(Demo.class, "zoomIn", "Zoom In",
                ClientActions.MAP_RECTANGLE)
        };
    }
}

Task results

Tasks generate results most of the time. The results can be from a spatial query, geocoding, or a geoprocessing operation. The task framework can work with any arbitrary Java object as results. The task results support the following three types of information.
  • Display text
  • Result details
  • Actions that can be performed on the results
By default, the task results are visualized in the form of a tree. The framework also supports representation of the results in other forms. The following diagram shows the task result items as they are visualized in a Web application.

Task visualization

By default, the task framework 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. As discussed previously, a TaskInfo class was used to describe the tool descriptors for a tool. The framework also supports the following three layout types.
  • Default
  • Absolute
  • Tabular
This is shown in the following sample code.
[Java]
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;
    }
}


See Also:

Writing a custom task
Writing an advanced custom task