Added delete/delete all button handlers in list search.

This commit is contained in:
adam-m 2012-01-05 17:42:05 -05:00
parent 8fefd9b23d
commit 89bceacdf7
3 changed files with 37 additions and 5 deletions

View File

@ -30,7 +30,7 @@ KeywordSearchListTopComponent.loadListButton.text=Load
KeywordSearchListTopComponent.addWordField.text= KeywordSearchListTopComponent.addWordField.text=
KeywordSearchListTopComponent.saveListButton.text=Save KeywordSearchListTopComponent.saveListButton.text=Save
KeywordSearchListTopComponent.chLiteralWord.text=Literal KeywordSearchListTopComponent.chLiteralWord.text=Literal
KeywordSearchListTopComponent.addWordLabel.text=Add a new word: KeywordSearchListTopComponent.addWordLabel.text=Add a new keyword:
KeywordSearchListTopComponent.deleteWordButton.text=Delete KeywordSearchListTopComponent.deleteWordButton.text=Delete
KeywordSearchListTopComponent.deleteAllWordsButton.text=Delete All KeywordSearchListTopComponent.deleteAllWordsButton.text=Delete All
KeywordSearchSimpleTopComponent.chRegex.text=RegEx KeywordSearchSimpleTopComponent.chRegex.text=RegEx

View File

@ -172,6 +172,9 @@
<ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="KeywordSearchListTopComponent.deleteAllWordsButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="org/sleuthkit/autopsy/keywordsearch/Bundle.properties" key="KeywordSearchListTopComponent.deleteAllWordsButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteAllWordsButtonActionPerformed"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="saveListButton"> <Component class="javax.swing.JButton" name="saveListButton">
<Properties> <Properties>

View File

@ -165,6 +165,11 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
}); });
org.openide.awt.Mnemonics.setLocalizedText(deleteAllWordsButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.deleteAllWordsButton.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(deleteAllWordsButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.deleteAllWordsButton.text")); // NOI18N
deleteAllWordsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteAllWordsButtonActionPerformed(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(saveListButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.saveListButton.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(saveListButton, org.openide.util.NbBundle.getMessage(KeywordSearchListTopComponent.class, "KeywordSearchListTopComponent.saveListButton.text")); // NOI18N
saveListButton.addActionListener(new java.awt.event.ActionListener() { saveListButton.addActionListener(new java.awt.event.ActionListener() {
@ -302,8 +307,13 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
}//GEN-LAST:event_chLiteralWordActionPerformed }//GEN-LAST:event_chLiteralWordActionPerformed
private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWordButtonActionPerformed private void deleteWordButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteWordButtonActionPerformed
// TODO add your handling code here: tableModel.deleteSelected();
}//GEN-LAST:event_deleteWordButtonActionPerformed }//GEN-LAST:event_deleteWordButtonActionPerformed
private void deleteAllWordsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteAllWordsButtonActionPerformed
tableModel.deleteAll();
}//GEN-LAST:event_deleteAllWordsButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addWordButton; private javax.swing.JButton addWordButton;
private javax.swing.JTextField addWordField; private javax.swing.JTextField addWordField;
@ -466,7 +476,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
List<String> getSelectedKeywords() { List<String> getSelectedKeywords() {
List<String> ret = new ArrayList<String>(); List<String> ret = new ArrayList<String>();
for (TableEntry e : keywordData) { for (TableEntry e : keywordData) {
if (e.isActive) { if (e.isActive && !e.keyword.equals("")) {
ret.add(e.keyword); ret.add(e.keyword);
} }
} }
@ -483,11 +493,30 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
this.fireTableRowsInserted(keywordData.size() - 1, keywordData.size()); this.fireTableRowsInserted(keywordData.size() - 1, keywordData.size());
} }
void deleteAll() {
keywordData.clear();
initEmpty();
}
void deleteSelected() {
List<TableEntry> toDel = new ArrayList<TableEntry>();
int i = 0;
for (TableEntry e: keywordData) {
if (e.isActive && !e.keyword.equals(""))
toDel.add(e);
}
for (TableEntry del : toDel) {
keywordData.remove(del);
}
fireTableDataChanged();
}
void initEmpty() { void initEmpty() {
for (int i = 0; i<20; ++i) { for (int i = 0; i<20; ++i) {
keywordData.add(0, new TableEntry("", false)); keywordData.add(0, new TableEntry("", false));
} }
this.fireTableDataChanged(); fireTableDataChanged();
} }
class TableEntry { class TableEntry {
@ -502,7 +531,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
TableEntry(String keyword) { TableEntry(String keyword) {
this.keyword = keyword; this.keyword = keyword;
this.isActive = true; this.isActive = false;
} }
} }
} }