コード例 #1
0
 @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);
   }
 }
コード例 #2
0
 @SuppressWarnings("unchecked")
 public void execute(Geocognition geocognition, GeocognitionElement element) {
   if (GeocognitionCustomQueryFactory.BUILT_IN_QUERY_ID.equals(element.getTypeId())) {
     Class<? extends CustomQuery> queryClass = (Class<? extends CustomQuery>) element.getObject();
     try {
       QueryManager.remove(queryClass.newInstance().getName());
       QueryManager.registerQuery(queryClass);
     } catch (InstantiationException e) {
       Services.getService(ErrorManager.class).error("Bug!", e);
     } catch (IllegalAccessException e) {
       Services.getService(ErrorManager.class).error("Bug!", e);
     }
   }
 }
コード例 #3
0
 @Override
 public void sourceNameChanged(SourceEvent e) {
   // If this layer source name was changed
   if (e.getName().equals(mainName)) {
     mainName = e.getNewName();
     // Add alias if necessary
     if (!getName().equals(mainName) && (getName().equals(e.getName()))) {
       SourceManager sourceManager = Services.getService(DataManager.class).getSourceManager();
       try {
         // If this layer name was the mainName
         sourceManager.addName(mainName, getName());
       } catch (NoSuchTableException e1) {
         // The table exists since mainName is the new name
         throw new RuntimeException(
             I18N.getString("orbisgis-core.org.orbisgis.layerModel.gdmsLayer.bug"),
             e1); //$NON-NLS-1$
       } catch (SourceAlreadyExistsException e1) {
         // This layer had the old source name so there is no
         // possibility for a conflict to happen
         throw new RuntimeException(
             I18N.getString("orbisgis-core.org.orbisgis.layerModel.gdmsLayer.bug"),
             e1); //$NON-NLS-1$
       }
     }
   }
 }
コード例 #4
0
  @Override
  public void setName(String name) throws LayerException {
    SourceManager sourceManager =
        ((DataManager) Services.getService(DataManager.class))
            .getDataSourceFactory()
            .getSourceManager();

    // Remove previous alias
    if (!mainName.equals(getName())) {
      sourceManager.removeName(getName());
    }
    if (!name.equals(mainName)) {
      super.setName(name);
      try {
        sourceManager.addName(mainName, name);
      } catch (NoSuchTableException e) {
        throw new RuntimeException(
            I18N.getString("orbisgis-core.org.orbisgis.layerModel.gdmsLayer.bug"),
            e); //$NON-NLS-1$
      } catch (SourceAlreadyExistsException e) {
        throw new LayerException(
            I18N.getString("orbisgis-core.org.orbisgis.layerModel.gdmsLayer.sourceAlreadyExists"),
            e); //$NON-NLS-1$
      }
    } else {
      super.setName(name);
    }
  }
コード例 #5
0
ファイル: NewSymbol.java プロジェクト: sennj/orbisgis
  public void runWizard() {
    SymbolManager symbolManager = Services.getService(SymbolManager.class);
    ArrayList<Symbol> availableSymbols = symbolManager.getAvailableSymbols();
    String[] names = new String[availableSymbols.size()];
    String[] ids = new String[availableSymbols.size()];
    for (int i = 0; i < ids.length; i++) {
      ids[i] = availableSymbols.get(i).getId();
      names[i] = availableSymbols.get(i).getClassName();
    }
    ChoosePanel cp = new ChoosePanel("Select the legend type", names, ids);
    if (UIFactory.showDialog(cp)) {

      Symbol symbol = symbolManager.createSymbol(ids[cp.getSelectedIndex()]);

      GeoCognitionSymbolBuilder symbolBuilder = new GeoCognitionSymbolBuilder();
      symbolBuilder.setSymbol(symbol);

      if (UIFactory.showDialog(symbolBuilder)) {
        this.symbol = symbolBuilder.getSymbolComposite();
      }

    } else {
      this.symbol = null;
    }
  }
コード例 #6
0
  public void initialize(PlugInContext context) throws Exception {
    menuTree = new MenuTree();
    Services.registerService(
        MapContextManager.class,
        "Gives access to the current MapContext",
        new DefaultMapContextManager());
    Services.registerService(ViewPlugIn.class, "Gives access to the current MapContext", this);

    Automaton defaultTool = (Automaton) Services.getService(Automaton.class);
    this.defaultTool = defaultTool;
    this.defaultMouseCursor = OrbisGISIcon.ZOOMIN;
    editors = new String[0];
    setPlugInContext(context);
    if (context
            .getWorkbenchContext()
            .getWorkbench()
            .getFrame()
            .getViewDecorator(Names.EDITOR_MAP_ID)
        == null)
      context
          .getWorkbenchContext()
          .getWorkbench()
          .getFrame()
          .getViews()
          .add(new ViewDecorator(this, Names.EDITOR_MAP_ID, getIcon("map.png"), editors));
  }
