arcgissamples\soe\pp\JavaSimpleRESTSOEWithPropertiesPropPage.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Simple REST SOE With properties sample
arcgissamples\soe\pp\JavaSimpleRESTSOEWithPropertiesPropPage.java
/* Copyright 2015 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 at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
package arcgissamples.soe.pp;

import java.io.IOException;
import java.util.HashMap;
import java.util.Set;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.interop.extn.ArcGISCategories;
import com.esri.arcgis.interop.extn.ArcGISExtension;
import com.esri.arcgis.server.BaseSOEPropertyPage;

@ArcGISExtension(categories = ArcGISCategories.AGSExtensionParameterPage)
public class JavaSimpleRESTSOEWithPropertiesPropPage extends
  BaseSOEPropertyPage {
    private static final long serialVersionUID = 1L;

    /* The SOE property names */
    public static final String LAYER_TYPE = "layerType";
    public static final String RETURN_FORMAT = "returnFormat";
    public static final String MAX_FEATURES = "maxNumFeatures";
    public static final String IS_EDITABLE = "isEditable";

    /* Default property values */
    public static final String FEATURE_LAYER = "Feature";
    public static final String JSON_FORMAT = "JSON";
    public static final String DEFAULT_COUNT = "100";
    public static final Boolean FLAG = false;

    /* The SOE name */
    private String soeName = "JavaSimpleRESTSOEWithProperties";

    /* The UI */
    PropertyPageUI ppUI = null;

    /* The modified property values to return */
    String layerType = "";
    String returnFormat = "";
    String maxFeatures = "";
    String isEditable = "";

    @Override
    @SuppressWarnings("all")
    public void apply(HashMap soProps, HashMap extnProps) throws IOException,
      AutomationException {
  try {
      SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
        /* Access UI on EDT */
        layerType = ppUI.getLayerType();
        returnFormat = ppUI.getReturnFormat();
        maxFeatures = ppUI.getMaxFeatures();
        isEditable = ppUI.getIsEditable();

        /*
         * User clicked OK and the Property page will be dismissed
         * shortly. Dispose the Java frame.
         */
        ppUI.dispose();
    }
      });
  } catch (Exception e) {
      e.printStackTrace();
  }

  /* Set them in the Map */
  Set<String> keys = extnProps.keySet();
  for (String key : keys) {
      if (key.equals(LAYER_TYPE))
    extnProps.put(key, layerType);
      else if (key.equals(RETURN_FORMAT))
    extnProps.put(key, returnFormat);
      else if (key.equals(MAX_FEATURES))
    extnProps.put(key, maxFeatures);
      else if (key.equals(IS_EDITABLE))
    extnProps.put(key, isEditable);
  }
    }

    /**
     * Returns the name of the SOE
     */
    public String getServerObjectExtensionType() throws IOException,
      AutomationException {
  return soeName;
    }

    /**
     * Returns the Server Object (MapServer, GeocodeServer, etc) that the SOE is
     * an extension to.
     */
    public String getServerObjectType() throws IOException, AutomationException {
  return "MapServer";
    }

    /**
     * Constructs a returns a JFrame containing the user interface that will be
     * shown in ArcCatalog
     */
    @Override
    @SuppressWarnings("all")
    public JFrame initGUI(HashMap soProps, HashMap extnProps) {
  /* Set the look and feel to match the operating system */
  try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  } catch (Exception ex) {/* ignore */
  }

  /* Set up good defaults if no properties are provided */
  String layerType = FEATURE_LAYER;
  String returnFormat = JSON_FORMAT;
  String maxNumFeatures = DEFAULT_COUNT;
  boolean isEditable = FLAG;

  /* Override defaults with properties passed in */
  if (extnProps != null && !extnProps.isEmpty()) {
      if (extnProps.containsKey(LAYER_TYPE)
        && !extnProps.get(LAYER_TYPE).equals(""))
    layerType = (String) extnProps.get(LAYER_TYPE);

      if (extnProps.containsKey(RETURN_FORMAT)
        && !extnProps.get(RETURN_FORMAT).equals(""))
    returnFormat = (String) extnProps.get(RETURN_FORMAT);

      if (extnProps.containsKey(MAX_FEATURES)
        && !extnProps.get(MAX_FEATURES).equals(""))
    maxNumFeatures = (String) extnProps.get(MAX_FEATURES);

      if (extnProps.containsKey(IS_EDITABLE)
        && !extnProps.get(IS_EDITABLE).equals(""))
    isEditable = new Boolean((String) extnProps.get(IS_EDITABLE));
  }

  /* Create Property Page UI */
  ppUI = new PropertyPageUI(this);

  /* Initialize it with default values */
  ppUI.initPage(soeName, layerType, returnFormat, maxNumFeatures,
    isEditable);

  /* return the UI to ArcCatalog */
  return ppUI;
    }

    /**
     * 
     * @param extnProps
     */
    void initProps(HashMap<String, String> extnProps) {
  if (extnProps.size() > 0)
      return;
  extnProps.put(LAYER_TYPE, FEATURE_LAYER);
  extnProps.put(RETURN_FORMAT, JSON_FORMAT);
  extnProps.put(MAX_FEATURES, DEFAULT_COUNT);
  extnProps.put(IS_EDITABLE, FLAG.toString());
    }

    /**
     * Informs ArcCatalog that property values have changed on the UI.
     */
    public void firePageChanged() {
  try {
      pageChanged();
  } catch (Exception ex) {/* ignore */
  }
    }
}