コード例 #1
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);
    }
  }
コード例 #2
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$
       }
     }
   }
 }
コード例 #3
0
  @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;
  }
コード例 #4
0
  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;
  }
コード例 #5
0
ファイル: Polygon.java プロジェクト: sennj/orbisgis
  public String[] getTransitionLabels() {
    ArrayList<String> ret = new ArrayList<String>();

    if ("Standby".equals(status)) {}

    if ("Point".equals(status)) {

      ret.add(I18N.getString("orbisgis.core.ui.editors.map.tool.polygon_point_to_done"));
      ret.add(I18N.getString("orbisgis.core.ui.editors.map.tool.cancel"));
    }

    if ("Done".equals(status)) {}

    if ("Cancel".equals(status)) {}

    return ret.toArray(new String[0]);
  }
コード例 #6
0
ファイル: FindReplaceDialog.java プロジェクト: sennj/orbisgis
 public FindReplaceDialog(RSyntaxTextArea rSyntaxTextArea) {
   super();
   this.rSyntaxTextArea = rSyntaxTextArea;
   getContentPane().add(createContentPane());
   this.setLocationRelativeTo(rSyntaxTextArea);
   this.setTitle(I18N.getString("orbisgis.org.orbisgis.ui.findReplace"));
   pack();
   setResizable(false);
 }
コード例 #7
0
 @Override
 public String validateInput() {
   String validateInput = null;
   validateInput =
       (getSelectedDBSources().length == 0)
           ? I18N.getString("orbisgis.org.orbisgis.core.db.selectAtLeastTableOrView")
           : null;
   return validateInput;
 }
コード例 #8
0
ファイル: Polygon.java プロジェクト: sennj/orbisgis
  public String getMessage() {

    if ("Standby".equals(status)) {
      return I18N.getString("orbisgis.core.ui.editors.map.tool.polygon_standby");
    }

    if ("Point".equals(status)) {
      return I18N.getString("orbisgis.core.ui.editors.map.tool.polygon_point");
    }

    if ("Done".equals(status)) {
      return "";
    }

    if ("Cancel".equals(status)) {
      return "";
    }

    throw new RuntimeException();
  }
コード例 #9
0
  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;
  }
コード例 #10
0
  @Override
  public DataSource createDataSource(String tableName, ProgressMonitor pm)
      throws DataSourceCreationException {
    if (!file.exists()) {
      throw new DataSourceCreationException(
          file + " " + I18N.getString("gdms.datasource.error.noexits"));
    }

    final FileDriver driver;
    try {
      driver = getDriver();
    } catch (DriverException ex) {
      throw new DataSourceCreationException(ex);
    }

    driver.setDataSourceFactory(getDataSourceFactory());

    FileDataSourceAdapter ds = new FileDataSourceAdapter(getSource(tableName), file, driver, false);
    return ds;
  }
コード例 #11
0
  private void validate(String beforeReformat, String afterReformat) {
    String normalizedBefore = getNormalized(beforeReformat);
    String normalizedAfter = getNormalized(afterReformat);

    if (!normalizedBefore.equalsIgnoreCase(normalizedAfter)) {
      int minLen = Math.min(normalizedAfter.length(), normalizedBefore.length());
      StringBuffer diffPos = new StringBuffer();
      for (int i = 0; i < minLen; ++i) {
        if (Character.toUpperCase(normalizedBefore.charAt(i))
            != Character.toUpperCase(normalizedAfter.charAt(i))) {
          break;
        }
        diffPos.append('-');
      }
      diffPos.append('^');

      // i18n[editextras.reformatFailed=Reformat failed, normalized
      // Strings differ]
      StringBuilder msg =
          new StringBuilder(
              I18N.getString(
                  "orbisgis.core.ui.plugins.views.sqlConsole.codereformat.reformatFailed"));
      msg.append(_lineSep);
      msg.append(normalizedBefore);
      msg.append(_lineSep);
      msg.append(normalizedAfter);
      msg.append(_lineSep);
      msg.append(diffPos.toString());
      msg.append(_lineSep);

      if (s_log.isInfoEnabled()) {
        s_log.info(msg.toString());
      }

      throw new IllegalStateException(msg.toString());
    }
  }
コード例 #12
0
 public void getI18n() {
   I18N.addI18n(langAndCountry, null, this.getClass());
 }
コード例 #13
0
 public void insertLayer(ILayer layer, int index) throws LayerException {
   throw new IllegalArgumentException(
       I18N.getString(
           "orbisgis-core.org.orbisgis.layerModel.gdmsLayer.layerCannotHaveChildren")); //$NON-NLS-1$
 }
