Coverage Report - org.argouml.uml.ui.ActionSaveProject
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionSaveProject
95%
23/24
66%
8/12
2.2
 
 1  
 /* $Id: ActionSaveProject.java 17881 2010-01-12 21:09:28Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    tfmorris
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2007 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.ui;
 40  
 
 41  
 import java.awt.event.ActionEvent;
 42  
 
 43  
 import javax.swing.AbstractAction;
 44  
 import javax.swing.Action;
 45  
 import javax.swing.Icon;
 46  
 
 47  
 import org.apache.log4j.Logger;
 48  
 import org.argouml.application.helpers.ResourceLoaderWrapper;
 49  
 import org.argouml.i18n.Translator;
 50  
 import org.argouml.kernel.ProjectManager;
 51  
 import org.argouml.ui.ProjectBrowser;
 52  
 
 53  
 /**
 54  
  * Action that saves the project.
 55  
  *
 56  
  * @see ActionOpenProject
 57  
  */
 58  
 public class ActionSaveProject extends AbstractAction {
 59  
         
 60  
     private static final long serialVersionUID = -5579548202585774293L;
 61  
         /**
 62  
      * Logger.
 63  
      */
 64  900
     private static final Logger LOG = Logger.getLogger(ActionSaveProject.class);
 65  
 
 66  
     /**
 67  
      * The constructor.
 68  
      */
 69  
     public ActionSaveProject() {
 70  900
         super(Translator.localize("action.save-project"),
 71  
                 ResourceLoaderWrapper.lookupIcon("action.save-project"));
 72  
         // Set the tooltip string:
 73  900
         putValue(Action.SHORT_DESCRIPTION, 
 74  
                 Translator.localize("action.save-project"));
 75  900
         super.setEnabled(false);
 76  900
     }
 77  
 
 78  
     /**
 79  
      * The constructor.
 80  
      * @param name the name of the action.
 81  
      * @param icon the icon to represent this action graphically.
 82  
      */
 83  
     protected ActionSaveProject(String name, Icon icon) {
 84  1800
         super(name, icon);
 85  1800
     }
 86  
 
 87  
     /*
 88  
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 89  
      */
 90  
     public void actionPerformed(ActionEvent e) {
 91  5
         LOG.info("Performing save action");
 92  5
         ProjectBrowser.getInstance().trySave(
 93  
                 ProjectManager.getManager().getCurrentProject() != null
 94  
                         && ProjectManager.getManager().getCurrentProject()
 95  
                                 .getURI() != null);
 96  0
     }
 97  
 
 98  
     /**
 99  
      * Set the enabled state of the save action. When we become enabled inform
 100  
      * the user by highlighting the title bar with an asterisk. This method is
 101  
      * undoable.  This method is synchronized so that it can be used from any
 102  
      * thread without external synchronization.
 103  
      * 
 104  
      * @param isEnabled new state for save command
 105  
      */
 106  
     @Override
 107  
     public synchronized void setEnabled(final boolean isEnabled) {
 108  4412
         if (isEnabled == this.enabled) {
 109  2237
             return;
 110  
         }
 111  2175
         if (LOG.isDebugEnabled()) {
 112  2175
             if (!enabled && isEnabled) {
 113  1207
                 Throwable throwable = new Throwable();
 114  1207
                 throwable.fillInStackTrace();
 115  1207
                 LOG.debug("Save action enabled by  ", throwable);
 116  1207
             } else {
 117  968
                 LOG.debug("Save state changed from " + enabled + " to "
 118  
                         + isEnabled);
 119  
             }
 120  
         }
 121  2175
         internalSetEnabled(isEnabled);
 122  2175
     }
 123  
     
 124  
     /**
 125  
      * Set the enabled state of this action and displays the save indicator
 126  
      * @param isEnabled true to enable the action
 127  
      */
 128  
     private void internalSetEnabled(boolean isEnabled) {
 129  2175
         super.setEnabled(isEnabled);
 130  2175
         ProjectBrowser.getInstance().showSaveIndicator();
 131  2175
     }
 132  
 
 133  
 }