public void execute(final MapContext viewContext, final ILayer layer) {

    try {
      RasterLegend legend = (RasterLegend) layer.getRasterLegend()[0];
      final RasterDefaultStyleUIPanel rasterDefaultStyleUIClass =
          new RasterDefaultStyleUIPanel(legend, layer.getRaster().getDefaultColorModel());

      if (UIFactory.showDialog(rasterDefaultStyleUIClass)) {
        ColorModel colorModel = rasterDefaultStyleUIClass.getColorModel();
        float opacity = rasterDefaultStyleUIClass.getOpacity();
        if (colorModel == null) {
          colorModel = legend.getColorModel();
        }
        RasterLegend newLegend = new RasterLegend(colorModel, opacity);
        layer.setLegend(newLegend);
      }

    } catch (DriverException e) {
      Services.getErrorManager().error("Cannot get the legend", e);
    } catch (IOException e) {
      Services.getErrorManager().error("Cannot get the default style", e);

      Services.getErrorManager().error("Cannot get the default style", e);
    }
  }
 @Override
 public void run(ProgressMonitor pm) {
   try {
     logger.debug("Info query: " + sql);
     final DataSource ds =
         ((DataManager) Services.getService(DataManager.class))
             .getDataSourceFactory()
             .getDataSourceFromSQL(sql, pm);
     if (!pm.isCancelled()) {
       try {
         Services.getService(InformationManager.class).setContents(ds);
       } catch (DriverException e) {
         Services.getErrorManager().error("Cannot show the data", e);
       }
     }
   } catch (DataSourceCreationException e) {
     Services.getErrorManager().error("Cannot get the result", e);
   } catch (DriverException e) {
     Services.getErrorManager().error("Cannot access the data", e);
   } catch (DriverLoadException e) {
     Services.getErrorManager().error("Cannot execute the query", e);
   } catch (ParseException e) {
     Services.getErrorManager().error("Cannot parse the instruction", e);
   }
 }
  public void setElement(EditableElement element) {
    MapContext mapContext = (MapContext) element.getObject();
    try {
      mapControl.setMapContext(mapContext);
      mapControl.setElement(element);
      mapControl.setDefaultTool(getIndependentToolInstance(defaultTool, defaultMouseCursor));
      mapControl.initMapControl();
      mapEditor.setContentPane(mapControl);
      mapToolBar.setPreferredSize(new Dimension(mapControl.getWidth(), 30));
      mapToolBar.setFloatable(false);
      mapEditor.add(mapToolBar, BorderLayout.PAGE_END);

    } catch (TransitionException e) {
      Services.getErrorManager().error(I18N.getString("orbisgis.core.tool.not_valid"), e);
    } catch (InstantiationException e) {
      Services.getErrorManager().error(I18N.getString("orbisgis.core.tool.not_valid"), e);
    } catch (IllegalAccessException e) {
      Services.getErrorManager().error(I18N.getString("orbisgis.core.tool.not_valid"), e);
    }

    this.mapElement = element;
  }
  public void execute(MapContext mapContext, ILayer layer) {
    try {

      final String geoRasterResult = evaluateResult(layer, mapContext);

      if (null != geoRasterResult) {
        // save the computed GeoRaster in a tempFile
        final DataSourceFactory dsf =
            ((DataManager) Services.getService(DataManager.class)).getDSF();

        DataSource dsResult = dsf.getDataSourceFromSQL(geoRasterResult);

        // populate the GeoView TOC with a new RasterLayer
        DataManager dataManager = (DataManager) Services.getService(DataManager.class);
        final ILayer newLayer = dataManager.createLayer(dsResult);
        mapContext.getLayerModel().insertLayer(newLayer, 0);
      }
    } catch (IOException e) {
      Services.getErrorManager().error("Cannot compute " + layer.getName(), e);
    } catch (LayerException e) {
      Services.getErrorManager()
          .error("Cannot insert resulting layer based on " + layer.getName(), e);
    } catch (DriverException e) {
      Services.getErrorManager().error("Cannot read the raster from the layer ", e);
    } catch (DriverLoadException e) {
      Services.getErrorManager().error("Cannot create the resulting layer of raster type ", e);
    } catch (OperationException e) {
      Services.getErrorManager().error("Error during the raster operation", e);
    } catch (DataSourceCreationException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (SemanticException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if ("modify".equals(e.getActionCommand())) {
      try {
        File globals = new File(configPath);

        // Table creation
        GdmsWriter globalsGW = new GdmsWriter(globals);
        String[] fieldNames1 = {
          "bufferSize",
          "amenitiesWeighting",
          "constructibilityWeighting",
          "idealhousingWeighting",
          "gaussDeviation",
          "segregationThreshold",
          "segregationTolerance",
          "householdMemory",
          "movingThreshold",
          "immigrantNumber",
          "numberOfTurns",
          "year",
          "threshold_1",
          "threshold_2",
          "threshold_3",
          "threshold_4"
        };

        org.gdms.data.types.Type integ = TypeFactory.createType(64);
        org.gdms.data.types.Type doubl = TypeFactory.createType(16);
        org.gdms.data.types.Type[] fieldTypes1 = {
          doubl, doubl, doubl, doubl, doubl, doubl, doubl, integ, doubl, integ, integ, integ, doubl,
          doubl, doubl, doubl
        };
        Metadata m1 = new DefaultMetadata(fieldTypes1, fieldNames1);
        globalsGW.writeMetadata(0, m1);

        // Table filling
        Map<String, JSpinner> sp = spp.getSpinners();
        Double hM = (Double) sp.get("householdMemory").getValue();
        Integer hMi = hM.intValue();
        Double iN = (Double) sp.get("immigrantNumber").getValue();
        Integer iNi = iN.intValue();
        Double nOT = (Double) sp.get("numberOfTurns").getValue();
        Integer nOTi = nOT.intValue();
        Double y = (Double) sp.get("year").getValue();
        Integer yi = y.intValue();
        globalsGW.addValues(
            new Value[] {
              ValueFactory.createValue((Double) sp.get("bufferSize").getValue()),
              ValueFactory.createValue((Double) sp.get("amenitiesWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("constructibilityWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("idealhousingWeighting").getValue()),
              ValueFactory.createValue((Double) sp.get("gaussDeviation").getValue()),
              ValueFactory.createValue((Double) sp.get("segregationThreshold").getValue()),
              ValueFactory.createValue((Double) sp.get("segregationTolerance").getValue()),
              ValueFactory.createValue(hMi),
              ValueFactory.createValue((Double) sp.get("movingThreshold").getValue()),
              ValueFactory.createValue(iNi),
              ValueFactory.createValue(nOTi),
              ValueFactory.createValue(yi),
              ValueFactory.createValue((Double) sp.get("threshold_1").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_2").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_3").getValue()),
              ValueFactory.createValue((Double) sp.get("threshold_4").getValue()),
            });

        // Table closing
        globalsGW.writeRowIndexes();
        globalsGW.writeExtent();
        globalsGW.writeWritenRowCount();
        globalsGW.close();

        try {
          if (spp.getSelections().get("statistical").isSelected()) {
            new LaunchFrame(configPath, "statistical");
          } else if (spp.getSelections().get("schelling").isSelected()) {
            new LaunchFrame(configPath, "schelling");
          }
        } catch (DriverException ex) {
          Services.getErrorManager().error("Driver Exception", ex);
          JOptionPane.showMessageDialog(
              this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
          return;
        } catch (DataSourceCreationException ex) {
          Services.getErrorManager().error("DataSourceCreation Exception", ex);
          JOptionPane.showMessageDialog(
              this,
              "Some DataSource creation error has occurred.",
              "DataSource Creation Error",
              JOptionPane.WARNING_MESSAGE);
          return;
        }
        dispose();
      } catch (IOException ex) {
        Services.getErrorManager().error("I/O Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some I/O error has occurred.", "I/O Error", JOptionPane.WARNING_MESSAGE);
        return;
      } catch (DriverException ex) {
        Services.getErrorManager().error("Driver Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
        return;
      }

    } else {
      try {
        new LaunchFrame(configPath, oldChoice);
      } catch (DriverException ex) {
        Services.getErrorManager().error("Driver Exception", ex);
        JOptionPane.showMessageDialog(
            this, "Some driver error has occurred.", "Driver Error", JOptionPane.WARNING_MESSAGE);
        return;
      } catch (DataSourceCreationException ex) {
        Services.getErrorManager().error("DataSourceCreation Exception", ex);
        JOptionPane.showMessageDialog(
            this,
            "Some DataSource creation error has occurred.",
            "DataSource Creation Error",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      dispose();
    }
  }