2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.actions
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.jface
.action
.IAction
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.ui
.IEditorInput
;
16 import org
.eclipse
.ui
.IEditorPart
;
17 import org
.eclipse
.ui
.IWorkbenchWindow
;
18 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
22 import eu
.etaxonomy
.taxeditor
.UiUtil
;
23 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SaveTaxonAction
;
24 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
25 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
28 * Calls <code>MultiPageTaxonEditor.doSave()</code> method for all
29 * open <code>MultiPageTaxonEditor</code>s. Commits universal transaction,
30 * then opens a new one.
32 * @see IWorkbenchWindowActionDelegate
38 public class SaveAllAction
implements IWorkbenchWindowActionDelegate
{
39 private static final Logger logger
= Logger
.getLogger(SaveAllAction
.class);
41 private IWorkbenchWindow window
;
45 public SaveAllAction() {
49 * The action has been activated. The argument of the
50 * method represents the 'real' action sitting
51 * in the workbench UI.
52 * @see IWorkbenchWindowActionDelegate#run
54 public void run(IAction action
) {
56 UiUtil
.setIsSaving(true);
58 // Get all open windows
59 for (IEditorPart taxonEditor
: UiUtil
.getOpenTaxonEditors()) {
61 // Save the dirty ones
62 if (taxonEditor
.isDirty()) {
63 IEditorInput input
= taxonEditor
.getEditorInput();
64 if (input
.getAdapter(Taxon
.class) != null) {
65 Taxon taxon
= (Taxon
) input
.getAdapter(Taxon
.class);
66 new SaveTaxonAction(taxon
).run();
67 if (taxonEditor
instanceof MultiPageTaxonEditor
) {
68 ((MultiPageTaxonEditor
) taxonEditor
).setDirtyExtern(false);
74 // Commit the transaction
75 TaxEditorPlugin
.getDefault().commitTransaction();
77 // Force library objects to be associated with new transaction
78 CdmUtil
.clearLibraryObjects();
80 // Start a new transaction
81 TaxEditorPlugin
.getDefault().startTransaction();
83 // Put all open taxa in the new transaction
84 for (Object taxon
: TaxEditorPlugin
.getDefault().getObservableSessionTaxa()) {
85 CdmUtil
.getTaxonService().saveTaxon((Taxon
) taxon
);
88 UiUtil
.setIsSaving(false);
92 * Selection in the workbench has been changed. We
93 * can change the state of the 'real' action here
94 * if we want, but this can only happen after
95 * the delegate has been created.
96 * @see IWorkbenchWindowActionDelegate#selectionChanged
98 public void selectionChanged(IAction action
, ISelection selection
) {
102 * We can use this method to dispose of any system
103 * resources we previously allocated.
104 * @see IWorkbenchWindowActionDelegate#dispose
106 public void dispose() {
110 * We will cache window object in order to
111 * be able to provide parent shell for the message dialog.
112 * @see IWorkbenchWindowActionDelegate#init
114 public void init(IWorkbenchWindow window
) {
115 this.window
= window
;