Package org.olat.core.commons.modules.bc.version

Examples of org.olat.core.commons.modules.bc.version.VersionCommentController


   */
  public void event(UserRequest ureq, Controller source, Event event) {
    if (source == editorc) {
      if (event == Event.DONE_EVENT) {
        if(currentItem instanceof MetaTagged && ((MetaTagged)currentItem).getMetaInfo().isLocked()) {
          unlockCtr = new VersionCommentController(ureq,getWindowControl(), true, false);
          listenTo(unlockCtr);
          unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
          unlockDialogBox.activate();
        } else {
          fireEvent(ureq, FOLDERCOMMAND_FINISHED);
View Full Code Here


              newFile.rename(fileName);
             
              // ... and notify listeners.
              finishUpload(ureq);
            } else {
              commentVersionCtr = new VersionCommentController(ureq,getWindowControl(), askForLock(existingVFSItem, ureq), true);
              listenTo(commentVersionCtr);
              commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
              commentVersionDialogBox.activate();
            }
          } else {
            //if the file is locked, ask for unlocking it
            if(existingVFSItem instanceof MetaTagged && ((MetaTagged)existingVFSItem).getMetaInfo().isLocked()) {
              cleanUpOverwriteDialog();
              unlockCtr = new VersionCommentController(ureq,getWindowControl(), true, false);
              listenTo(unlockCtr);
              unlockDialogBox = new CloseableModalController(getWindowControl(), translate("ok"), unlockCtr.getInitialComponent());
              unlockDialogBox.activate();
            } else {
              // Overwrite...
              String fileName = existingVFSItem.getName();
              existingVFSItem.delete();
              newFile.rename(fileName);
             
              // ... and notify listeners.
              finishUpload(ureq);
            }
          }
        } else if (buttonClickedEvent.getPosition() == 1) { //not ok
          // Upload renamed. Since we've already uploaded the file with a changed name, don't do anything much here...
          this.fileOverwritten = true;

          // ... and notify listeners.
          finishUpload(ureq);
        } else if (buttonClickedEvent.getPosition() == 2) { // cancel
          // Cancel. Remove the new file since it has already been uploaded. Note that we don't have to explicitly close the
          // dialog box since it closes itself whenever something gets clicked.
          newFile.delete();
          VersionsManager.getInstance().delete(newFile, true);//force delete the auto-versioning of this temp. file
        } else {
          throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
        }
      }
    } else if (source == lockedFileDialog) {

      if (event instanceof ButtonClickedEvent) {
        ButtonClickedEvent buttonClickedEvent = (ButtonClickedEvent) event;
        switch(buttonClickedEvent.getPosition()) {
          case 0: {
            //upload the file with a new name
            this.fileOverwritten = true;
            // ... and notify listeners.
            finishUpload(ureq);
            break;
          }
          case 1: {//cancel
            newFile.delete();
            VersionsManager.getInstance().delete(newFile, true);//force delete the auto-versioning of this temp. file
            fireEvent(ureq, Event.CANCELLED_EVENT);
            break;
          }
          default:
            throw new RuntimeException("Unknown button number " + buttonClickedEvent.getPosition());
        }
      }
    } else if (source == commentVersionCtr) {
      String comment = commentVersionCtr.getComment();
      if(existingVFSItem instanceof MetaTagged) {
        MetaInfo info = ((MetaTagged)existingVFSItem).getMetaInfo();
        if(info.isLocked() && !commentVersionCtr.keepLocked()) {
          info.setLocked(false);
          info.write();
        }
      }
     
      cleanUpCommentDialog();
      cleanUpRevisionDialog();

      //ok, new version of the file
      Versionable existingVersionableItem = (Versionable)existingVFSItem;
      boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), comment, newFile.getInputStream());
      if(ok) {
        newFile.delete();
        VersionsManager.getInstance().delete(newFile, true);
        //what can i do if existingVFSItem is a container
        if(existingVFSItem instanceof VFSLeaf) {
          newFile = (VFSLeaf)existingVFSItem;
        }
      }
      finishUpload(ureq);
    } else if (source == unlockCtr) {
      // Overwrite...
      String fileName = existingVFSItem.getName();
      if(!unlockCtr.keepLocked()) {
        MetaInfo info = ((MetaTagged)existingVFSItem).getMetaInfo();
        info.setLocked(false);
        info.setLockedBy(null);
        info.write();
      }
     
      cleanUpUnlockDialog();
     
      existingVFSItem.delete();
      newFile.rename(fileName);

      // ... and notify listeners.
      finishUpload(ureq);
     
    } else if (source == revisionListCtr) {
      if(FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) {
        //don't want to delete revisions, clean the temporary file
        cleanUpRevisionDialog();
        newFile.delete();
        VersionsManager.getInstance().delete(newFile, true);
        fireEvent(ureq, Event.CANCELLED_EVENT);
      } else {
        if (existingVFSItem instanceof Versionable && ((Versionable)existingVFSItem).getVersions().isVersioned()) {
          cleanUpRevisionDialog();
 
          Versionable versionable = (Versionable)existingVFSItem;
          Versions versions = versionable.getVersions();
          int maxNumOfRevisions = FolderConfig.versionsAllowed(null);
          if(maxNumOfRevisions < 0 || maxNumOfRevisions > versions.getRevisions().size()) {
            commentVersionCtr = new VersionCommentController(ureq,getWindowControl(), askForLock(existingVFSItem, ureq), true);
            listenTo(commentVersionCtr);
            commentVersionDialogBox = new CloseableModalController(getWindowControl(), translate("save"), commentVersionCtr.getInitialComponent());
            commentVersionDialogBox.activate();
          } else {
            //delete first some old revisions
View Full Code Here

TOP

Related Classes of org.olat.core.commons.modules.bc.version.VersionCommentController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.