@Override
  public boolean execute(PlugInContext context) throws Exception {
    String[] res = getPlugInContext().getSelectedSources();
    final Catalog geocatalog =
        context.getWorkbenchContext().getWorkbench().getFrame().getGeocatalog();
    for (int i = 0; i < res.length; i++) {
      final String name = res[i];
      final EditableSource s = geocatalog.getEditingSource(name);
      if (s.isModified()) {
        try {
          s.getDataSource().commit();
        } catch (DriverException e) {
          ErrorMessages.error(ErrorMessages.CannotSaveSource, e);
        } catch (NonEditableDataSourceException e) {
          ErrorMessages.error(ErrorMessages.CannotSaveSource, e);
        }
      }
      JOptionPane.showMessageDialog(
          geocatalog, I18N.getString("orbisgis.org.orbisgis.core.geocatalog.sourceSaved"));
    }
    // DO NOT REMOVE
    // this call is needed to work around a strange Swing painting problem
    // when using for the first time our custom SourceListRender
    // to display a change in the font of a listed source
    geocatalog.repaint();

    return true;
  }
  public DBSource[] getSelectedDBSources() {
    List<TableNode> tables = new ArrayList<TableNode>();
    TreePath[] treePath;
    try {
      treePath = getTableTree().getSelectionPaths();
      if (treePath == null) return new DBSource[0];
      for (int i = 0; i < treePath.length; i++) {
        Object selectedObject =
            ((DefaultMutableTreeNode) treePath[i].getLastPathComponent()).getUserObject();
        if (selectedObject instanceof TableNode) tables.add(((TableNode) selectedObject));
      }
    } catch (SQLException e) {
      ErrorMessages.error(I18N.getString(""));
      e.printStackTrace();
    } catch (DriverException e) {
      e.printStackTrace();
    }

    final DBSource[] dbSources = new DBSource[tables.size()];
    int i = 0;
    for (TableNode table : tables) {
      dbSources[i] = firstPanel.getDBSource();
      dbSources[i].setTableName(table.getName());
      dbSources[i].setSchemaName(table.getSchema());
      i++;
    }
    return dbSources;
  }
Exemplo n.º 3
0
 public boolean execute(PlugInContext context) throws Exception {
   IEditor editor = getPlugInContext().getActiveEditor();
   MapContext map = (MapContext) editor.getElement().getObject();
   ILayer activeLayer = map.getActiveLayer();
   int[] sel = activeLayer.getSelection().clone();
   Arrays.sort(sel);
   DataSource dataSource = activeLayer.getDataSource();
   try {
     dataSource.setDispatchingMode(DataSource.STORE);
     for (int i = sel.length - 1; i >= 0; i--) {
       dataSource.deleteRow(sel[i]);
     }
     dataSource.setDispatchingMode(DataSource.DISPATCH);
   } catch (DriverException e) {
     ErrorMessages.error(ErrorMessages.CannotDeleteSelectedRow, e);
   }
   return true;
 }