19 package org.sleuthkit.autopsy.centralrepository.persona;
21 import javax.swing.JDialog;
22 import javax.swing.JOptionPane;
23 import javax.swing.SwingUtilities;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.util.NbBundle.Messages;
26 import org.openide.windows.WindowManager;
32 @SuppressWarnings(
"PMD.SingularField")
35 private static final long serialVersionUID = 1L;
44 @Messages({
"AddMetadataDialog.title.text=Add Metadata",})
46 super(SwingUtilities.windowForComponent(pdp),
47 Bundle.AddMetadataDialog_title_text(),
48 ModalityType.APPLICATION_MODAL);
56 super(SwingUtilities.windowForComponent(pdp),
57 Bundle.AddMetadataDialog_title_text(),
58 ModalityType.APPLICATION_MODAL);
63 confidenceComboBox.setSelectedItem(md.confidence);
64 justificationTextField.setText(md.justification);
65 nameTextField.setText(md.name);
66 valueTextField.setText(md.value);
68 nameTextField.setEnabled(
false);
69 valueTextField.setEnabled(
false);
79 @SuppressWarnings(
"unchecked")
81 private
void initComponents() {
83 settingsPanel =
new javax.swing.JPanel();
84 nameLbl =
new javax.swing.JLabel();
85 nameTextField =
new javax.swing.JTextField();
86 valueLbl =
new javax.swing.JLabel();
87 valueTextField =
new javax.swing.JTextField();
88 confidenceLbl =
new javax.swing.JLabel();
89 confidenceComboBox =
new javax.swing.JComboBox<>();
90 justificationLbl =
new javax.swing.JLabel();
91 justificationTextField =
new javax.swing.JTextField();
92 cancelBtn =
new javax.swing.JButton();
93 okBtn =
new javax.swing.JButton();
95 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
98 settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
100 org.openide.awt.Mnemonics.setLocalizedText(nameLbl,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.nameLbl.text"));
102 nameTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.nameTextField.text"));
104 org.openide.awt.Mnemonics.setLocalizedText(valueLbl,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.valueLbl.text"));
106 valueTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.valueTextField.text"));
108 org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.confidenceLbl.text"));
112 org.openide.awt.Mnemonics.setLocalizedText(justificationLbl,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.justificationLbl.text"));
114 justificationTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.justificationTextField.text"));
116 javax.swing.GroupLayout settingsPanelLayout =
new javax.swing.GroupLayout(settingsPanel);
117 settingsPanel.setLayout(settingsPanelLayout);
118 settingsPanelLayout.setHorizontalGroup(
119 settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120 .addGroup(settingsPanelLayout.createSequentialGroup()
122 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123 .addGroup(settingsPanelLayout.createSequentialGroup()
124 .addComponent(nameLbl)
125 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
126 .addComponent(nameTextField))
127 .addGroup(settingsPanelLayout.createSequentialGroup()
128 .addComponent(valueLbl)
129 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
130 .addComponent(valueTextField))
131 .addGroup(settingsPanelLayout.createSequentialGroup()
132 .addComponent(justificationLbl)
133 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
134 .addComponent(justificationTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE))
135 .addGroup(settingsPanelLayout.createSequentialGroup()
136 .addComponent(confidenceLbl)
137 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
138 .addComponent(confidenceComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
141 settingsPanelLayout.setVerticalGroup(
142 settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143 .addGroup(settingsPanelLayout.createSequentialGroup()
145 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146 .addComponent(nameLbl)
147 .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
148 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150 .addComponent(valueLbl)
151 .addComponent(valueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
152 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
153 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(confidenceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
155 .addComponent(confidenceLbl))
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
158 .addComponent(justificationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
159 .addComponent(justificationLbl))
160 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
163 org.openide.awt.Mnemonics.setLocalizedText(cancelBtn,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.cancelBtn.text"));
164 cancelBtn.setMaximumSize(
new java.awt.Dimension(79, 23));
165 cancelBtn.setMinimumSize(
new java.awt.Dimension(79, 23));
166 cancelBtn.setPreferredSize(
new java.awt.Dimension(79, 23));
167 cancelBtn.addActionListener(
new java.awt.event.ActionListener() {
168 public void actionPerformed(java.awt.event.ActionEvent evt) {
169 cancelBtnActionPerformed(evt);
173 org.openide.awt.Mnemonics.setLocalizedText(okBtn,
org.openide.util.NbBundle.getMessage(
PersonaMetadataDialog.class,
"PersonaMetadataDialog.okBtn.text"));
174 okBtn.addActionListener(
new java.awt.event.ActionListener() {
175 public void actionPerformed(java.awt.event.ActionEvent evt) {
176 okBtnActionPerformed(evt);
180 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
181 getContentPane().setLayout(layout);
182 layout.setHorizontalGroup(
183 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184 .addGroup(layout.createSequentialGroup()
185 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
187 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
190 .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelBtn, okBtn});
195 layout.setVerticalGroup(
196 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addGroup(layout.createSequentialGroup()
198 .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
199 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
200 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
202 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
203 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
210 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
215 "AddMetadataDialog_dup_Title=Metadata add failure",
216 "AddMetadataDialog_dup_msg=A metadata entry with this name has already been added to this persona.",
217 "AddMetadataDialog_empty_name_Title=Missing field(s)",
218 "AddMetadataDialog_empty_name_msg=A metadata entry cannot have an empty name or value.",})
220 if (StringUtils.isBlank(nameTextField.getText()) || StringUtils.isBlank(valueTextField.getText())) {
221 JOptionPane.showMessageDialog(
this,
222 Bundle.AddMetadataDialog_empty_name_msg(),
223 Bundle.AddMetadataDialog_empty_name_Title(),
224 JOptionPane.ERROR_MESSAGE);
227 if (StringUtils.isBlank(justificationTextField.getText())) {
228 JOptionPane.showMessageDialog(
this,
229 Bundle.PersonaDetailsPanel_empty_justification_msg(),
230 Bundle.PersonaDetailsPanel_empty_justification_Title(),
231 JOptionPane.ERROR_MESSAGE);
236 String justification = justificationTextField.getText();
238 if (currentMetadata != null) {
239 currentMetadata.confidence = confidence;
240 currentMetadata.justification = justification;
243 if (pdp.addMetadata(nameTextField.getText(), valueTextField.getText(), justification, confidence)) {
246 JOptionPane.showMessageDialog(
this,
247 Bundle.AddMetadataDialog_dup_msg(),
248 Bundle.AddMetadataDialog_dup_Title(),
249 JOptionPane.ERROR_MESSAGE);