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.profileDescLabel.text=Description:",
 
   37         "ProfilePanel.profileNameLabel.text=Profile Name:",
 
   38         "ProfilePanel.newProfileText=NewEmptyProfile",
 
   39         "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
 
   40         "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character"})
 
   42     private final IngestJobSettingsPanel ingestSettingsPanel;
 
   43     private final IngestJobSettings settings;
 
   44     private IngestProfile profile;
 
   45     private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class, 
"ProfilePanel.newProfileText");
 
   46     private static final List<String> ILLEGAL_NAME_CHARS = Collections.unmodifiableList(
new ArrayList<>(Arrays.asList(
"\\", 
"/", 
":", 
"*", 
"?", 
"\"", 
"<", 
">")));
 
   53         settings = 
new IngestJobSettings(NEW_PROFILE_NAME);
 
   54         ingestSettingsPanel = 
new IngestJobSettingsPanel(settings);
 
   55         ingestSettingsPanel.setPastJobsButtonVisible(
false);
 
   56         jPanel1.add(ingestSettingsPanel, 0);
 
   60     ProfilePanel(IngestProfile selectedProfile) {
 
   62         profile = selectedProfile;
 
   63         profileDescArea.setText(profile.getDescription());
 
   64         profileNameField.setText(profile.getName());
 
   65         settings = 
new IngestJobSettings(selectedProfile.getName());
 
   66         ingestSettingsPanel = 
new IngestJobSettingsPanel(settings);
 
   67         ingestSettingsPanel.setPastJobsButtonVisible(
false);
 
   68         jPanel1.add(ingestSettingsPanel, 0);
 
   78     String getProfileName() {
 
   79         return profileNameField.getText().trim();
 
   82     String getProfileDesc() {
 
   83         return profileDescArea.getText();
 
   86     IngestJobSettings getSettings() {
 
   87         return ingestSettingsPanel.getSettings();
 
   95     @SuppressWarnings(
"unchecked")
 
   97     private 
void initComponents() {
 
   99         jScrollPane1 = 
new javax.swing.JScrollPane();
 
  100         jPanel2 = 
new javax.swing.JPanel();
 
  101         profileNameField = 
new javax.swing.JTextField();
 
  102         profileDescLabel = 
new javax.swing.JLabel();
 
  103         profileDescPane = 
new javax.swing.JScrollPane();
 
  104         profileDescArea = 
new javax.swing.JTextArea();
 
  105         profileNameLabel = 
new javax.swing.JLabel();
 
  106         jPanel1 = 
new javax.swing.JPanel();
 
  108         jScrollPane1.setPreferredSize(
new java.awt.Dimension(650, 323));
 
  110         org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel, 
org.openide.util.NbBundle.getMessage(ProfilePanel.class, 
"ProfilePanel.profileDescLabel.text")); 
 
  112         profileDescArea.setColumns(20);
 
  113         profileDescArea.setLineWrap(
true);
 
  114         profileDescArea.setRows(8);
 
  115         profileDescArea.setWrapStyleWord(
true);
 
  116         profileDescArea.setMinimumSize(
new java.awt.Dimension(164, 44));
 
  117         profileDescArea.setName(
""); 
 
  118         profileDescPane.setViewportView(profileDescArea);
 
  120         org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel, 
org.openide.util.NbBundle.getMessage(ProfilePanel.class, 
"ProfilePanel.profileNameLabel.text")); 
 
  122         jPanel1.setMinimumSize(
new java.awt.Dimension(625, 450));
 
  123         jPanel1.setPreferredSize(
new java.awt.Dimension(625, 450));
 
  124         jPanel1.setLayout(
new java.awt.BorderLayout());
 
  126         javax.swing.GroupLayout jPanel2Layout = 
new javax.swing.GroupLayout(jPanel2);
 
  127         jPanel2.setLayout(jPanel2Layout);
 
  128         jPanel2Layout.setHorizontalGroup(
 
  129             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  130             .addGroup(jPanel2Layout.createSequentialGroup()
 
  132                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
 
  133                     .addComponent(profileDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  134                     .addComponent(profileNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  135                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  136                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  137                     .addComponent(profileDescPane)
 
  138                     .addComponent(profileNameField))
 
  140             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  142         jPanel2Layout.setVerticalGroup(
 
  143             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  144             .addGroup(jPanel2Layout.createSequentialGroup()
 
  146                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  147                     .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  148                     .addComponent(profileNameLabel))
 
  149                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  150                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  151                     .addComponent(profileDescLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  152                     .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  153                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  157         jScrollPane1.setViewportView(jPanel2);
 
  159         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  160         this.setLayout(layout);
 
  161         layout.setHorizontalGroup(
 
  162             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  163             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
 
  165         layout.setVerticalGroup(
 
  166             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  167             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
 
  171     public void removePropertyChangeListener(PropertyChangeListener l) {
 
  172         ingestSettingsPanel.removePropertyChangeListener(l);
 
  176     public void addPropertyChangeListener(PropertyChangeListener l) {
 
  177         ingestSettingsPanel.addPropertyChangeListener(l);
 
  180     private javax.swing.JPanel jPanel1;
 
  181     private javax.swing.JPanel jPanel2;
 
  182     private javax.swing.JScrollPane jScrollPane1;
 
  183     private javax.swing.JTextArea profileDescArea;
 
  184     private javax.swing.JLabel profileDescLabel;
 
  185     private javax.swing.JScrollPane profileDescPane;
 
  186     private javax.swing.JTextField profileNameField;
 
  187     private javax.swing.JLabel profileNameLabel;
 
  194     public void saveSettings() {
 
  195         if (profile == null) {
 
  196             IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
 
  197         } 
else if (!profile.getName().equals(getProfileName())) {
 
  198             IngestProfile.renameProfile(profile.getName(), getProfileName());
 
  200         profile = 
new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileIngestFilter().getName());
 
  201         IngestProfile.saveProfile(profile);
 
  202         ingestSettingsPanel.getSettings().saveAs(getProfileName());
 
  220     boolean isValidDefinition() {
 
  221         if (getProfileName().isEmpty()) {
 
  222             NotifyDescriptor notifyDesc = 
new NotifyDescriptor.Message(
 
  223                     NbBundle.getMessage(ProfilePanel.class, 
"ProfilePanel.messages.profilesMustBeNamed"),
 
  224                     NotifyDescriptor.WARNING_MESSAGE);
 
  225             DialogDisplayer.getDefault().notify(notifyDesc);
 
  228         if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
 
  229             NotifyDescriptor notifyDesc = 
new NotifyDescriptor.Message(
 
  230                     NbBundle.getMessage(ProfilePanel.class, 
"ProfilePanel.messages.profileNameContainsIllegalCharacter"),
 
  231                     NotifyDescriptor.WARNING_MESSAGE);
 
  232             DialogDisplayer.getDefault().notify(notifyDesc);
 
  247     private static boolean containsOnlyLegalChars(String toBeChecked, List<String> illegalChars) {
 
  248         for (String illegalChar : illegalChars) {
 
  249             if (toBeChecked.contains(illegalChar)) {