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
.editor
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.ui
.IEditorInput
;
18 import org
.eclipse
.ui
.IEditorSite
;
19 import org
.eclipse
.ui
.PartInitException
;
20 import org
.eclipse
.ui
.part
.MultiPageEditorPart
;
21 import org
.springframework
.transaction
.TransactionStatus
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.taxeditor
.actions
.SaveAllAction
;
26 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SaveTaxonAction
;
27 import eu
.etaxonomy
.taxeditor
.editor
.description
.TaxonDescriptionEditor
;
28 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
29 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.RecentNamesView
;
34 * Generates the tabbed editor with <code>TaxonNameEditor</code> on top and tabs for
35 * "Desriptions", "Concepts", "Geography", etc.
41 public class MultiPageTaxonEditor
extends MultiPageEditorPart
{
42 private static final Logger logger
= Logger
.getLogger(MultiPageTaxonEditor
.class);
44 public static final String ID
= "eu.etaxonomy.taxeditor.editor.multipagetaxonview";
47 private boolean dirty
;
49 private TransactionStatus tx
;
51 public MultiPageTaxonEditor() {
53 // tx = CdmUtil.startTransaction();
57 public void dispose() {
59 // CdmUtil.commitTransaction(tx);
63 protected void createPages() {
66 addPage(0, new TaxonNameEditor(), getEditorInput());
67 setPageText(0, "Name");
70 addPage(1, new TaxonDescriptionEditor(), getEditorInput());
71 setPageText(1, "Descriptive");
73 // addPage(2, new EmptyEditorView(), getEditorInput());
74 // setPageText(2, "Concepts");
76 // addPage(3, new EmptyEditorView(), getEditorInput());
77 // setPageText(3, "Geographic");
79 // Hook undo to workbench
80 // IUndoContext undoContext = UiUtil.getWorkbenchUndoContext();
81 // getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));
82 // getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));
84 } catch (PartInitException e
) {
90 public void doSave(IProgressMonitor monitor
) {
92 // Bummer quick fix - saving individual taxa leads to too many
94 new SaveAllAction().run(null);
96 // Show new taxon being saved for the first time in recent names
97 RecentNamesView
.addRecentName(taxon
);
99 //// monitor.beginTask(name, totalWork)
100 // new SaveTaxonAction(taxon).run();
101 //// CdmUtil.commitTransaction(tx);
103 //// tx = CdmUtil.startTransaction();
104 //// CdmUtil.getTaxonService().saveTaxon(taxon);
107 private void setDirty(boolean dirty
) {
109 firePropertyChange(PROP_DIRTY
);
113 * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty()
115 public boolean isDirty() {
120 * Checks whether nested editors are calling <code>firePropertyChange(PROP_DIRTY)</code>
121 * to signal an edit has taken place before passing property change along to
122 * <code>super.handlePropertyChange(int propertyId)</code>.
125 * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
127 protected void handlePropertyChange(int propertyId
) {
128 if (propertyId
== PROP_DIRTY
) {
131 super.handlePropertyChange(propertyId
);
135 public void doSaveAs() {}
138 public boolean isSaveAsAllowed() {
143 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
145 if (!(input
instanceof IEditorInput
))
146 throw new PartInitException(
147 "Invalid Input: Must be IEditorInput");
149 // Get taxon from editor input
150 if (input
.getAdapter(Taxon
.class) != null) {
151 taxon
= (Taxon
) input
.getAdapter(Taxon
.class);
156 // Save taxon to put it into current transaction
157 CdmUtil
.getTaxonService().saveTaxon(taxon
);
159 // Listen for name changes,
160 // change tab for this taxon editor accordingly
161 taxon
.addPropertyChangeListener("name", new PropertyChangeListener() {
162 public void propertyChange(PropertyChangeEvent e
) {
169 super.init(site
, input
);
173 * Calls <code>MultiPageEditorPart.setPartName(String partName)</code>
174 * with text appropriate to the state of the taxon: any taxon that has
175 * been saved will by necessity have a name to display; a new taxon
176 * should display "New taxon" in the editor tab.
178 private void setPartName() {
180 String partName
= null;
181 TaxonNameBase name
= taxon
.getName();
184 partName
= name
.getTitleCache();
187 if (partName
== null || partName
.equals("")) {
188 partName
= ("New taxon");
191 setPartName(partName
);
195 * SaveAllAction needs to set this.
199 public void setDirtyExtern(boolean IS_DIRTY
) {
203 public Taxon
getTaxon(){