19 package org.sleuthkit.autopsy.ingest;
21 import java.beans.PropertyChangeListener;
22 import org.openide.DialogDisplayer;
23 import org.openide.NotifyDescriptor;
24 import org.openide.util.NbBundle;
30 @SuppressWarnings(
"PMD.SingularField")
31 class ProfilePanel extends IngestModuleGlobalSettingsPanel {
33 @NbBundle.Messages({
"ProfilePanel.title.text=Profile",
34 "ProfilePanel.profileDescLabel.text=Description:",
35 "ProfilePanel.profileNameLabel.text=Profile Name:",
36 "ProfilePanel.newProfileText=NewEmptyProfile",
37 "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
38 "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character. Only \nletters, digits, and underscore characters are allowed."})
40 private final IngestJobSettingsPanel ingestSettingsPanel;
41 private final IngestJobSettings settings;
42 private IngestProfile profile;
43 private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.newProfileText");
50 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
51 settings =
new IngestJobSettings(NEW_PROFILE_NAME);
52 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
53 ingestSettingsPanel.setPastJobsButtonVisible(
false);
54 jPanel1.add(ingestSettingsPanel, 0);
58 ProfilePanel(IngestProfile selectedProfile) {
60 setName(
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.title.text"));
61 profile = selectedProfile;
62 profileDescArea.setText(profile.getDescription());
63 profileNameField.setText(profile.getName());
64 settings =
new IngestJobSettings(selectedProfile.getName());
65 ingestSettingsPanel =
new IngestJobSettingsPanel(settings);
66 ingestSettingsPanel.setPastJobsButtonVisible(
false);
67 jPanel1.add(ingestSettingsPanel, 0);
77 String getProfileName() {
78 return profileNameField.getText().trim();
81 String getProfileDesc() {
82 return profileDescArea.getText();
85 IngestJobSettings getSettings() {
86 return ingestSettingsPanel.getSettings();
94 @SuppressWarnings(
"unchecked")
96 private
void initComponents() {
98 jScrollPane1 =
new javax.swing.JScrollPane();
99 jPanel2 =
new javax.swing.JPanel();
100 profileNameField =
new javax.swing.JTextField();
101 profileDescLabel =
new javax.swing.JLabel();
102 profileDescPane =
new javax.swing.JScrollPane();
103 profileDescArea =
new javax.swing.JTextArea();
104 profileNameLabel =
new javax.swing.JLabel();
105 jPanel1 =
new javax.swing.JPanel();
107 jScrollPane1.setPreferredSize(
new java.awt.Dimension(650, 323));
109 org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileDescLabel.text"));
111 profileDescArea.setColumns(20);
112 profileDescArea.setLineWrap(
true);
113 profileDescArea.setRows(8);
114 profileDescArea.setWrapStyleWord(
true);
115 profileDescArea.setMinimumSize(
new java.awt.Dimension(164, 44));
116 profileDescArea.setName(
"");
117 profileDescPane.setViewportView(profileDescArea);
119 org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileNameLabel.text"));
121 jPanel1.setMinimumSize(
new java.awt.Dimension(625, 450));
122 jPanel1.setPreferredSize(
new java.awt.Dimension(625, 450));
123 jPanel1.setLayout(
new java.awt.BorderLayout());
125 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
126 jPanel2.setLayout(jPanel2Layout);
127 jPanel2Layout.setHorizontalGroup(
128 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129 .addGroup(jPanel2Layout.createSequentialGroup()
131 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
132 .addComponent(profileDescLabel)
133 .addComponent(profileNameLabel))
134 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
135 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136 .addComponent(profileDescPane)
137 .addComponent(profileNameField))
139 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
141 jPanel2Layout.setVerticalGroup(
142 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143 .addGroup(jPanel2Layout.createSequentialGroup()
145 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146 .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
147 .addComponent(profileNameLabel))
148 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150 .addComponent(profileDescLabel)
151 .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
152 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
156 jScrollPane1.setViewportView(jPanel2);
158 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
159 this.setLayout(layout);
160 layout.setHorizontalGroup(
161 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
164 layout.setVerticalGroup(
165 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
170 public void removePropertyChangeListener(PropertyChangeListener l) {
171 ingestSettingsPanel.removePropertyChangeListener(l);
175 public void addPropertyChangeListener(PropertyChangeListener l) {
176 super.addPropertyChangeListener(l);
196 if (null != ingestSettingsPanel) {
197 ingestSettingsPanel.addPropertyChangeListener(l);
201 private javax.swing.JPanel jPanel1;
202 private javax.swing.JPanel jPanel2;
203 private javax.swing.JScrollPane jScrollPane1;
204 private javax.swing.JTextArea profileDescArea;
205 private javax.swing.JLabel profileDescLabel;
206 private javax.swing.JScrollPane profileDescPane;
207 private javax.swing.JTextField profileNameField;
208 private javax.swing.JLabel profileNameLabel;
215 public void saveSettings() {
216 if (profile == null) {
217 IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
218 }
else if (!profile.getName().equals(getProfileName())) {
219 IngestProfile.renameProfile(profile.getName(), getProfileName());
221 profile =
new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
222 IngestProfile.saveProfile(profile);
223 ingestSettingsPanel.getSettings().saveAs(getProfileName());
230 if (!isValidDefinition(
false)) {
247 boolean isValidDefinition(
boolean dispayWarnings) {
248 String profileName = getProfileName();
249 if (profileName.isEmpty()) {
250 if (dispayWarnings) {
251 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
252 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profilesMustBeNamed"),
253 NotifyDescriptor.WARNING_MESSAGE);
254 DialogDisplayer.getDefault().notify(notifyDesc);
260 String sanitizedName = profileName.replaceAll(
"[^A-Za-z0-9_]",
"");
261 if (!(profileName.equals(sanitizedName))) {
262 if (dispayWarnings) {
263 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
264 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profileNameContainsIllegalCharacter"),
265 NotifyDescriptor.WARNING_MESSAGE);
266 DialogDisplayer.getDefault().notify(notifyDesc);