19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
21 import java.awt.Component;
22 import java.awt.Dialog;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.DefaultListCellRenderer;
26 import javax.swing.DefaultListModel;
27 import javax.swing.JDialog;
28 import javax.swing.JFrame;
29 import javax.swing.JOptionPane;
30 import javax.swing.event.ListSelectionEvent;
31 import javax.swing.event.ListSelectionListener;
32 import org.openide.util.NbBundle.Messages;
33 import org.openide.windows.WindowManager;
43 @SuppressWarnings(
"PMD.SingularField")
46 private static final long serialVersionUID = 1L;
50 private final DefaultListModel<CentralRepoOrganization> rulesListModel =
new DefaultListModel<>();
53 @Messages({
"ManageOrganizationsDialog.title.text=Manage Organizations"})
60 Bundle.ManageOrganizationsDialog_title_text(),
72 Bundle.ManageOrganizationsDialog_title_text(),
82 this((JFrame) WindowManager.getDefault().getMainWindow());
93 organizationList.setCellRenderer(
new DefaultListCellRenderer() {
94 private static final long serialVersionUID = 1L;
96 @SuppressWarnings(
"rawtypes")
98 public Component getListCellRendererComponent(javax.swing.JList list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
99 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
104 organizationList.setModel(rulesListModel);
107 setButtonsEnabled(organizationList.getSelectedValue());
110 logger.log(Level.WARNING,
"Error getting Central Repo for Organizations dialog", ex);
116 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
122 rulesListModel.clear();
124 if (orgs.size() > 0) {
126 rulesListModel.addElement(
org);
127 if (selected != null &&
org.getOrgID() == selected.getOrgID()) {
131 if (orgs.contains(selected)) {
132 organizationList.setSelectedValue(selected,
true);
134 organizationList.setSelectedIndex(0);
136 organizationList.validate();
137 organizationList.repaint();
143 populateListAndSelect(selected);
146 @Messages({
"ManageOrganizationsDialog.pocNameLabel.text=Point of Contact Name:",
147 "ManageOrganizationsDialog.deleteButton.text=Delete",
148 "ManageOrganizationsDialog.newButton.text=New",
149 "ManageOrganizationsDialog.closeButton.text=Close",
150 "ManageOrganizationsDialog.orgNameLabel.text=Organization Name:",
151 "ManageOrganizationsDialog.pocEmailLabel.text=Point of Contact Email:",
152 "ManageOrganizationsDialog.editButton.text=Edit",
153 "ManageOrganizationsDialog.pocPhoneLabel.text=Point of Contact Phone:",
154 "ManageOrganizationsDialog.orgDescriptionTextArea.text=Organizations are used to provide additional contact information for the content they are associated with.",
155 "ManageOrganizationsDialog.orgListLabel.text=Organizations",
156 "ManageOrganizationsDialog.orgDetailsLabel.text=Organization Details",
157 "ManageOrganizationsDialog.confirmDeletion.title=Confirm Deletion",
158 "ManageOrganizationsDialog.confirmDeletion.message=Are you sure you want to delete the selected organization from the central repo?",
159 "ManageOrganizationsDialog.unableToDeleteOrg.title=Unable to Delete",
160 "ManageOrganizationsDialog.unableToDeleteOrg.message=Unable to delete selected organizaiton."})
166 @SuppressWarnings(
"unchecked")
168 private
void initComponents() {
170 manageOrganizationsScrollPane =
new javax.swing.JScrollPane();
171 manageOrganizationsPanel =
new javax.swing.JPanel();
172 orgListScrollPane =
new javax.swing.JScrollPane();
173 organizationList =
new javax.swing.JList<>();
174 orgDescriptionScrollPane =
new javax.swing.JScrollPane();
175 orgDescriptionTextArea =
new javax.swing.JTextArea();
176 newButton =
new javax.swing.JButton();
177 deleteButton =
new javax.swing.JButton();
178 closeButton =
new javax.swing.JButton();
179 orgListLabel =
new javax.swing.JLabel();
180 jSeparator1 =
new javax.swing.JSeparator();
181 pocNameLabel =
new javax.swing.JLabel();
182 pocPhoneLabel =
new javax.swing.JLabel();
183 pocEmailLabel =
new javax.swing.JLabel();
184 orgNameLabel =
new javax.swing.JLabel();
185 orgNameTextField =
new javax.swing.JTextField();
186 pocNameTextField =
new javax.swing.JTextField();
187 pocPhoneTextField =
new javax.swing.JTextField();
188 pocEmailTextField =
new javax.swing.JTextField();
189 editButton =
new javax.swing.JButton();
190 orgDetailsLabel =
new javax.swing.JLabel();
192 setMinimumSize(
new java.awt.Dimension(600, 450));
193 setPreferredSize(
new java.awt.Dimension(600, 450));
195 manageOrganizationsScrollPane.setMinimumSize(null);
196 manageOrganizationsScrollPane.setPreferredSize(
new java.awt.Dimension(535, 415));
198 manageOrganizationsPanel.setPreferredSize(
new java.awt.Dimension(527, 407));
200 organizationList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
201 orgListScrollPane.setViewportView(organizationList);
203 orgDescriptionTextArea.setEditable(
false);
204 orgDescriptionTextArea.setBackground(
new java.awt.Color(240, 240, 240));
205 orgDescriptionTextArea.setColumns(20);
206 orgDescriptionTextArea.setLineWrap(
true);
207 orgDescriptionTextArea.setRows(3);
208 orgDescriptionTextArea.setText(
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDescriptionTextArea.text"));
209 orgDescriptionTextArea.setWrapStyleWord(
true);
210 orgDescriptionScrollPane.setViewportView(orgDescriptionTextArea);
212 org.openide.awt.Mnemonics.setLocalizedText(newButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.newButton.text"));
213 newButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
214 newButton.setMaximumSize(
new java.awt.Dimension(70, 23));
215 newButton.setMinimumSize(
new java.awt.Dimension(70, 23));
216 newButton.setPreferredSize(
new java.awt.Dimension(70, 23));
217 newButton.addActionListener(
new java.awt.event.ActionListener() {
218 public void actionPerformed(java.awt.event.ActionEvent evt) {
219 newButtonActionPerformed(evt);
223 org.openide.awt.Mnemonics.setLocalizedText(deleteButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.deleteButton.text"));
224 deleteButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
225 deleteButton.setMaximumSize(
new java.awt.Dimension(70, 23));
226 deleteButton.setMinimumSize(
new java.awt.Dimension(70, 23));
227 deleteButton.setPreferredSize(
new java.awt.Dimension(70, 23));
228 deleteButton.addActionListener(
new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 deleteButtonActionPerformed(evt);
234 org.openide.awt.Mnemonics.setLocalizedText(closeButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.closeButton.text"));
235 closeButton.addActionListener(
new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 closeButtonActionPerformed(evt);
241 org.openide.awt.Mnemonics.setLocalizedText(orgListLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgListLabel.text"));
243 jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
245 org.openide.awt.Mnemonics.setLocalizedText(pocNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocNameLabel.text"));
247 org.openide.awt.Mnemonics.setLocalizedText(pocPhoneLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocPhoneLabel.text"));
249 org.openide.awt.Mnemonics.setLocalizedText(pocEmailLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocEmailLabel.text"));
251 org.openide.awt.Mnemonics.setLocalizedText(orgNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgNameLabel.text"));
253 orgNameTextField.setEditable(
false);
255 pocNameTextField.setEditable(
false);
257 pocPhoneTextField.setEditable(
false);
259 pocEmailTextField.setEditable(
false);
261 org.openide.awt.Mnemonics.setLocalizedText(editButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.editButton.text"));
262 editButton.setMaximumSize(
new java.awt.Dimension(70, 23));
263 editButton.setMinimumSize(
new java.awt.Dimension(70, 23));
264 editButton.setPreferredSize(
new java.awt.Dimension(70, 23));
265 editButton.addActionListener(
new java.awt.event.ActionListener() {
266 public void actionPerformed(java.awt.event.ActionEvent evt) {
267 editButtonActionPerformed(evt);
271 org.openide.awt.Mnemonics.setLocalizedText(orgDetailsLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDetailsLabel.text"));
273 javax.swing.GroupLayout manageOrganizationsPanelLayout =
new javax.swing.GroupLayout(manageOrganizationsPanel);
274 manageOrganizationsPanel.setLayout(manageOrganizationsPanelLayout);
275 manageOrganizationsPanelLayout.setHorizontalGroup(
276 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
279 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
280 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
281 .addComponent(orgListLabel)
282 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
283 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
284 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
285 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
286 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
287 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
288 .addComponent(orgListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
289 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
290 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
291 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
293 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
296 .addComponent(closeButton))
297 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
299 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
300 .addComponent(pocNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
301 .addComponent(orgNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
302 .addComponent(pocPhoneLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
303 .addComponent(pocEmailLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
304 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
305 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addComponent(pocNameTextField)
307 .addComponent(pocPhoneTextField)
308 .addComponent(pocEmailTextField, javax.swing.GroupLayout.Alignment.TRAILING)
309 .addComponent(orgNameTextField))))
311 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
313 .addComponent(orgDetailsLabel)
314 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
316 manageOrganizationsPanelLayout.setVerticalGroup(
317 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
320 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
321 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
322 .addComponent(orgDetailsLabel)
323 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
325 .addComponent(orgNameLabel)
326 .addComponent(orgNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
327 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
328 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
329 .addComponent(pocNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
330 .addComponent(pocNameLabel))
331 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
332 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
333 .addComponent(pocPhoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
334 .addComponent(pocPhoneLabel))
335 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
336 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
337 .addComponent(pocEmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
338 .addComponent(pocEmailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
339 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
340 .addComponent(closeButton))
341 .addComponent(jSeparator1)
342 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
343 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
344 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
345 .addComponent(orgListLabel)
346 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
347 .addComponent(orgListScrollPane)
348 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
349 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
350 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
351 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
352 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
356 manageOrganizationsScrollPane.setViewportView(manageOrganizationsPanel);
358 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
359 getContentPane().setLayout(layout);
360 layout.setHorizontalGroup(
361 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
364 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE))
366 layout.setVerticalGroup(
367 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
368 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
370 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE))
378 if (orgToDelete != null) {
379 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
this,
380 Bundle.ManageOrganizationsDialog_confirmDeletion_message(),
381 Bundle.ManageOrganizationsDialog_confirmDeletion_title(),
382 JOptionPane.YES_NO_OPTION)) {
387 JOptionPane.showMessageDialog(
this,
388 ex.getMessage(), Bundle.ManageOrganizationsDialog_unableToDeleteOrg_title(), JOptionPane.WARNING_MESSAGE);
389 logger.log(Level.INFO,
"Was unable to delete organization from central repository", ex);
400 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog(
this);
401 if (dialogO.isChanged()) {
403 newOrg = dialogO.getNewOrg();
404 populateListAndSelect(dialogO.getNewOrg());
413 if (orgToEdit != null) {
414 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog(
this, orgToEdit);
415 if (dialogO.isChanged()) {
417 newOrg = dialogO.getNewOrg();
418 populateListAndSelect(dialogO.getNewOrg());
451 return newOrg != null;
459 boolean isSelected = (selectedOrg != null);
460 boolean isDefaultOrg =
false;
461 if(selectedOrg != null){
465 editButton.setEnabled(isSelected && (! isDefaultOrg));
466 deleteButton.setEnabled(isSelected && (! isDefaultOrg));
476 if (e.getValueIsAdjusting()) {
480 setButtonsEnabled(selected);
481 if (selected != null) {
482 orgNameTextField.setText(selected.
getName());
483 pocNameTextField.setText(selected.
getPocName());
487 orgNameTextField.setText(
"");
488 pocNameTextField.setText(
"");
489 pocPhoneTextField.setText(
"");
490 pocEmailTextField.setText(
"");
void editButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JTextField pocPhoneTextField
void closeButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JTextField orgNameTextField
void valueChanged(ListSelectionEvent e)
javax.swing.JButton deleteButton
void deleteButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JScrollPane orgDescriptionScrollPane
void deleteOrganization(CentralRepoOrganization organizationToDelete)
javax.swing.JPanel manageOrganizationsPanel
javax.swing.JScrollPane manageOrganizationsScrollPane
javax.swing.JLabel pocPhoneLabel
javax.swing.JLabel pocEmailLabel
ManageOrganizationsDialog()
javax.swing.JLabel pocNameLabel
javax.swing.JLabel orgDetailsLabel
javax.swing.JLabel orgListLabel
javax.swing.JSeparator jSeparator1
void newButtonActionPerformed(java.awt.event.ActionEvent evt)
void setButtonsEnabled(CentralRepoOrganization selectedOrg)
void populateListAndSelect(CentralRepoOrganization selected)
javax.swing.JTextArea orgDescriptionTextArea
javax.swing.JScrollPane orgListScrollPane
ManageOrganizationsDialog(Dialog parent)
CentralRepoOrganization getNewOrg()
javax.swing.JTextField pocNameTextField
List< CentralRepoOrganization > getOrganizations()
CentralRepository dbManager
javax.swing.JButton editButton
synchronized static Logger getLogger(String name)
javax.swing.JLabel orgNameLabel
CentralRepoOrganization newOrg
static boolean isDefaultOrg(CentralRepoOrganization org)
ManageOrganizationsDialog(JFrame parent)
static CentralRepository getInstance()
javax.swing.JList< org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoOrganization > organizationList
javax.swing.JButton closeButton
javax.swing.JButton newButton
javax.swing.JTextField pocEmailTextField