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(IngestProfiles.getExecutionContext(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(IngestProfiles.getExecutionContext(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();
89 String getIngestProfileName() {
90 if (profile != null) {
91 return profile.getName();
93 return NEW_PROFILE_NAME;
102 @SuppressWarnings(
"unchecked")
104 private
void initComponents() {
106 jScrollPane1 =
new javax.swing.JScrollPane();
107 jPanel2 =
new javax.swing.JPanel();
108 profileNameField =
new javax.swing.JTextField();
109 profileDescLabel =
new javax.swing.JLabel();
110 profileDescPane =
new javax.swing.JScrollPane();
111 profileDescArea =
new javax.swing.JTextArea();
112 profileNameLabel =
new javax.swing.JLabel();
113 jPanel1 =
new javax.swing.JPanel();
115 jScrollPane1.setPreferredSize(
new java.awt.Dimension(650, 323));
117 org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileDescLabel.text"));
119 profileDescArea.setColumns(20);
120 profileDescArea.setLineWrap(
true);
121 profileDescArea.setRows(8);
122 profileDescArea.setWrapStyleWord(
true);
123 profileDescArea.setMinimumSize(
new java.awt.Dimension(164, 44));
124 profileDescArea.setName(
"");
125 profileDescPane.setViewportView(profileDescArea);
127 org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel,
org.openide.util.NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.profileNameLabel.text"));
129 jPanel1.setMinimumSize(
new java.awt.Dimension(625, 450));
130 jPanel1.setPreferredSize(
new java.awt.Dimension(625, 450));
131 jPanel1.setLayout(
new java.awt.BorderLayout());
133 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
134 jPanel2.setLayout(jPanel2Layout);
135 jPanel2Layout.setHorizontalGroup(
136 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addGroup(jPanel2Layout.createSequentialGroup()
139 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
140 .addComponent(profileDescLabel)
141 .addComponent(profileNameLabel))
142 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
143 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addComponent(profileDescPane)
145 .addComponent(profileNameField))
147 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
149 jPanel2Layout.setVerticalGroup(
150 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151 .addGroup(jPanel2Layout.createSequentialGroup()
153 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
155 .addComponent(profileNameLabel))
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addComponent(profileDescLabel)
159 .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
160 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
164 jScrollPane1.setViewportView(jPanel2);
166 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
167 this.setLayout(layout);
168 layout.setHorizontalGroup(
169 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
172 layout.setVerticalGroup(
173 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
174 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
178 public void removePropertyChangeListener(PropertyChangeListener l) {
179 ingestSettingsPanel.removePropertyChangeListener(l);
183 public void addPropertyChangeListener(PropertyChangeListener l) {
184 super.addPropertyChangeListener(l);
204 if (null != ingestSettingsPanel) {
205 ingestSettingsPanel.addPropertyChangeListener(l);
209 private javax.swing.JPanel jPanel1;
210 private javax.swing.JPanel jPanel2;
211 private javax.swing.JScrollPane jScrollPane1;
212 private javax.swing.JTextArea profileDescArea;
213 private javax.swing.JLabel profileDescLabel;
214 private javax.swing.JScrollPane profileDescPane;
215 private javax.swing.JTextField profileNameField;
216 private javax.swing.JLabel profileNameLabel;
223 public void saveSettings() {
224 if (profile == null) {
225 IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
226 }
else if (!profile.getName().equals(getProfileName())) {
227 IngestProfile.renameProfile(profile.getName(), getProfileName());
229 profile =
new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
230 IngestProfile.saveProfile(profile);
231 ingestSettingsPanel.getSettings().saveAs(IngestProfiles.getExecutionContext(getProfileName()));
238 if (!isValidDefinition(
false)) {
255 boolean isValidDefinition(
boolean dispayWarnings) {
256 String profileName = getProfileName();
257 if (profileName.isEmpty()) {
258 if (dispayWarnings) {
259 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
260 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profilesMustBeNamed"),
261 NotifyDescriptor.WARNING_MESSAGE);
262 DialogDisplayer.getDefault().notify(notifyDesc);
268 String sanitizedName = profileName.replaceAll(
"[^A-Za-z0-9_]",
"");
269 if (!(profileName.equals(sanitizedName))) {
270 if (dispayWarnings) {
271 NotifyDescriptor notifyDesc =
new NotifyDescriptor.Message(
272 NbBundle.getMessage(ProfilePanel.class,
"ProfilePanel.messages.profileNameContainsIllegalCharacter"),
273 NotifyDescriptor.WARNING_MESSAGE);
274 DialogDisplayer.getDefault().notify(notifyDesc);