Esempio n. 1
0
  public boolean execute(PlugInContext context) throws Exception {
    reportNothingToUndoYet(context);

    // limpiamos lo que haya podido quedar de ejecuciones anteriores
    emptyBlackboard();

    WizardDialog d =
        new WizardDialog(
            GeopistaUtil.getFrame(context.getWorkbenchGuiComponent()),
            Constants.APLICACION.getI18nString("ExtractDialogGestionar"),
            context.getErrorHandler());
    d.init(
        new WizardPanel[] {
          new MobileModifyPanel01("MobileModifyPanel01", null, context),
        });

    d.setSize(520, 650);
    d.setLocation(10, 20);
    d.setVisible(true);

    if (!d.wasFinishPressed()) {
      LayerManager layerManager = context.getLayerManager();
      if (layerManager != null) {
        Layer graticuleLayer = layerManager.getLayer(GraticuleCreatorEngine.getGraticuleName());
        // si existe una cuadrícula la borramos
        if (graticuleLayer != null) {
          layerManager.remove(graticuleLayer);
        }
      }
      return false;
    }

    return true;
  }
 public boolean isInputValid() {
   LayerManager layerManager = context.getLayerManager();
   Layer graticuleLayer = layerManager.getLayer(GraticuleCreatorEngine.getGraticuleName());
   if (graticuleLayer == null) {
     return false;
   }
   return true;
 }
