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 class ProfilePanel
extends IngestModuleGlobalSettingsPanel {
36 @NbBundle.Messages({
"ProfilePanel.title.text=Profile",
37 "ProfilePanel.profileDescLabel.text=Description:",
38 "ProfilePanel.profileNameLabel.text=Profile Name:",
39 "ProfilePanel.newProfileText=NewEmptyProfile",
40 "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
41 "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character"})
43 private final IngestJobSettingsPanel ingestSettingsPanel;
44 private final IngestJobSettings settings;
45 private IngestProfile profile;
46 private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.newProfileText");
47 private static final List<String> ILLEGAL_NAME_CHARS = Collections.unmodifiableList(
new ArrayList<>(Arrays.asList(
"\\",
"/",
":",
"*",
"?",
"\"",
"<",
">")));
54 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
55 settings =
new IngestJobSettings(NEW_PROFILE_NAME);
56 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
57 ingestSettingsPanel.setPastJobsButtonVisible(
false);
58 jPanel1.add(ingestSettingsPanel, 0);
62 ProfilePanel(IngestProfile selectedProfile) {
64 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
65 profile = selectedProfile;
66 profileDescArea.setText(profile.getDescription());
67 profileNameField.setText(profile.getName());
68 settings =
new IngestJobSettings(selectedProfile.getName());
69 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
70 ingestSettingsPanel.setPastJobsButtonVisible(
false);
71 jPanel1.add(ingestSettingsPanel, 0);
81 String getProfileName() {
82 return profileNameField.getText().trim();
85 String getProfileDesc() {
86 return profileDescArea.getText();
89 IngestJobSettings getSettings() {
90 return ingestSettingsPanel.getSettings();
98 @SuppressWarnings(
"unchecked")
100 private
void initComponents() {
102 jScrollPane1 =
new javax.swing.JScrollPane();
103 jPanel2 =
new javax.swing.JPanel();
104 profileNameField =
new javax.swing.JTextField();
105 profileDescLabel =
new javax.swing.JLabel();
106 profileDescPane =
new javax.swing.JScrollPane();
107 profileDescArea =
new javax.swing.JTextArea();
108 profileNameLabel =
new javax.swing.JLabel();
109 jPanel1 =
new javax.swing.JPanel();
111 jScrollPane1.setPreferredSize(
new java.awt.Dimension(650, 323));
113 org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileDescLabel.text"));
115 profileDescArea.setColumns(20);
116 profileDescArea.setLineWrap(
true);
117 profileDescArea.setRows(8);
118 profileDescArea.setWrapStyleWord(
true);
119 profileDescArea.setMinimumSize(
new java.awt.Dimension(164, 44));
120 profileDescArea.setName(
"");
121 profileDescPane.setViewportView(profileDescArea);
123 org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileNameLabel.text"));
125 jPanel1.setMinimumSize(
new java.awt.Dimension(625, 450));
126 jPanel1.setPreferredSize(
new java.awt.Dimension(625, 450));
127 jPanel1.setLayout(
new java.awt.BorderLayout());
129 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
130 jPanel2.setLayout(jPanel2Layout);
131 jPanel2Layout.setHorizontalGroup(
132 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133 .addGroup(jPanel2Layout.createSequentialGroup()
135 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
136 .addComponent(profileDescLabel)
137 .addComponent(profileNameLabel))
138 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
139 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140 .addComponent(profileDescPane)
141 .addComponent(profileNameField))
143 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
145 jPanel2Layout.setVerticalGroup(
146 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147 .addGroup(jPanel2Layout.createSequentialGroup()
149 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150 .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
151 .addComponent(profileNameLabel))
152 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
153 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
154 .addComponent(profileDescLabel)
155 .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
156 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
160 jScrollPane1.setViewportView(jPanel2);
162 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
163 this.setLayout(layout);
164 layout.setHorizontalGroup(
165 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
168 layout.setVerticalGroup(
169 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
174 public void removePropertyChangeListener(PropertyChangeListener l) {
175 ingestSettingsPanel.removePropertyChangeListener(l);
179 public void addPropertyChangeListener(PropertyChangeListener l) {
180 super.addPropertyChangeListener(l);
200 if (null != ingestSettingsPanel) {
201 ingestSettingsPanel.addPropertyChangeListener(l);
205 private javax.swing.JPanel jPanel1;
206 private javax.swing.JPanel jPanel2;
207 private javax.swing.JScrollPane jScrollPane1;
208 private javax.swing.JTextArea profileDescArea;
209 private javax.swing.JLabel profileDescLabel;
210 private javax.swing.JScrollPane profileDescPane;
211 private javax.swing.JTextField profileNameField;
212 private javax.swing.JLabel profileNameLabel;
219 public void saveSettings() {
220 if (profile == null) {
221 IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
222 }
else if (!profile.getName().equals(getProfileName())) {
223 IngestProfile.renameProfile(profile.getName(), getProfileName());
225 profile =
new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
226 IngestProfile.saveProfile(profile);
227 ingestSettingsPanel.getSettings().saveAs(getProfileName());
245 boolean isValidDefinition() {
246 if (getProfileName().isEmpty()) {
247 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
248 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profilesMustBeNamed"),
249 NotifyDescriptor.WARNING_MESSAGE);
250 DialogDisplayer.getDefault().notify(notifyDesc);
253 if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
254 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
255 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profileNameContainsIllegalCharacter"),
256 NotifyDescriptor.WARNING_MESSAGE);
257 DialogDisplayer.getDefault().notify(notifyDesc);
272 private static boolean containsOnlyLegalChars(String toBeChecked, List<String> illegalChars) {
273 for (String illegalChar : illegalChars) {
274 if (toBeChecked.contains(illegalChar)) {