@Override
 public void propertyChanged(String key) {
   // Auto-generate an output name from the input grid.
   if (key.equals(_inputGrid.getKey())) {
     updateOutputName();
   } else if (key.equals(_filterMethodProp.getKey())) {
     _kernelString.set(getKernel());
     updateOutputName();
   } else if (key.equals(_size.getKey())) {
     if (_filterMethodProp.get().getFilter().validateSize(_size.get())) {
       _kernelString.set(getKernel());
       updateOutputName();
     }
   }
 }
  public void updateOutputName() {

    String nameSuffix = "_" + _filterMethodProp.get().getAbbrev() + _size.get();
    String outputName =
        _inputGrid.isNull()
            ? ""
            : _inputGrid
                .get()
                .getMapper()
                .createOutputDisplayName(_inputGrid.get().getDisplayName(), nameSuffix);
    _outputGridName.set(outputName);
  }
 public String getKernel() {
   float[][] kernel = _filterMethodProp.get().getFilter().getDefaultKernel(_size.get());
   StringBuilder builder = new StringBuilder();
   Formatter formatter = new Formatter(builder);
   for (float[] row : kernel) {
     for (float element : row) {
       formatter.format(" %11.9f", element);
     }
     formatter.format("\n");
   }
   return builder.toString();
 }
  /** @throws CoreException */
  @Override
  public void run(IProgressMonitor monitor, ILogger logger, IRepository repository)
      throws CoreException {

    Grid3d property = _inputGrid.get();
    int size = _size.get();
    String propertyName = _outputGridName.get();
    String outputComments = _outputComments.get();
    float[][] kernel = _filterMethodProp.get().getFilter().getDefaultKernel(_size.get());

    // apply the filter on the horizon
    float[][] result = _filterMethodProp.get().getFilter().execute(property, size, kernel, monitor);

    // Create the new property
    Grid3d newProperty = Grid3dFactory.create(repository, property, result, propertyName);
    newProperty.setComment(outputComments);
    try {
      newProperty.update();
    } catch (IOException ex) {
      throw new RuntimeException(ex.getMessage());
    }
  }
  @Override
  public void validate(IValidation results) {
    // Validate the input grid is non-null and of the correct type.
    if (_inputGrid.isNull()) {
      results.error(_inputGrid, "No input grid specified.");
    }

    // Validate the output name is non-zero length.
    if (_outputGridName.isEmpty()) {
      results.error(_outputGridName, "No output grid name specified.");
    }

    // Validate the filter size
    if (!_filterMethodProp.get().getFilter().validateSize(_size.get())) {
      results.error(_size, _filterMethodProp.get().getFilter().getMessage());
    }

    // Check if an entry already exists in the datastore.
    if (!_inputGrid.isNull() && !_outputGridName.isEmpty()) {
      if (Grid3dFactory.existsInStore(_inputGrid.get(), _outputGridName.get())) {
        results.warning(_outputGridName, "Exists in datastore and will be overwritten.");
      }
    }
  }
  @Override
  public void buildView(IModelForm form) {
    // Build the input parameters section.
    FormSection inputSection = form.addSection("Input", false);
    inputSection.addEntityComboField(_inputGrid, Grid3d.class);

    inputSection.addListSelectionField(_filterMethodProp.getKey(), FilterMethod.values());

    FormSection parametersSection = form.addSection("Parameters", false);
    parametersSection.addTextField(_size);
    parametersSection.addTextBox(_kernelString);

    // Build the output parameters section.
    FormSection outputSection = form.addSection("Output", false);
    outputSection.addTextField(_outputGridName);
    outputSection.addTextBox(_outputComments);
  }