52288d367ce858b60a55131d781e1f1bbb9108db
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
.handlers
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.IHandler
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IEditorPart
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SaveTaxonAction
;
22 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
23 import eu
.etaxonomy
.taxeditor
.datasource
.CdmTransactionController
;
24 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
25 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
32 public class SaveAllHandler
extends AbstractHandler
implements IHandler
{
33 private static final Logger logger
= Logger
.getLogger(SaveAllHandler
.class);
36 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
40 logger
.debug("Save all handler called.");
41 EditorController
.setSaving(true);
43 // Get all open windows
44 for (IEditorPart taxonEditor
: EditorController
.getOpenEditors()) {
46 // Save the dirty ones
47 if (taxonEditor
.isDirty()) {
48 IEditorInput input
= taxonEditor
.getEditorInput();
49 if (input
.getAdapter(Taxon
.class) != null) {
50 Taxon taxon
= (Taxon
) input
.getAdapter(Taxon
.class);
51 new SaveTaxonAction(taxon
).run();
52 if (taxonEditor
instanceof MultiPageTaxonEditor
) {
53 ((MultiPageTaxonEditor
) taxonEditor
).setDirtyExtern(false);
59 // Commit the transaction
60 CdmTransactionController
.commitTransaction();
62 // Force library objects to be associated with new transaction
63 CdmSessionDataRepository
.getDefault().clearNonTaxonData();
65 // Start a new transaction
66 CdmTransactionController
.startTransaction();
68 // Put all open taxa in the new transaction
69 CdmTransactionController
.addSessionTaxaToTransaction();
71 EditorController
.setSaving(false);
72 // TODO: delete undoHistory