/**
   * DOCUMENT ME!
   *
   * @param mapContext DOCUMENT ME!
   * @param layer DOCUMENT ME!
   * @param duplicate DOCUMENT ME!
   * @throws ReadDriverException
   * @throws EditionException DOCUMENT ME!
   * @throws DriverIOException DOCUMENT ME!
   */
  public void saveToShp(MapContext mapContext, Annotation_Layer layer, String duplicate)
      throws ReadDriverException {
    try {
      JFileChooser jfc = new JFileChooser();
      SimpleFileFilter filterShp =
          new SimpleFileFilter("shp", PluginServices.getText(this, "shp_files"));
      jfc.setFileFilter(filterShp);

      if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
          == JFileChooser.APPROVE_OPTION) {
        File newFile = jfc.getSelectedFile();
        String path = newFile.getAbsolutePath();

        if (newFile.exists()) {
          int resp =
              JOptionPane.showConfirmDialog(
                  (Component) PluginServices.getMainFrame(),
                  PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo"),
                  PluginServices.getText(this, "guardar"),
                  JOptionPane.YES_NO_OPTION);

          if (resp != JOptionPane.YES_OPTION) {
            return;
          }
        }

        if (!(path.toLowerCase().endsWith(".shp"))) {
          path = path + ".shp";
        }

        newFile = new File(path);

        SelectableDataSource sds = layer.getRecordset();
        FieldDescription[] fieldsDescrip = sds.getFieldsDescription();

        ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter("Shape Writer");
        Driver driver = null;

        SHPLayerDefinition lyrDefPoint = new SHPLayerDefinition();
        lyrDefPoint.setFieldsDesc(fieldsDescrip);

        File filePoints = new File(path);
        lyrDefPoint.setFile(filePoints);
        lyrDefPoint.setName(filePoints.getName());
        lyrDefPoint.setShapeType(FShape.POINT);
        writer.setFile(filePoints);
        writer.initialize(lyrDefPoint);
        driver = getOpenAnnotationDriver(filePoints);
        writeFeatures(mapContext, layer, writer, driver, duplicate);
      }
    } catch (InitializeWriterException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (DriverLoadException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    } catch (IOException e) {
      throw new ReadDriverException(layerAnnotation.getName(), e);
    }
  }
  /** DOCUMENT ME! */
  public void performAction() {
    myWizardComponents.getFinishButton().setEnabled(false);

    Annotation_FieldSelect panel1 = (Annotation_FieldSelect) myWizardComponents.getWizardPanel(0);
    Annotation_ConfigureLabel panel2 =
        (Annotation_ConfigureLabel) myWizardComponents.getWizardPanel(1);

    SelectableDataSource source;
    Annotation_Mapping mapping = new Annotation_Mapping();

    try {
      source = this.layerAnnotation.getRecordset();

      mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));

      if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
        mapping.setColumnRotate(source.getFieldIndexByName(panel2.getAngleFieldName()));
      }

      if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
        mapping.setColumnColor(source.getFieldIndexByName(panel2.getColorFieldName()));
      }

      if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
        mapping.setColumnHeight(source.getFieldIndexByName(panel2.getSizeFieldName()));
      }

      if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
        mapping.setColumnTypeFont(source.getFieldIndexByName(panel2.getFontFieldName()));
      }
    } catch (ReadDriverException e) {
      NotificationManager.addError(e);
    }

    try {
      this.layerAnnotation.setMapping(mapping);
      // AttrInTableLabelingStrategy labeling = new
      // AttrInTableLabelingStrategy();
      ((Annotation_Legend) layerAnnotation.getLegend())
          .setUnits(panel2.getCmbUnits().getSelectedUnitIndex());
      // this.layerAnnotation.setLabelingStrategy(labeling);
      // ((FSymbol)
      // this.layerAnnotation.getLegend().getDefaultSymbol()).setFontSizeInPixels(panel2.sizeUnitsInPixels());
      saveToShp(map, this.layerAnnotation, panel1.getDuplicate());
    } catch (LegendLayerException e) {
      NotificationManager.addError(e);
    } catch (ReadDriverException e) {
      NotificationManager.addError(e);
    }

    this.myWizardComponents.getCancelAction().performAction();
  }