Exemplo n.º 1
0
  public void addTableRow(ArrayList<Serializable> data) {
    ignoreChanges = true;
    DataTableModel model = (DataTableModel) jtable.getModel();
    model.addRow(data.toArray(new Serializable[data.size()]));
    model.setRowColor(model.getRowCount() - 1, Color.GREEN);

    repaint();
    ignoreChanges = false;
  }
  private boolean newValueIsBad() {
    if (!(editor instanceof JTextComponent)) return false;

    String value = ((JTextComponent) editor).getText();
    if (value == null) return false;
    if (CHAR.matcher(value).find() == false) return false;
    if (DIGIT.matcher(value).find() == true) return false;

    if (timePerPersonColumn == -1) timePerPersonColumn = dataModel.findColumn("Time Per Person");
    if (timePerPersonColumn == -1) return false;

    double timePerPerson =
        NumericDataValue.parse(dataModel.getValueAt(editingRow, timePerPersonColumn));
    return !(timePerPerson > 0);
  }
Exemplo n.º 3
0
    public void addRow(Object... cellValues) {
      if (model == null) {
        throw new IllegalStateException("Model not set");
      }

      model.addRow(cellValues);
    }
Exemplo n.º 4
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<PartitionData> partitionsToRemove = new HashSet<PartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    //        if (options.allowDifferentTaxa && options.dataPartitions.size() < 2) {
    //            uncheckAllowDifferentTaxa();
    //        }

    if (options.getNonTraitsDataList().size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
Exemplo n.º 5
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<AbstractPartitionData> partitionsToRemove = new HashSet<AbstractPartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    boolean hasIdenticalTaxa =
        options.hasIdenticalTaxa(); // need to check this before removing partitions

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    if (options.dataPartitions.size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.setupStarBEAST(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    } else if (!hasIdenticalTaxa) {
      options.updateTaxonList();
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
Exemplo n.º 6
0
    public Object getCellValue(int rowIndex, int columnIndex) {
      if (model == null) {
        throw new IllegalStateException("Model not set");
      }

      int modelIndex = sorter.convertRowIndexToModel(rowIndex);
      return model.getValueAt(modelIndex, columnIndex);
    }
Exemplo n.º 7
0
 void setFile(File file) {
   this.file = file;
   this.ok = mainTreeModel.setFile(file);
   generalTableModel.setFile(file);
   datasourceTableModel.setFile(file);
   archiveTableModel.setFile(file);
   dataTableModel.setFile(file);
 }
Exemplo n.º 8
0
 public void update() {
   if (model != null) {
     model.fireTableDataChanged();
     if (!isFooter) {
       resizeColumns();
       sorter.sort();
     }
   }
 }
Exemplo n.º 9
0
  public void setOptions(BeautiOptions options) {

    this.options = options;

    modelsChanged();

    useStarBEASTCheck.setEnabled(
        options.getNonTraitsDataList().size() > 0); // single partition is allowed
    createImportTraitButton.setEnabled(options.getNonTraitsDataList().size() > 0);

    dataTableModel.fireTableDataChanged();
  }
Exemplo n.º 10
0
  public void setOptions(BeautiOptions options) {

    this.options = options;

    modelsChanged();

    boolean taxaAvailable = options.taxonList != null && options.taxonList.getTaxonCount() > 0;
    boolean traitAvailable =
        options.traits != null && options.traits.size() > 0 && (!options.useStarBEAST);

    useStarBEASTCheck.setEnabled(taxaAvailable);
    createTraitPartitionAction.setEnabled(traitAvailable);

    dataTableModel.fireTableDataChanged();
  }
Exemplo n.º 11
0
    public void setCellValue(int rowIndex, int columnIndex, Object value) {
      if (model == null) {
        throw new IllegalStateException("Model not set");
      }

      if (columnIndex < getColumnCount()) {
        if (rowIndex < getRowCount()) {
          model.getRows()[rowIndex].setCellValue(columnIndex, value);
        } else {
          throw new IllegalArgumentException("rowIndex out of bounds: " + rowIndex);
        }
      } else {
        throw new IllegalArgumentException("columnIndex out of bounds: " + columnIndex);
      }
    }
Exemplo n.º 12
0
  public boolean createFromTraits(List<TraitData> traits) {
    int selRow = -1;

    if (selectTraitDialog == null) {
      selectTraitDialog = new SelectTraitDialog(frame);
    }

    if (traits == null || traits.size() == 0) {
      int result = selectTraitDialog.showDialog(options.traits, null);
      if (result != JOptionPane.CANCEL_OPTION) {
        TraitData trait = selectTraitDialog.getTrait();
        String name = trait.getName();
        if (selectTraitDialog.getMakeCopy()) {
          name = selectTraitDialog.getName();
        }

        selRow = options.createPartitionForTraits(name, trait);
      } else {
        return false;
      }
    } else {
      if (traits.size() > 1) {
        // a set of traits have been passed to the function
        int result = selectTraitDialog.showDialog(null, null);
        if (result != JOptionPane.CANCEL_OPTION) {
          String name = selectTraitDialog.getName();
          selRow = options.createPartitionForTraits(name, traits);
        } else {
          return false;
        }
      } else {
        selRow = options.createPartitionForTraits(traits.get(0).getName(), traits);
      }
    }

    modelsChanged();
    dataTableModel.fireTableDataChanged();

    if (selRow != -1) {
      dataTable.getSelectionModel().setSelectionInterval(selRow, selRow);
    }
    fireDataChanged();
    repaint();

    return true;
  }
Exemplo n.º 13
0
  public void query(String query) throws IOException {
    EntrySet data;
    try {
      data = DatabaseService.getConnection().query(query);
    } catch (QueryException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          Main.MAIN_FRAME, e.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
      return;
    }

    removeAll();
    mainPanel.removeAll();
    toolbarPanel.removeAll();
    jtable = new JTable(new DataTableModel(data));
    jtable.setDefaultRenderer(Object.class, new DataTableRenderer());
    DataTableModel model = (DataTableModel) jtable.getModel();

    for (Entry entry : data.getEntries()) {
      model.addRow(entry.getData());
    }

    jtable.addMouseListener(new RowSelectionPopupListener(jtable, data));
    jtable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                if (!ignoreChanges) {
                  if (e.getType() == TableModelEvent.UPDATE) {
                    ignoreChanges = true;
                    int row = e.getLastRow();

                    if (row < data.size()) {
                      Entry entry = data.getEntries()[row];
                      Change change =
                          new Change(
                              entry.getEntryID(), Change.SET, new ArrayList<>(), new ArrayList<>());
                      Change previous = ChangeService.getService().getChange(entry.getEntryID());
                      if (previous != null) {
                        change.setOriginalData(previous.getOriginalData());
                      } else {
                        change.setOriginalData(new ArrayList<>(Arrays.asList(entry.getData())));
                      }

                      for (int col = 0; col < jtable.getColumnCount(); col++) {
                        change.getData().add((Serializable) jtable.getValueAt(row, col));
                      }

                      model.setRowColor(row, Color.orange);
                      ChangeService.getService().change(change);
                      setCanCommit(true);
                      ignoreChanges = false;
                    } else {
                      JOptionPane.showMessageDialog(
                          Main.MAIN_FRAME,
                          "You must commit this entry before editing it.",
                          "Error Editing",
                          JOptionPane.WARNING_MESSAGE);
                    }
                  }
                }
              }
            });

    JButton queryButton = new JButton("Query");
    queryField.setText(lastQuery);
    AutoCompleteDocument auto = new AutoCompleteDocument(queryField, data);

    queryField.getDocument().addDocumentListener(auto);
    queryField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL, 0), "autocomplete");
    queryField.getActionMap().put("autocomplete", auto.getAutocompleteAction());
    mainPanel.add(queryField, 0, 0);
    mainPanel.c.anchor = GridBagConstraints.NORTHEAST;
    mainPanel.add(queryButton, 0, 0);

    queryButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (canCommit) {
              if (JOptionPane.showConfirmDialog(
                      Main.MAIN_FRAME,
                      "Requerying the table will remove your uncommited changes. Continue?",
                      "Discard Uncommited Changes?",
                      JOptionPane.YES_NO_CANCEL_OPTION)
                  != JOptionPane.YES_OPTION) {
                return;
              }
            }
            ChangeService.getService().setChanges(new ArrayList<>());
            setCanCommit(false);

            try {
              lastQuery = queryField.getText();
              DatabaseService.getConnection()
                  .query(queryField.getText() + " IN " + DatabaseService.getCurrentTableName());
              query(lastQuery.toLowerCase().startsWith("get") ? lastQuery : "GET");
            } catch (QueryException e1) {
              JOptionPane.showMessageDialog(
                  Main.MAIN_FRAME, e1.getMessage(), "Error Querying", JOptionPane.ERROR_MESSAGE);
            } catch (IOException e1) {
              e1.printStackTrace();
            }
            return;
          }
        });

    if (commitButton.getActionListeners().length > 0) {
      commitButton.removeActionListener(commitButton.getActionListeners()[0]);
    }
    commitButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            CommitChangesWindow window = new CommitChangesWindow(data);
            window.open();
          }
        });
    JButton addButton = new JButton(new ImageIcon("assets/GreenPlus.png"));
    addButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            AddEntryWindow window = new AddEntryWindow(data);
            window.open();
          }
        });

    canCommit = false;
    commitButton.setEnabled(false);
    toolbarPanel.add(addButton, 0, 0);
    toolbarPanel.add(commitButton, 0, 1);

    addButton.setToolTipText("Add Entry");
    commitButton.setToolTipText("Commit Changes");

    mainPanel.c.anchor = GridBagConstraints.NORTHWEST;
    mainPanel.add(status, 0, 1);
    mainPanel.add(new JScrollPane(jtable), 0, 2);

    add(toolbarPanel);
    add(mainPanel);
    Main.MAIN_FRAME.pack();

    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    Main.MAIN_FRAME.setLocation(
        dim.width / 2 - Main.MAIN_FRAME.getSize().width / 2,
        dim.height / 2 - Main.MAIN_FRAME.getSize().height / 2);
  }
