001package csheets.ext.comments.ui; 002 003import csheets.ext.comments.CommentableCell; 004import csheets.ui.ctrl.UIController; 005 006/** 007 * A controller for updating the user-specified comment of a cell. 008 * @author Alexandre Braganca 009 * @author Einar Pehrson 010 */ 011public class CommentController { 012 013 /** The user interface controller */ 014 private UIController uiController; 015 016 /** 017 * Creates a new comment controller. 018 * @param uiController the user interface controller 019 */ 020 public CommentController(UIController uiController) { 021 this.uiController = uiController; 022 } 023 024 /** 025 * Attempts to create a new comment from the given string. 026 * If successful, adds the comment to the given cell. 027 * If the input string is empty or null, the comment is set to null. 028 * @param cell the cell for which the comment should be set 029 * @param commentString the comment, as entered by the user 030 * @return true if the cell's comment was changed 031 */ 032 public boolean setComment(CommentableCell cell, String commentString) { 033 // Clears comment, if insufficient input 034 if (commentString == null || commentString.equals("")) { 035 cell.setUserComment(null); 036 return true; 037 } 038 039 // Stores the comment 040 cell.setUserComment(commentString); 041 uiController.setWorkbookModified(cell.getSpreadsheet().getWorkbook()); 042 043 return true; 044 } 045}