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.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.setCaseParentDir(lastBaseDirectory);
174 component.readSettings();
175 createdDirectory = (String) settings.getProperty(
"createdDirectory");
176 if (createdDirectory != null && !createdDirectory.equals(
"")) {
177 logger.log(Level.INFO,
"Deleting a case dir in readSettings(): " + createdDirectory);
178 Case.deleteCaseDirectory(
new File(createdDirectory));
180 }
catch (Exception e) {
181 logger.log(Level.WARNING,
"Could not read wizard settings in NewCaseWizardPanel1, ", e);
195 public void storeSettings(WizardDescriptor settings) {
196 CaseType caseType = getComponent().getCaseType();
197 settings.putProperty(
"caseName", getComponent().getCaseName());
198 settings.putProperty(
"caseParentDir", getComponent().getCaseParentDir());
199 settings.putProperty(
"createdDirectory", createdDirectory);
200 settings.putProperty(
"caseType", caseType.ordinal());
201 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, ModuleSettings.CURRENT_CASE_TYPE, caseType.toString());
202 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, getComponent().getCaseParentDir());
206 public void validate() throws WizardValidationException {
207 String caseName = getComponent().getCaseName();
208 String caseParentDir = getComponent().getCaseParentDir();
209 String caseDirPath = caseParentDir + caseName;
213 if (!Case.isValidName(caseName)) {
214 String errorMsg = NbBundle
215 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.invalidSymbols");
216 validationError(errorMsg);
219 if (
new File(caseDirPath).exists()) {
221 String errorMsg = NbBundle
222 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.dirExists", caseDirPath);
223 validationError(errorMsg);
226 File baseDir =
new File(caseParentDir);
227 if (baseDir.isAbsolute()) {
229 if (!baseDir.exists()) {
231 String confMsg = NbBundle
232 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.confMsg.createDir.msg",
234 NotifyDescriptor d2 =
new NotifyDescriptor.Confirmation(confMsg,
235 NbBundle.getMessage(
this.getClass(),
236 "NewCaseWizardPanel1.validate.confMsg.createDir.title"),
237 NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
238 d2.setValue(NotifyDescriptor.NO_OPTION);
240 Object res2 = DialogDisplayer.getDefault().notify(d2);
241 if (res2 != null && res2 == DialogDescriptor.YES_OPTION) {
244 createDirectory(caseDirPath, getComponent().getCaseType());
245 }
catch (Exception ex) {
246 String errorMsg = NbBundle.getMessage(this.getClass(),
247 "NewCaseWizardPanel1.validate.errMsg.cantCreateParDir.msg",
249 logger.log(Level.WARNING, errorMsg, ex);
250 validationError(errorMsg);
253 if (res2 != null && res2 == DialogDescriptor.NO_OPTION) {
255 validationError(NbBundle.getMessage(
this.getClass(),
256 "NewCaseWizardPanel1.validate.errMsg.prevCreateBaseDir.msg",
261 createDirectory(caseDirPath, getComponent().getCaseType());
262 }
catch (Exception ex) {
263 String errorMsg = NbBundle
264 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.cantCreateDir");
265 logger.log(Level.WARNING, errorMsg, ex);
266 validationError(errorMsg);
271 String errorMsg = NbBundle
272 .getMessage(this.getClass(),
"NewCaseWizardPanel1.validate.errMsg.invalidBaseDir.msg");
273 validationError(errorMsg);
279 private void validationError(String errorMsg)
throws WizardValidationException {
280 throw new WizardValidationException(this.getComponent(), errorMsg, null);
286 private void createDirectory(
final String caseDirPath, CaseType caseType)
throws WizardValidationException {
288 boolean success =
false;
290 Case.createCaseDirectory(caseDirPath, caseType);
292 }
catch (CaseActionException ex) {
293 logger.log(Level.SEVERE,
"Could not createDirectory for the case, ", ex);
300 if (
new File(caseDirPath).exists()) {
301 Case.deleteCaseDirectory(
new File(caseDirPath));
304 String errorMsg = NbBundle.getMessage(this.getClass(),
305 "NewCaseWizardPanel1.createDir.errMsg.cantCreateDir.msg");
307 validationError(errorMsg);
311 createdDirectory = caseDirPath;
314 StartupWindowProvider.getInstance().close();
315 }
catch (Exception ex) {
316 logger.log(Level.WARNING,
"Startup window didn't close as expected.", ex);