19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
21 import java.awt.Component;
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.DefaultListCellRenderer;
25 import javax.swing.DefaultListModel;
26 import javax.swing.JDialog;
27 import javax.swing.JFrame;
28 import javax.swing.JOptionPane;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.event.ListSelectionListener;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.windows.WindowManager;
42 @SuppressWarnings(
"PMD.SingularField")
45 private static final long serialVersionUID = 1L;
49 private final DefaultListModel<CentralRepoOrganization> rulesListModel =
new DefaultListModel<>();
52 @Messages({
"ManageOrganizationsDialog.title.text=Manage Organizations"})
57 super((JFrame) WindowManager.getDefault().getMainWindow(),
58 Bundle.ManageOrganizationsDialog_title_text(),
63 organizationList.setCellRenderer(
new DefaultListCellRenderer() {
64 private static final long serialVersionUID = 1L;
66 @SuppressWarnings(
"rawtypes")
68 public Component getListCellRendererComponent(javax.swing.JList list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
69 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
74 organizationList.setModel(rulesListModel);
77 setButtonsEnabled(organizationList.getSelectedValue());
80 logger.log(Level.WARNING,
"Error getting Central Repo for Organizations dialog", ex);
86 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
91 rulesListModel.clear();
93 if (orgs.size() > 0) {
95 rulesListModel.addElement(
org);
96 if (selected != null &&
org.getOrgID() == selected.getOrgID()) {
100 if (orgs.contains(selected)) {
101 organizationList.setSelectedValue(selected,
true);
103 organizationList.setSelectedIndex(0);
105 organizationList.validate();
106 organizationList.repaint();
112 populateListAndSelect(selected);
115 @Messages({
"ManageOrganizationsDialog.pocNameLabel.text=Point of Contact Name:",
116 "ManageOrganizationsDialog.deleteButton.text=Delete",
117 "ManageOrganizationsDialog.newButton.text=New",
118 "ManageOrganizationsDialog.closeButton.text=Close",
119 "ManageOrganizationsDialog.orgNameLabel.text=Organization Name:",
120 "ManageOrganizationsDialog.pocEmailLabel.text=Point of Contact Email:",
121 "ManageOrganizationsDialog.editButton.text=Edit",
122 "ManageOrganizationsDialog.pocPhoneLabel.text=Point of Contact Phone:",
123 "ManageOrganizationsDialog.orgDescriptionTextArea.text=Organizations are used to provide additional contact information for the content they are associated with.",
124 "ManageOrganizationsDialog.orgListLabel.text=Organizations",
125 "ManageOrganizationsDialog.orgDetailsLabel.text=Organization Details",
126 "ManageOrganizationsDialog.confirmDeletion.title=Confirm Deletion",
127 "ManageOrganizationsDialog.confirmDeletion.message=Are you sure you want to delete the selected organization from the central repo?",
128 "ManageOrganizationsDialog.unableToDeleteOrg.title=Unable to Delete",
129 "ManageOrganizationsDialog.unableToDeleteOrg.message=Unable to delete selected organizaiton."})
135 @SuppressWarnings(
"unchecked")
137 private
void initComponents() {
139 manageOrganizationsScrollPane =
new javax.swing.JScrollPane();
140 manageOrganizationsPanel =
new javax.swing.JPanel();
141 orgListScrollPane =
new javax.swing.JScrollPane();
142 organizationList =
new javax.swing.JList<>();
143 orgDescriptionScrollPane =
new javax.swing.JScrollPane();
144 orgDescriptionTextArea =
new javax.swing.JTextArea();
145 newButton =
new javax.swing.JButton();
146 deleteButton =
new javax.swing.JButton();
147 closeButton =
new javax.swing.JButton();
148 orgListLabel =
new javax.swing.JLabel();
149 jSeparator1 =
new javax.swing.JSeparator();
150 pocNameLabel =
new javax.swing.JLabel();
151 pocPhoneLabel =
new javax.swing.JLabel();
152 pocEmailLabel =
new javax.swing.JLabel();
153 orgNameLabel =
new javax.swing.JLabel();
154 orgNameTextField =
new javax.swing.JTextField();
155 pocNameTextField =
new javax.swing.JTextField();
156 pocPhoneTextField =
new javax.swing.JTextField();
157 pocEmailTextField =
new javax.swing.JTextField();
158 editButton =
new javax.swing.JButton();
159 orgDetailsLabel =
new javax.swing.JLabel();
161 setMinimumSize(
new java.awt.Dimension(600, 450));
162 setPreferredSize(
new java.awt.Dimension(600, 450));
164 manageOrganizationsScrollPane.setMinimumSize(null);
165 manageOrganizationsScrollPane.setPreferredSize(
new java.awt.Dimension(535, 415));
167 manageOrganizationsPanel.setPreferredSize(
new java.awt.Dimension(527, 407));
169 organizationList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
170 orgListScrollPane.setViewportView(organizationList);
172 orgDescriptionTextArea.setEditable(
false);
173 orgDescriptionTextArea.setBackground(
new java.awt.Color(240, 240, 240));
174 orgDescriptionTextArea.setColumns(20);
175 orgDescriptionTextArea.setLineWrap(
true);
176 orgDescriptionTextArea.setRows(3);
177 orgDescriptionTextArea.setText(
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDescriptionTextArea.text"));
178 orgDescriptionTextArea.setWrapStyleWord(
true);
179 orgDescriptionScrollPane.setViewportView(orgDescriptionTextArea);
181 org.openide.awt.Mnemonics.setLocalizedText(newButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.newButton.text"));
182 newButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
183 newButton.setMaximumSize(
new java.awt.Dimension(70, 23));
184 newButton.setMinimumSize(
new java.awt.Dimension(70, 23));
185 newButton.setPreferredSize(
new java.awt.Dimension(70, 23));
186 newButton.addActionListener(
new java.awt.event.ActionListener() {
187 public void actionPerformed(java.awt.event.ActionEvent evt) {
188 newButtonActionPerformed(evt);
192 org.openide.awt.Mnemonics.setLocalizedText(deleteButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.deleteButton.text"));
193 deleteButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
194 deleteButton.setMaximumSize(
new java.awt.Dimension(70, 23));
195 deleteButton.setMinimumSize(
new java.awt.Dimension(70, 23));
196 deleteButton.setPreferredSize(
new java.awt.Dimension(70, 23));
197 deleteButton.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 deleteButtonActionPerformed(evt);
203 org.openide.awt.Mnemonics.setLocalizedText(closeButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.closeButton.text"));
204 closeButton.addActionListener(
new java.awt.event.ActionListener() {
205 public void actionPerformed(java.awt.event.ActionEvent evt) {
206 closeButtonActionPerformed(evt);
210 org.openide.awt.Mnemonics.setLocalizedText(orgListLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgListLabel.text"));
212 jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
214 org.openide.awt.Mnemonics.setLocalizedText(pocNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocNameLabel.text"));
216 org.openide.awt.Mnemonics.setLocalizedText(pocPhoneLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocPhoneLabel.text"));
218 org.openide.awt.Mnemonics.setLocalizedText(pocEmailLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocEmailLabel.text"));
220 org.openide.awt.Mnemonics.setLocalizedText(orgNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgNameLabel.text"));
222 orgNameTextField.setEditable(
false);
224 pocNameTextField.setEditable(
false);
226 pocPhoneTextField.setEditable(
false);
228 pocEmailTextField.setEditable(
false);
230 org.openide.awt.Mnemonics.setLocalizedText(editButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.editButton.text"));
231 editButton.setMaximumSize(
new java.awt.Dimension(70, 23));
232 editButton.setMinimumSize(
new java.awt.Dimension(70, 23));
233 editButton.setPreferredSize(
new java.awt.Dimension(70, 23));
234 editButton.addActionListener(
new java.awt.event.ActionListener() {
235 public void actionPerformed(java.awt.event.ActionEvent evt) {
236 editButtonActionPerformed(evt);
240 org.openide.awt.Mnemonics.setLocalizedText(orgDetailsLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDetailsLabel.text"));
242 javax.swing.GroupLayout manageOrganizationsPanelLayout =
new javax.swing.GroupLayout(manageOrganizationsPanel);
243 manageOrganizationsPanel.setLayout(manageOrganizationsPanelLayout);
244 manageOrganizationsPanelLayout.setHorizontalGroup(
245 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
248 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
250 .addComponent(orgListLabel)
251 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
252 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
254 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
257 .addComponent(orgListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
258 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
259 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
260 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
262 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
264 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
265 .addComponent(closeButton))
266 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
268 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
269 .addComponent(pocNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
270 .addComponent(orgNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
271 .addComponent(pocPhoneLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
272 .addComponent(pocEmailLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
273 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
274 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275 .addComponent(pocNameTextField)
276 .addComponent(pocPhoneTextField)
277 .addComponent(pocEmailTextField, javax.swing.GroupLayout.Alignment.TRAILING)
278 .addComponent(orgNameTextField))))
280 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
281 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
282 .addComponent(orgDetailsLabel)
283 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
285 manageOrganizationsPanelLayout.setVerticalGroup(
286 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
289 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
290 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
291 .addComponent(orgDetailsLabel)
292 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
294 .addComponent(orgNameLabel)
295 .addComponent(orgNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
297 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
298 .addComponent(pocNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
299 .addComponent(pocNameLabel))
300 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
301 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
302 .addComponent(pocPhoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
303 .addComponent(pocPhoneLabel))
304 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
306 .addComponent(pocEmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
307 .addComponent(pocEmailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
309 .addComponent(closeButton))
310 .addComponent(jSeparator1)
311 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
312 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
313 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
314 .addComponent(orgListLabel)
315 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316 .addComponent(orgListScrollPane)
317 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
318 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
319 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
320 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
321 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
325 manageOrganizationsScrollPane.setViewportView(manageOrganizationsPanel);
327 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
328 getContentPane().setLayout(layout);
329 layout.setHorizontalGroup(
330 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
331 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
333 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE))
335 layout.setVerticalGroup(
336 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
339 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE))
347 if (orgToDelete != null) {
348 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
349 Bundle.ManageOrganizationsDialog_confirmDeletion_message(),
350 Bundle.ManageOrganizationsDialog_confirmDeletion_title(),
351 JOptionPane.YES_NO_OPTION)) {
356 JOptionPane.showMessageDialog(
this,
357 ex.getMessage(), Bundle.ManageOrganizationsDialog_unableToDeleteOrg_title(), JOptionPane.WARNING_MESSAGE);
358 logger.log(Level.INFO,
"Was unable to delete organization from central repository", ex);
369 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog();
370 if (dialogO.isChanged()) {
372 newOrg = dialogO.getNewOrg();
373 populateListAndSelect(dialogO.getNewOrg());
382 if (orgToEdit != null) {
383 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog(orgToEdit);
384 if (dialogO.isChanged()) {
386 newOrg = dialogO.getNewOrg();
387 populateListAndSelect(dialogO.getNewOrg());
420 return newOrg != null;
428 boolean isSelected = (selectedOrg != null);
429 boolean isDefaultOrg =
false;
430 if(selectedOrg != null){
434 editButton.setEnabled(isSelected && (! isDefaultOrg));
435 deleteButton.setEnabled(isSelected && (! isDefaultOrg));
445 if (e.getValueIsAdjusting()) {
449 setButtonsEnabled(selected);
450 if (selected != null) {
451 orgNameTextField.setText(selected.
getName());
452 pocNameTextField.setText(selected.
getPocName());
456 orgNameTextField.setText(
"");
457 pocNameTextField.setText(
"");
458 pocPhoneTextField.setText(
"");
459 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
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)
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