Add Source Task
com\esri\arcgis\sample\AddSourceSample\AddSourceTaskInfo.java
/* Copyright 2010 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions.
* 
*/
package com.esri.arcgis.sample.AddSourceSample;

import com.esri.adf.web.data.tasks.SimpleTaskInfo;
import com.esri.adf.web.data.tasks.TabularLayout;
import com.esri.adf.web.data.tasks.TabularPosition;
import com.esri.adf.web.data.tasks.TaskActionDescriptor;
import com.esri.adf.web.data.tasks.TaskActionDescriptorModel;
import com.esri.adf.web.data.tasks.TaskDescriptor;
import com.esri.adf.web.data.tasks.TaskLayout;
import com.esri.adf.web.data.tasks.TaskParamDescriptor;
import com.esri.adf.web.data.tasks.TaskParamDescriptorModel;
import com.esri.adf.web.data.tasks.TaskToolDescriptor;

public class AddSourceTaskInfo extends SimpleTaskInfo {

  private TaskDescriptor taskDesc = null;

  private TaskActionDescriptor[] taskActions = null;

  private TaskParamDescriptor[] taskParams = null;

  private TabularLayout[] taskLayout = null;

  private TaskParamDescriptor addSourceParamLbl = null;
  private TaskParamDescriptor addSourceParam = null;

  private TaskActionDescriptor addSourceAction = null;

  public AddSourceTaskInfo() {
    taskDesc = new TaskDescriptor(AddSourceTask.class, "AddSource",
        "AddSource Overlay");

    // params
    addSourceParamLbl = new TaskParamDescriptor(AddSourceTask.class,
        "serverTypeLbl", "", "getServerTypeLbl", null);
    addSourceParam = new TaskParamDescriptor(AddSourceTask.class,
        "serverType", "", "getServerTypeList");
    addSourceParam.setRendererType(TaskParamDescriptor.SELECT_RENDERER_TYPE);
    taskParams = new TaskParamDescriptor[2];
    taskParams[0] = addSourceParam;
    taskParams[1] = addSourceParamLbl;

    // actions
    addSourceAction = new TaskActionDescriptor(AddSourceTask.class,
        "setAddSourceUI", "Select");
    addSourceAction.setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);
    taskActions = new TaskActionDescriptor[1];
    taskActions[0] = addSourceAction;

