コード例 #1
0
ファイル: CaseDeleteAction.java プロジェクト: nrv3/autopsy
  /**
   * Deletes the current opened case.
   *
   * @param e
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    Logger.noteAction(this.getClass());

    Case currentCase = Case.getCurrentCase();
    File configFile = new File(currentCase.getConfigFilePath());
    File caseFolder = new File(configFile.getParent());
    String caseName = currentCase.getName();
    if (!caseFolder.exists()) {
      // throw an error

      logger.log(
          Level.WARNING,
          "Couldn't delete case.",
          new Exception("The case directory doesn't exist."));
    } else {
      // show the confirmation first to close the current case and open the "New Case" wizard panel
      String closeCurrentCase =
          "Are you sure want to close and delete this case? \n     Case Name: "
              + caseName
              + "\n     Case Directory: "
              + caseFolder.getPath();
      NotifyDescriptor d =
          new NotifyDescriptor.Confirmation(
              closeCurrentCase,
              "Warning: Closing the Current Case",
              NotifyDescriptor.YES_NO_OPTION,
              NotifyDescriptor.WARNING_MESSAGE);
      d.setValue(NotifyDescriptor.NO_OPTION);

      Object res = DialogDisplayer.getDefault().notify(d);
      if (res != null && res == DialogDescriptor.YES_OPTION) {
        boolean success = false;

        try {
          Case.getCurrentCase().deleteCase(caseFolder); // delete the current case
          success = true;
        } catch (CaseActionException ex) {
          logger.log(Level.WARNING, "Could not delete the case folder: " + caseFolder);
        }

        // show notification whether the case has been deleted or it failed to delete...
        if (!success) {
          JOptionPane.showMessageDialog(
              caller,
              "The delete action can't be fully completed because the folder or file in it is open by another program.\n \nClose the folder and file and try again or you can delete the case manually.",
              "Error: Folder In Use",
              JOptionPane.ERROR_MESSAGE); // throw an error
        } else {
          CasePropertiesAction
              .closeCasePropertiesWindow(); // because the "Delete Case" button is in the
                                            // "CaseProperties" window, we have to close that window
                                            // when we delete the case.
          JOptionPane.showMessageDialog(caller, "Case " + caseName + " has been deleted.");
        }
      }
    }
  }
コード例 #2
0
  /**
   * Called only when top component was closed on all workspaces before and now is opened for the
   * first time on some workspace. The intent is to provide subclasses information about
   * TopComponent's life cycle across all existing workspaces. Subclasses will usually perform
   * initializing tasks here.
   */
  @Override
  public void componentOpened() {
    // change the cursor to "waiting cursor" for this operation
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
      if (Case.existsCurrentCase()) {
        Case currentCase = Case.getCurrentCase();

        // close the top component if there's no image in this case
        if (currentCase.hasData() == false) {
          // this.close();
          ((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root
        } else {
          // if there's at least one image, load the image and open the top component
          List<Object> items = new ArrayList<>();
          final SleuthkitCase tskCase = currentCase.getSleuthkitCase();
          items.add(new DataSources());
          items.add(new Views(tskCase));
          items.add(new Results(tskCase));
          items.add(new Reports());
          contentChildren = new RootContentChildren(items);
          Node root =
              new AbstractNode(contentChildren) {
                /**
                 * to override the right click action in the white blank space area on the directory
                 * tree window
                 */
                @Override
                public Action[] getActions(boolean popup) {
                  return new Action[] {};
                }

                // Overide the AbstractNode use of DefaultHandle to return
                // a handle which can be serialized without a parent
                @Override
                public Node.Handle getHandle() {
                  return new Node.Handle() {
                    @Override
                    public Node getNode() throws IOException {
                      return em.getRootContext();
                    }
                  };
                }
              };

          root = new DirectoryTreeFilterNode(root, true);

          em.setRootContext(root);
          em.getRootContext().setName(currentCase.getName());
          em.getRootContext().setDisplayName(currentCase.getName());
          ((BeanTreeView) this.jScrollPane1).setRootVisible(false); // hide the root

          // Reset the forward and back lists because we're resetting the root context
          resetHistory();

          Children childNodes = em.getRootContext().getChildren();
          TreeView tree = getTree();

          Node results = childNodes.findChild(ResultsNode.NAME);
          tree.expandNode(results);

          Children resultsChilds = results.getChildren();
          tree.expandNode(resultsChilds.findChild(KeywordHits.NAME));
          tree.expandNode(resultsChilds.findChild(ExtractedContent.NAME));

          Node views = childNodes.findChild(ViewsNode.NAME);
          Children viewsChilds = views.getChildren();
          for (Node n : viewsChilds.getNodes()) {
            tree.expandNode(n);
          }

          tree.collapseNode(views);

          // if the dataResult is not opened
          if (!dataResult.isOpened()) {
            dataResult
                .open(); // open the data result top component as well when the directory tree is
                         // opened
          }

          // select the first image node, if there is one
          // (this has to happen after dataResult is opened, because the event
          // of changing the selected node fires a handler that tries to make
          // dataResult active)
          if (childNodes.getNodesCount() > 0) {
            try {
              em.setSelectedNodes(new Node[] {childNodes.getNodeAt(0)});
            } catch (Exception ex) {
              logger.log(Level.SEVERE, "Error setting default selected node.", ex); // NON-NLS
            }
          }
        }
      }
    } finally {
      this.setCursor(null);
    }
  }