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
.UiUtil
;
22 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SaveTaxonAction
;
23 import eu
.etaxonomy
.taxeditor
.datasource
.CdmTransactionController
;
24 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
25 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
26 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
29 * Calls <code>MultiPageTaxonEditor.doSave()</code> method for all
30 * open <code>MultiPageTaxonEditor</code>s. Commits universal transaction,
31 * then opens a new one.
33 * @see IWorkbenchWindowActionDelegate
39 public class SaveAllAction
implements IWorkbenchWindowActionDelegate
{
40 private static final Logger logger
= Logger
.getLogger(SaveAllAction
.class);
42 private IWorkbenchWindow window
;
46 public SaveAllAction() {
50 * The action has been activated. The argument of the
51 * method represents the 'real' action sitting
52 * in the workbench UI.
53 * @see IWorkbenchWindowActionDelegate#run
55 public void run(IAction action
) {
57 UiUtil
.setIsSaving(true);
59 // Get all open windows
60 for (IEditorPart taxonEditor
: UiUtil
.getOpenTaxonEditors()) {
62 // Save the dirty ones
63 if (taxonEditor
.isDirty()) {
64 IEditorInput input
= taxonEditor
.getEditorInput();
65 if (input
.getAdapter(Taxon
.class) != null) {
66 Taxon taxon
= (Taxon
) input
.getAdapter(Taxon
.class);
67 new SaveTaxonAction(taxon
).run();
68 if (taxonEditor
instanceof MultiPageTaxonEditor
) {
69 ((MultiPageTaxonEditor
) taxonEditor
).setDirtyExtern(false);
75 // Commit the transaction
76 CdmTransactionController
.commitTransaction();
78 // Force library objects to be associated with new transaction
79 CdmSessionDataRepository
.getDefault().clearNonTaxonData();
81 // Start a new transaction
82 CdmTransactionController
.startTransaction();
84 // Put all open taxa in the new transaction
85 CdmTransactionController
.addSessionTaxaToTransaction();
87 UiUtil
.setIsSaving(false);
88 // TODO: delete undoHistory
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
;