View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: SaveAllAction.java
13   * Created: 2009-07-14
14   * Author: kpietak
15   * $Id$
16   */
17  
18  package pl.edu.agh.cast.editor.action;
19  
20  import org.eclipse.gef.ui.actions.UpdateAction;
21  import org.eclipse.jface.action.Action;
22  import org.eclipse.ui.IEditorPart;
23  import org.eclipse.ui.PlatformUI;
24  import org.eclipse.ui.actions.ActionFactory;
25  
26  import pl.edu.agh.cast.util.Messages;
27  
28  /**
29   * Saves all opened dirty editors. If no editors are opened or dirty it is disabled.
30   * 
31   * @author AGH CAST Team
32   */
33  public class SaveAllAction extends Action implements UpdateAction {
34  
35  	/**
36  	 * Constructor.
37  	 */
38  	public SaveAllAction() {
39  		setId(ActionFactory.SAVE_ALL.getId());
40  		setText(Messages.SaveAllAction_0);
41  		setToolTipText(Messages.SaveAllAction_1);
42  	}
43  
44  	/**
45  	 * 
46  	 * {@inheritDoc}
47  	 * 
48  	 * @see org.eclipse.jface.action.Action#run()
49  	 */
50  	@Override
51  	public void run() {
52  		IEditorPart[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
53  		if (editors != null) {
54  			for (IEditorPart editor : editors) {
55  				editor.doSave(null);
56  			}
57  		}
58  	}
59  
60  	/**
61  	 * {@inheritDoc}
62  	 * 
63  	 * @see org.eclipse.gef.ui.actions.UpdateAction#update()
64  	 */
65  	@Override
66  	public void update() {
67  		IEditorPart[] editors = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getDirtyEditors();
68  		if (editors == null || editors.length == 0) {
69  			setEnabled(false);
70  		} else {
71  			setEnabled(true);
72  		}
73  
74  	}
75  }