19 package org.sleuthkit.autopsy.casemodule;
22 import java.util.HashSet;
23 import java.util.Iterator;
25 import java.util.logging.Level;
27 import org.openide.util.NbBundle;
29 import javax.swing.event.ChangeEvent;
30 import javax.swing.event.ChangeListener;
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.NotifyDescriptor;
34 import org.openide.WizardDescriptor;
35 import org.openide.WizardValidationException;
36 import org.openide.util.Exceptions;
37 import org.openide.util.HelpCtx;
45 class NewCaseWizardPanel1
implements WizardDescriptor.ValidatingPanel<WizardDescriptor> {
51 private NewCaseVisualPanel1 component;
52 private Boolean isFinish =
false;
53 private static String createdDirectory;
54 private static final String PROP_BASECASE =
"LBL_BaseCase_PATH";
55 private static final Logger logger = Logger.getLogger(NewCaseWizardPanel1.class.getName());
66 public NewCaseVisualPanel1 getComponent() {
67 if (component == null) {
68 component =
new NewCaseVisualPanel1(
this);
80 public HelpCtx getHelp() {
82 return HelpCtx.DEFAULT_HELP;
95 public boolean isValid() {
104 private final Set<ChangeListener> listeners =
new HashSet<ChangeListener>(1);
112 public final void addChangeListener(ChangeListener l) {
113 synchronized (listeners) {
124 public final void removeChangeListener(ChangeListener l) {
125 synchronized (listeners) {
134 protected final void fireChangeEvent() {
135 Iterator<ChangeListener> it;
136 synchronized (listeners) {
137 it =
new HashSet<ChangeListener>(listeners).iterator();
139 ChangeEvent ev =
new ChangeEvent(
this);
140 while (it.hasNext()) {
141 it.next().stateChanged(ev);
151 public void setIsFinish(Boolean isFinish) {
152 this.isFinish = isFinish;
169 public void readSettings(WizardDescriptor settings) {
170 NewCaseVisualPanel1 component = getComponent();
172 String lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE);
173 component.getCaseParentDirTextField().setText(lastBaseDirectory);
174 createdDirectory = (String) settings.getProperty(
"createdDirectory");
175 if (createdDirectory != null && !createdDirectory.equals(
"")) {
176 logger.log(Level.INFO,
"Deleting a case dir in readSettings(): " + createdDirectory);
177 Case.deleteCaseDirectory(
new File(createdDirectory));
179 }
catch (Exception e) {
180 logger.log(Level.WARNING,
"Could not read wizard settings in NewCaseWizardPanel1, ", e);
194 public void storeSettings(WizardDescriptor settings) {
195 settings.putProperty(
"caseName", getComponent().getCaseName());
196 settings.putProperty(
"caseParentDir", getComponent().getCaseParentDir());
197 settings.putProperty(
"createdDirectory", createdDirectory);
198 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, getComponent().getCaseParentDir());
202 public void validate() throws WizardValidationException {
203 String caseName = getComponent().getCaseName();
204 String caseParentDir = getComponent().getCaseParentDir();
205 String caseDirPath = caseParentDir + caseName;
209 if (!Case.isValidName(caseName)) {
210 String errorMsg = NbBundle
211 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.invalidSymbols");
212 validationError(errorMsg);
215 if (
new File(caseDirPath).exists()) {
217 String errorMsg = NbBundle
218 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.dirExists", caseDirPath);
219 validationError(errorMsg);
222 File baseDir =
new File(caseParentDir);
223 if (baseDir.isAbsolute()) {
225 if (!baseDir.exists()) {
227 String confMsg = NbBundle
228 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.confMsg.createDir.msg",
230 NotifyDescriptor d2 =
new NotifyDescriptor.Confirmation(confMsg,
231 NbBundle.getMessage(
this.getClass(),
232 "NewCaseWizardPanel1.validate.confMsg.createDir.title"),
233 NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
234 d2.setValue(NotifyDescriptor.NO_OPTION);
236 Object res2 = DialogDisplayer.getDefault().notify(d2);
237 if (res2 != null && res2 == DialogDescriptor.YES_OPTION) {
240 createDirectory(caseDirPath);
241 }
catch (Exception ex) {
242 String errorMsg = NbBundle.getMessage(this.getClass(),
243 "NewCaseWizardPanel1.validate.errMsg.cantCreateParDir.msg",
245 logger.log(Level.WARNING, errorMsg, ex);
246 validationError(errorMsg);
249 if (res2 != null && res2 == DialogDescriptor.NO_OPTION) {
251 validationError(NbBundle.getMessage(
this.getClass(),
252 "NewCaseWizardPanel1.validate.errMsg.prevCreateBaseDir.msg",
257 createDirectory(caseDirPath);
258 }
catch (Exception ex) {
259 String errorMsg = NbBundle
260 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.cantCreateDir");
261 logger.log(Level.WARNING, errorMsg, ex);
262 validationError(errorMsg);
267 String errorMsg = NbBundle
268 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.invalidBaseDir.msg");
269 validationError(errorMsg);
275 private void validationError(String errorMsg)
throws WizardValidationException {
276 throw new WizardValidationException(this.getComponent(), errorMsg, null);
282 private void createDirectory(
final String caseDirPath)
throws WizardValidationException {
284 boolean success =
false;
286 Case.createCaseDirectory(caseDirPath);
288 }
catch (CaseActionException ex) {
289 logger.log(Level.SEVERE,
"Could not createDirectory for the case, ", ex);
296 if (
new File(caseDirPath).exists()) {
297 Case.deleteCaseDirectory(
new File(caseDirPath));
300 String errorMsg = NbBundle.getMessage(this.getClass(),
301 "NewCaseWizardPanel1.createDir.errMsg.cantCreateDir.msg");
303 validationError(errorMsg);
307 createdDirectory = caseDirPath;
310 StartupWindowProvider.getInstance().close();
311 }
catch (Exception ex) {
312 logger.log(Level.WARNING,
"Startup window didn't close as expected.", ex);