Example #1
0
  /**
   * Publishes file system item write error.
   *
   * @param projectDiagram is the diagram that is supposed to be written
   * @param projectItemFile is the file path to the not existing file of diagram
   */
  private void publicAddDiagramError(
      final ProjectDiagram projectDiagram, final File projectItemFile) {
    syncDialog.appendErrorInfo(DIAGRAM_LABEL + " " + projectDiagram.getDisplayName(), false);
    syncDialog.appendErrorInfo(
        NOTATION_LABEL + " " + projectDiagram.getNotationIdentifier(), false);
    syncDialog.appendErrorInfo(DIAGRAM_WRITE_ERROR_LABEL, false);
    syncDialog.appendErrorInfo(" >> " + projectItemFile.getAbsolutePath(), true);

    LOG.error(
        "Sync PN -> FS: Diagram " + projectItemFile.getAbsolutePath() + " has NOT been saved.");
  }
Example #2
0
 /**
  * Publishes file system item overwrite error.
  *
  * @param projectDiagram is the diagram that is supposed to be overwritten
  * @param projectItemFile is the file path to the existing file of diagram
  */
 private void publicOverwriteError(
     final ProjectDiagram projectDiagram, final File projectItemFile) {
   syncDialog.appendErrorInfo(DIAGRAM_LABEL + " " + projectDiagram.getDisplayName(), false);
   syncDialog.appendErrorInfo(
       NOTATION_LABEL + " " + projectDiagram.getNotationIdentifier(), false);
   syncDialog.appendErrorInfo(DIAGRAM_OVERWRITE_ERROR_LABEL, false);
   syncDialog.appendErrorInfo(" >> " + projectItemFile.getAbsolutePath(), true);
   LOG.error(
       "Sync PN -> FS: Diagram "
           + projectItemFile.getAbsolutePath()
           + " was NOT possible to overwrite.");
 }
