Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ManageCorrelationPropertiesDialog.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2019 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.centralrepository.optionspanel;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.JFrame;
25 import javax.swing.event.TableModelEvent;
26 import javax.swing.event.TableModelListener;
27 import javax.swing.table.DefaultTableModel;
28 import javax.swing.table.TableModel;
29 import org.openide.util.NbBundle.Messages;
30 import org.openide.windows.WindowManager;
35 
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
41 final class ManageCorrelationPropertiesDialog extends javax.swing.JDialog {
42 
43  private static final Logger LOGGER = Logger.getLogger(ManageCorrelationPropertiesDialog.class.getName());
44 
45  private final List<CorrelationAttributeInstance.Type> correlationTypes;
46 
51  @Messages({"ManageCorrelationPropertiesDialog.title=Manage Correlation Properties"})
52  ManageCorrelationPropertiesDialog() {
53  super((JFrame) WindowManager.getDefault().getMainWindow(),
54  Bundle.ManageCorrelationPropertiesDialog_title(),
55  true); // NON-NLS
56  this.correlationTypes = new ArrayList<>();
57  initComponents();
58  customizeComponents();
59  display();
60  valid();
61  }
62 
63  private void customizeComponents() {
64  lbWarningMsg.setText("");
65 
66  loadData();
67  }
68 
69  private void loadData() {
70  DefaultTableModel model = (DefaultTableModel) tbCorrelatableTypes.getModel();
71  try {
72  EamDb dbManager = EamDb.getInstance();
73  correlationTypes.clear();
74  correlationTypes.addAll(dbManager.getDefinedCorrelationTypes());
75  } catch (EamDbException ex) {
76  LOGGER.log(Level.WARNING, "Error loading data", ex);
77  }
78 
79  correlationTypes.forEach((aType) -> {
80  model.addRow(new Object[]{aType.getDisplayName(), aType.isEnabled()});
81  });
82  model.addTableModelListener(new TableModelListener() {
83  @Override
84  public void tableChanged(TableModelEvent evt) {
85  int row = evt.getFirstRow();
86  TableModel model = (TableModel) evt.getSource();
87  Object displayName = model.getValueAt(row, 0);
88  Boolean enabled = (Boolean) model.getValueAt(row, 1);
89 
90  correlationTypes.stream().filter((aType) -> (aType.getDisplayName().equals(displayName))).forEachOrdered((aType) -> {
91  aType.setEnabled(enabled);
92  });
93  valid();
94  }
95  });
96  }
97 
98  private void display() {
99  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
100  setVisible(true);
101  }
102 
103  @Messages({"ManageCorrelationPropertiesDialog.noneSelected=There are no correlation properties enabled."})
104  private boolean valid() {
105  lbWarningMsg.setText("");
106 
107  int countEnabled = 0;
108  countEnabled = correlationTypes.stream().filter((aType) -> (aType.isEnabled())).map((_item) -> 1).reduce(countEnabled, Integer::sum);
109 
110  if (0 == countEnabled) {
111  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_noneSelected());
112  }
113  return true;
114  }
115 
121  @SuppressWarnings({"unchecked", "rawtypes"})
122  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123  private void initComponents() {
124 
125  buttonGroup1 = new javax.swing.ButtonGroup();
126  okButton = new javax.swing.JButton();
127  cancelButton = new javax.swing.JButton();
128  jScrollPane1 = new javax.swing.JScrollPane();
129  tbCorrelatableTypes = new javax.swing.JTable();
130  lbWarningMsg = new javax.swing.JLabel();
131  taInstructions = new javax.swing.JTextArea();
132 
133  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
134  setResizable(false);
135 
136  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.okButton.text")); // NOI18N
137  okButton.addActionListener(new java.awt.event.ActionListener() {
138  public void actionPerformed(java.awt.event.ActionEvent evt) {
139  okButtonActionPerformed(evt);
140  }
141  });
142 
143  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.cancelButton.text")); // NOI18N
144  cancelButton.addActionListener(new java.awt.event.ActionListener() {
145  public void actionPerformed(java.awt.event.ActionEvent evt) {
146  cancelButtonActionPerformed(evt);
147  }
148  });
149 
150  jScrollPane1.setMinimumSize(new java.awt.Dimension(150, 23));
151 
152  tbCorrelatableTypes.setModel(new javax.swing.table.DefaultTableModel(
153  new Object [][] {
154 
155  },
156  new String [] {
157  "Correlation Properties", "Enable"
158  }
159  ) {
160  Class[] types = new Class [] {
161  java.lang.String.class, java.lang.Boolean.class
162  };
163  boolean[] canEdit = new boolean [] {
164  false, true
165  };
166 
167  public Class getColumnClass(int columnIndex) {
168  return types [columnIndex];
169  }
170 
171  public boolean isCellEditable(int rowIndex, int columnIndex) {
172  return canEdit [columnIndex];
173  }
174  });
175  tbCorrelatableTypes.setMaximumSize(new java.awt.Dimension(400, 0));
176  tbCorrelatableTypes.setMinimumSize(new java.awt.Dimension(150, 0));
177  jScrollPane1.setViewportView(tbCorrelatableTypes);
178 
179  lbWarningMsg.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
180  lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0));
181  org.openide.awt.Mnemonics.setLocalizedText(lbWarningMsg, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.lbWarningMsg.text")); // NOI18N
182 
183  taInstructions.setEditable(false);
184  taInstructions.setBackground(new java.awt.Color(240, 240, 240));
185  taInstructions.setColumns(20);
186  taInstructions.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
187  taInstructions.setLineWrap(true);
188  taInstructions.setRows(5);
189  taInstructions.setText(org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageArtifactTypesDialog.taInstructionsMsg.text")); // NOI18N
190  taInstructions.setWrapStyleWord(true);
191  taInstructions.setAutoscrolls(false);
192  taInstructions.setBorder(null);
193  taInstructions.setFocusable(false);
194  taInstructions.setRequestFocusEnabled(false);
195  taInstructions.setVerifyInputWhenFocusTarget(false);
196 
197  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
198  getContentPane().setLayout(layout);
199  layout.setHorizontalGroup(
200  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
202  .addContainerGap()
203  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
204  .addComponent(taInstructions)
205  .addComponent(lbWarningMsg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
206  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
207  .addGap(0, 0, Short.MAX_VALUE)
208  .addComponent(okButton)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210  .addComponent(cancelButton))
211  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
212  .addContainerGap())
213  );
214 
215  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
216 
217  layout.setVerticalGroup(
218  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
220  .addGap(20, 20, 20)
221  .addComponent(taInstructions, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
222  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
223  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
224  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225  .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
226  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
227  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
228  .addComponent(okButton)
229  .addComponent(cancelButton))
230  .addContainerGap())
231  );
232 
233  pack();
234  }// </editor-fold>//GEN-END:initComponents
235 
236  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
237  dispose();
238  }//GEN-LAST:event_cancelButtonActionPerformed
239 
240  @Messages({"ManageCorrelationPropertiesDialog.okbutton.failure=Error saving updated selections."})
241  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
242 
243  if (0 == correlationTypes.size()) {
244  dispose();
245  } else {
246  EamDb dbManager;
247  try {
248  dbManager = EamDb.getInstance();
249  } catch (EamDbException ex) {
250  LOGGER.log(Level.SEVERE, "Failed to connect to central repository database.", ex);
251  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
252  return;
253  }
254  correlationTypes.forEach((aType) -> {
255  try {
256  dbManager.updateCorrelationType(aType);
257  dispose();
258  } catch (EamDbException ex) {
259  LOGGER.log(Level.SEVERE, "Failed to update correlation properties with selections from dialog.", ex); // NON-NLS
260  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
261  }
262  });
263  }
264  }//GEN-LAST:event_okButtonActionPerformed
265 
266  // Variables declaration - do not modify//GEN-BEGIN:variables
267  private javax.swing.ButtonGroup buttonGroup1;
268  private javax.swing.JButton cancelButton;
269  private javax.swing.JScrollPane jScrollPane1;
270  private javax.swing.JLabel lbWarningMsg;
271  private javax.swing.JButton okButton;
272  private javax.swing.JTextArea taInstructions;
273  private javax.swing.JTable tbCorrelatableTypes;
274  // End of variables declaration//GEN-END:variables
275 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.