Autopsy  4.7.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-2018 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.Exceptions;
30 import org.openide.util.NbBundle.Messages;
31 import org.openide.windows.WindowManager;
36 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 final class ManageCorrelationPropertiesDialog extends javax.swing.JDialog {
43 
44  private static final Logger LOGGER = Logger.getLogger(ManageCorrelationPropertiesDialog.class.getName());
45 
46  private final List<CorrelationAttribute.Type> correlationTypes;
47 
52  @Messages({"ManageCorrelationPropertiesDialog.title=Manage Correlation Properties"})
53  ManageCorrelationPropertiesDialog() {
54  super((JFrame) WindowManager.getDefault().getMainWindow(),
55  Bundle.ManageCorrelationPropertiesDialog_title(),
56  true); // NON-NLS
57  this.correlationTypes = new ArrayList<>();
58  initComponents();
59  customizeComponents();
60  display();
61  valid();
62  }
63 
64  private void customizeComponents() {
65  lbWarningMsg.setText("");
66 
67  loadData();
68  }
69 
70  private void loadData() {
71  DefaultTableModel model = (DefaultTableModel) tbCorrelatableTypes.getModel();
72  try {
73  EamDb dbManager = EamDb.getInstance();
74  correlationTypes.clear();
75  correlationTypes.addAll(dbManager.getDefinedCorrelationTypes());
76  } catch (EamDbException ex) {
77  Exceptions.printStackTrace(ex);
78  }
79 
80  correlationTypes.forEach((aType) -> {
81  model.addRow(new Object[]{aType.getDisplayName(), aType.isEnabled()});
82  });
83  model.addTableModelListener(new TableModelListener() {
84  @Override
85  public void tableChanged(TableModelEvent evt) {
86  int row = evt.getFirstRow();
87  TableModel model = (TableModel) evt.getSource();
88  Object displayName = model.getValueAt(row, 0);
89  Boolean enabled = (Boolean) model.getValueAt(row, 1);
90 
91  correlationTypes.stream().filter((aType) -> (aType.getDisplayName().equals(displayName))).forEachOrdered((aType) -> {
92  aType.setEnabled(enabled);
93  });
94  valid();
95  }
96  });
97  }
98 
99  private void display() {
100  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
101  setVisible(true);
102  }
103 
104  @Messages({"ManageCorrelationPropertiesDialog.noneSelected=There are no correlation properties enabled."})
105  private boolean valid() {
106  lbWarningMsg.setText("");
107 
108  int countEnabled = 0;
109  countEnabled = correlationTypes.stream().filter((aType) -> (aType.isEnabled())).map((_item) -> 1).reduce(countEnabled, Integer::sum);
110 
111  if (0 == countEnabled) {
112  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_noneSelected());
113  }
114  return true;
115  }
116 
122  @SuppressWarnings({"unchecked", "rawtypes"})
123  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
124  private void initComponents() {
125 
126  buttonGroup1 = new javax.swing.ButtonGroup();
127  okButton = new javax.swing.JButton();
128  cancelButton = new javax.swing.JButton();
129  jScrollPane1 = new javax.swing.JScrollPane();
130  tbCorrelatableTypes = new javax.swing.JTable();
131  lbWarningMsg = new javax.swing.JLabel();
132  taInstructions = new javax.swing.JTextArea();
133 
134  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
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.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
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-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.