コード例 #7
0
  GetCapabilitiesHandler(Map<String, Layer> lMap, Map<String, String[]> lS, WMSProperties props) {
    this.properties = props;
    layerMap = lMap;
    layerStyles = lS;
    try {
      jaxbContext =
          JAXBContext.newInstance(
              "net.opengis.wms:net.opengis.sld._1_2:net.opengis.se._2_0.core:oasis.names.tc.ciq.xsdschema.xal._2");
    } catch (JAXBException ex) {
      throw new RuntimeException(
          "Failed to build the JAXB Context, can't build the associated XML.", ex);
    }
    Set<String> codes = DataSourceFactory.getCRSFactory().getSupportedCodes("EPSG");
    LinkedList<String> ll = new LinkedList<String>();
    for (String s : codes) {
      ll.add("EPSG:" + s);
    }
    authCRS = ll;

    final DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
    final SourceManager sm = dsf.getSourceManager();
    SourceListener sourceListener = new CapListener(dsf);
    String[] layerNames = sm.getSourceNames();
    for (int i = 0; i < layerNames.length; i++) {
      SourceEvent sEvent =
          new SourceEvent(layerNames[i], sm.getSource(layerNames[i]).isWellKnownName(), sm);
      sourceListener.sourceAdded(sEvent);
    }
    sm.addSourceListener(sourceListener);
  }
コード例 #8
0
ファイル: Geomark.java プロジェクト: albacore-xx/orbisgis
  public ObjectDriver evaluate(
      DataSourceFactory dsf, DataSource[] tables, Value[] values, IProgressMonitor pm)
      throws ExecutionException {
    WorkbenchContext wbContext = Services.getService(WorkbenchContext.class);
    final GeomarkPanel geomarkPanel =
        (GeomarkPanel) wbContext.getWorkbench().getFrame().getView("Geomark");
    final String prefix = ((0 == values.length) ? tables[0].getName() : values[0]) + "-";

    try {
      final SpatialDataSourceDecorator sds = new SpatialDataSourceDecorator(tables[0]);
      sds.open();
      final int rowCount = (int) sds.getRowCount();
      for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {

        if (rowIndex / 100 == rowIndex / 100.0) {
          if (pm.isCancelled()) {
            break;
          } else {
            pm.progressTo((int) (100 * rowIndex / rowCount));
          }
        }

        final Envelope envelope = sds.getGeometry(rowIndex).getEnvelopeInternal();
        geomarkPanel.add(prefix + rowIndex, envelope);
      }
      sds.close();
      return null;
    } catch (DriverException e) {
      throw new ExecutionException(e);
    }
  }
コード例 #9
0
ファイル: JobListModel.java プロジェクト: JimmyFarcy/orbisgis
 /**
  * Attach listeners to the BackgroundManager
  *
  * @return itself
  */
 public JobListModel listenToBackgroundManager() {
   BackgroundManager bm = Services.getService(BackgroundManager.class);
   // bm.addBackgroundListener(EventHandler.create(BackgroundListener.class,this,"onJobListChange"));
   bm.addBackgroundListener(new JobListBackgroundListener());
   labelUpdateListener =
       EventHandler.create(PropertyChangeListener.class, this, "onJobItemLabelChange", "source");
   return this;
 }
コード例 #10
0
  public void close() throws LayerException {
    SourceManager sourceManager = Services.getService(DataManager.class).getSourceManager();

    sourceManager.removeSourceListener(listener);

    // Remove alias
    if (!mainName.equals(getName())) {
      sourceManager.removeName(getName());
    }
  }
コード例 #11
0
  public MapEditorPlugIn() {
    WorkbenchContext wbContext = Services.getService(WorkbenchContext.class);
    mapEditor = new RootPanePanel();
    mapControl = new MapControl();
    // Map editor tool bar
    mapToolBar = new WorkbenchToolBar(wbContext, Names.MAP_TOOLBAR_NAME);

    WorkbenchToolBar scaleToolBar = new WorkbenchToolBar(wbContext, Names.MAP_TOOLBAR_SCALE);
    mapToolBar.add(scaleToolBar);
    mapToolBar.add(Box.createHorizontalGlue());

    WorkbenchToolBar projectionToolBar =
        new WorkbenchToolBar(wbContext, Names.MAP_TOOLBAR_PROJECTION);
    mapToolBar.add(projectionToolBar);
  }
