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
.cdm
.SaveTaxonAction
;
26 import eu
.etaxonomy
.taxeditor
.editor
.description
.TaxonDescriptionEditorView
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditorView
;
28 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
32 * Generates the tabbed editor with <code>TaxonNameEditorView</code> on top and tabs for
33 * "Desriptions", "Concepts", "Geography", etc.
39 public class MultiPageTaxonEditor
extends MultiPageEditorPart
{
40 private static final Logger logger
= Logger
.getLogger(MultiPageTaxonEditor
.class);
42 public static final String ID
= "eu.etaxonomy.taxeditor.editor.multipagetaxonview";
45 private boolean dirty
;
47 private TransactionStatus tx
;
49 public MultiPageTaxonEditor() {
51 // tx = CdmUtil.startTransaction();
55 public void dispose() {
57 // CdmUtil.commitTransaction(tx);
61 protected void createPages() {
64 addPage(0, new TaxonNameEditorView(), getEditorInput());
65 setPageText(0, "Name");
68 addPage(1, new TaxonDescriptionEditorView(), getEditorInput());
69 setPageText(1, "Descriptive");
71 addPage(2, new EmptyEditorView(), getEditorInput());
72 setPageText(2, "Concepts");
74 addPage(3, new EmptyEditorView(), getEditorInput());
75 setPageText(3, "Geographic");
77 // Hook undo to workbench
78 // IUndoContext undoContext = UiUtil.getWorkbenchUndoContext();
79 // getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.UNDO.getId(), new UndoActionHandler(getSite(), undoContext));
80 // getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REDO.getId(), new RedoActionHandler(getSite(), undoContext));
82 } catch (PartInitException e
) {
88 public void doSave(IProgressMonitor monitor
) {
89 // monitor.beginTask(name, totalWork)
90 new SaveTaxonAction(taxon
).run();
91 // CdmUtil.commitTransaction(tx);
93 // tx = CdmUtil.startTransaction();
94 // CdmUtil.getTaxonService().saveTaxon(taxon);
97 private void setDirty(boolean dirty
) {
99 firePropertyChange(PROP_DIRTY
);
103 * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty()
105 public boolean isDirty() {
110 * Checks whether nested editors are calling <code>firePropertyChange(PROP_DIRTY)</code>
111 * to signal an edit has taken place before passing property change along to
112 * <code>super.handlePropertyChange(int propertyId)</code>.
115 * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
117 protected void handlePropertyChange(int propertyId
) {
118 if (propertyId
== PROP_DIRTY
) {
121 super.handlePropertyChange(propertyId
);
125 public void doSaveAs() {}
128 public boolean isSaveAsAllowed() {
133 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
135 if (!(input
instanceof IEditorInput
))
136 throw new PartInitException(
137 "Invalid Input: Must be IEditorInput");
139 // Get taxon from editor input
140 if (input
.getAdapter(Taxon
.class) != null) {
141 taxon
= (Taxon
) input
.getAdapter(Taxon
.class);
146 // Save taxon to put it into current transaction
147 CdmUtil
.getTaxonService().saveTaxon(taxon
);
149 // Listen for name changes,
150 // change tab for this taxon editor accordingly
151 taxon
.addPropertyChangeListener("name", new PropertyChangeListener() {
152 public void propertyChange(PropertyChangeEvent e
) {
159 super.init(site
, input
);
163 * Calls <code>MultiPageEditorPart.setPartName(String partName)</code>
164 * with text appropriate to the state of the taxon: any taxon that has
165 * been saved will by necessity have a name to display; a new taxon
166 * should display "New taxon" in the editor tab.
168 private void setPartName() {
170 String partName
= null;
171 TaxonNameBase name
= taxon
.getName();
174 partName
= name
.getTitleCache();
177 if (partName
== null || partName
.equals("")) {
178 partName
= ("New taxon");
181 setPartName(partName
);