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.Exceptions;
30 import org.openide.util.NbBundle.Messages;
31 import org.openide.windows.WindowManager;
41 @SuppressWarnings(
"PMD.SingularField")
42 final class ManageCorrelationPropertiesDialog extends javax.swing.JDialog {
44 private static final Logger LOGGER = Logger.getLogger(ManageCorrelationPropertiesDialog.class.getName());
46 private final List<CorrelationAttribute.Type> correlationTypes;
52 @Messages({
"ManageCorrelationPropertiesDialog.title=Manage Correlation Properties"})
53 ManageCorrelationPropertiesDialog() {
54 super((JFrame) WindowManager.getDefault().getMainWindow(),
55 Bundle.ManageCorrelationPropertiesDialog_title(),
57 this.correlationTypes =
new ArrayList<>();
59 customizeComponents();
64 private void customizeComponents() {
65 lbWarningMsg.setText(
"");
70 private void loadData() {
71 DefaultTableModel model = (DefaultTableModel) tbCorrelatableTypes.getModel();
73 EamDb dbManager = EamDb.getInstance();
74 correlationTypes.clear();
75 correlationTypes.addAll(dbManager.getDefinedCorrelationTypes());
76 }
catch (EamDbException ex) {
77 Exceptions.printStackTrace(ex);
80 correlationTypes.forEach((aType) -> {
81 model.addRow(
new Object[]{aType.getDisplayName(), aType.isEnabled()});
83 model.addTableModelListener(
new TableModelListener() {
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);
91 correlationTypes.stream().filter((aType) -> (aType.getDisplayName().equals(displayName))).forEachOrdered((aType) -> {
92 aType.setEnabled(enabled);
99 private void display() {
100 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
104 @Messages({
"ManageCorrelationPropertiesDialog.noneSelected=There are no correlation properties enabled."})
105 private boolean valid() {
106 lbWarningMsg.setText(
"");
108 int countEnabled = 0;
109 countEnabled = correlationTypes.stream().filter((aType) -> (aType.isEnabled())).map((_item) -> 1).reduce(countEnabled, Integer::sum);
111 if (0 == countEnabled) {
112 lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_noneSelected());
122 @SuppressWarnings({
"unchecked",
"rawtypes"})
124 private void initComponents() {
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();
134 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(
new java.awt.Font(
"Tahoma", 0, 12));
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.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
187 taInstructions.setLineWrap(
true);
188 taInstructions.setRows(5);
189 taInstructions.setText(
org.openide.util.NbBundle.getMessage(ManageCorrelationPropertiesDialog.class,
"ManageArtifactTypesDialog.taInstructionsMsg.text"));
190 taInstructions.setWrapStyleWord(
true);
191 taInstructions.setAutoscrolls(
false);
192 taInstructions.setBorder(null);
193 taInstructions.setFocusable(
false);
194 taInstructions.setRequestFocusEnabled(
false);
195 taInstructions.setVerifyInputWhenFocusTarget(
false);
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()
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))
215 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
217 layout.setVerticalGroup(
218 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
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))
236 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
240 @Messages({
"ManageCorrelationPropertiesDialog.okbutton.failure=Error saving updated selections."})
241 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
243 if (0 == correlationTypes.size()) {
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());
254 correlationTypes.forEach((aType) -> {
256 dbManager.updateCorrelationType(aType);
258 }
catch (EamDbException ex) {
259 LOGGER.log(Level.SEVERE,
"Failed to update correlation properties with selections from dialog.", ex);
260 lbWarningMsg.setText(Bundle.ManageCorrelationPropertiesDialog_okbutton_failure());
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;