コード例 #12
0
  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();
    }
  }
コード例 #13
0
  @Override
  protected void rectangleDone(
      Rectangle2D rect, boolean smallerThanTolerance, MapContext vc, ToolManager tm)
      throws TransitionException {
    ILayer layer = vc.getSelectedLayers()[0];
    DataSource sds = layer.getDataSource();
    String sql = null;
    try {
      GeometryFactory gf = ToolManager.toolsGeometryFactory;
      double minx = rect.getMinX();
      double miny = rect.getMinY();
      double maxx = rect.getMaxX();
      double maxy = rect.getMaxY();

      Coordinate lowerLeft = new Coordinate(minx, miny);
      Coordinate upperRight = new Coordinate(maxx, maxy);
      LinearRing envelopeShell =
          gf.createLinearRing(
              new Coordinate[] {
                lowerLeft,
                new Coordinate(minx, maxy),
                upperRight,
                new Coordinate(maxx, miny),
                lowerLeft,
              });
      Geometry geomEnvelope = gf.createPolygon(envelopeShell, new LinearRing[0]);
      WKTWriter writer = new WKTWriter();
      sql =
          "select * from "
              + layer.getName()
              + " where ST_intersects("
              + sds.getMetadata().getFieldName(sds.getSpatialFieldIndex())
              + ", ST_geomfromtext('"
              + writer.write(geomEnvelope)
              + "'));";
      BackgroundManager bm = (BackgroundManager) Services.getService(BackgroundManager.class);
      bm.backgroundOperation(
          new DefaultJobId("org.orbisgis.jobs.InfoTool"), new PopulateViewJob(sql));
    } catch (DriverException e) {
      throw new TransitionException(e);
    } catch (DriverLoadException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #14
0
 @Override
 public void open() throws LayerException {
   SourceManager sourceManager = Services.getService(DataManager.class).getSourceManager();
   sourceManager.addSourceListener(listener);
 }
コード例 #15
0
  private JTree getTableTree() throws SQLException, DriverException {
    if (tableTree == null) {

      DBDriver dbDriver = firstPanel.getDBDriver();
      final Connection connection = firstPanel.getConnection();
      final String[] schemas = dbDriver.getSchemas(connection);
      OutputManager om = Services.getService(OutputManager.class);

      DefaultMutableTreeNode rootNode =
          // new DefaultMutableTreeNode ("Schemas");
          new DefaultMutableTreeNode(connection.getCatalog());

      // Add Data to the tree
      for (String schema : schemas) {

        final TableDescription[] tableDescriptions =
            dbDriver.getTables(connection, null, schema, null, new String[] {"TABLE"});
        final TableDescription[] viewDescriptions =
            dbDriver.getTables(connection, null, schema, null, new String[] {"VIEW"});

        if (tableDescriptions.length == 0 && viewDescriptions.length == 0) {
          continue;
        }

        // list schemas
        DefaultMutableTreeNode schemaNode = new DefaultMutableTreeNode(new SchemaNode(schema));
        rootNode.add(schemaNode);

        // list Tables
        DefaultMutableTreeNode tableNode =
            new DefaultMutableTreeNode(I18N.getString("orbisgis.org.orbisgis.core.db.tables"));

        // we send possible loading errors to the Output window
        DriverException[] exs = dbDriver.getLastNonBlockingErrors();
        if (exs.length != 0) {
          for (int i = 0; i < exs.length; i++) {
            om.println(exs[i].getMessage(), Color.ORANGE);
          }
        }

        if (tableDescriptions.length > 0) {
          schemaNode.add(tableNode);
          for (TableDescription tableDescription : tableDescriptions) {
            tableNode.add(new DefaultMutableTreeNode(new TableNode(tableDescription)));
          }
        }

        // list View
        DefaultMutableTreeNode viewNode =
            new DefaultMutableTreeNode(I18N.getString("orbisgis.org.orbisgis.core.db.views"));
        if (viewDescriptions.length > 0) {
          schemaNode.add(viewNode);
          for (TableDescription viewDescription : viewDescriptions) {
            viewNode.add(new DefaultMutableTreeNode(new ViewNode(viewDescription)));
          }
        }
      }

      connection.close();

      tableTree = new JTree(rootNode);
      tableTree.setRootVisible(true);
      tableTree.setShowsRootHandles(true);
      tableTree.setCellRenderer(new TableTreeCellRenderer());
    }
    return tableTree;
  }