コード例 #14
0
 private void delI18n() {
   I18N.delI18n(null, this.getClass());
 }
コード例 #15
0
 @Override
 public String getName() {
   return I18N.getString("orbisgis.core.ui.editors.map.tool.information");
 }
コード例 #16
0
 public ILayer remove(String layerName) {
   throw new IllegalArgumentException(
       I18N.getString(
           "orbisgis-core.org.orbisgis.layerModel.gdmsLayer.layerCannotDoesntChildren")); //$NON-NLS-1$
 }
コード例 #17
0
 public ILayer getLayer(final int index) {
   throw new ArrayIndexOutOfBoundsException(
       I18N.getString(
           "orbisgis-core.org.orbisgis.layerModel.gdmsLayer.layerDoesntContainAnyChild")); //$NON-NLS-1$
 }
コード例 #18
0
 public String getName() {
   return I18N.getString("orbisgis.org.orbisgis.mapEditor.view");
 }
コード例 #19
0
 public DeleteMapSelectionPlugIn() {
   btn = new JButton(OrbisGISIcon.REMOVE);
   btn.setToolTipText(I18N.getString("orbisgis.ui.popupmenu.table.deleteFromSelection"));
 }
コード例 #20
0
 public ILayer remove(ILayer layer, boolean isMoving) throws LayerException {
   throw new IllegalArgumentException(
       I18N.getString(
           "orbisgis-core.org.orbisgis.layerModel.gdmsLayer.layerCannotHaveChildren")); //$NON-NLS-1$
 }
コード例 #21
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;
  }
コード例 #22
0
 @Override
 public String getTitle() {
   return I18N.getString("orbisgis.org.orbisgis.core.db.selectTableOrView");
 }
コード例 #23
0
ファイル: FindReplaceDialog.java プロジェクト: sennj/orbisgis
  /**
   * Create the main panel
   *
   * @return
   */
  private JPanel createContentPane() {
    // ... Create an independent GridLayout panel of buttons.
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(5, 1, GAP, GAP));

    findBtn = new JButton(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.find"));
    findBtn.setActionCommand("FindNext");
    findBtn.setMnemonic('f');
    findBtn.addActionListener(this);

    replaceBtn = new JButton(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.replace"));
    replaceBtn.setActionCommand("Replace");
    replaceBtn.setMnemonic('r');
    replaceBtn.addActionListener(this);

    replAllBtn = new JButton(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.replaceAll"));
    replAllBtn.setActionCommand("ReplaceAll");
    replAllBtn.setMnemonic('a');
    replAllBtn.addActionListener(this);

    closeBtn = new JButton(I18N.getString("orbisgis.org.orbisgis.ui.close"));
    closeBtn.setActionCommand("Close");
    closeBtn.setMnemonic('c');
    closeBtn.addActionListener(this);
    closeBtn.setDefaultCapable(true);

    buttonPanel.add(findBtn);
    buttonPanel.add(replaceBtn);
    buttonPanel.add(replAllBtn);
    buttonPanel.add(closeBtn);

    // ... Create an independent GridLayout panel of check boxes.
    JPanel checkBoxPanel = new JPanel();
    checkBoxPanel.setLayout(new GridLayout(3, 2));
    matchCaseCB = new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.matchCase"));
    matchCaseCB.setMnemonic('m');

    wholeWrdsCB = new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.wholeWords"));
    wholeWrdsCB.setMnemonic('w');

    regexCB =
        new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.regularExpressions"));
    regexCB.setMnemonic('x');
    regexCB.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (regexCB.isSelected()) {
              wholeWrdsCB.setSelected(false);
              matchCaseCB.setSelected(false);
              wholeWrdsCB.setEnabled(false);
              matchCaseCB.setEnabled(false);
            } else {
              wholeWrdsCB.setEnabled(true);
              matchCaseCB.setEnabled(true);
            }
          }
        });

    markAllCB = new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.markAll"));
    markAllCB.setMnemonic('a');
    markAllCB.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (!markAllCB.isSelected()) {
              rSyntaxTextArea.clearMarkAllHighlights();
            }
          }
        });

    upCB = new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.searchUp"), true);
    upCB.setMnemonic('u');
    upCB.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (!upCB.isSelected()) {
              downCB.setSelected(true);
            } else {
              downCB.setSelected(false);
            }
          }
        });
    downCB = new JCheckBox(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.searchDown"));
    downCB.setMnemonic('d');
    downCB.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (!downCB.isSelected()) {
              upCB.setSelected(true);
            } else {
              upCB.setSelected(false);
            }
          }
        });

    checkBoxPanel.add(matchCaseCB);
    checkBoxPanel.add(wholeWrdsCB);
    checkBoxPanel.add(regexCB);
    checkBoxPanel.add(markAllCB);
    checkBoxPanel.add(upCB);
    checkBoxPanel.add(downCB);

    // ... Create GridBagLayout content pane; set border.
    JPanel content = new JPanel(new GridBagLayout());
    content.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER));

    // GridBagLayout code begins here
    GBHelper pos = new GBHelper(); // Create GridBag helper object.

    // ... First row
    findLbl =
        new JLabel(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.findWhat"), JLabel.LEFT);
    content.add(findLbl, pos);
    content.add(new Gap(GAP), pos.nextCol());
    findTF = new JTextField(20);
    content.add(findTF, pos.nextCol().expandW());
    content.add(new Gap(GAP), pos.nextCol());
    content.add(buttonPanel, pos.nextCol().height(5).align(GridBagConstraints.NORTH));

    content.add(new Gap(GAP), pos.nextRow()); // Add a gap below

    // ... Next row.
    replaceLbl =
        new JLabel(I18N.getString("orbisgis.org.orbisgis.ui.findReplace.replaceWith"), JLabel.LEFT);
    content.add(replaceLbl, pos.nextRow());
    content.add(new Gap(GAP), pos.nextCol());
    replaceTF = new JTextField(20);
    content.add(replaceTF, pos.nextCol().expandW());

    content.add(new Gap(2 * GAP), pos.nextRow()); // Add a big gap below

    // ... Last content row.
    content.add(checkBoxPanel, pos.nextRow().nextCol().nextCol());

    // ... Add an area that can expand at the bottom.
    content.add(new Gap(), pos.nextRow().width().expandH());
    return content;
  }