Esempio n. 3
0
  /*
   * Se ejecuta una vez finalizado el interfaz despues de pasar por todas las pantallas.
   * (non-Javadoc)
   * @see com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn#run(com.vividsolutions.jump.task.TaskMonitor, com.vividsolutions.jump.workbench.plugin.PlugInContext)
   */
  public void run(TaskMonitor monitor, PlugInContext context) throws Exception {
    try {
      monitor.report(
          I18N.get(
              PluginMobileExtracti18n, MobilePluginI18NResource.MobileModifyPanel01_deletingProy));

      ExtractionProject eProject =
          (ExtractionProject) blackboard.get(MobileModifyPanel01.SELECTED_EXTRACT_PROJECT);

      // guardamos la informacion en base de datos
      final String sUrlPrefix =
          Constants.APLICACION.getString(UserPreferenceConstants.LOCALGIS_SERVER_URL);
      AdministradorCartografiaClient administradorCartografiaClient =
          new AdministradorCartografiaClient(
              sUrlPrefix
                  + WebAppConstants.GEOPISTA_WEBAPP_NAME
                  + ServletConstants.ADMINISTRADOR_CARTOGRAFIA_SERVLET_NAME);
      administradorCartografiaClient.deleteExtractProject(eProject);

      // Borramos los datos subidos al servidor.
      httpDeleteProject(Constants.URL_DELETE_SERVER, eProject);

      String dirBase =
          UserPreferenceStore.getUserPreference(
              UserPreferenceConstants.PREFERENCES_DATA_PATH_KEY,
              UserPreferenceConstants.DEFAULT_DATA_PATH,
              true);
      dirBase += File.separator + "maps";

      String projectName = eProject.getNombreProyecto();
      String idProyecto = eProject.getIdProyecto();

      String dirMapName = projectName + "." + idProyecto;
      File dirBaseMake = new File(dirBase, dirMapName);
      if (dirBaseMake.exists()) {
        MobileUtils.deleteDir(dirBaseMake);
        logger.info("Borrando fichero local:" + dirBaseMake);
      }

    } finally {
      // borramos la cuadrícula
      LayerManager layerManager = context.getLayerManager();
      Layer graticuleLayer = layerManager.getLayer(GraticuleCreatorEngine.getGraticuleName());
      if (graticuleLayer != null) {
        layerManager.remove(graticuleLayer);
      }
    }
  }
  private JScrollPane getGraticuleCells() {
    // sacamos las cuadrículas de la rejilla
    LayerManager layerManager = context.getLayerManager();
    Layer graticuleLayer = layerManager.getLayer(GraticuleCreatorEngine.getGraticuleName());
    if (graticuleLayer != null) {
      FeatureCollectionWrapper fCollWrapper = graticuleLayer.getFeatureCollectionWrapper();
      List featList = fCollWrapper.getFeatures();
      jComboList = new ArrayList<JComboBox>();
      Feature feature = null;
      Integer cellId = null;
      JPanel jPaneCells = new JPanel();
      int cols = featList.size() / 2;
      if (featList.size() % 2 != 0) {
        cols++;
      }
      jPaneCells.setLayout(new GridLayout(cols, 2));

      //	        //capas extraídas
      //	        ArrayList<GeopistaLayer> writeableLayers = (ArrayList<GeopistaLayer>)
      // blackboard.get(MobileExtractPanel01.MOBILE_WRITEABLE_LAYERS);
      //	        ArrayList<GeopistaLayer> readableLayers = (ArrayList<GeopistaLayer>)
      // blackboard.get(MobileExtractPanel01.MOBILE_READABLE_LAYERS);
      //	        ArrayList<String> listLayersId = new ArrayList<String>();
      //	        GeopistaLayer geopistaLayer = null;
      //	        for(int i=0; i<writeableLayers.size(); i++){
      //	        	geopistaLayer = writeableLayers.get(i);
      //	        	listLayersId.add(String.valueOf(geopistaLayer.getId_LayerDataBase()));
      //	        }
      //	        for(int i=0; i<readableLayers.size(); i++){
      //	        	geopistaLayer = readableLayers.get(i);
      //	        	listLayersId.add(String.valueOf(geopistaLayer.getId_LayerDataBase()));
      //	        }

      // obtenemos el proyecto de extracción seleccionado de la pantalla anterior
      ExtractionProject eProject =
          (ExtractionProject) blackboard.get(MobileAssignCellsPanel01.SELECTED_EXTRACT_PROJECT);

      JPanel auxPanel = null;
      arrayNombresUsuarios = null;
      listaUsuariosPermisos = null;
      HashMap<String, String> usuariosAsignados = null;
      final String sUrlPrefix = Constants.APLICACION.getString("geopista.conexion.servidorurl");
      try {
        // añadimos los usuarios a los combos
        AdministradorCartografiaClient administradorCartografiaClient =
            new AdministradorCartografiaClient(
                sUrlPrefix
                    + WebAppConstants.GEOPISTA_WEBAPP_NAME
                    + ServletConstants.ADMINISTRADOR_CARTOGRAFIA_SERVLET_NAME);
        ListaUsuarios usersRealList =
            (ListaUsuarios)
                administradorCartografiaClient.getUsersPermLayers(
                    eProject.getIdExtractLayersList());
        // usuarios ya asignados
        usuariosAsignados =
            administradorCartografiaClient.getAssignCellsExtractProject(eProject.getIdProyecto());
        // usuarios con permisos sobre las capas
        Hashtable<String, Usuario> usuariosReales =
            (Hashtable<String, Usuario>) usersRealList.gethUsuarios();
        Set<String> keySetUsers = usuariosReales.keySet();
        arrayNombresUsuarios = new String[keySetUsers.size() + 1];
        arrayNombresUsuarios[0] = ComboItemGraticuleListener.SIN_ASIGNAR;
        listaUsuariosPermisos = new ArrayList<Usuario>();
        String userKey = null;
        Usuario usuario = null;
        int k = 1;
        for (Iterator iterator = keySetUsers.iterator(); iterator.hasNext(); ) {
          userKey = (String) iterator.next();
          usuario = usuariosReales.get(userKey);
          arrayNombresUsuarios[k] = usuario.getName();
          listaUsuariosPermisos.add(usuario);
          k++;
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      JComboBox jcombo = null;
      ILayerViewPanel layerViewPanel = (ILayerViewPanel) context.getLayerViewPanel();
      JLabel jLabelCelda = null;
      String cellIdStr = null;
      Map<Layer, HashSet<Feature>> visibleLayerToFeaturesInFenceMap = null;
      graticuleLayer.setVisible(false); // para quitar la cuadrícula de la intersección
      // añadimos el identificador de cada una al panel
      for (int i = 0; i < featList.size(); i++) {
        feature = (Feature) featList.get(i);
        visibleLayerToFeaturesInFenceMap =
            layerViewPanel.visibleLayerToFeaturesInFenceMap(feature.getGeometry());
        cellId = (Integer) feature.getAttribute(GraticuleCreatorEngine.ATR_CELL_ID);
        auxPanel = new JPanel();
        jLabelCelda =
            new JLabel(
                I18N.get(
                        MobileAssignCellsPlugin.PluginMobileExtracti18n,
                        MobilePluginI18NResource.MobileAssignCellsPanel02_celda)
                    + cellId);
        jcombo = new JComboBox(arrayNombresUsuarios);
        cellIdStr = String.valueOf(cellId);
        jcombo.setName(cellIdStr);

        // celdas con features o sin ellas
        if (visibleLayerToFeaturesInFenceMap == null
            || visibleLayerToFeaturesInFenceMap.size() == 0) {
          jLabelCelda.setEnabled(false);
          jcombo.setEnabled(false);
        } else {
          jLabelCelda.setForeground(Color.RED);
          jcombo.addItemListener(
              new ComboItemGraticuleListener(
                  layerViewPanel, graticuleLayer, feature, jLabelCelda, wizardContext));
          jComboList.add(jcombo);
        }

        auxPanel.add(jLabelCelda);
        auxPanel.add(jcombo);
        jPaneCells.add(auxPanel);
      }
      graticuleLayer.setVisible(true);

      // seleccionamos los usuario asignados en los combos
      if (usuariosAsignados != null && usuariosAsignados.size() != 0) {
        for (int i = 0; i < jComboList.size(); i++) {
          jcombo = jComboList.get(i);
          cellIdStr = jcombo.getName();
          if (usuariosAsignados.containsKey(cellIdStr)) {
            seleccionaUsuarioComboCelda(jcombo, usuariosAsignados.get(cellIdStr));
          }
        }
      }

      jPaneInternal = new JScrollPane();
      jPaneInternal.setViewportView(jPaneCells);
      jPaneInternal.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    }

    return jPaneInternal;
  }
  /**
   * Crea una cuadrícula con los parámetros indicados y centra el mapa sobre la misma
   *
   * @param plugContext
   * @param cellSideLengthX
   * @param cellSideLengthY
   * @param layerHeightInCells
   * @param layerWidthInCells
   * @param southwestCornerOfLeftLayer
   * @throws NoninvertibleTransformException
   */
  public static void crearCentrarCuadricula(
      PlugInContext plugContext,
      double cellSideLengthX,
      double cellSideLengthY,
      int layerWidthInCells,
      int layerHeightInCells,
      Coordinate southwestCornerOfLeftLayer) {
    // creación de la última cuadrícula
    GraticuleCreatorEngine graticuleCreator = new GraticuleCreatorEngine();
    graticuleCreator.setCellSideLengthX(cellSideLengthX);
    graticuleCreator.setCellSideLengthY(cellSideLengthY);
    graticuleCreator.setLayerWidthInCells(layerWidthInCells);
    graticuleCreator.setLayerHeightInCells(layerHeightInCells);
    graticuleCreator.setSouthwestCornerOfLeftLayer(southwestCornerOfLeftLayer);
    //        graticuleCreator.setCellSideLengthX((Double)
    // blackboard.get(GraticuleCreatorPlugIn.CELL_SIDE_LENGTH_X));
    //        graticuleCreator.setCellSideLengthY((Double)
    // blackboard.get(GraticuleCreatorPlugIn.CELL_SIDE_LENGTH_Y));
    //        graticuleCreator.setLayerWidthInCells((Integer)
    // blackboard.get(GraticuleCreatorPlugIn.LAYER_WIDTH_IN_CELLS));
    //      graticuleCreator.setLayerHeightInCells((Integer)
    // blackboard.get(GraticuleCreatorPlugIn.LAYER_HEIGHT_IN_CELLS));
    //        graticuleCreator.setSouthwestCornerOfLeftLayer((Coordinate)
    // blackboard.get(GraticuleCreatorPlugIn.SOUTHWEST_CORNER_OF_LEFT_LAYER));
    graticuleCreator.execute(plugContext);

    // centrado de la visión
    double minX = graticuleCreator.getSouthwestCornerOfLeftLayer().x;
    double minY = graticuleCreator.getSouthwestCornerOfLeftLayer().y;
    double maxX =
        minX + graticuleCreator.getLayerWidthInCells() * graticuleCreator.getCellSideLengthX();
    double maxY =
        minY + graticuleCreator.getLayerHeightInCells() * graticuleCreator.getCellSideLengthY();
    Envelope modelEnvelope = new Envelope(minX, maxX, minY, maxY);
    try {
      plugContext.getLayerViewPanel().getViewport().zoom(modelEnvelope);
    } catch (NoninvertibleTransformException e) {
      e.printStackTrace();
    }
  }
  private JButton getGraticuleButton() {
    jButtonGraticule =
        new JButton(
            I18N.get(
                MobileExtractPlugin.PluginMobileExtracti18n,
                MobilePluginI18NResource.MobileExtractPanel03_crearCuadricula));

    LayerManager layerManager = context.getLayerManager();
    Layer graticuleLayer = layerManager.getLayer(GraticuleCreatorEngine.getGraticuleName());

    // si ya existe una capa cuadrícula significa que se trata de un fichero importado previamente a
    // ejecutar el asistente
    if (graticuleLayer != null) {
      jButtonGraticule.setEnabled(false);

      if (bCuadriculaCreada == true) {
        // solo ejecutamos este código una vez
        return jButtonGraticule;
      }

      FeatureCollectionWrapper graticuleCollectionWrapper =
          graticuleLayer.getFeatureCollectionWrapper();
      FeatureSchema featureSchema = graticuleCollectionWrapper.getFeatureSchema();

      // cuadriculas visionadas
      IViewport viewport = (IViewport) context.getLayerViewPanel().getViewport();
      Envelope viewEnvelope = viewport.getEnvelopeInModelCoordinates();
      List<Feature> graticuleFeatures = graticuleCollectionWrapper.query(viewEnvelope);
      // ordenamos por distancia al origen las features
      List<SortedFeature> sortedGraticuleFeatures = new ArrayList<SortedFeature>();
      Feature feature = null;
      SortedFeature sortFeat = null;
      for (Iterator iterator = graticuleFeatures.iterator(); iterator.hasNext(); ) {
        feature = (Feature) iterator.next();
        sortFeat = new SortedFeature(feature);
        sortedGraticuleFeatures.add(sortFeat);
      }
      Collections.sort(sortedGraticuleFeatures);

      // borramos el resto de cuadrículas
      graticuleCollectionWrapper.clear();
      graticuleCollectionWrapper.addAll(graticuleFeatures);
      Envelope newWrapperEnvelope = graticuleCollectionWrapper.getEnvelope();

      // zoom al envelope actual
      try {
        viewport.zoom(newWrapperEnvelope);
      } catch (NoninvertibleTransformException e) {
        log.warn("No se ha podido alcanzar el zoom " + newWrapperEnvelope);
      }

      // ajustamos la ventana al envelope de la cuadrícula
      resizeViewToEnvelope(context, newWrapperEnvelope, viewport);

      // guardamos las propiedades gráficas de la extracción
      Envelope featEnvelope =
          sortedGraticuleFeatures.get(0).getFeature().getGeometry().getEnvelopeInternal();
      Double featWidth = featEnvelope.getWidth();
      Double featHeight = featEnvelope.getHeight();
      Double minX = newWrapperEnvelope.getMinX();
      Double minY = newWrapperEnvelope.getMinY();
      Coordinate coordCorner = new Coordinate(minX, minY);
      blackboard.put(GraticuleCreatorPlugIn.SOUTHWEST_CORNER_OF_LEFT_LAYER, coordCorner);
      blackboard.put(GraticuleCreatorPlugIn.CELL_SIDE_LENGTH_X, featWidth);
      blackboard.put(GraticuleCreatorPlugIn.CELL_SIDE_LENGTH_Y, featHeight);
      Integer numCeldasAncho = (int) (newWrapperEnvelope.getWidth() / featWidth);
      Integer numCeldasAlto = (int) (newWrapperEnvelope.getHeight() / featHeight);
      blackboard.put(GraticuleCreatorPlugIn.LAYER_WIDTH_IN_CELLS, numCeldasAncho);
      blackboard.put(GraticuleCreatorPlugIn.LAYER_HEIGHT_IN_CELLS, numCeldasAlto);

      // creamos celdas para los espacios en blanco
      if (sortedGraticuleFeatures.size() < numCeldasAncho * numCeldasAlto) {
        Double curMinX = minX;
        Double curMinY = minY;
        Double fMinX = 0.0;
        GeometryFactory geoFact = new GeometryFactory();
        Feature newFeature = null;
        for (int i = 0; i < sortedGraticuleFeatures.size(); i++) {
          sortFeat = sortedGraticuleFeatures.get(i);
          feature = sortFeat.getFeature();
          fMinX = feature.getGeometry().getEnvelopeInternal().getMinX();
          if (curMinX.doubleValue() != fMinX.doubleValue()) {
            // creamos la feature
            newFeature = (Feature) feature.clone();
            Coordinate[] coordArray = {
              new Coordinate(curMinX, curMinY),
              new Coordinate(curMinX + featWidth, curMinY),
              new Coordinate(curMinX + featWidth, curMinY + featHeight),
              new Coordinate(curMinX, curMinY + featHeight),
              new Coordinate(curMinX, curMinY)
            };

            newFeature.setGeometry(
                geoFact.createPolygon(geoFact.createLinearRing(coordArray), null));
            sortedGraticuleFeatures.add(i, new SortedFeature(newFeature));
            graticuleCollectionWrapper.add(newFeature);
          }
          // para lo último
          else if ((i == sortedGraticuleFeatures.size() - 1)
              && ((minX + (featWidth * numCeldasAncho)) != (fMinX + featWidth))) {
            curMinX = fMinX + featWidth;
            newFeature = (Feature) feature.clone();
            Coordinate[] coordArray = {
              new Coordinate(curMinX, curMinY),
              new Coordinate(curMinX + featWidth, curMinY),
              new Coordinate(curMinX + featWidth, curMinY + featHeight),
              new Coordinate(curMinX, curMinY + featHeight),
              new Coordinate(curMinX, curMinY)
            };

            newFeature.setGeometry(
                geoFact.createPolygon(geoFact.createLinearRing(coordArray), null));
            sortedGraticuleFeatures.add(
                sortedGraticuleFeatures.size(), new SortedFeature(newFeature));
            graticuleCollectionWrapper.add(newFeature);
            continue;
          }

          if (((i + 1) % numCeldasAncho) != 0) {
            curMinX = curMinX + featWidth;
          } else { // ultima celda de cada fila
            curMinX = minX;
            curMinY += featHeight;
          }
        }
      }

      // añadimos el atributo cellid
      featureSchema.addAttribute(GraticuleCreatorEngine.ATR_CELL_ID, AttributeType.INTEGER);
      int k = 1;
      Object[] featAttribs = null;
      Object[] newFeatAttribs = null;
      for (Iterator iterator = sortedGraticuleFeatures.iterator(); iterator.hasNext(); k++) {
        feature = ((SortedFeature) iterator.next()).getFeature();
        featAttribs = feature.getAttributes();
        newFeatAttribs = new Object[featAttribs.length + 1];
        for (int i = 0; i < featAttribs.length; i++) {
          newFeatAttribs[i] = featAttribs[i];
        }
        newFeatAttribs[newFeatAttribs.length - 1] = k;
        feature.setAttributes(newFeatAttribs);
      }
      // pintamos el atributo en la capa
      LabelStyle labelStyle = graticuleLayer.getLabelStyle();
      labelStyle.setColor(Color.RED);
      labelStyle.setHeight(labelStyle.getHeight() * 4);
      labelStyle.setAttribute(GraticuleCreatorEngine.ATR_CELL_ID);
      labelStyle.setEnabled(true);

      // evitamos que se modifiquen las cuadrículas
      graticuleLayer.setEditable(false);
      graticuleLayer.fireAppearanceChanged();

      bCuadriculaCreada = true;
    }
    // llamada al graticulePlugin
    else {
      jButtonGraticule.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              GraticuleCreatorPlugIn graticulePlugin = new GraticuleCreatorPlugIn();
              try {
                graticulePlugin.execute(context);
              } catch (Exception e1) {
                e1.printStackTrace();
              }
              wizardContext.inputChanged(); // indicamos que ya se puede habilitar el boton
            }
          });
    }

    return jButtonGraticule;
  }