19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
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;
40 @SuppressWarnings(
"PMD.SingularField")
41 final class ManageCorrelationPropertiesDialog extends javax.swing.JDialog {
43 private static final Logger LOGGER = Logger.getLogger(ManageCorrelationPropertiesDialog.class.getName());
45 private final List<CorrelationAttributeInstance.Type> correlationTypes;
51 @Messages({
"ManageCorrelationPropertiesDialog.title=Manage Correlation Properties"})
52 ManageCorrelationPropertiesDialog() {
53 super((JFrame) WindowManager.getDefault().getMainWindow(),
54 Bundle.ManageCorrelationPropertiesDialog_title(),
56 this.correlationTypes =
new ArrayList<>();
58 customizeComponents();
63 private void customizeComponents() {
64 lbWarningMsg.setText(
"");
69 private void loadData() {
70 DefaultTableModel model = (DefaultTableModel) tbCorrelatableTypes.getModel();
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);
79 correlationTypes.forEach((aType) -> {
80 model.addRow(
new Object[]{aType.getDisplayName(), aType.isEnabled()});
82 model.addTableModelListener(
new TableModelListener() {
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);
90 correlationTypes.stream().filter((aType) -> (aType.getDisplayName().equals(displayName))).forEachOrdered((aType) -> {
91 aType.setEnabled(enabled);
98 private void display() {
99 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
103 @Messages({
"ManageCorrelationPropertiesDialog.noneSelected=There are no correlation properties enabled."})
104 private boolean valid() {
105 lbWarningMsg.setText(
"");
107 int countEnabled = 0;
108 countEnabled = correlationTypes.stream().filter((aType) -> (aType.isEnabled())).map((_item) -> 1).reduce(countEnabled, Integer::sum);
110 if (0 == countEnabled) {
111 lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_noneSelected());
121 @SuppressWarnings({
"unchecked",
"rawtypes"})
123 private void initComponents() {
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();
133 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
136 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class,
"ManageCorrelationPropertiesDialog.okButton.text"));
137 okButton.addActionListener(
new java.awt.event.ActionListener() {
138 public void actionPerformed(java.awt.event.ActionEvent evt) {
139 okButtonActionPerformed(evt);
143 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class,
"ManageCorrelationPropertiesDialog.cancelButton.text"));
144 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
145 public void actionPerformed(java.awt.event.ActionEvent evt) {
146 cancelButtonActionPerformed(evt);
150 jScrollPane1.setMinimumSize(
new java.awt.Dimension(150, 23));
152 tbCorrelatableTypes.setModel(
new javax.swing.table.DefaultTableModel(
157 "Correlation Properties",
"Enable"
160 Class[] types =
new Class [] {
161 java.lang.String.class, java.lang.Boolean.class
163 boolean[] canEdit =
new boolean [] {
167 public Class getColumnClass(
int columnIndex) {
168 return types [columnIndex];
171 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
172 return canEdit [columnIndex];
175 tbCorrelatableTypes.setMaximumSize(
new java.awt.Dimension(400, 0));
176 tbCorrelatableTypes.setMinimumSize(
new java.awt.Dimension(150, 0));
177 jScrollPane1.setViewportView(tbCorrelatableTypes);
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"));
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"));
189 taInstructions.setWrapStyleWord(
true);
190 taInstructions.setAutoscrolls(
false);
191 taInstructions.setBorder(null);
192 taInstructions.setFocusable(
false);
193 taInstructions.setRequestFocusEnabled(
false);
194 taInstructions.setVerifyInputWhenFocusTarget(
false);
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()
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))
214 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
216 layout.setVerticalGroup(
217 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
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))
235 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
239 @Messages({
"ManageCorrelationPropertiesDialog.okbutton.failure=Error saving updated selections."})
240 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
242 if (0 == correlationTypes.size()) {
245 CentralRepository dbManager;
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());
253 correlationTypes.forEach((aType) -> {
255 dbManager.updateCorrelationType(aType);
257 }
catch (CentralRepoException ex) {
258 LOGGER.log(Level.SEVERE,
"Failed to update correlation properties with selections from dialog.", ex);
259 lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
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;