19 package org.sleuthkit.autopsy.ingest;
21 import java.beans.PropertyChangeListener;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle;
34 @SuppressWarnings(
"PMD.SingularField")
35 class ProfilePanel extends IngestModuleGlobalSettingsPanel {
37 @NbBundle.Messages({
"ProfilePanel.title.text=Profile",
38 "ProfilePanel.profileDescLabel.text=Description:",
39 "ProfilePanel.profileNameLabel.text=Profile Name:",
40 "ProfilePanel.newProfileText=NewEmptyProfile",
41 "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
42 "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character"})
44 private final IngestJobSettingsPanel ingestSettingsPanel;
45 private final IngestJobSettings settings;
46 private IngestProfile profile;
47 private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.newProfileText");
48 private static final List<String> ILLEGAL_NAME_CHARS = Collections.unmodifiableList(
new ArrayList<>(Arrays.asList(
"\\",
"/",
":",
"*",
"?",
"\"",
"<",
">")));
55 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
56 settings =
new IngestJobSettings(NEW_PROFILE_NAME);
57 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
58 ingestSettingsPanel.setPastJobsButtonVisible(
false);
59 jPanel1.add(ingestSettingsPanel, 0);
63 ProfilePanel(IngestProfile selectedProfile) {
65 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
66 profile = selectedProfile;
67 profileDescArea.setText(profile.getDescription());
68 profileNameField.setText(profile.getName());
69 settings =
new IngestJobSettings(selectedProfile.getName());
70 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
71 ingestSettingsPanel.setPastJobsButtonVisible(
false);
72 jPanel1.add(ingestSettingsPanel, 0);
82 String getProfileName() {
83 return profileNameField.getText().trim();
86 String getProfileDesc() {
87 return profileDescArea.getText();
90 IngestJobSettings getSettings() {
91 return ingestSettingsPanel.getSettings();
99 @SuppressWarnings(
"unchecked")
101 private
void initComponents() {
103 jScrollPane1 =
new javax.swing.JScrollPane();
104 jPanel2 =
new javax.swing.JPanel();
105 profileNameField =
new javax.swing.JTextField();
106 profileDescLabel =
new javax.swing.JLabel();
107 profileDescPane =
new javax.swing.JScrollPane();
108 profileDescArea =
new javax.swing.JTextArea();
109 profileNameLabel =
new javax.swing.JLabel();
110 jPanel1 =
new javax.swing.JPanel();
112 jScrollPane1.setPreferredSize(
new java.awt.Dimension(650, 323));
114 org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileDescLabel.text"));
116 profileDescArea.setColumns(20);
117 profileDescArea.setLineWrap(
true);
118 profileDescArea.setRows(8);
119 profileDescArea.setWrapStyleWord(
true);
120 profileDescArea.setMinimumSize(
new java.awt.Dimension(164, 44));
121 profileDescArea.setName(
"");
122 profileDescPane.setViewportView(profileDescArea);
124 org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileNameLabel.text"));
126 jPanel1.setMinimumSize(
new java.awt.Dimension(625, 450));
127 jPanel1.setPreferredSize(
new java.awt.Dimension(625, 450));
128 jPanel1.setLayout(
new java.awt.BorderLayout());
130 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
131 jPanel2.setLayout(jPanel2Layout);
132 jPanel2Layout.setHorizontalGroup(
133 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addGroup(jPanel2Layout.createSequentialGroup()
136 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
137 .addComponent(profileDescLabel)
138 .addComponent(profileNameLabel))
139 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
140 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141 .addComponent(profileDescPane)
142 .addComponent(profileNameField))
144 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
146 jPanel2Layout.setVerticalGroup(
147 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148 .addGroup(jPanel2Layout.createSequentialGroup()
150 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
151 .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152 .addComponent(profileNameLabel))
153 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155 .addComponent(profileDescLabel)
156 .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
157 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
161 jScrollPane1.setViewportView(jPanel2);
163 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
164 this.setLayout(layout);
165 layout.setHorizontalGroup(
166 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
169 layout.setVerticalGroup(
170 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
175 public void removePropertyChangeListener(PropertyChangeListener l) {
176 ingestSettingsPanel.removePropertyChangeListener(l);
180 public void addPropertyChangeListener(PropertyChangeListener l) {
181 super.addPropertyChangeListener(l);
201 if (null != ingestSettingsPanel) {
202 ingestSettingsPanel.addPropertyChangeListener(l);
206 private javax.swing.JPanel jPanel1;
207 private javax.swing.JPanel jPanel2;
208 private javax.swing.JScrollPane jScrollPane1;
209 private javax.swing.JTextArea profileDescArea;
210 private javax.swing.JLabel profileDescLabel;
211 private javax.swing.JScrollPane profileDescPane;
212 private javax.swing.JTextField profileNameField;
213 private javax.swing.JLabel profileNameLabel;
220 public void saveSettings() {
221 if (profile == null) {
222 IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
223 }
else if (!profile.getName().equals(getProfileName())) {
224 IngestProfile.renameProfile(profile.getName(), getProfileName());
226 profile =
new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
227 IngestProfile.saveProfile(profile);
228 ingestSettingsPanel.getSettings().saveAs(getProfileName());
246 boolean isValidDefinition() {
247 if (getProfileName().isEmpty()) {
248 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
249 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profilesMustBeNamed"),
250 NotifyDescriptor.WARNING_MESSAGE);
251 DialogDisplayer.getDefault().notify(notifyDesc);
254 if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
255 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
256 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profileNameContainsIllegalCharacter"),
257 NotifyDescriptor.WARNING_MESSAGE);
258 DialogDisplayer.getDefault().notify(notifyDesc);
273 private static boolean containsOnlyLegalChars(String toBeChecked, List<String> illegalChars) {
274 for (String illegalChar : illegalChars) {
275 if (toBeChecked.contains(illegalChar)) {