コード例 #24
0
ファイル: FindReplaceDialog.java プロジェクト: sennj/orbisgis
  @Override
  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if ("FindNext".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      boolean markAll = markAllCB.isSelected();
      boolean forward = downCB.isSelected();
      boolean matchCase = matchCaseCB.isSelected();
      boolean wholeWord = wholeWrdsCB.isSelected();
      boolean regex = regexCB.isSelected();
      if (markAll) {
        rSyntaxTextArea.clearMarkAllHighlights();
        rSyntaxTextArea.markAll(text, matchCase, wholeWord, regex);
      }

      SearchContext c = new SearchContext();
      c.setMatchCase(matchCase);
      c.setSearchFor(text);
      c.setWholeWord(wholeWord);
      c.setRegularExpression(regex);
      c.setSearchForward(forward);
      boolean found = SearchEngine.find(rSyntaxTextArea, c);
      if (!found) {
        JOptionPane.showMessageDialog(
            this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound"));
      }
    } else if ("Close".equals(command)) {
      setVisible(false);
    } else if ("Replace".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      String textReplace = replaceTF.getText();
      if (textReplace.equals(text)) {
        return;
      } else {
        boolean forward = downCB.isSelected();
        boolean matchCase = matchCaseCB.isSelected();
        boolean wholeWord = wholeWrdsCB.isSelected();
        boolean regex = regexCB.isSelected();
        SearchContext c = new SearchContext();
        c.setMatchCase(matchCase);
        c.setSearchFor(text);
        c.setReplaceWith(textReplace);
        c.setWholeWord(wholeWord);
        c.setRegularExpression(regex);
        c.setSearchForward(forward);
        boolean found = SearchEngine.find(rSyntaxTextArea, c);
        if (!found) {
          JOptionPane.showMessageDialog(
              this, I18N.getString("orbisgis.org.orbisgis.ui.findReplace.textNotFound"));
        }
      }

    } else if ("ReplaceAll".equals(command)) {
      String text = findTF.getText();
      if (text.length() == 0) {
        return;
      }
      String textReplace = replaceTF.getText();
      if (textReplace.equals(text)) {
        return;
      } else {
        boolean matchCase = matchCaseCB.isSelected();
        boolean wholeWord = wholeWrdsCB.isSelected();
        boolean regex = regexCB.isSelected();
        SearchContext c = new SearchContext();
        c.setMatchCase(matchCase);
        c.setSearchFor(text);
        c.setWholeWord(wholeWord);
        c.setRegularExpression(regex);
        c.setReplaceWith(textReplace);
        SearchEngine.find(rSyntaxTextArea, c);
      }
    }
  }
コード例 #25
0
ファイル: Polygon.java プロジェクト: sennj/orbisgis
 public String getTooltip() {
   return I18N.getString("orbisgis.core.ui.editors.map.tool.polygon_tooltip");
 }