Exemplo n.º 14
0
 public void clear() {
   if (model != null) {
     model.clear();
   }
 }
Exemplo n.º 15
0
 public void createFromTraits() {
   frame.createImportTraits();
   dataTableModel.fireTableDataChanged();
 }
Exemplo n.º 16
0
 @Override
 public TableCellRenderer getCellRenderer(int rowIndex, int columnIndex) {
   return model.getCellRenderer(rowIndex, columnIndex);
 }
Exemplo n.º 17
0
 void selectModel(int dsIndex, int arcIndex) {
   datasourceTableModel.setIndex(dsIndex);
   archiveTableModel.setIndex(dsIndex, arcIndex);
   dataTableModel.setIndex(dsIndex, arcIndex);
 }
Exemplo n.º 18
0
 public Row[] getRows() {
   return (model != null) ? model.getRows() : null;
 }
Exemplo n.º 19
0
 @Override
 public int getRowCount() {
   return (model != null) ? model.getRowCount() : 0;
 }
Exemplo n.º 20
0
 public Column[] getColumns() {
   return (model != null) ? model.getColumns() : null;
 }
Exemplo n.º 21
0
 public void clearChangeColors(int row) {
   DataTableModel model = (DataTableModel) jtable.getModel();
   model.clearRowColor(row);
 }