001
002package csheets.core;
003
004import csheets.core.formula.compiler.FormulaCompilationException;
005import java.text.NumberFormat;
006
007/**
008 * A singleton to update a cell's content
009 * @author João Carreira
010 */
011public class UpdateCellContent 
012{
013    
014    private static UpdateCellContent instance = null;
015    
016    /* private constructor as required in the singleton pattern */
017    private UpdateCellContent()
018    {
019    }
020    
021    /**
022     * updates a cell's content
023     * @param cell  targeted cell
024     * @param value new cell's value
025     * @throws FormulaCompilationException 
026     */
027    public void triggerUpdate(Cell cell, Value value) throws FormulaCompilationException
028    {
029        if(value.getType() == Value.Type.NUMERIC)
030        {
031            cell.setContent(value.toString(NumberFormat.getInstance()));
032        }
033        else
034        {
035            cell.setContent(value.toString());
036        }
037    }
038    
039    /**
040     * getInstance
041     * @return UpdateCellContent instance
042     */
043    public static UpdateCellContent getInstance()
044    {
045        if(instance == null)
046        {
047            return new UpdateCellContent();
048        }
049        return instance;
050    }
051}