Coverage Report - org.homeunix.thecave.buddi.view.menu.items.FileSave
 
Classes in this File Line Coverage Branch Coverage Complexity
FileSave
64%
11/17
50%
1/2
2.333
 
 1  
 /*
 2  
  * Created on Aug 6, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.view.menu.items;
 5  
 
 6  
 import java.awt.Toolkit;
 7  
 import java.awt.event.ActionEvent;
 8  
 import java.awt.event.KeyEvent;
 9  
 import java.io.File;
 10  
 
 11  
 import javax.swing.JOptionPane;
 12  
 import javax.swing.KeyStroke;
 13  
 
 14  
 import org.homeunix.thecave.buddi.i18n.BuddiKeys;
 15  
 import org.homeunix.thecave.buddi.i18n.keys.MenuKeys;
 16  
 import org.homeunix.thecave.buddi.model.impl.ConcurrentSaveException;
 17  
 import org.homeunix.thecave.buddi.model.prefs.PrefsModel;
 18  
 import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter;
 19  
 
 20  
 import ca.digitalcave.moss.application.document.StandardDocument;
 21  
 import ca.digitalcave.moss.application.document.exception.DocumentSaveException;
 22  
 import ca.digitalcave.moss.swing.MossDocumentFrame;
 23  
 import ca.digitalcave.moss.swing.MossFrame;
 24  
 import ca.digitalcave.moss.swing.MossMenuItem;
 25  
 
 26  
 public class FileSave extends MossMenuItem {
 27  
         public static final long serialVersionUID = 0;
 28  
         
 29  
         public FileSave(MossFrame frame) {
 30  6020
                 super(frame, PrefsModel.getInstance().getTranslator().get(MenuKeys.MENU_FILE_SAVE),
 31  
                                 KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
 32  6020
         }
 33  
         
 34  
         @Override
 35  
         public void actionPerformed(ActionEvent e) {
 36  160
                 StandardDocument model = ((MossDocumentFrame) getFrame()).getDocument(); 
 37  160
                 File f = model.getFile();
 38  
                 try {
 39  160
                         if (f == null) {
 40  160
                                 new FileSaveAs((MossDocumentFrame) getFrame()).doClick();
 41  
                         }
 42  
                         else {
 43  0
                                 model.save();
 44  0
                                 getFrame().updateContent();
 45  
                         }
 46  
                 }
 47  0
                 catch (ConcurrentSaveException cse){
 48  0
                         JOptionPane.showMessageDialog(
 49  
                                         null, 
 50  
                                         TextFormatter.getTranslation(BuddiKeys.MESSAGE_CONCURRENT_SAVE_EXCEPTION_TEXT),
 51  
                                         TextFormatter.getTranslation(BuddiKeys.WARNING),
 52  
                                         JOptionPane.WARNING_MESSAGE);
 53  
                 }                
 54  0
                 catch (DocumentSaveException dse){
 55  
                         //TODO Do something less drastic here.  For debugging, we will
 56  
                         // throw a runtime exception to ensure that we catch all error
 57  
                         // conditions.
 58  0
                         throw new RuntimeException("Error saving file: " + dse, dse);
 59  19
                 }
 60  19
         }
 61  
         
 62  
         @Override
 63  
         public void updateMenus() {
 64  42468
                 super.updateMenus();
 65  
 
 66  42468
                 this.setEnabled(getFrame() instanceof MossDocumentFrame);
 67  42468
         }
 68  
 }