Esempio n. 1
0
  /**
   * Edits an {@link com.noiraak.enhrick.model.Entry Entry} at the specified index with the given
   * String and adds it to the corresponding file on the disk.
   *
   * @param newText The content of the edited {@link com.noiraak.enhrick.model.Entry Entry}
   * @param selectedIndex The index of the {@link com.noiraak.enhrick.model.Entry Entry} to edit
   * @return the list with including the newly generated {@link com.noiraak.enhrick.model.Entry
   *     Entry}
   */
  public List<Entry> editEntry(String newText, int selectedIndex) {
    List<Entry> clonedEntries = new ArrayList<>(entries);
    Entry entry = entries.get(selectedIndex);
    entry.setText(newText + "\n");
    entry.setModified(System.currentTimeMillis());

    fileManager.saveEditedEntry(entry, selectedIndex, FileConfigurationProvider.getFilePath());
    // For some bizarre reason fileManager.editEntry() completely empties entries sometimes - hence
    // the cloned list.
    if (entries.size() < clonedEntries.size()) {
      entries = clonedEntries;
    }
    entries.set(selectedIndex, entry);

    return entries;
  }
Esempio n. 2
0
  /**
   * Updates the username of entries. Also re-writes the entry-file.
   *
   * @param oldUsername the old username
   */
  public void updateUsername(String oldUsername) {
    if (oldUsername.equals(
        ConfigurationProvider.getStringConfiguration(ConfigurationKey.USERNAME))) {
      return;
    }

    for (Entry entry : entries) {
      if (entry.getModifier() != null && entry.getModifier().equals(oldUsername)) {
        entry.setModifier(ConfigurationProvider.getStringConfiguration(ConfigurationKey.USERNAME));
      }
    }

    fileManager.rewriteEntries(
        FileConfigurationProvider.getFilePath(),
        oldUsername,
        ConfigurationProvider.getStringConfiguration(ConfigurationKey.USERNAME));
  }
  private void listSelectionChanged(int index) {
    enhRick.getTaNewText().setEnabled(true);

    if (index >= 0) {
      Entry entry = enhRick.getEntryService().getEntryAt(index);

      enhRick.getTaNewText().setText(entry.getText().substring(0, entry.getText().length() - 1));
      enhRick.getTaNewText().setCaretPosition(0);
      if (index > 0
          || entry.getModifier() == null
          || (!entry
              .getModifier()
              .equals(ConfigurationProvider.getStringConfiguration(ConfigurationKey.USERNAME)))) {
        enhRick.getTaNewText().setEnabled(false);
      }
    } else {
      enhRick.getTaNewText().setText("");
    }
  }