Autopsy  4.5.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  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
102  setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
103  setVisible(true);
104  }
105 
106  @Messages({"ManageCorrelationPropertiesDialog.noneSelected=There are no correlation properties enabled."})
107  private boolean valid() {
108  lbWarningMsg.setText("");
109 
110  int countEnabled = 0;
111  countEnabled = correlationTypes.stream().filter((aType) -> (aType.isEnabled())).map((_item) -> 1).reduce(countEnabled, Integer::sum);
112 
113  if (0 == countEnabled) {
114  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_noneSelected());
115  }
116  return true;
117  }
118 
124  @SuppressWarnings({"unchecked", "rawtypes"})
125  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
126  private void initComponents() {
127 
128  buttonGroup1 = new javax.swing.ButtonGroup();
129  okButton = new javax.swing.JButton();
130  cancelButton = new javax.swing.JButton();
131  jScrollPane1 = new javax.swing.JScrollPane();
132  tbCorrelatableTypes = new javax.swing.JTable();
133  lbWarningMsg = new javax.swing.JLabel();
134  taInstructions = new javax.swing.JTextArea();
135 
136  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
137 
138  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.okButton.text")); // NOI18N
139  okButton.addActionListener(new java.awt.event.ActionListener() {
140  public void actionPerformed(java.awt.event.ActionEvent evt) {
141  okButtonActionPerformed(evt);
142  }
143  });
144 
145  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.cancelButton.text")); // NOI18N
146  cancelButton.addActionListener(new java.awt.event.ActionListener() {
147  public void actionPerformed(java.awt.event.ActionEvent evt) {
148  cancelButtonActionPerformed(evt);
149  }
150  });
151 
152  jScrollPane1.setMinimumSize(new java.awt.Dimension(150, 23));
153 
154  tbCorrelatableTypes.setModel(new javax.swing.table.DefaultTableModel(
155  new Object [][] {
156 
157  },
158  new String [] {
159  "Correlation Properties", "Enable"
160  }
161  ) {
162  Class[] types = new Class [] {
163  java.lang.String.class, java.lang.Boolean.class
164  };
165  boolean[] canEdit = new boolean [] {
166  false, true
167  };
168 
169  public Class getColumnClass(int columnIndex) {
170  return types [columnIndex];
171  }
172 
173  public boolean isCellEditable(int rowIndex, int columnIndex) {
174  return canEdit [columnIndex];
175  }
176  });
177  tbCorrelatableTypes.setMaximumSize(new java.awt.Dimension(400, 0));
178  tbCorrelatableTypes.setMinimumSize(new java.awt.Dimension(150, 0));
179  jScrollPane1.setViewportView(tbCorrelatableTypes);
180 
181  lbWarningMsg.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
182  lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0));
183  org.openide.awt.Mnemonics.setLocalizedText(lbWarningMsg, org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageCorrelationPropertiesDialog.lbWarningMsg.text")); // NOI18N
184 
185  taInstructions.setEditable(false);
186  taInstructions.setBackground(new java.awt.Color(240, 240, 240));
187  taInstructions.setColumns(20);
188  taInstructions.setFont(new java.awt.Font("Tahoma", 0, 11)); // NOI18N
189  taInstructions.setLineWrap(true);
190  taInstructions.setRows(5);
191  taInstructions.setText(org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageArtifactTypesDialog.taInstructionsMsg.text")); // NOI18N
192  taInstructions.setWrapStyleWord(true);
193  taInstructions.setAutoscrolls(false);
194  taInstructions.setBorder(null);
195  taInstructions.setFocusable(false);
196  taInstructions.setRequestFocusEnabled(false);
197  taInstructions.setVerifyInputWhenFocusTarget(false);
198 
199  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
200  getContentPane().setLayout(layout);
201  layout.setHorizontalGroup(
202  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
204  .addContainerGap()
205  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
206  .addComponent(taInstructions)
207  .addComponent(lbWarningMsg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
208  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
209  .addGap(0, 0, Short.MAX_VALUE)
210  .addComponent(okButton)
211  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
212  .addComponent(cancelButton))
213  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
214  .addContainerGap())
215  );
216 
217  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
218 
219  layout.setVerticalGroup(
220  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
222  .addGap(20, 20, 20)
223  .addComponent(taInstructions, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
224  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
225  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
226  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
227  .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
228  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
229  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
230  .addComponent(okButton)
231  .addComponent(cancelButton))
232  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
233  );
234 
235  pack();
236  }// </editor-fold>//GEN-END:initComponents
237 
238  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
239  dispose();
240  }//GEN-LAST:event_cancelButtonActionPerformed
241 
242  @Messages({"ManageCorrelationPropertiesDialog.okbutton.failure=Error saving updated selections."})
243  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
244 
245  if (0 == correlationTypes.size()) {
246  dispose();
247  } else {
248  EamDb dbManager;
249  try {
250  dbManager = EamDb.getInstance();
251  } catch (EamDbException ex) {
252  LOGGER.log(Level.SEVERE, "Failed to connect to central repository database.", ex);
253  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
254  return;
255  }
256  correlationTypes.forEach((aType) -> {
257  try {
258  dbManager.updateCorrelationType(aType);
259  dispose();
260  } catch (EamDbException ex) {
261  LOGGER.log(Level.SEVERE, "Failed to update correlation properties with selections from dialog.", ex); // NON-NLS
262  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
263  }
264  });
265  }
266  }//GEN-LAST:event_okButtonActionPerformed
267 
268  // Variables declaration - do not modify//GEN-BEGIN:variables
269  private javax.swing.ButtonGroup buttonGroup1;
270  private javax.swing.JButton cancelButton;
271  private javax.swing.JScrollPane jScrollPane1;
272  private javax.swing.JLabel lbWarningMsg;
273  private javax.swing.JButton okButton;
274  private javax.swing.JTextArea taInstructions;
275  private javax.swing.JTable tbCorrelatableTypes;
276  // End of variables declaration//GEN-END:variables
277 }

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