From 5faaeb06ef88c181566ff70f548dd3e0e628e8da Mon Sep 17 00:00:00 2001 From: Sophie Mori Date: Wed, 24 Aug 2016 14:38:52 -0400 Subject: [PATCH] Fixed properties file behavior, TODO: deleted tag names not appear in quick tag --- .../casemodule/services/Bundle.properties | 6 +- .../casemodule/services/TagsManager.java | 27 +++++++-- .../services/TagsManagerOptionsPanel.java | 55 +++++++++++-------- .../TagsManagerOptionsPanelController.java | 5 +- 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/services/Bundle.properties index cfaaa7bb20..6e35787c25 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/Bundle.properties @@ -13,8 +13,8 @@ TagsManagerOptionsPanel.addTagNameButton.empty=Tag name text is empty. TagsManagerOptionsPanel.addTagNameButton.containComma=Tag name may not contain commas. TagsManagerOptionsPanel.addTagNameButton.alreadyExists=Tag name already exists. TagsManagerOptionsPanel.jLabel1.text=Autopsy keeps a list of the tag names you have used in the past. Add more or delete them here. -TagsManagerOptionsPanel.tagNamesListLabel.text=\ -TagsManagerOptionsPanel.userTagNameTextField.text=\ +TagsManagerOptionsPanel.tagNamesListLabel.text=Your tag names: +TagsManagerOptionsPanel.userTagNameTextField.text= TagsManagerOptionsPanel.addTagNameButton.text=Add Tag Name TagsManagerOptionsPanel.deleteTagNameButton.text=Delete Tag Name -TagsManagerOptionsPanel.tagNameErrLabel.text=\ \ No newline at end of file +TagsManagerOptionsPanel.tagNameErrLabel.text= \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java index 318b4ce75f..e120ca1361 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java @@ -180,8 +180,8 @@ public class TagsManager implements Closeable { * Add the tag name to the tags settings. */ uniqueTagNames.put(newTagName.getDisplayName(), newTagName); - saveTagNamesToTagsSettings(); - + addNewTagNameToTagsSettings(newTagName); + return newTagName; } @@ -585,7 +585,7 @@ public class TagsManager implements Closeable { } /** - * Closes the tags manager, saving the avaialble tag names to secondary + * Closes the tags manager, saving the available tag names to secondary * storage. * * @throws IOException If there is a problem closing the tags manager. @@ -594,7 +594,7 @@ public class TagsManager implements Closeable { @Override @Deprecated public synchronized void close() throws IOException { - saveTagNamesToTagsSettings(); + //saveTagNamesToTagsSettings(); caseDb = null; } @@ -604,10 +604,10 @@ public class TagsManager implements Closeable { */ private void lazyLoadExistingTagNames() { if (!tagNamesLoaded) { - //addTagNamesFromCurrentCase(); addTagNamesFromTagsSettings(); addPredefinedTagNames(); saveTagNamesToTagsSettings(); + addTagNamesFromCurrentCase(); tagNamesLoaded = true; } } @@ -687,7 +687,22 @@ public class TagsManager implements Closeable { ModuleSettings.setConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY, setting.toString()); } } - + + /** + * + */ + private void addNewTagNameToTagsSettings(TagName tagName) { + String setting = ModuleSettings.getConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY); + if (setting == null || setting.isEmpty()) { + setting = ""; + } + else { + setting += ";"; + } + setting += tagName.getDisplayName() + "," + tagName.getDescription() + "," + tagName.getColor().name(); + ModuleSettings.setConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY, setting); + } + /** * Exception thrown if there is an attempt to add a duplicate tag name. */ diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanel.java index e0c90f8eee..a603bb3c12 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanel.java @@ -13,10 +13,13 @@ import java.util.TreeSet; import java.util.logging.Level; import javax.swing.DefaultListModel; import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.Exceptions; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; +import org.sleuthkit.datamodel.TskCoreException; /** * @@ -31,7 +34,7 @@ public class TagsManagerOptionsPanel extends javax.swing.JPanel implements Optio private static final String DEFAULT_COLOR_STRING = "NONE"; private final DefaultListModel tagNamesListModel; - private final Set tagNames; + private Set tagNames; /** * Creates new form TagsManagerPanel @@ -41,27 +44,23 @@ public class TagsManagerOptionsPanel extends javax.swing.JPanel implements Optio tagNamesListModel = new DefaultListModel<>(); tagNamesList.setModel(tagNamesListModel); - tagNames = new TreeSet<>(); - - customizeComponents(); - } - - private void customizeComponents() { - addTagNamesFromTagsSettings(); - + tagNames = getTagNamesFromTagsSettings(); + userTagNameTextField.setText(""); tagNameErrLabel.setText(""); } - private void addTagNamesFromTagsSettings() { + private Set getTagNamesFromTagsSettings() { + Set tagNamesFromSettings = new TreeSet<>(); String setting = ModuleSettings.getConfigSetting(TAGS_SETTINGS_NAME, TAG_NAMES_SETTING_KEY); if ((setting != null) && !setting.isEmpty()) { List tagNameTuples = Arrays.asList(setting.split(";")); for (String tagNameTuple : tagNameTuples) { String[] tagNameAttributes = tagNameTuple.split(","); CustomTagName tagName = new CustomTagName(tagNameAttributes[0], tagNameAttributes[1], tagNameAttributes[2]); - tagNames.add(tagName); + tagNamesFromSettings.add(tagName); } } + return tagNamesFromSettings; } private void updateTagNamesListModel() { @@ -222,8 +221,8 @@ public class TagsManagerOptionsPanel extends javax.swing.JPanel implements Optio } CustomTagName tagName = new CustomTagName(newTagName, DEFAULT_DESCRIPTION, DEFAULT_COLOR_STRING); - boolean added = tagNames.add(tagName); - if (!added) { + boolean addedToTagNames = tagNames.add(tagName); + if (!addedToTagNames) { tagNameErrLabel.setText(NbBundle.getMessage(TagsManagerOptionsPanel.class, "TagsManagerOptionsPanel.addTagNameButton.alreadyExists")); return; } @@ -237,16 +236,19 @@ public class TagsManagerOptionsPanel extends javax.swing.JPanel implements Optio private void deleteTagNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteTagNameButtonActionPerformed CustomTagName tagName = tagNamesList.getSelectedValue(); - if (tagName != null) { - tagNames.remove(tagName); - updateTagNamesListModel(); + if (tagName == null) { + tagNameErrLabel.setText("No tag name selected."); + } else { + tagNames.remove(tagName); + updateTagNamesListModel(); + + + if (!tagNamesListModel.isEmpty()) { + tagNamesList.setSelectedIndex(0); + } - if (!tagNamesListModel.isEmpty()) { - tagNamesList.setSelectedIndex(0); + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); } - - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - } }//GEN-LAST:event_deleteTagNameButtonActionPerformed @@ -281,9 +283,16 @@ public class TagsManagerOptionsPanel extends javax.swing.JPanel implements Optio @Override public void load() { - addTagNamesFromTagsSettings(); + tagNames = getTagNamesFromTagsSettings(); updateTagNamesListModel(); - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (!tagNamesListModel.isEmpty()) { + tagNamesList.setSelectedIndex(0); + } + tagNameErrLabel.setText(""); + } + + public void cancelChanges() { + tagNames = getTagNamesFromTagsSettings(); } /** diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanelController.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanelController.java index 00e461262d..bb876d82df 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanelController.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManagerOptionsPanelController.java @@ -42,7 +42,10 @@ public final class TagsManagerOptionsPanelController extends OptionsPanelControl @Override public void cancel() { - //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (changed) { + getPanel().cancelChanges(); + changed = false; + } } @Override