Example #3
0
  /**
   * Synchronize the selected project subtree to the file system. This methods requires the correct
   * starting level on the file system with respect to the project subtree to exist.
   *
   * <p>Important to note that this method synchronize only the SUBTREE 'under' the last tree node
   * in the treePath variable.
   *
   * @param fsLevel is the starting point for the synchronization on the file system
   * @param treePath is the starting point in the project structure for the synchronization
   * @param addProjectItems indicates whether new items are supposed to be created on the file
   *     system if they are missing
   * @param overwriteProjectItems indicates whether diagrams that already exists on the file system
   *     are supposed to be overwritten
   * @param deleteProjectItems indicates whether not projects items (files or diagrams) are supposed
   *     to be deleted from file system
   * @return true if and only if no error occurs, false otherwise
   * @throws InterruptedException when user cancels the synchronization
   */
  private boolean syncSubtreeToFS(
      final File fsLevel,
      final TreePath treePath,
      final boolean addProjectItems,
      final boolean overwriteProjectItems,
      final boolean deleteProjectItems)
      throws InterruptedException {

    checkInterruption();

    boolean retValue = true;

    final DefaultMutableTreeNode lastTreePathNode =
        (DefaultMutableTreeNode) treePath.getLastPathComponent();
    final Object userObject = lastTreePathNode.getUserObject();
    final ProjectItem projectItem;

    projectItem = (ProjectItem) userObject;

    // sync a project diagram
    if (userObject instanceof ProjectDiagram) {
      final ProjectDiagram projectDiagram = (ProjectDiagram) userObject;
      final String fileExtension =
          ProjectServiceUtils.getNotationFileExtension(projectDiagram.getNotationIdentifier());

      final File projectItemFile =
          new File(fsLevel.getAbsolutePath(), projectItem.getDisplayName() + fileExtension);

      NotationLocalIOController.SaveResult successSaveResult =
          NotationLocalIOController.SaveResult.SUCCESS;

      if (projectItemFile.exists() && overwriteProjectItems) {
        successSaveResult =
            ModelerSession.getNotationService()
                .getNotation(projectDiagram.getNotationIdentifier())
                .getLocalIOController()
                .saveProjectDiagram(projectDiagram, projectItemFile.getParent(), false);

        if (successSaveResult == NotationLocalIOController.SaveResult.SUCCESS) {
          LOG.debug(
              "Sync PN -> FS: Diagram "
                  + projectItemFile.getAbsolutePath()
                  + " has been overwritten.");

        } else {
          publicOverwriteError(projectDiagram, projectItemFile);
        }

      } else if (!projectItemFile.exists() && addProjectItems) {
        successSaveResult =
            ModelerSession.getNotationService()
                .getNotation(projectDiagram.getNotationIdentifier())
                .getLocalIOController()
                .saveProjectDiagram(projectDiagram, projectItemFile.getParent(), false);

        if (successSaveResult == NotationLocalIOController.SaveResult.SUCCESS) {
          LOG.debug(
              "Sync PN -> FS: Diagram " + projectItemFile.getAbsolutePath() + " has been saved.");
        } else {
          publicAddDiagramError(projectDiagram, projectItemFile);
        }
      }

      if (successSaveResult != NotationLocalIOController.SaveResult.SUCCESS) {
        retValue = false;
      }

      // user object is project root or a subfolder
    } else if (userObject instanceof ProjectContainer) {
      final Set<String> synchronizedItems = new HashSet<String>();

      if (userObject instanceof ProjectRoot) {
        // add project file (.pmp) to the list of synchronizedItems = do not delete it
        synchronizedItems.add(
            (((ProjectItem) userObject)).getDisplayName() + ProjectService.PROJECT_FILE_EXTENSION);
      }

      for (int i = 0; i < lastTreePathNode.getChildCount(); i++) {
        checkInterruption();

        final DefaultMutableTreeNode defaultMutableTreeNode =
            (DefaultMutableTreeNode) lastTreePathNode.getChildAt(i);
        final ProjectItem projectItemOfChildNode =
            (ProjectItem) defaultMutableTreeNode.getUserObject();

        final File projectItemFile;
        if (projectItemOfChildNode instanceof ProjectContainer) {
          // project containers are without file extension
          projectItemFile =
              new File(fsLevel.getAbsolutePath(), projectItemOfChildNode.getDisplayName());
        } else if (projectItemOfChildNode instanceof ProjectDiagram) {
          // project diagram files do have a file extension
          final String fileExtension =
              ProjectServiceUtils.getNotationFileExtension(
                  ((ProjectDiagram) projectItemOfChildNode).getNotationIdentifier());
          projectItemFile =
              new File(
                  fsLevel.getAbsolutePath(),
                  projectItemOfChildNode.getDisplayName() + fileExtension);
        } else {
          LOG.error("A project item has to be either project container or project diagram.");
          syncDialog.appendErrorInfo(INVALID_PARENT_ERROR_LABEL, true);
          return false;
        }

        if (projectItemFile.exists()) {
          if (projectItemOfChildNode instanceof ProjectDiagram) {
            retValue &=
                syncSubtreeToFS(
                    projectItemFile.getParentFile(),
                    treePath.pathByAddingChild(defaultMutableTreeNode),
                    addProjectItems,
                    overwriteProjectItems,
                    deleteProjectItems);

          } else {
              /* next child is container */
            retValue &=
                syncSubtreeToFS(
                    projectItemFile,
                    treePath.pathByAddingChild(defaultMutableTreeNode),
                    addProjectItems,
                    overwriteProjectItems,
                    deleteProjectItems);
          }

          synchronizedItems.add(projectItemFile.getName());

        } else if (!projectItemFile.exists() && addProjectItems) {

          /* next child is diagram */
          if (projectItemOfChildNode instanceof ProjectDiagram) {

            final String fileExtension =
                ProjectServiceUtils.getNotationFileExtension(
                    ((ProjectDiagram) projectItemOfChildNode).getNotationIdentifier());

            retValue &=
                syncSubtreeToFS(
                    projectItemFile.getParentFile(),
                    treePath.pathByAddingChild(defaultMutableTreeNode),
                    addProjectItems,
                    overwriteProjectItems,
                    deleteProjectItems);

            synchronizedItems.add(projectItemOfChildNode.getDisplayName() + fileExtension);

          } else {
              /* next child is container */

            if (projectItemFile.mkdir()) { // make new subfolder
              LOG.debug(
                  "Sync PN -> FS: new subfolder has been created, "
                      + projectItemFile.getAbsolutePath()
                      + ".");

              retValue &=
                  syncSubtreeToFS(
                      projectItemFile,
                      treePath.pathByAddingChild(defaultMutableTreeNode),
                      addProjectItems,
                      overwriteProjectItems,
                      deleteProjectItems);

              synchronizedItems.add(projectItemOfChildNode.getDisplayName());

            } else {
              publicMkdirError(projectItemFile);
            }
          }
        }
      }

      // delete non PN items in this fs level
      if (deleteProjectItems) {
        final String[] fsLevelItems = fsLevel.list();

        for (final String fsItem : fsLevelItems) {
          if (!synchronizedItems.contains(fsItem)) { // delete not PN item from FS
            final File itemToDelete = new File(fsLevel.getAbsolutePath(), fsItem);

            if (ProjectServiceUtils.removeDirectory(itemToDelete)) {
              LOG.debug("File system item has been deleted, " + itemToDelete.getAbsolutePath());

            } else {
              publicDeleteError(itemToDelete);
              retValue = false;
            }
          }
        }
      }
    }

    return retValue;
  }