arcgissamples\editing\ShowDialogCommand.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Manage snap agents
arcgissamples\editing\ShowDialogCommand.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.editing;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import com.esri.arcgis.controls.BaseCommand;
import com.esri.arcgis.controls.EngineEditor;
import com.esri.arcgis.controls.HookHelper;
import com.esri.arcgis.controls.esriEngineEditState;

public class ShowDialogCommand extends BaseCommand {
  private static final long serialVersionUID = 1L;
  private HookHelper hookHelper;
  private EngineEditor editor;
  private JFrame mainWindow;
  private SnappingDialog dialog;
  public ShowDialogCommand(JFrame mainWindow){
    this.mainWindow = mainWindow;
  }
  public void onCreate(Object hook) {
    try{
      this.editor = new EngineEditor();
      this.hookHelper = new HookHelper();
      this.hookHelper.setHookByRef(hook);
      this.enabled = true;
      this.caption = "Snapping Dialog";
      this.name = "SnappingDialog";
    }catch(Exception e){
      e.printStackTrace();
    }
  }

  public void onClick() {
    try{
      if(editor.getEditState() ==
        esriEngineEditState.esriEngineStateNotEditing){
        //Prompt the user to start an edit session
        //Use Swing's EDT (event dispatching thread)
        SwingUtilities.invokeLater(new Runnable(){
          public void run() {
            JOptionPane.showMessageDialog(mainWindow,
              "Please start an edit session",
              "",
              JOptionPane.ERROR_MESSAGE
            );
          }
        });
      }else{
        //Display the Snapping dialog
        //Use Swing's EDT (event dispatching thread)
        SwingUtilities.invokeLater(new Runnable(){
          public void run() {
            if(dialog == null)
              dialog =
                new SnappingDialog(mainWindow,"Snapping Dialog");
            dialog.setVisible(true);
          }
        });
      }
    }catch(Exception e){
      e.printStackTrace();
    }
  }

}