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.Exceptions;
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<EamOrganization> rulesListModel =
new DefaultListModel<>();
53 @Messages({
"ManageOrganizationsDialog.title.text=Manage Organizations"})
58 super((JFrame) WindowManager.getDefault().getMainWindow(),
59 Bundle.ManageOrganizationsDialog_title_text(),
64 organizationList.setCellRenderer(
new DefaultListCellRenderer() {
65 private static final long serialVersionUID = 1L;
67 @SuppressWarnings(
"rawtypes")
69 public Component getListCellRendererComponent(javax.swing.JList list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
70 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
75 organizationList.setModel(rulesListModel);
78 setButtonsEnabled(organizationList.getSelectedValue());
81 Exceptions.printStackTrace(ex);
87 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
92 rulesListModel.clear();
94 if (orgs.size() > 0) {
96 rulesListModel.addElement(
org);
97 if (selected != null &&
org.getOrgID() == selected.getOrgID()) {
101 if (orgs.contains(selected)) {
102 organizationList.setSelectedValue(selected,
true);
104 organizationList.setSelectedIndex(0);
106 organizationList.validate();
107 organizationList.repaint();
113 populateListAndSelect(selected);
116 @Messages({
"ManageOrganizationsDialog.pocNameLabel.text=Point of Contact Name:",
117 "ManageOrganizationsDialog.deleteButton.text=Delete",
118 "ManageOrganizationsDialog.newButton.text=New",
119 "ManageOrganizationsDialog.closeButton.text=Close",
120 "ManageOrganizationsDialog.orgNameLabel.text=Organization Name:",
121 "ManageOrganizationsDialog.pocEmailLabel.text=Point of Contact Email:",
122 "ManageOrganizationsDialog.editButton.text=Edit",
123 "ManageOrganizationsDialog.pocPhoneLabel.text=Point of Contact Phone:",
124 "ManageOrganizationsDialog.orgDescriptionTextArea.text=Organizations are used to provide additional contact information for the content they are associated with.",
125 "ManageOrganizationsDialog.orgListLabel.text=Organizations",
126 "ManageOrganizationsDialog.orgDetailsLabel.text=Organization Details",
127 "ManageOrganizationsDialog.confirmDeletion.title=Confirm Deletion",
128 "ManageOrganizationsDialog.confirmDeletion.message=Are you sure you want to delete the selected organization from the central repo?",
129 "ManageOrganizationsDialog.unableToDeleteOrg.title=Unable to Delete",
130 "ManageOrganizationsDialog.unableToDeleteOrg.message=Unable to delete selected organizaiton."})
136 @SuppressWarnings(
"unchecked")
138 private
void initComponents() {
140 manageOrganizationsScrollPane =
new javax.swing.JScrollPane();
141 manageOrganizationsPanel =
new javax.swing.JPanel();
142 orgListScrollPane =
new javax.swing.JScrollPane();
143 organizationList =
new javax.swing.JList<>();
144 orgDescriptionScrollPane =
new javax.swing.JScrollPane();
145 orgDescriptionTextArea =
new javax.swing.JTextArea();
146 newButton =
new javax.swing.JButton();
147 deleteButton =
new javax.swing.JButton();
148 closeButton =
new javax.swing.JButton();
149 orgListLabel =
new javax.swing.JLabel();
150 jSeparator1 =
new javax.swing.JSeparator();
151 pocNameLabel =
new javax.swing.JLabel();
152 pocPhoneLabel =
new javax.swing.JLabel();
153 pocEmailLabel =
new javax.swing.JLabel();
154 orgNameLabel =
new javax.swing.JLabel();
155 orgNameTextField =
new javax.swing.JTextField();
156 pocNameTextField =
new javax.swing.JTextField();
157 pocPhoneTextField =
new javax.swing.JTextField();
158 pocEmailTextField =
new javax.swing.JTextField();
159 editButton =
new javax.swing.JButton();
160 orgDetailsLabel =
new javax.swing.JLabel();
162 setMinimumSize(
new java.awt.Dimension(545, 415));
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.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
176 orgDescriptionTextArea.setLineWrap(
true);
177 orgDescriptionTextArea.setRows(3);
178 orgDescriptionTextArea.setText(
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDescriptionTextArea.text"));
179 orgDescriptionTextArea.setWrapStyleWord(
true);
180 orgDescriptionScrollPane.setViewportView(orgDescriptionTextArea);
182 org.openide.awt.Mnemonics.setLocalizedText(newButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.newButton.text"));
183 newButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
184 newButton.setMaximumSize(
new java.awt.Dimension(70, 23));
185 newButton.setMinimumSize(
new java.awt.Dimension(70, 23));
186 newButton.setPreferredSize(
new java.awt.Dimension(70, 23));
187 newButton.addActionListener(
new java.awt.event.ActionListener() {
188 public void actionPerformed(java.awt.event.ActionEvent evt) {
189 newButtonActionPerformed(evt);
193 org.openide.awt.Mnemonics.setLocalizedText(deleteButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.deleteButton.text"));
194 deleteButton.setMargin(
new java.awt.Insets(2, 6, 2, 6));
195 deleteButton.setMaximumSize(
new java.awt.Dimension(70, 23));
196 deleteButton.setMinimumSize(
new java.awt.Dimension(70, 23));
197 deleteButton.setPreferredSize(
new java.awt.Dimension(70, 23));
198 deleteButton.addActionListener(
new java.awt.event.ActionListener() {
199 public void actionPerformed(java.awt.event.ActionEvent evt) {
200 deleteButtonActionPerformed(evt);
204 org.openide.awt.Mnemonics.setLocalizedText(closeButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.closeButton.text"));
205 closeButton.addActionListener(
new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
207 closeButtonActionPerformed(evt);
211 org.openide.awt.Mnemonics.setLocalizedText(orgListLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgListLabel.text"));
213 jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
215 org.openide.awt.Mnemonics.setLocalizedText(pocNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocNameLabel.text"));
217 org.openide.awt.Mnemonics.setLocalizedText(pocPhoneLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocPhoneLabel.text"));
219 org.openide.awt.Mnemonics.setLocalizedText(pocEmailLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.pocEmailLabel.text"));
221 org.openide.awt.Mnemonics.setLocalizedText(orgNameLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgNameLabel.text"));
223 orgNameTextField.setEditable(
false);
225 pocNameTextField.setEditable(
false);
227 pocPhoneTextField.setEditable(
false);
229 pocEmailTextField.setEditable(
false);
231 org.openide.awt.Mnemonics.setLocalizedText(editButton,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.editButton.text"));
232 editButton.setMaximumSize(
new java.awt.Dimension(70, 23));
233 editButton.setMinimumSize(
new java.awt.Dimension(70, 23));
234 editButton.setPreferredSize(
new java.awt.Dimension(70, 23));
235 editButton.addActionListener(
new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 editButtonActionPerformed(evt);
241 org.openide.awt.Mnemonics.setLocalizedText(orgDetailsLabel,
org.openide.util.NbBundle.getMessage(
ManageOrganizationsDialog.class,
"ManageOrganizationsDialog.orgDetailsLabel.text"));
243 javax.swing.GroupLayout manageOrganizationsPanelLayout =
new javax.swing.GroupLayout(manageOrganizationsPanel);
244 manageOrganizationsPanel.setLayout(manageOrganizationsPanelLayout);
245 manageOrganizationsPanelLayout.setHorizontalGroup(
246 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
249 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)
251 .addComponent(orgListLabel)
252 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
253 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
254 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
255 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
256 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
257 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
258 .addComponent(orgListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
259 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
260 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
261 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
263 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
265 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
266 .addComponent(closeButton))
267 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
269 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
270 .addComponent(pocNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
271 .addComponent(orgNameLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
272 .addComponent(pocPhoneLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
273 .addComponent(pocEmailLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276 .addComponent(pocNameTextField)
277 .addComponent(pocPhoneTextField)
278 .addComponent(pocEmailTextField, javax.swing.GroupLayout.Alignment.TRAILING)
279 .addComponent(orgNameTextField))))
281 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
282 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
283 .addComponent(orgDetailsLabel)
284 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
286 manageOrganizationsPanelLayout.setVerticalGroup(
287 manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
290 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
291 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
292 .addComponent(orgDetailsLabel)
293 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
294 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
295 .addComponent(orgNameLabel)
296 .addComponent(orgNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
297 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
298 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
299 .addComponent(pocNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
300 .addComponent(pocNameLabel))
301 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
302 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
303 .addComponent(pocPhoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
304 .addComponent(pocPhoneLabel))
305 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
306 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
307 .addComponent(pocEmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
308 .addComponent(pocEmailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
309 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
310 .addComponent(closeButton))
311 .addComponent(jSeparator1)
312 .addGroup(manageOrganizationsPanelLayout.createSequentialGroup()
313 .addComponent(orgDescriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
314 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315 .addComponent(orgListLabel)
316 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
317 .addComponent(orgListScrollPane)
318 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
319 .addGroup(manageOrganizationsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
320 .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
321 .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
322 .addComponent(editButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
326 manageOrganizationsScrollPane.setViewportView(manageOrganizationsPanel);
328 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
329 getContentPane().setLayout(layout);
330 layout.setHorizontalGroup(
331 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
332 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
334 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
336 layout.setVerticalGroup(
337 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
340 .addComponent(manageOrganizationsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
348 if (orgToDelete != null) {
349 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
350 Bundle.ManageOrganizationsDialog_confirmDeletion_message(),
351 Bundle.ManageOrganizationsDialog_confirmDeletion_title(),
352 JOptionPane.YES_NO_OPTION)) {
357 JOptionPane.showMessageDialog(
this,
358 ex.getMessage(), Bundle.ManageOrganizationsDialog_unableToDeleteOrg_title(), JOptionPane.WARNING_MESSAGE);
359 logger.log(Level.INFO,
"Was unable to delete organization from central repository", ex);
370 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog();
371 if (dialogO.isChanged()) {
373 newOrg = dialogO.getNewOrg();
374 populateListAndSelect(dialogO.getNewOrg());
383 if (orgToEdit != null) {
384 AddNewOrganizationDialog dialogO =
new AddNewOrganizationDialog(orgToEdit);
385 if (dialogO.isChanged()) {
387 newOrg = dialogO.getNewOrg();
388 populateListAndSelect(dialogO.getNewOrg());
421 return newOrg != null;
429 boolean isSelected = (selectedOrg != null);
430 boolean isDefaultOrg =
false;
431 if(selectedOrg != null){
435 editButton.setEnabled(isSelected && (! isDefaultOrg));
436 deleteButton.setEnabled(isSelected && (! isDefaultOrg));
446 if (e.getValueIsAdjusting()) {
450 setButtonsEnabled(selected);
451 if (selected != null) {
452 orgNameTextField.setText(selected.
getName());
453 pocNameTextField.setText(selected.
getPocName());
457 orgNameTextField.setText(
"");
458 pocNameTextField.setText(
"");
459 pocPhoneTextField.setText(
"");
460 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.JList< EamOrganization > organizationList
javax.swing.JButton deleteButton
void deleteButtonActionPerformed(java.awt.event.ActionEvent evt)
static boolean isDefaultOrg(EamOrganization org)
javax.swing.JScrollPane orgDescriptionScrollPane
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
List< EamOrganization > getOrganizations()
void newButtonActionPerformed(java.awt.event.ActionEvent evt)
static EamDb getInstance()
javax.swing.JTextArea orgDescriptionTextArea
javax.swing.JScrollPane orgListScrollPane
javax.swing.JTextField pocNameTextField
void populateListAndSelect(EamOrganization selected)
javax.swing.JButton editButton
synchronized static Logger getLogger(String name)
javax.swing.JLabel orgNameLabel
void deleteOrganization(EamOrganization organizationToDelete)
void setButtonsEnabled(EamOrganization selectedOrg)
javax.swing.JButton closeButton
javax.swing.JButton newButton
javax.swing.JTextField pocEmailTextField
EamOrganization getNewOrg()