    // layout
    taskLayout = new TabularLayout[1];
    taskLayout[0] = new TabularLayout();
    taskLayout[0].setStyle("width:500px;");
    taskLayout[0].setId("Add Source Task");
    taskLayout[0].addComponent(addSourceParamLbl, new TabularPosition(0, 0, 0,
        0));
    taskLayout[0].addComponent(addSourceParam, new TabularPosition(0, 1, 0,
        0));
    taskLayout[0].addComponent(addSourceAction, new TabularPosition(0, 2,
        0, 0));
  }

  public TaskLayout[] getTaskLayout() {
    return taskLayout;
  }

  public TaskDescriptor getTaskDescriptor() {
    return taskDesc;
  }

  public TaskParamDescriptorModel[] getParamDescriptors() {
    return taskParams;
  }

  public TaskActionDescriptorModel[] getActionDescriptors() {
    return taskActions;
  }

  /*
   * public TaskToolDescriptorModel[] getToolDescriptors() { return taskTools; }
   */

  public void setUI(String serverType) {
    taskParams = null;
    taskActions = null;
    taskLayout[0] = new TabularLayout();
    taskLayout[0].setStyle("width:500px;");
    taskLayout[0].setStyleClass("table{table-layout:fixed}");

    if (serverType.equals("ARCGIS_SERVER_LOCAL")) {
      // params
      taskParams = new TaskParamDescriptor[12];
      taskParams[0] = addSourceParamLbl;
      taskParams[1] = addSourceParam;
      taskParams[2] = new TaskParamDescriptor(AddSourceTask.class,
          "agsServerNameLbl","", "getAgsServerNameLbl", null);
      taskParams[3] = new TaskParamDescriptor(AddSourceTask.class,
          "agsServerName", "");
      taskParams[4] = new TaskParamDescriptor(AddSourceTask.class,
          "agsDomainLbl", "", "getAgsDomainLbl", null);
      taskParams[5] = new TaskParamDescriptor(AddSourceTask.class,
          "agsDomain", "");
      taskParams[6] = new TaskParamDescriptor(AddSourceTask.class,
          "agsUserNameLbl", "", "getAgsUserNameLbl", null);
      taskParams[7] = new TaskParamDescriptor(AddSourceTask.class,
          "agsUserName", "");
      taskParams[8] = new TaskParamDescriptor(AddSourceTask.class,
          "agsPasswordLbl", "", "getAgsPasswordLbl", null);
      taskParams[9] = new TaskParamDescriptor(AddSourceTask.class,
          "ags_password", "");
      taskParams[10] = new TaskParamDescriptor(AddSourceTask.class,
          "agsObjectNameLbl", "", "getAgsObjectNameLbl", null);
      taskParams[11] = new TaskParamDescriptor(AddSourceTask.class,
          "agsObjectName", "", "getServicesList");
      taskParams[11]
          .setRendererType(TaskParamDescriptor.SELECT_RENDERER_TYPE);

      // actions
      taskActions = new TaskActionDescriptor[3];
      taskActions[0] = addSourceAction;
      taskActions[1] = new TaskActionDescriptor(AddSourceTask.class,
          "connectToFetchList", "Connect");
      taskActions[1]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);
      taskActions[1].setStyle("text-align:center;");
      taskActions[2] = new TaskActionDescriptor(AddSourceTask.class,
          "addAgsLocalSource", "Add to map");
      taskActions[2]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);

      // layout
      taskLayout[0].setId("Add AGS source");
      taskLayout[0].addComponent(taskParams[0], new TabularPosition(0, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[1], new TabularPosition(0, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[0], new TabularPosition(0,
          2, 0, 0));
      taskLayout[0].addComponent(taskParams[2], new TabularPosition(1, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[3], new TabularPosition(1, 1,
          0, 0));
      taskLayout[0].addComponent(taskParams[4], new TabularPosition(2, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[5], new TabularPosition(2, 1,
          0, 0));
      taskLayout[0].addComponent(taskParams[6], new TabularPosition(3, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[7], new TabularPosition(3, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[8], new TabularPosition(4, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[9], new TabularPosition(4, 0,
          0, 0));
      taskLayout[0].addComponent(taskActions[1], new TabularPosition(5,
          1, 0, 0));
      taskLayout[0].addComponent(taskParams[10], new TabularPosition(6, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[11], new TabularPosition(6, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[2], new TabularPosition(7, 1,
          0, 0));
    }
    if (serverType.equals("ARCGIS_SERVER_INTERNET")) {
      // params
      taskParams = new TaskParamDescriptor[6];
      taskParams[0] = addSourceParamLbl;
      taskParams[1] = addSourceParam;
      taskParams[2] = new TaskParamDescriptor(AddSourceTask.class,
          "agsInternetCatalogURLLbl", "", "getAgsInternetCatalogURLLbl", null);
      taskParams[3] = new TaskParamDescriptor(AddSourceTask.class,
          "agsInternetCatalogURL", "");
      taskParams[4] = new TaskParamDescriptor(AddSourceTask.class,
          "agsInternetURLLbl", "", "getAgsInternetURLLbl", null);
      taskParams[5] = new TaskParamDescriptor(AddSourceTask.class,
          "agsInternetURL", "", "getServicesList");
      taskParams[5]
          .setRendererType(TaskParamDescriptor.SELECT_RENDERER_TYPE);

      // actions
      taskActions = new TaskActionDescriptor[3];
      taskActions[0] = addSourceAction;
      taskActions[1] = new TaskActionDescriptor(AddSourceTask.class,
          "connectToFetchList", "Connect");
      taskActions[1]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);
      taskActions[2] = new TaskActionDescriptor(AddSourceTask.class,
          "addAgsInternetSource", "Add to map");
      taskActions[2]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);

      // layout
      taskLayout[0].setId("Add AGS Internet Source");
      taskLayout[0].addComponent(taskParams[0], new TabularPosition(0, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[1], new TabularPosition(0, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[0], new TabularPosition(0,
          2, 0, 0));
      taskLayout[0].addComponent(taskParams[2], new TabularPosition(1, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[3], new TabularPosition(1, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[1], new TabularPosition(2,
          1, 0, 0));
      taskLayout[0].addComponent(taskParams[4], new TabularPosition(3, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[5], new TabularPosition(3, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[2], new TabularPosition(4,
          1, 0, 0));
    }
    if (serverType.equals("ARCIMS")) {
      // params
      taskParams = new TaskParamDescriptor[12];
      taskParams[0] = addSourceParamLbl;
      taskParams[1] = addSourceParam;
      taskParams[2] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsHostLbl", "", "getAimsHostLbl", null);
      taskParams[3] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsHost", "");
      taskParams[4] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsPortLbl", "", "getAimsPortLbl", null);
      taskParams[5] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsPort", "");
      taskParams[6] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsUsernameLbl", "", "getAimsUsernameLbl", null);
      taskParams[7] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsUsername", "");
      taskParams[8] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsPasswordLbl", "", "getAimsPasswordLbl", null);
      taskParams[9] = new TaskParamDescriptor(AddSourceTask.class,
          "aims_password", "");
      taskParams[10] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsServiceLbl", "", "getAimsServiceLbl", null);
      taskParams[11] = new TaskParamDescriptor(AddSourceTask.class,
          "aimsService", "", "getServicesList");
      taskParams[11]
          .setRendererType(TaskParamDescriptor.SELECT_RENDERER_TYPE);

      // actions
      taskActions = new TaskActionDescriptor[3];
      taskActions[0] = addSourceAction;
      taskActions[1] = new TaskActionDescriptor(AddSourceTask.class,
          "connectToFetchList", "Connect");
      taskActions[1]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);
      taskActions[2] = new TaskActionDescriptor(AddSourceTask.class,
          "addAimsSource", "Add to map");
      taskActions[2]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);

      // layout
      taskLayout[0].setId("Add AIMS Source");
      taskLayout[0].addComponent(taskParams[0], new TabularPosition(0, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[1], new TabularPosition(0, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[0], new TabularPosition(0,
          2, 0, 0));
      taskLayout[0].addComponent(taskParams[2], new TabularPosition(1, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[3], new TabularPosition(1, 1,
          0, 0));
      taskLayout[0].addComponent(taskParams[4], new TabularPosition(2, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[5], new TabularPosition(2, 1,
          0, 0));
      taskLayout[0].addComponent(taskParams[6], new TabularPosition(3, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[7], new TabularPosition(3, 1,
          0, 0));
      taskLayout[0].addComponent(taskParams[8], new TabularPosition(4, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[9], new TabularPosition(4, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[1], new TabularPosition(5,
          1, 0, 0));
      taskLayout[0].addComponent(taskParams[10], new TabularPosition(6, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[11], new TabularPosition(6, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[2], new TabularPosition(7,
          1, 0, 0));

    }
    if (serverType.equals("ARCWMS")) {
      // params
      taskParams = new TaskParamDescriptor[4];
      taskParams[0] = addSourceParamLbl;
      taskParams[1] = addSourceParam;
      taskParams[2] = new TaskParamDescriptor(AddSourceTask.class,
          "wmsURLLbl", "", "getWmsURLLbl", null);
      taskParams[3] = new TaskParamDescriptor(AddSourceTask.class,
          "wmsURL", "");

      // actions
      taskActions = new TaskActionDescriptor[2];
      taskActions[0] = addSourceAction;
      taskActions[1] = new TaskActionDescriptor(AddSourceTask.class,
          "addWMSSource", "Add to map");
      taskActions[1]
          .setRendererType(TaskToolDescriptor.TEXT_RENDERER_TYPE);

      // layout
      taskLayout[0].setId("Add WMS Source");
      taskLayout[0].addComponent(taskParams[0], new TabularPosition(0, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[1], new TabularPosition(0, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[0], new TabularPosition(0,
          2, 0, 0));
      taskLayout[0].addComponent(taskParams[2], new TabularPosition(1, 0,
          0, 0));
      taskLayout[0].addComponent(taskParams[3], new TabularPosition(1, 1,
          0, 0));
      taskLayout[0].addComponent(taskActions[1], new TabularPosition(2,
          1, 0, 0));
    }
  }

}