/**
   * Reload the service, to which the location refers to. This is ment to be used when new maps are
   * added inside a mapset and the catalog doesn't care to see them. So the tree has to be reloaded.
   *
   * @param locationPath the path to the affected location
   * @param monitor the progress monitor
   */
  public static void refreshJGrassService(String locationPath, final IProgressMonitor monitor) {

    System.out.println("Lock on locationPath = " + Thread.holdsLock(locationPath));
    synchronized (locationPath) {

      /*
       * if the catalog is active, refresh the location in the catalog window
       */
      ID id = null;
      if (JGrassPlugin.getDefault() != null) {
        File locationFile = new File(locationPath);
        try {
          id = new ID(locationFile.toURI().toURL());
        } catch (MalformedURLException e) {
          e.printStackTrace();
          return;
        }
      } else {
        return;
      }
      /*
       * test code to make the catalog understand that the map should be added
       */
      final ICatalog catalog = CatalogPlugin.getDefault().getLocalCatalog();
      final JGrassService originalJGrassService = catalog.getById(JGrassService.class, id, monitor);

      /*
       * create the same service
       */
      if (originalJGrassService == null) return;
      final URL ID = originalJGrassService.getIdentifier();
      Map<String, Serializable> connectionParams = originalJGrassService.getConnectionParams();
      IServiceFactory locator = CatalogPlugin.getDefault().getServiceFactory();
      final List<IService> rereadService = locator.acquire(ID, connectionParams);

      /*
       * replace the service
       */
      if (rereadService.size() > 0) {
        Runnable refreshCatalogRunner =
            new Runnable() {
              public void run() {
                final IService newJGrassService = rereadService.get(0);
                catalog.remove(originalJGrassService);
                catalog.add(newJGrassService);
              }
            };

        new Thread(refreshCatalogRunner).start();
      }
    }
  }
Ejemplo n.º 2
0
  public static void load(String mapname) {
    if (JGrassPlugin.getDefault() != null) {
      JGrassMapGeoResource addedMap =
          JGrassCatalogUtilities.addMapToCatalog(
              p_locationPath, p_mapsetName, mapname, JGrassConstants.GRASSBINARYRASTERMAP);
      if (addedMap == null)
        p_err.println("An error occurred while trying to add the map to the catalog.");

      IMap activeMap = ApplicationGIS.getActiveMap();
      ApplicationGIS.addLayersToMap(
          activeMap,
          Collections.singletonList((IGeoResource) addedMap),
          activeMap.getMapLayers().size());
    }
  }