Editing using the toolkit

Editing using the toolkit

There are a number of useful Swing JComponents available within the toolkit jar for building rich applications in Java quickly. For editing, the key UI components in the toolkit are the JEditToolsPicker, JTemplatePicker, PopupView, and the JAttachmentEditor. These components are very easy to program with, and they hide some of the low-level API details of editing features, editing attributes and tables, and adding attachment items to features when building editing apps. These components are also showcased in the Sample Application Viewer with the key code snippets highlighted for you to cut and paste.


This component provides all the editing tools your application needs to add, update, and delete features in a feature layer, all within a single Swing component that you can add to your visual application. It is also designed to allow the user to edit all feature layers at the same time or just individual layers in the map it is associated with.

From left to right, the tools are described as follows:

  1. Select/Add features to the current selection set
  2. Remove features from the selection
  3. Clear the selection set
  4. Delete selected feature or features
  5. For linear or polygon features, edit the verticies (move, add, delete)

Individual layers can be chosen for editing using the "Selected Layers" radio button:

Based on the layer type chosen for editing, some additional tools will appear on the toolbar. If the chosen layer is a point feature layer, it will appear as follows. The tool will add a point feature to the layer:

When a line or polygon layer is specified, the toolbar appears as follows:

In the application code, the JEditToolsPicker component is created by passing in a map that contains the feature layers to be edited.

// add edit tools picker
JEditToolsPicker editToolsPicker = new JEditToolsPicker(map);
jPanel.add(editToolsPicker, BorderLayout.NORTH);


This class extends JList to provide a list for picking feature "types" from "feature templates" provided by the feature layer itself. Feature templates have properties that define all the information required to create a feature. That is, they specify the exact symbology to draw when created and added to the map, and they specify the pre-determined schema of the feature and default attributes. Effective use of feature templates can help make your editing easier and more efficient.

In the example above, the map contains 2 feature layers. The first layer is called "Evacuations" with a simple yellow fill symbol, and the second layer is a point layer called "PointsOfInterest" with a unique value renderer for each type of interest. So, instead of adding "graphic elements" to the map, the editor is adding "campsites" or "evacuation areas" to the database, and they display with the correct symbology, as they should. This greatly streamlines the editing process down to fewer edits at a time.

The templates come directly from the feature layers in the map. The developer can control properties on the JTemplatPicker such as the size of the icons in the template and visibility of the text for each feature type. The following code shows how to add a JTemplatePicker to the user interface of an editing application.

// add template picker
JTemplatePicker jPicker = new JTemplatePicker(map);
jPanel.add(jPicker, BorderLayout.WEST);

A demonstration of the JTemplatePicker and the JEditToolsPicker working together in an editing app can be found in the Sample Viewer Application. The sample is called "Edit Tools".


The PopupView component can be used as a very simple way to edit the tabular attributes of features from a feature layer.

The PopupView can be created in a number of ways, for either editing or even for just showing the attribute names and values in a popup. In the following case, we create a PopupView that is going to allow the user to type in edits into the appropriate attribute fields. This view is created by calling the static "createEditView". It will display the attributes in a popup entitled "Edit Attributes" with the values displayed from non-null fields in the featureLayer.

PopupView content = PopupView.createEditView("Edit Attributes", featureLayer);

Once you have the PopupView defined, it is used with a MapPopup component that displays the PopupView in a dialog.

MapPopup popup = aMap.createPopup(new JComponent[]{content}, hitGraphic, true);                   

Going back to the PopupView for a moment, it uses a PopupViewListener to handle the Cancel, Save, or Zoom (if one exists) actions on the MapPopup dialog.

content.addPopupViewListener(new PopupViewListener() { 
 public void zoomToGraphic(PopupViewEvent popupViewEvent, Graphic _graphic) {
 public void commitEdit(PopupViewEvent popupViewEvent, Graphic _graphic) { 
 public void cancelEdit(PopupViewEvent popupViewEvent, Graphic _graphic) { 

To bring this together to make it work all work in your editing application, you will add an overlay to your map called the HitTestOverlay. This overlay uses a HitTestListener that sends back a list of hit graphics, if there were any graphic features near to where you clicked on the map. One of these graphics can then be used to construct your Popup in the code shown above.

HitTestOverlay hitTestOverlay = new HitTestOverlay(featureLayer); 
hitTestOverlay.addHitTestListener(new HitTestListener() { 
 public void graphicHit(HitTestEvent event) { 
  /// get first (top-most) graphic hit by the mouse 
  HitTestOverlay overlay = (HitTestOverlay) event.getSource(); 
  Graphic hitGraphic = overlay.getHitGraphics().get(0); 
  PopupView content = PopupView.createEditView("Edit Attributes", featureLayer);


In some situations, you may want to associate a downloadable file with a feature, whether it is a photo, spreadsheet or other kind of document. For example, you might want users to be able to click a feature representing a piece of real estate and see a link to a PDF file of the title deed. In the ArcGIS Runtime SDK for Java, an associated downloadable file like this is known as a "feature attachment".

The JAttachmentEditor is a JComponent in the ArcGIS_Runtime_Java_Toolkit.jar that helps users upload and view feature attachments. The JAttachmentEditor includes a list of current attachments, as well as an Add button that can be used to upload more attachments. The JAttachmentEditor can be added to your Swing apps easily by simply constructing it with a JMap that contains a Feature Layer, and by setting the Feature Layer as a JAttachmentEditor property.

JAttachmentEditor attachmentEditor = new JAttachmentEditor(jMap);
// Now, add the editor to your app...
JScrollPane scrollPane = new JScrollPane();
jPanel.add(panel, BorderLayout.WEST);

In order to use feature attachments, attachments must be "enabled" on the source feature class. You can enable attachments for a feature class in ArcCatalog or the Catalog window in ArcMap.