Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
GlobalListSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.beans.PropertyChangeListener;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JOptionPane;
27 import org.openide.util.NbBundle;
29 
30 final class GlobalListSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
31 
32  private static final long serialVersionUID = 1L;
33 
34  private final GlobalListsManagementPanel listsManagementPanel = new GlobalListsManagementPanel(this);
35  private final GlobalEditListPanel editListPanel = new GlobalEditListPanel();
36 
37  GlobalListSettingsPanel() {
38  initComponents();
39  customizeComponents();
40  setName(org.openide.util.NbBundle.getMessage(DropdownToolbar.class, "ListBundleConfig"));
41  }
42 
43  private void customizeComponents() {
44  listsManagementPanel.addListSelectionListener(editListPanel);
45  listsManagementPanel.addDeleteButtonActionPerformed(new ActionListener() {
46  @Override
47  public void actionPerformed(ActionEvent e) {
48  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
49  String toDelete = editListPanel.getCurrentKeywordList().getName();
50  deleteAction(toDelete);
51  listsManagementPanel.resync();
52  }
53  }
54  });
55 
56  listsManagementPanel.addRenameButtonActionPerformed(new ActionListener() {
57  @Override
58  public void actionPerformed(ActionEvent e) {
59  String toDelete = editListPanel.getCurrentKeywordList().getName();
60  if (copyAction()) {
61  deleteAction(toDelete);
62  listsManagementPanel.resync();
63  }
64  }
65  });
66 
67  listsManagementPanel.addCopyButtonActionPerformed(new ActionListener() {
68  @Override
69  public void actionPerformed(ActionEvent e) {
70  copyAction();
71  listsManagementPanel.resync();
72  }
73  });
74 
75  mainSplitPane.setLeftComponent(listsManagementPanel);
76  mainSplitPane.setRightComponent(editListPanel);
77  mainSplitPane.revalidate();
78  mainSplitPane.repaint();
79  }
80 
86  private void deleteAction(String toDelete) {
87  XmlKeywordSearchList deleter = XmlKeywordSearchList.getCurrent();
88  deleter.deleteList(toDelete);
89  editListPanel.setCurrentKeywordList(null);
90  editListPanel.setButtonStates();
91  listsManagementPanel.setButtonStates();
92  }
93 
100  private boolean copyAction() {
101  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
102  "KeywordSearchGlobalListSettingsPanel.component.featureName.text");
103  KeywordList currentKeywordList = editListPanel.getCurrentKeywordList();
104 
105  List<Keyword> keywords = new ArrayList<>();
106  keywords.addAll(currentKeywordList.getKeywords());
107 
108  String listName = (String) JOptionPane.showInputDialog(
109  null,
110  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKwListTitle"),
111  FEATURE_NAME,
112  JOptionPane.PLAIN_MESSAGE,
113  null,
114  null,
115  currentKeywordList.getName());
116 
117  if (listName == null) {
118  return false;
119  }
120  //remove trailing and leading spaces so lists can't have visually identical names
121  listName = listName.trim();
122  //if the name is empty or unchanged return without changing anything
123  if (listName.equals("") || listName.equals(currentKeywordList.getName())) {
124  return false;
125  }
126  XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
127  if (writer.listExists(listName) && writer.getList(listName).isEditable()) {
128  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.noOwDefaultMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
129  return false;
130  }
131  if (writer.listExists(listName)) {
132  if (!KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListExistMsg", listName),
133  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
134  return false;
135  }
136  }
137  writer.addList(listName, keywords);
138  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListSavedMsg", listName), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
139  return true;
140  }
141 
142  @Override
143  public void addPropertyChangeListener(PropertyChangeListener l) {
144  listsManagementPanel.addPropertyChangeListener(l);
145  editListPanel.addPropertyChangeListener(l);
146  }
147 
148  @Override
149  public void removePropertyChangeListener(PropertyChangeListener l) {
150  listsManagementPanel.removePropertyChangeListener(l);
151  editListPanel.removePropertyChangeListener(l);
152  }
153 
154  @Override
155  public void store() {
156  XmlKeywordSearchList.getCurrent().save(false);
157  //refresh the list viewer/searcher panel
158  DropdownListSearchPanel.getDefault().resync();
159  }
160 
161  @Override
162  public void load() {
163  listsManagementPanel.load();
164  }
165 
169  void setFocusOnKeywordTextBox() {
170  editListPanel.setFocusOnKeywordTextBox();
171  }
172 
178  @SuppressWarnings("unchecked")
179  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
180  private void initComponents() {
181 
182  jScrollPane1 = new javax.swing.JScrollPane();
183  mainSplitPane = new javax.swing.JSplitPane();
184  leftPanel = new javax.swing.JPanel();
185  rightPanel = new javax.swing.JPanel();
186 
187  mainSplitPane.setBorder(null);
188  mainSplitPane.setDividerLocation(361);
189  mainSplitPane.setDividerSize(1);
190 
191  leftPanel.setPreferredSize(new java.awt.Dimension(309, 327));
192  leftPanel.setVerifyInputWhenFocusTarget(false);
193 
194  javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
195  leftPanel.setLayout(leftPanelLayout);
196  leftPanelLayout.setHorizontalGroup(
197  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addGap(0, 361, Short.MAX_VALUE)
199  );
200  leftPanelLayout.setVerticalGroup(
201  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202  .addGap(0, 327, Short.MAX_VALUE)
203  );
204 
205  mainSplitPane.setLeftComponent(leftPanel);
206 
207  rightPanel.setPreferredSize(new java.awt.Dimension(360, 327));
208 
209  javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
210  rightPanel.setLayout(rightPanelLayout);
211  rightPanelLayout.setHorizontalGroup(
212  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213  .addGap(0, 311, Short.MAX_VALUE)
214  );
215  rightPanelLayout.setVerticalGroup(
216  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217  .addGap(0, 327, Short.MAX_VALUE)
218  );
219 
220  mainSplitPane.setRightComponent(rightPanel);
221 
222  jScrollPane1.setViewportView(mainSplitPane);
223 
224  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
225  this.setLayout(layout);
226  layout.setHorizontalGroup(
227  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addGroup(layout.createSequentialGroup()
229  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
230  .addGap(0, 0, 0))
231  );
232  layout.setVerticalGroup(
233  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234  .addGroup(layout.createSequentialGroup()
235  .addComponent(jScrollPane1)
236  .addGap(0, 0, 0))
237  );
238  }// </editor-fold>//GEN-END:initComponents
239  // Variables declaration - do not modify//GEN-BEGIN:variables
240  private javax.swing.JScrollPane jScrollPane1;
241  private javax.swing.JPanel leftPanel;
242  private javax.swing.JSplitPane mainSplitPane;
243  private javax.swing.JPanel rightPanel;
244  // End of variables declaration//GEN-END:variables
245 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.