Autopsy  4.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  deleteAction();
50  listsManagementPanel.resync();
51  }
52  }
53  });
54 
55  listsManagementPanel.addRenameButtonActionPerformed(new ActionListener() {
56  @Override
57  public void actionPerformed(ActionEvent e) {
58  if (copyAction()) {
59  deleteAction();
60  listsManagementPanel.resync();
61  }
62  }
63  });
64 
65  listsManagementPanel.addCopyButtonActionPerformed(new ActionListener() {
66  @Override
67  public void actionPerformed(ActionEvent e) {
68  copyAction();
69  listsManagementPanel.resync();
70  }
71  });
72 
73  mainSplitPane.setLeftComponent(listsManagementPanel);
74  mainSplitPane.setRightComponent(editListPanel);
75  mainSplitPane.revalidate();
76  mainSplitPane.repaint();
77  }
78 
84  private void deleteAction() {
85  listsManagementPanel.deleteSelected();
86  editListPanel.setCurrentKeywordList(null);
87  editListPanel.setButtonStates();
88  listsManagementPanel.setButtonStates();
89  }
90 
97  private boolean copyAction() {
98  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
99  "KeywordSearchGlobalListSettingsPanel.component.featureName.text");
100  KeywordList currentKeywordList = editListPanel.getCurrentKeywordList();
101 
102  List<Keyword> keywords = new ArrayList<>();
103  keywords.addAll(currentKeywordList.getKeywords());
104 
105  String listName = (String) JOptionPane.showInputDialog(
106  null,
107  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKwListTitle"),
108  FEATURE_NAME,
109  JOptionPane.PLAIN_MESSAGE,
110  null,
111  null,
112  currentKeywordList.getName());
113 
114  if (listName == null) {
115  return false;
116  }
117  //remove trailing and leading spaces so lists can't have visually identical names
118  listName = listName.trim();
119  //if the name is empty or unchanged return without changing anything
120  if (listName.equals("") || listName.equals(currentKeywordList.getName())) {
121  return false;
122  }
123  XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
124  if (writer.listExists(listName) && writer.getList(listName).isEditable()) {
125  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.noOwDefaultMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
126  return false;
127  }
128  if (writer.listExists(listName)) {
129  if (!KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListExistMsg", listName),
130  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
131  return false;
132  }
133  }
134  writer.addList(listName, keywords);
135  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListSavedMsg", listName), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
136  return true;
137  }
138 
139  @Override
140  public void addPropertyChangeListener(PropertyChangeListener l) {
141  listsManagementPanel.addPropertyChangeListener(l);
142  editListPanel.addPropertyChangeListener(l);
143  }
144 
145  @Override
146  public void removePropertyChangeListener(PropertyChangeListener l) {
147  listsManagementPanel.removePropertyChangeListener(l);
148  editListPanel.removePropertyChangeListener(l);
149  }
150 
151  @Override
152  public void store() {
153  XmlKeywordSearchList.getCurrent().save(false);
154  //refresh the list viewer/searcher panel
155  DropdownListSearchPanel.getDefault().resync();
156  }
157 
158  @Override
159  public void load() {
160  listsManagementPanel.load();
161  }
162 
166  void setFocusOnKeywordTextBox() {
167  editListPanel.setFocusOnKeywordTextBox();
168  }
169 
175  @SuppressWarnings("unchecked")
176  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
177  private void initComponents() {
178 
179  jScrollPane1 = new javax.swing.JScrollPane();
180  mainSplitPane = new javax.swing.JSplitPane();
181  leftPanel = new javax.swing.JPanel();
182  rightPanel = new javax.swing.JPanel();
183 
184  mainSplitPane.setBorder(null);
185  mainSplitPane.setDividerLocation(361);
186  mainSplitPane.setDividerSize(1);
187 
188  leftPanel.setPreferredSize(new java.awt.Dimension(309, 327));
189  leftPanel.setVerifyInputWhenFocusTarget(false);
190 
191  javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
192  leftPanel.setLayout(leftPanelLayout);
193  leftPanelLayout.setHorizontalGroup(
194  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addGap(0, 361, Short.MAX_VALUE)
196  );
197  leftPanelLayout.setVerticalGroup(
198  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199  .addGap(0, 327, Short.MAX_VALUE)
200  );
201 
202  mainSplitPane.setLeftComponent(leftPanel);
203 
204  rightPanel.setPreferredSize(new java.awt.Dimension(360, 327));
205 
206  javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
207  rightPanel.setLayout(rightPanelLayout);
208  rightPanelLayout.setHorizontalGroup(
209  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210  .addGap(0, 311, Short.MAX_VALUE)
211  );
212  rightPanelLayout.setVerticalGroup(
213  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214  .addGap(0, 327, Short.MAX_VALUE)
215  );
216 
217  mainSplitPane.setRightComponent(rightPanel);
218 
219  jScrollPane1.setViewportView(mainSplitPane);
220 
221  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
222  this.setLayout(layout);
223  layout.setHorizontalGroup(
224  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
225  .addGroup(layout.createSequentialGroup()
226  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
227  .addGap(0, 0, 0))
228  );
229  layout.setVerticalGroup(
230  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231  .addGroup(layout.createSequentialGroup()
232  .addComponent(jScrollPane1)
233  .addGap(0, 0, 0))
234  );
235  }// </editor-fold>//GEN-END:initComponents
236  // Variables declaration - do not modify//GEN-BEGIN:variables
237  private javax.swing.JScrollPane jScrollPane1;
238  private javax.swing.JPanel leftPanel;
239  private javax.swing.JSplitPane mainSplitPane;
240  private javax.swing.JPanel rightPanel;
241  // End of variables declaration//GEN-END:variables
242 }

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