Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ConfigVisualPanel2.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.logicalimager.configuration;
20 
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.List;
26 import javax.swing.JButton;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JTable;
30 import javax.swing.table.AbstractTableModel;
31 import org.apache.commons.lang3.tuple.ImmutablePair;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbBundle.Messages;
34 
38 @NbBundle.Messages({
39  "ConfigVisualPanel2.ok=OK",
40  "ConfigVisualPanel2.cancel=Cancel"
41 })
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 final class ConfigVisualPanel2 extends JPanel {
44 
45  private static final long serialVersionUID = 1L;
46  private String configFilename;
47  private LogicalImagerConfig config = null;
48  private final JButton okButton = new JButton(Bundle.ConfigVisualPanel2_ok());
49  private final JButton cancelButton = new JButton(Bundle.ConfigVisualPanel2_cancel());
50  private boolean flagEncryptionPrograms = false;
51 
55  ConfigVisualPanel2() {
56  initComponents();
57  if (config != null) {
58  updatePanel(configFilename, config);
59  }
60  }
61 
62  @NbBundle.Messages({
63  "ConfigVisualPanel2.editConfiguration=Configure imager"
64  })
65  @Override
66  public String getName() {
67  return Bundle.ConfigVisualPanel2_editConfiguration();
68  }
69 
75  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
76  private void initComponents() {
77 
78  modifiedDateLabel = new javax.swing.JLabel();
79  modifiedWithinTextField = new javax.swing.JTextField();
80  daysIncludedLabel = new javax.swing.JLabel();
81  fullPathsLabel = new javax.swing.JLabel();
82  flagEncryptionProgramsCheckBox = new javax.swing.JCheckBox();
83  ruleNameLabel = new javax.swing.JLabel();
84  ruleNameEditTextField = new javax.swing.JTextField();
85  newRuleButton = new javax.swing.JButton();
86  descriptionLabel = new javax.swing.JLabel();
87  editRuleButton = new javax.swing.JButton();
88  descriptionEditTextField = new javax.swing.JTextField();
89  deleteRuleButton = new javax.swing.JButton();
90  fullPathsScrollPane = new javax.swing.JScrollPane();
91  fullPathsTable = new javax.swing.JTable();
92  filenamesScrollPane = new javax.swing.JScrollPane();
93  filenamesTable = new javax.swing.JTable();
94  shouldSaveCheckBox = new javax.swing.JCheckBox();
95  shouldAlertCheckBox = new javax.swing.JCheckBox();
96  folderNamesScrollPane = new javax.swing.JScrollPane();
97  folderNamesTable = new javax.swing.JTable();
98  extensionsLabel = new javax.swing.JLabel();
99  extensionsTextField = new javax.swing.JTextField();
100  filenamesLabel = new javax.swing.JLabel();
101  configFileTextField = new javax.swing.JTextField();
102  ruleSetFileLabel = new javax.swing.JLabel();
103  finalizeImageWriter = new javax.swing.JCheckBox();
104  rulesScrollPane = new javax.swing.JScrollPane();
105  rulesTable = new javax.swing.JTable();
106  folderNamesLabel = new javax.swing.JLabel();
107  fileSizeLabel = new javax.swing.JLabel();
108  jSeparator1 = new javax.swing.JSeparator();
109  minSizeLabel = new javax.swing.JLabel();
110  minSizeTextField = new javax.swing.JFormattedTextField();
111  maxSizeLabel = new javax.swing.JLabel();
112  maxSizeTextField = new javax.swing.JFormattedTextField();
113  promptBeforeExit = new javax.swing.JCheckBox();
114  createVHDCheckBox = new javax.swing.JCheckBox();
115 
116  org.openide.awt.Mnemonics.setLocalizedText(modifiedDateLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.modifiedDateLabel.text")); // NOI18N
117 
118  modifiedWithinTextField.setEditable(false);
119  modifiedWithinTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
120  modifiedWithinTextField.setEnabled(false);
121  modifiedWithinTextField.setMinimumSize(new java.awt.Dimension(60, 20));
122  modifiedWithinTextField.setPreferredSize(new java.awt.Dimension(60, 20));
123 
124  org.openide.awt.Mnemonics.setLocalizedText(daysIncludedLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.daysIncludedLabel.text")); // NOI18N
125 
126  org.openide.awt.Mnemonics.setLocalizedText(fullPathsLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fullPathsLabel.text")); // NOI18N
127 
128  org.openide.awt.Mnemonics.setLocalizedText(flagEncryptionProgramsCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.flagEncryptionProgramsCheckBox.text")); // NOI18N
129  flagEncryptionProgramsCheckBox.addActionListener(new java.awt.event.ActionListener() {
130  public void actionPerformed(java.awt.event.ActionEvent evt) {
131  flagEncryptionProgramsCheckBoxActionPerformed(evt);
132  }
133  });
134 
135  org.openide.awt.Mnemonics.setLocalizedText(ruleNameLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.ruleNameLabel.text")); // NOI18N
136 
137  ruleNameEditTextField.setEnabled(false);
138 
139  newRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/add16.png"))); // NOI18N
140  org.openide.awt.Mnemonics.setLocalizedText(newRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.newRuleButton.text")); // NOI18N
141  newRuleButton.addActionListener(new java.awt.event.ActionListener() {
142  public void actionPerformed(java.awt.event.ActionEvent evt) {
143  newRuleButtonActionPerformed(evt);
144  }
145  });
146 
147  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.descriptionLabel.text")); // NOI18N
148 
149  editRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/edit16.png"))); // NOI18N
150  org.openide.awt.Mnemonics.setLocalizedText(editRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.editRuleButton.text")); // NOI18N
151  editRuleButton.addActionListener(new java.awt.event.ActionListener() {
152  public void actionPerformed(java.awt.event.ActionEvent evt) {
153  editRuleButtonActionPerformed(evt);
154  }
155  });
156 
157  descriptionEditTextField.setEnabled(false);
158 
159  deleteRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/delete16.png"))); // NOI18N
160  org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.deleteRuleButton.text")); // NOI18N
161  deleteRuleButton.addActionListener(new java.awt.event.ActionListener() {
162  public void actionPerformed(java.awt.event.ActionEvent evt) {
163  deleteRuleButtonActionPerformed(evt);
164  }
165  });
166 
167  fullPathsTable.setColumnSelectionAllowed(true);
168  fullPathsTable.setEnabled(false);
169  fullPathsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
170  fullPathsTable.setShowHorizontalLines(false);
171  fullPathsTable.setShowVerticalLines(false);
172  fullPathsTable.getTableHeader().setReorderingAllowed(false);
173  fullPathsScrollPane.setViewportView(fullPathsTable);
174  fullPathsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
175  if (fullPathsTable.getColumnModel().getColumnCount() > 0) {
176  fullPathsTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fullPathsTable.columnModel.title0")); // NOI18N
177  }
178 
179  filenamesTable.setEnabled(false);
180  filenamesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
181  filenamesTable.setShowHorizontalLines(false);
182  filenamesTable.setShowVerticalLines(false);
183  filenamesTable.getTableHeader().setReorderingAllowed(false);
184  filenamesScrollPane.setViewportView(filenamesTable);
185  if (filenamesTable.getColumnModel().getColumnCount() > 0) {
186  filenamesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.filenamesTable.columnModel.title0")); // NOI18N
187  }
188 
189  org.openide.awt.Mnemonics.setLocalizedText(shouldSaveCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldSaveCheckBox.text")); // NOI18N
190  shouldSaveCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldSaveCheckBox.toolTipText")); // NOI18N
191  shouldSaveCheckBox.setEnabled(false);
192 
193  org.openide.awt.Mnemonics.setLocalizedText(shouldAlertCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldAlertCheckBox.text")); // NOI18N
194  shouldAlertCheckBox.setEnabled(false);
195 
196  folderNamesTable.setEnabled(false);
197  folderNamesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
198  folderNamesTable.setShowHorizontalLines(false);
199  folderNamesTable.setShowVerticalLines(false);
200  folderNamesTable.getTableHeader().setReorderingAllowed(false);
201  folderNamesScrollPane.setViewportView(folderNamesTable);
202  if (folderNamesTable.getColumnModel().getColumnCount() > 0) {
203  folderNamesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.folderNamesTable.columnModel.title0")); // NOI18N
204  }
205 
206  org.openide.awt.Mnemonics.setLocalizedText(extensionsLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.extensionsLabel.text")); // NOI18N
207 
208  extensionsTextField.setEnabled(false);
209 
210  org.openide.awt.Mnemonics.setLocalizedText(filenamesLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.filenamesLabel.text")); // NOI18N
211 
212  configFileTextField.setToolTipText("");
213  configFileTextField.setEnabled(false);
214 
215  org.openide.awt.Mnemonics.setLocalizedText(ruleSetFileLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.ruleSetFileLabel.text")); // NOI18N
216 
217  org.openide.awt.Mnemonics.setLocalizedText(finalizeImageWriter, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.finalizeImageWriter.text")); // NOI18N
218  finalizeImageWriter.setEnabled(false);
219  finalizeImageWriter.addActionListener(new java.awt.event.ActionListener() {
220  public void actionPerformed(java.awt.event.ActionEvent evt) {
221  finalizeImageWriterActionPerformed(evt);
222  }
223  });
224 
225  rulesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
226  rulesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
227  rulesTable.setShowHorizontalLines(false);
228  rulesTable.setShowVerticalLines(false);
229  rulesTable.getTableHeader().setReorderingAllowed(false);
230  rulesTable.addMouseListener(new java.awt.event.MouseAdapter() {
231  public void mouseReleased(java.awt.event.MouseEvent evt) {
232  rulesTableMouseReleased(evt);
233  }
234  });
235  rulesTable.addKeyListener(new java.awt.event.KeyAdapter() {
236  public void keyReleased(java.awt.event.KeyEvent evt) {
237  rulesTableKeyReleased(evt);
238  }
239  });
240  rulesScrollPane.setViewportView(rulesTable);
241  if (rulesTable.getColumnModel().getColumnCount() > 0) {
242  rulesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.rulesTable.columnModel.title0")); // NOI18N
243  rulesTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.rulesTable.columnModel.title1")); // NOI18N
244  }
245 
246  org.openide.awt.Mnemonics.setLocalizedText(folderNamesLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.folderNamesLabel.text")); // NOI18N
247 
248  org.openide.awt.Mnemonics.setLocalizedText(fileSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fileSizeLabel.text")); // NOI18N
249 
250  org.openide.awt.Mnemonics.setLocalizedText(minSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.minSizeLabel.text")); // NOI18N
251 
252  minSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
253  minSizeTextField.setEnabled(false);
254 
255  org.openide.awt.Mnemonics.setLocalizedText(maxSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.maxSizeLabel.text")); // NOI18N
256 
257  maxSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
258  maxSizeTextField.setEnabled(false);
259 
260  promptBeforeExit.setSelected(true);
261  org.openide.awt.Mnemonics.setLocalizedText(promptBeforeExit, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.promptBeforeExit.text")); // NOI18N
262  promptBeforeExit.setActionCommand(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.promptBeforeExit.actionCommand")); // NOI18N
263  promptBeforeExit.addActionListener(new java.awt.event.ActionListener() {
264  public void actionPerformed(java.awt.event.ActionEvent evt) {
265  promptBeforeExitActionPerformed(evt);
266  }
267  });
268 
269  org.openide.awt.Mnemonics.setLocalizedText(createVHDCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.createVHDCheckBox.text")); // NOI18N
270  createVHDCheckBox.addActionListener(new java.awt.event.ActionListener() {
271  public void actionPerformed(java.awt.event.ActionEvent evt) {
272  createVHDCheckBoxActionPerformed(evt);
273  }
274  });
275 
276  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
277  this.setLayout(layout);
278  layout.setHorizontalGroup(
279  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280  .addGroup(layout.createSequentialGroup()
281  .addGap(17, 17, 17)
282  .addComponent(ruleSetFileLabel)
283  .addGap(18, 18, 18)
284  .addComponent(configFileTextField)
285  .addContainerGap())
286  .addGroup(layout.createSequentialGroup()
287  .addContainerGap()
288  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
290  .addComponent(newRuleButton)
291  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
292  .addComponent(editRuleButton)
293  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
294  .addComponent(deleteRuleButton))
295  .addComponent(rulesScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE))
296  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297  .addGroup(layout.createSequentialGroup()
298  .addGap(10, 10, 10)
299  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
300  .addGroup(layout.createSequentialGroup()
301  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302  .addComponent(extensionsLabel)
303  .addComponent(filenamesLabel)
304  .addComponent(descriptionLabel)
305  .addComponent(ruleNameLabel)
306  .addComponent(fullPathsLabel)
307  .addComponent(folderNamesLabel))
308  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
309  .addGroup(layout.createSequentialGroup()
310  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311  .addGroup(layout.createSequentialGroup()
312  .addGap(129, 129, 129)
313  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
314  .addComponent(ruleNameEditTextField, javax.swing.GroupLayout.Alignment.LEADING)
315  .addComponent(descriptionEditTextField, javax.swing.GroupLayout.Alignment.LEADING)
316  .addComponent(extensionsTextField, javax.swing.GroupLayout.Alignment.LEADING)
317  .addComponent(fullPathsScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
318  .addComponent(filenamesScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
319  .addComponent(folderNamesScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
320  .addGroup(layout.createSequentialGroup()
321  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
322  .addComponent(shouldSaveCheckBox)
323  .addComponent(shouldAlertCheckBox)
324  .addGroup(layout.createSequentialGroup()
325  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326  .addComponent(modifiedDateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
327  .addComponent(fileSizeLabel))
328  .addGap(4, 4, 4)
329  .addComponent(minSizeLabel)
330  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
332  .addGap(18, 18, 18)
333  .addComponent(maxSizeLabel)
334  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
335  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
336  .addGroup(layout.createSequentialGroup()
337  .addGap(129, 129, 129)
338  .addComponent(modifiedWithinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
339  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
340  .addComponent(daysIncludedLabel)))
341  .addGap(0, 0, Short.MAX_VALUE)))
342  .addContainerGap())))
343  .addGroup(layout.createSequentialGroup()
344  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
345  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346  .addGroup(layout.createSequentialGroup()
347  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
348  .addComponent(flagEncryptionProgramsCheckBox)
349  .addComponent(createVHDCheckBox)
350  .addComponent(promptBeforeExit)
351  .addGroup(layout.createSequentialGroup()
352  .addGap(21, 21, 21)
353  .addComponent(finalizeImageWriter)))
354  .addGap(0, 0, Short.MAX_VALUE))
355  .addComponent(jSeparator1)))))
356  );
357 
358  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteRuleButton, editRuleButton, newRuleButton});
359 
360  layout.setVerticalGroup(
361  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362  .addGroup(layout.createSequentialGroup()
363  .addContainerGap()
364  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
365  .addComponent(configFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
366  .addComponent(ruleSetFileLabel))
367  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
368  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
369  .addGroup(layout.createSequentialGroup()
370  .addComponent(rulesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
371  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
372  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
373  .addComponent(newRuleButton)
374  .addComponent(editRuleButton)
375  .addComponent(deleteRuleButton))
376  .addContainerGap())
377  .addGroup(layout.createSequentialGroup()
378  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
379  .addGroup(layout.createSequentialGroup()
380  .addGap(30, 30, 30)
381  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
382  .addComponent(descriptionEditTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
383  .addComponent(descriptionLabel))
384  .addGap(9, 9, 9)
385  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
386  .addComponent(extensionsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
387  .addComponent(extensionsLabel)))
388  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
389  .addComponent(ruleNameEditTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
390  .addComponent(ruleNameLabel)))
391  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
392  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
393  .addComponent(filenamesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
394  .addComponent(filenamesLabel))
395  .addGap(16, 16, 16)
396  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
397  .addComponent(folderNamesScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
398  .addComponent(folderNamesLabel))
399  .addGap(18, 18, 18)
400  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401  .addComponent(fullPathsLabel)
402  .addComponent(fullPathsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
403  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
404  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
405  .addComponent(minSizeLabel)
406  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
407  .addComponent(maxSizeLabel)
408  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
409  .addComponent(fileSizeLabel))
410  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
411  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
412  .addComponent(modifiedDateLabel)
413  .addComponent(modifiedWithinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
414  .addComponent(daysIncludedLabel))
415  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
416  .addComponent(shouldSaveCheckBox)
417  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
418  .addComponent(shouldAlertCheckBox)
419  .addGap(18, 18, 18)
420  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
421  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
422  .addComponent(flagEncryptionProgramsCheckBox)
423  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
424  .addComponent(createVHDCheckBox)
425  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
426  .addComponent(finalizeImageWriter)
427  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
428  .addComponent(promptBeforeExit)
429  .addGap(19, 19, 19))))
430  );
431  }// </editor-fold>//GEN-END:initComponents
432 
433  private void rulesTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rulesTableKeyReleased
434  updateForSelectedRule();
435  }//GEN-LAST:event_rulesTableKeyReleased
436 
437  @NbBundle.Messages({
438  "ConfigVisualPanel2.editRuleSet=Edit Rule",
439  "ConfigVisualPanel2.editRuleError=Edit rule error"
440  })
441  private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRuleButtonActionPerformed
442  int row = rulesTable.getSelectedRow();
443  if (row != -1) {
444  String ruleName = (String) rulesTable.getModel().getValueAt(row, 0);
445  LogicalImagerRule rule = getRuleSetFromCurrentConfig().getRules().get(row);
446  EditRulePanel editPanel = new EditRulePanel(okButton, cancelButton, ruleName, rule);
447  editPanel.setEnabled(true);
448  editPanel.setVisible(true);
449 
450  while (true) {
451  int option = JOptionPane.showOptionDialog(this, editPanel.getPanel(), Bundle.ConfigVisualPanel2_editRuleSet(),
452  JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
453  null, new Object[]{okButton, cancelButton}, okButton);
454  if (option == JOptionPane.OK_OPTION) {
455  try {
456  ImmutablePair<String, LogicalImagerRule> ruleMap = editPanel.toRule();
457  if (!ruleName.equals(ruleMap.getKey()) && ruleExists(ruleMap)) {
458  JOptionPane.showMessageDialog(this,
459  Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()),
460  Bundle.ConfigVisualPanel2_editRuleError(),
461  JOptionPane.ERROR_MESSAGE);
462  continue;
463  }
464  updateRow(row, ruleMap);
465  break;
466  } catch (IOException | NumberFormatException ex) {
467  JOptionPane.showMessageDialog(this,
468  ex.getMessage(),
469  Bundle.ConfigVisualPanel2_editRuleError(),
470  JOptionPane.ERROR_MESSAGE);
471  // let user fix the error
472  }
473  } else {
474  break;
475  }
476  }
477  }
478  }//GEN-LAST:event_editRuleButtonActionPerformed
479 
480  @Messages({"ConfigVisualPanel2.newRule.name=New Rule",
481  "ConfigVisualPanel2.newRuleError.title=New rule error",
482  "# {0} - ruleName",
483  "ConfigVisualPanel2.newRuleError.duplicateName=A rule with name \"{0}\" already exists. Please enter a different rule name"})
484  private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRuleButtonActionPerformed
485  NewRulePanel panel;
486  panel = new NewRulePanel(okButton, cancelButton);
487  panel.setEnabled(true);
488  panel.setVisible(true);
489 
490  while (true) {
491  int option = JOptionPane.showOptionDialog(this, panel, Bundle.ConfigVisualPanel2_newRule_name(),
492  JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
493  null, new Object[]{okButton, cancelButton}, okButton);
494  if (option == JOptionPane.OK_OPTION) {
495  try {
496 
497  ImmutablePair<String, LogicalImagerRule> ruleMap = panel.toRule();
498  if (ruleExists(ruleMap)) {
499  JOptionPane.showMessageDialog(this,
500  Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()),
501  Bundle.ConfigVisualPanel2_newRuleError_title(),
502  JOptionPane.ERROR_MESSAGE);
503  continue;
504  }
505  // Save the new rule
506  appendRow(ruleMap);
507  break;
508  } catch (IOException | NumberFormatException ex) {
509  JOptionPane.showMessageDialog(this,
510  ex.getMessage(),
511  Bundle.ConfigVisualPanel2_newRuleError_title(),
512  JOptionPane.ERROR_MESSAGE);
513  // let user fix the error
514  }
515  } else {
516  break;
517  }
518  }
519  }//GEN-LAST:event_newRuleButtonActionPerformed
520 
521  @NbBundle.Messages({
522  "ConfigVisualPanel2.deleteRuleSet=Delete rule ",
523  "ConfigVisualPanel2.deleteRuleSetConfirmation=Delete rule confirmation",})
524  private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRuleButtonActionPerformed
525  int index = rulesTable.getSelectedRow();
526  if (index != -1) {
527  String ruleName = (String) rulesTable.getModel().getValueAt(index, 0);
528 
529  int option = JOptionPane.showOptionDialog(this,
530  Bundle.ConfigVisualPanel2_deleteRuleSet() + ruleName,
531  Bundle.ConfigVisualPanel2_deleteRuleSetConfirmation(),
532  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
533  if (option == JOptionPane.NO_OPTION) {
534  return;
535  }
536 
537  getRuleSetFromCurrentConfig().getRules().remove(index);
538  updatePanel(configFilename, config);
539  if (rulesTable.getRowCount() > 0) {
540  rulesTable.setRowSelectionInterval(0, 0);
541  updateForSelectedRule();
542  }
543  }
544  }//GEN-LAST:event_deleteRuleButtonActionPerformed
545 
546  private void rulesTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rulesTableMouseReleased
547  updateForSelectedRule();
548  }//GEN-LAST:event_rulesTableMouseReleased
549 
550  private void flagEncryptionProgramsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flagEncryptionProgramsCheckBoxActionPerformed
551  flagEncryptionPrograms = flagEncryptionProgramsCheckBox.isSelected();
552  setEnabledEncryptionProgramsRule(flagEncryptionPrograms);
553  }//GEN-LAST:event_flagEncryptionProgramsCheckBoxActionPerformed
554 
555  private void finalizeImageWriterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finalizeImageWriterActionPerformed
556  config.setFinalizeImageWriter(finalizeImageWriter.isSelected());
557  }//GEN-LAST:event_finalizeImageWriterActionPerformed
558 
559  private void promptBeforeExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_promptBeforeExitActionPerformed
560  config.setPromptBeforeExit(promptBeforeExit.isSelected());
561  }//GEN-LAST:event_promptBeforeExitActionPerformed
562 
563  private void createVHDCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createVHDCheckBoxActionPerformed
564  config.setCreateVHD(createVHDCheckBox.isSelected());
565  finalizeImageWriter.setEnabled(createVHDCheckBox.isSelected());
566  }//GEN-LAST:event_createVHDCheckBoxActionPerformed
567 
575  private void setEnabledEncryptionProgramsRule(boolean flagEncryptionPrograms) {
576  if (flagEncryptionPrograms) {
577  // add the special rule
578  ImmutablePair<String, LogicalImagerRule> ruleMap = createEncryptionProgramsRule();
579  appendRow(ruleMap);
580  } else {
581  // remove it
582  int index = ((RulesTableModel) rulesTable.getModel()).findRow(EncryptionProgramsRule.getName());
583  if (index != -1) {
584  getRuleSetFromCurrentConfig().getRules().remove(index);
585  updatePanel(configFilename, config);
586  if (rulesTable.getRowCount() > 0) {
587  rulesTable.setRowSelectionInterval(0, 0);
588  updateForSelectedRule();
589  }
590  }
591  }
592  }
593 
594  /*
595  * Create an encryption programs rule
596  */
597  private ImmutablePair<String, LogicalImagerRule> createEncryptionProgramsRule() {
598  LogicalImagerRule.Builder builder = new LogicalImagerRule.Builder();
599  builder.getName(EncryptionProgramsRule.getName())
600  .getDescription(EncryptionProgramsRule.getDescription())
601  .getShouldAlert(true)
602  .getShouldSave(true)
603  .getFilenames(EncryptionProgramsRule.getFilenames());
604  LogicalImagerRule rule = builder.build();
605  return new ImmutablePair<>(EncryptionProgramsRule.getName(), rule);
606  }
607 
608  // Variables declaration - do not modify//GEN-BEGIN:variables
609  private javax.swing.JTextField configFileTextField;
610  private javax.swing.JCheckBox createVHDCheckBox;
611  private javax.swing.JLabel daysIncludedLabel;
612  private javax.swing.JButton deleteRuleButton;
613  private javax.swing.JTextField descriptionEditTextField;
614  private javax.swing.JLabel descriptionLabel;
615  private javax.swing.JButton editRuleButton;
616  private javax.swing.JLabel extensionsLabel;
617  private javax.swing.JTextField extensionsTextField;
618  private javax.swing.JLabel fileSizeLabel;
619  private javax.swing.JLabel filenamesLabel;
620  private javax.swing.JScrollPane filenamesScrollPane;
621  private javax.swing.JTable filenamesTable;
622  private javax.swing.JCheckBox finalizeImageWriter;
623  private javax.swing.JCheckBox flagEncryptionProgramsCheckBox;
624  private javax.swing.JLabel folderNamesLabel;
625  private javax.swing.JScrollPane folderNamesScrollPane;
626  private javax.swing.JTable folderNamesTable;
627  private javax.swing.JLabel fullPathsLabel;
628  private javax.swing.JScrollPane fullPathsScrollPane;
629  private javax.swing.JTable fullPathsTable;
630  private javax.swing.JSeparator jSeparator1;
631  private javax.swing.JLabel maxSizeLabel;
632  private javax.swing.JFormattedTextField maxSizeTextField;
633  private javax.swing.JLabel minSizeLabel;
634  private javax.swing.JFormattedTextField minSizeTextField;
635  private javax.swing.JLabel modifiedDateLabel;
636  private javax.swing.JTextField modifiedWithinTextField;
637  private javax.swing.JButton newRuleButton;
638  private javax.swing.JCheckBox promptBeforeExit;
639  private javax.swing.JTextField ruleNameEditTextField;
640  private javax.swing.JLabel ruleNameLabel;
641  private javax.swing.JLabel ruleSetFileLabel;
642  private javax.swing.JScrollPane rulesScrollPane;
643  private javax.swing.JTable rulesTable;
644  private javax.swing.JCheckBox shouldAlertCheckBox;
645  private javax.swing.JCheckBox shouldSaveCheckBox;
646  // End of variables declaration//GEN-END:variables
647 
648  private LogicalImagerRuleSet getRuleSetFromCurrentConfig() {
649  if (config.getRuleSets().isEmpty()) {
650  List<LogicalImagerRuleSet> ruleSets = new ArrayList<>();
651  ruleSets.add(new LogicalImagerRuleSet("no-set-name", new ArrayList<>())); // NON-NLS
652  config.setRuleSet(ruleSets);
653  }
654  return config.getRuleSets().get(0);
655  }
656 
664  private void updatePanel(String configFilePath, LogicalImagerConfig config, String rowSelectionkey) {
665  configFileTextField.setText(configFilePath);
666  finalizeImageWriter.setSelected(config.isFinalizeImageWriter());
667  promptBeforeExit.setSelected(config.isPromptBeforeExit());
668  createVHDCheckBox.setSelected(config.isCreateVHD());
669  finalizeImageWriter.setEnabled(config.isCreateVHD());
670  LogicalImagerRuleSet ruleSet = getRuleSetFromCurrentConfig();
671  flagEncryptionProgramsCheckBox.setSelected(ruleSet.find(EncryptionProgramsRule.getName()) != null);
672  RulesTableModel rulesTableModel = new RulesTableModel();
673  int row = 0;
674  int selectThisRow = 0;
675 
676  Collections.sort(ruleSet.getRules(), new SortRuleByName());
677 
678  for (LogicalImagerRule rule : ruleSet.getRules()) {
679  rulesTableModel.setValueAt(rule.getName(), row, 0);
680  if (rowSelectionkey != null && rowSelectionkey.equals(rule.getName())) {
681  selectThisRow = row;
682  }
683  rulesTableModel.setValueAt(rule.getDescription(), row, 1);
684  rulesTableModel.setValueAt(rule, row, 2);
685  row++;
686  }
687  rulesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
688  rulesTable.setModel(rulesTableModel);
689  // If there are any rules, select the first one
690  if (rulesTableModel.getRowCount() > 0) {
691  rulesTable.setRowSelectionInterval(selectThisRow, selectThisRow);
692  updateForSelectedRule();
693  } else {
694  clearRuleDetails();
695  updateRuleButtons(false);
696  }
697  }
698 
705  private void updatePanel(String configFilePath, LogicalImagerConfig config) {
706  updatePanel(configFilePath, config, null);
707  }
708 
712  private void updateForSelectedRule() {
713  int index = rulesTable.getSelectedRow();
714  if (index != -1) {
715  String ruleName = (String) rulesTable.getModel().getValueAt(index, 0);
716  String description = (String) rulesTable.getModel().getValueAt(index, 1);
717  updateRuleDetails(ruleName, description);
718  updateRuleButtons(!ruleName.equals(EncryptionProgramsRule.getName()));
719  } else {
720  clearRuleDetails();
721  updateRuleButtons(false);
722  }
723  }
724 
731  private void updateRuleDetails(String ruleName, String description) {
732  clearRuleDetails();
733  LogicalImagerRule rule = getRuleSetFromCurrentConfig().find(ruleName);
734  shouldAlertCheckBox.setSelected(rule.isShouldAlert());
735  shouldSaveCheckBox.setSelected(rule.isShouldSave());
736  ruleNameEditTextField.setText(ruleName);
737  descriptionEditTextField.setText(description);
738  updateExtensions(rule.getExtensions());
739  updateList(filenamesTable, rule.getFilenames());
740  updateList(folderNamesTable, rule.getPaths());
741  updateList(fullPathsTable, rule.getFullPaths());
742  if (rule.getMinFileSize() == null) {
743  minSizeTextField.setText("");
744  } else {
745  minSizeTextField.setText(rule.getMinFileSize().toString());
746  }
747  if (rule.getMaxFileSize() == null) {
748  maxSizeTextField.setText("");
749  } else {
750  maxSizeTextField.setText(rule.getMaxFileSize().toString());
751  }
752  if (rule.getMinDays() == null) {
753  modifiedWithinTextField.setText("");
754  } else {
755  modifiedWithinTextField.setText(Integer.toString(rule.getMinDays()));
756  }
757  }
758 
762  private void clearRuleDetails() {
763  ruleNameEditTextField.setText("");
764  descriptionEditTextField.setText("");
765  extensionsTextField.setText("");
766  updateExtensions(null);
767  updateList(filenamesTable, null);
768  updateList(folderNamesTable, null);
769  updateList(fullPathsTable, null);
770  minSizeTextField.setText("");
771  maxSizeTextField.setText("");
772  modifiedWithinTextField.setText("");
773  shouldSaveCheckBox.setSelected(true);
774  shouldAlertCheckBox.setSelected(false);
775  }
776 
783  private void updateExtensions(List<String> extensions) {
784  extensionsTextField.setText("");
785  if (extensions == null) {
786  return;
787  }
788  String content = "";
789  boolean first = true;
790  for (String ext : extensions) {
791  content += (first ? "" : ",") + ext;
792  first = false;
793  }
794  extensionsTextField.setText(content);
795  }
796 
803  private void updateList(javax.swing.JTable jTable, List<String> list) {
804  SingleColumnTableModel tableModel = new SingleColumnTableModel();
805  jTable.setTableHeader(null);
806  if (list == null) {
807  jTable.setModel(tableModel);
808  return;
809  }
810  int row = 0;
811  for (String s : list) {
812  tableModel.setValueAt(s, row, 0);
813  row++;
814  }
815  jTable.setModel(tableModel);
816  }
817 
818  void setConfiguration(String configFilename, LogicalImagerConfig config) {
819  this.configFilename = configFilename;
820  this.config = config;
821  updatePanel(configFilename, config);
822  }
823 
824  private void updateRow(int index, ImmutablePair<String, LogicalImagerRule> ruleMap) {
825  getRuleSetFromCurrentConfig().getRules().remove(index);
826  getRuleSetFromCurrentConfig().getRules().add(ruleMap.getValue());
827  updatePanel(configFilename, config, ruleMap.getKey());
828  }
829 
837  private boolean ruleExists(ImmutablePair<String, LogicalImagerRule> ruleMap) {
838  for (LogicalImagerRule rule : getRuleSetFromCurrentConfig().getRules()) {
839  if (rule.getName().equals(ruleMap.getKey())) {
840  return true;
841  }
842  }
843  return false;
844  }
845 
846  private void appendRow(ImmutablePair<String, LogicalImagerRule> ruleMap) {
847  getRuleSetFromCurrentConfig().getRules().add(ruleMap.getValue());
848  updatePanel(configFilename, config, ruleMap.getKey());
849  }
850 
857  private void updateRuleButtons(boolean isRowSelected) {
858  newRuleButton.setEnabled(true);
859  editRuleButton.setEnabled(isRowSelected);
860  deleteRuleButton.setEnabled(isRowSelected);
861  }
862 
866  private class SortRuleByName implements Comparator<LogicalImagerRule> {
867 
868  @Override
869  public int compare(LogicalImagerRule a, LogicalImagerRule b) {
870  return a.getName().compareToIgnoreCase(b.getName());
871  }
872  }
873 
877  private class RulesTableModel extends AbstractTableModel {
878 
879  private static final long serialVersionUID = 1L;
880  private final List<String> ruleName = new ArrayList<>();
881  private final List<String> ruleDescription = new ArrayList<>();
882  private final List<LogicalImagerRule> rule = new ArrayList<>();
883 
884  int findRow(String name) {
885  return ruleName.indexOf(name);
886  }
887 
888  @Override
889  public int getRowCount() {
890  return ruleName.size();
891  }
892 
893  @Override
894  public int getColumnCount() {
895  return 2;
896  }
897 
898  @NbBundle.Messages({
899  "ConfigVisualPanel2.rulesTable.columnModel.title0=Rule Name",
900  "ConfigVisualPanel2.rulesTable.columnModel.title1=Description"
901  })
902  @Override
903  public String getColumnName(int column) {
904  String colName = null;
905  switch (column) {
906  case 0:
907  colName = Bundle.ConfigVisualPanel2_rulesTable_columnModel_title0();
908  break;
909  case 1:
910  colName = Bundle.ConfigVisualPanel2_rulesTable_columnModel_title1();
911  break;
912  default:
913  break;
914  }
915  return colName;
916  }
917 
918  @Override
919  public Object getValueAt(int rowIndex, int columnIndex) {
920  Object ret = null;
921  switch (columnIndex) {
922  case 0:
923  ret = ruleName.get(rowIndex);
924  break;
925  case 1:
926  ret = ruleDescription.get(rowIndex);
927  break;
928  case 2:
929  ret = rule.get(rowIndex);
930  break;
931  default:
932  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
933  }
934  return ret;
935  }
936 
937  @Override
938  public boolean isCellEditable(int rowIndex, int columnIndex) {
939  return false;
940  }
941 
942  @Override
943  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
944  switch (columnIndex) {
945  case 0:
946  ruleName.add((String) aValue);
947  break;
948  case 1:
949  ruleDescription.add((String) aValue);
950  break;
951  case 2:
952  rule.add((LogicalImagerRule) aValue);
953  break;
954  default:
955  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
956  }
957  // Only show the name and description column
958  if (columnIndex < 2) {
959  super.setValueAt(aValue, rowIndex, columnIndex);
960  }
961  }
962  }
963 
967  private class SingleColumnTableModel extends AbstractTableModel {
968 
969  private static final long serialVersionUID = 1L;
970 
971  private final List<String> list = new ArrayList<>();
972 
973  @Override
974  public int getRowCount() {
975  return list.size();
976  }
977 
978  @Override
979  public int getColumnCount() {
980  return 1;
981  }
982 
983  @Override
984  public String getColumnName(int column) {
985  return "";
986  }
987 
988  @Override
989  public Object getValueAt(int rowIndex, int columnIndex) {
990  Object ret = null;
991  if (columnIndex == 0) {
992  ret = list.get(rowIndex);
993  } else {
994  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
995  }
996  return ret;
997  }
998 
999  @Override
1000  public boolean isCellEditable(int rowIndex, int columnIndex) {
1001  return true;
1002  }
1003 
1004  @Override
1005  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
1006  if (columnIndex == 0) {
1007  list.add((String) aValue);
1008  } else {
1009  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
1010  }
1011  }
1012  }
1013 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.