| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CloseAllAction |
|
| 2.0;2 |
| 1 | /* |
|
| 2 | * $Id: CloseAllAction.java,v 1.6 2007/07/04 19:42:49 edankert Exp $ |
|
| 3 | * |
|
| 4 | * The contents of this file are subject to the Mozilla Public License |
|
| 5 | * Version 1.1 (the "License"); you may not use this file except in |
|
| 6 | * compliance with the License. You may obtain a copy of the License at |
|
| 7 | * http://www.mozilla.org/MPL/ |
|
| 8 | * |
|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis, |
|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|
| 11 | * for the specific language governing rights and limitations under the License. |
|
| 12 | * |
|
| 13 | * The Original Code is XML Hammer code. (org.xmlhammer.*) |
|
| 14 | * |
|
| 15 | * The Initial Developer of the Original Code is Edwin Dankert. Portions created |
|
| 16 | * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. |
|
| 17 | * All Rights Reserved. |
|
| 18 | * |
|
| 19 | * Contributor(s): Edwin Dankert <edankert@gmail.com> |
|
| 20 | */ |
|
| 21 | package org.xmlhammer.gui.actions; |
|
| 22 | ||
| 23 | import java.awt.Toolkit; |
|
| 24 | import java.awt.event.InputEvent; |
|
| 25 | import java.awt.event.KeyEvent; |
|
| 26 | ||
| 27 | import javax.swing.JOptionPane; |
|
| 28 | import javax.swing.KeyStroke; |
|
| 29 | ||
| 30 | import org.bounce.RunnableAction; |
|
| 31 | import org.xmlhammer.gui.ProjectsView; |
|
| 32 | import org.xmlhammer.gui.XMLHammer; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * An action that can be used to close all projects. |
|
| 36 | * |
|
| 37 | * @version $Revision: 1.6 $, $Date: 2007/07/04 19:42:49 $ |
|
| 38 | * @author Edwin Dankert <edankert@gmail.com> |
|
| 39 | */ |
|
| 40 | public class CloseAllAction extends RunnableAction { |
|
| 41 | private static final long serialVersionUID = -5318818717517600451L; |
|
| 42 | ||
| 43 | 220 | private XMLHammer parent = null; |
| 44 | ||
| 45 | /** |
|
| 46 | * The constructor for the action which closes all projects. |
|
| 47 | * |
|
| 48 | * @param parent the parent frame. |
|
| 49 | */ |
|
| 50 | public CloseAllAction( XMLHammer parent) { |
|
| 51 | 220 | super( "Close All"); |
| 52 | ||
| 53 | 220 | putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() + InputEvent.SHIFT_MASK, false)); |
| 54 | 220 | putValue( SHORT_DESCRIPTION, "Close All Projects"); |
| 55 | ||
| 56 | 220 | this.parent = parent; |
| 57 | ||
| 58 | 220 | setEnabled( false); |
| 59 | 220 | } |
| 60 | ||
| 61 | /** |
|
| 62 | * The implementation of the close all project action, called |
|
| 63 | * after a user action. |
|
| 64 | */ |
|
| 65 | public void run() { |
|
| 66 | 0 | execute( parent); |
| 67 | 0 | } |
| 68 | ||
| 69 | public static int execute( XMLHammer parent) { |
|
| 70 | 220 | ProjectsView projects = parent.getProjectsView(); |
| 71 | ||
| 72 | 220 | for ( int i = projects.getViewCount()-1; i >= 0; i--) { |
| 73 | 0 | if ( CloseAction.execute( parent, projects.getViewAt(i)) == JOptionPane.CANCEL_OPTION) { |
| 74 | 0 | return JOptionPane.CANCEL_OPTION; |
| 75 | } |
|
| 76 | } |
|
| 77 | ||
| 78 | 220 | return JOptionPane.OK_OPTION; |
| 79 | } |
|
| 80 | } |