public void preApply() {
    // collect new info for the active region
    double n = Double.parseDouble(northText.getText());
    double s = Double.parseDouble(southText.getText());
    double w = Double.parseDouble(westText.getText());
    double e = Double.parseDouble(eastText.getText());
    double xr = Double.parseDouble(xresText.getText());
    double yr = Double.parseDouble(yresText.getText());

    // write the region to file
    JGrassRegion newRegion = new JGrassRegion(w, e, s, n, xr, yr);
    try {
      File mapsetFile = new File(style.windPath).getParentFile();
      File locationFile = mapsetFile.getParentFile();
      JGrassRegion.writeWINDToMapset(mapsetFile.getAbsolutePath(), newRegion);
      CoordinateReferenceSystem locationCrs =
          JGrassCatalogUtilities.getLocationCrs(locationFile.getAbsolutePath());
      style.fAlpha = Float.parseFloat(forgroundAlphaText.getText());
      style.bAlpha = Float.parseFloat(backgroundAlphaText.getText());
      RGB bg = backgroundColour.getColorValue();
      style.backgroundColor = new Color(bg.red, bg.green, bg.blue);
      bg = foregroundColor.getColorValue();
      style.foregroundColor = new Color(bg.red, bg.green, bg.blue);
      style.doGrid = gridButton.getSelection();

      commitToBlackboards(newRegion, locationCrs, style.windPath);
      super.preApply();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
  }
  @Override
  public boolean performFinish() {
    // TODO create a nice workspace with the properties
    for (String m : props.mapsets) {
      System.out.println(m);
    }
    System.out.println(props.locationPath);
    System.out.println(props.north);
    System.out.println(props.xres);
    System.out.println(props.crs.getName().toString());

    try {
      JGrassRegion window =
          new JGrassRegion(
              props.west, props.east, props.south, props.north, props.xres, props.yres);
      JGrassCatalogUtilities.createLocation(props.locationPath, props.crs, window);
      for (String mapset : props.mapsets) {
        JGrassCatalogUtilities.createMapset(props.locationPath, mapset, null, null);
        // set the WIND file
        String mapsetPath = props.locationPath + File.separator + mapset;
        JGrassRegion.writeWINDToMapset(mapsetPath, window);
      }

      JGrassCatalogUtilities.addServiceToCatalog(
          props.locationPath + File.separator + JGrassCatalogUtilities.JGRASS_WORKSPACE_FILENAME,
          new NullProgressMonitor());
    } catch (IOException e) {
      JGrassPlugin.log(
          "JGrassPlugin problem: eu.hydrologis.udig.catalog.workspacecreation.wizard#NewJGrassLocationWizard#performFinish",
          e); //$NON-NLS-1$
      e.printStackTrace();
    }

    return true;
  }
  public static boolean createMapset(
      String locationPath, String mapset, CoordinateReferenceSystem crs, JGrassRegion window) {
    String path = locationPath + File.separator + mapset;

    /* Create mapset directory */
    if (!(new File(path).mkdirs())) return false;

    if (mapset.equals(JGrassConstants.PERMANENT_MAPSET)) {
      /* Create blank DEFAULT_WIND and WIND files */
      try {
        if (window != null) {
          JGrassRegion.writeWINDToMapset(path, window);
          JGrassRegion.writeDEFAULTWINDToLocation(locationPath, window);
        } else {
          // create blank windows
          BufferedWriter out =
              new BufferedWriter(
                  new FileWriter(path + File.separator + JGrassConstants.DEFAULT_WIND));
          out.write(JGrassRegion.BLACKBOARD_KEY);
          out.close();

          out = new BufferedWriter(new FileWriter(path + File.separator + JGrassConstants.WIND));
          out.write(JGrassRegion.BLANK_REGION);
          out.close();
        }

        /* Create projection files */
        if (crs != null) {
          // FIXME create GRASS proj files

          BufferedWriter prjOut =
              new BufferedWriter(new FileWriter(path + File.separator + JGrassConstants.PROJ_WKT));
          prjOut.write(crs.toWKT());
          prjOut.close();
        }
      } catch (IOException e) {
        JGrassPlugin.log(
            "JGrassPlugin problem: eu.hydrologis.udig.catalog.utils#JGrassCatalogUtilities#createMapset",
            e);
        e.printStackTrace();
        return false;
      }

    } else {
      /* Copy WIND file from PERMANENT mapset of this location */
      try {
        BufferedReader in =
            new BufferedReader(
                new FileReader(
                    locationPath
                        + File.separator
                        + JGrassConstants.PERMANENT_MAPSET
                        + File.separator
                        + JGrassConstants.DEFAULT_WIND));
        BufferedWriter out =
            new BufferedWriter(new FileWriter(path + File.separator + JGrassConstants.WIND));
        String line;
        while ((line = in.readLine()) != null) {
          out.write(line);
          out.write("\n");
        }
        out.close();
        in.close();
      } catch (IOException e) {
        JGrassPlugin.log(
            "JGrassPlugin problem: eu.hydrologis.udig.catalog.utils#JGrassCatalogUtilities#createMapset",
            e);
        e.printStackTrace();
        return false;
      }
    }

    /* Create point/site directories */
    if (!(new File(path + File.separator + JGrassConstants.SITE_LISTS).mkdirs())) return false;

    /* Create raster directories */
    if (!(new File(path + File.separator + JGrassConstants.FCELL).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.CELL).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.CELLHD).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.CATS).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.COLR).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.CELL_MISC).mkdirs())) return false;

    /* Create vector directories */
    if (!(new File(path + File.separator + JGrassConstants.DIG).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.DIG_ATTS).mkdirs())) return false;
    if (!(new File(path + File.separator + JGrassConstants.DIG_CATS).mkdirs())) return false;

    if (!createJGrassFolders(path)) return false;

    return true;
  }