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

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