Autopsy  4.20.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  CentralRepository dbManager = CentralRepository.getInstance();
73  correlationTypes.clear();
74  correlationTypes.addAll(dbManager.getDefinedCorrelationTypes());
75  } catch (CentralRepoException 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(lbWarningMsg.getFont().deriveFont(lbWarningMsg.getFont().getSize()+1f));
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.setLineWrap(true);
187  taInstructions.setRows(5);
188  taInstructions.setText(org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class, "ManageArtifactTypesDialog.taInstructionsMsg.text")); // NOI18N
189  taInstructions.setWrapStyleWord(true);
190  taInstructions.setAutoscrolls(false);
191  taInstructions.setBorder(null);
192  taInstructions.setFocusable(false);
193  taInstructions.setRequestFocusEnabled(false);
194  taInstructions.setVerifyInputWhenFocusTarget(false);
195 
196  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
197  getContentPane().setLayout(layout);
198  layout.setHorizontalGroup(
199  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
201  .addContainerGap()
202  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
203  .addComponent(taInstructions)
204  .addComponent(lbWarningMsg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
205  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
206  .addGap(0, 0, Short.MAX_VALUE)
207  .addComponent(okButton)
208  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209  .addComponent(cancelButton))
210  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
211  .addContainerGap())
212  );
213 
214  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
215 
216  layout.setVerticalGroup(
217  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
219  .addGap(20, 20, 20)
220  .addComponent(taInstructions, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
221  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
222  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
223  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
224  .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
225  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
227  .addComponent(okButton)
228  .addComponent(cancelButton))
229  .addContainerGap())
230  );
231 
232  pack();
233  }// </editor-fold>//GEN-END:initComponents
234 
235  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
236  dispose();
237  }//GEN-LAST:event_cancelButtonActionPerformed
238 
239  @Messages({"ManageCorrelationPropertiesDialog.okbutton.failure=Error saving updated selections."})
240  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
241 
242  if (0 == correlationTypes.size()) {
243  dispose();
244  } else {
245  CentralRepository dbManager;
246  try {
247  dbManager = CentralRepository.getInstance();
248  } catch (CentralRepoException ex) {
249  LOGGER.log(Level.SEVERE, "Failed to connect to central repository database.", ex);
250  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
251  return;
252  }
253  correlationTypes.forEach((aType) -> {
254  try {
255  dbManager.updateCorrelationType(aType);
256  dispose();
257  } catch (CentralRepoException ex) {
258  LOGGER.log(Level.SEVERE, "Failed to update correlation properties with selections from dialog.", ex); // NON-NLS
259  lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
260  }
261  });
262  }
263  }//GEN-LAST:event_okButtonActionPerformed
264 
265  // Variables declaration - do not modify//GEN-BEGIN:variables
266  private javax.swing.ButtonGroup buttonGroup1;
267  private javax.swing.JButton cancelButton;
268  private javax.swing.JScrollPane jScrollPane1;
269  private javax.swing.JLabel lbWarningMsg;
270  private javax.swing.JButton okButton;
271  private javax.swing.JTextArea taInstructions;
272  private javax.swing.JTable tbCorrelatableTypes;
273  // End of variables declaration//GEN-END:variables
274 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.