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
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
19 import org
.eclipse
.core
.commands
.operations
.UndoContext
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.ui
.IEditorInput
;
22 import org
.eclipse
.ui
.IEditorPart
;
23 import org
.eclipse
.ui
.IEditorSite
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
27 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
28 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
32 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
33 import eu
.etaxonomy
.taxeditor
.editor
.descriptiontree
.TaxonDescriptionTreeEditor
;
34 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
35 import eu
.etaxonomy
.taxeditor
.model
.DataChangeBridge
;
36 import eu
.etaxonomy
.taxeditor
.model
.IDataChangeBehavior
;
37 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
41 * Generates the tabbed editor with <code>TaxonNameEditor</code> on top and tabs for
42 * "Descriptions", "Concepts", "Geography", etc.
49 //public class MultiPageTaxonEditor extends MultiPageEditorPart implements IConversationEnabled, IPostOperationEnabled {
50 public class MultiPageTaxonEditor
extends FormEditor
implements IConversationEnabled
, IPostOperationEnabled
{
51 private static final Logger logger
= Logger
.getLogger(MultiPageTaxonEditor
.class);
53 public static final String ID
= "eu.etaxonomy.taxeditor.editor.multipagetaxonview";
55 private boolean dirty
;
57 private ConversationHolder conversation
;
58 private IDataChangeBehavior dataChangeBehavior
;
59 private IUndoContext undoContext
;
61 private TaxonEditorInput input
;
64 public MultiPageTaxonEditor() {
66 undoContext
= new UndoContext();
72 public void dispose() {
74 // EditorUtil.checkHidePropertySheet();
81 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
84 protected void addPages() {
85 input
= (TaxonEditorInput
) getEditorInput();
86 conversation
= input
.getConversationHolder();
87 conversation
.registerForDataStoreChanges(this);
90 addPage(Page
.NAME
.getIndex(), new TaxonNameEditor(this), getEditorInput());
91 setPageText(Page
.NAME
.getIndex(), Page
.NAME
.getTitle());
93 // // TODO lazy create
94 // addPage(Page.DESCRIPTIVE.getIndex(), new TaxonDescriptionEditor(this), getEditorInput());
95 // setPageText(Page.DESCRIPTIVE.getIndex(), Page.DESCRIPTIVE.getTitle());
97 // // TODO lazy create
98 // addPage(Page.IMAGE.getIndex(), new TaxonImageEditor(this), getEditorInput());
99 // setPageText(Page.IMAGE.getIndex(), Page.IMAGE.getTitle());
102 addPage(Page
.DESCRIPTIVE
.getIndex(), new TaxonDescriptionTreeEditor(this), getEditorInput());
103 // addPage(Page.DESCRIPTIVE_NEW.getIndex(), new TaxonDescriptionTreeEditor(this));
104 setPageText(Page
.DESCRIPTIVE
.getIndex(), Page
.DESCRIPTIVE
.getTitle());
106 EditorUtil
.showPropertySheet();
108 } catch (PartInitException e
) {
109 logger
.error("Could not create MultiPageTaxonEditor.", e
);
114 // protected void createPages() {
120 public void doSave(IProgressMonitor monitor
) {
122 if( ! conversation
.isBound()){
126 //handle existing names and authors
127 DuplicateArbitrator duplicateArbitrator
= (DuplicateArbitrator
) getAdapter(DuplicateArbitrator
.class);
129 if(duplicateArbitrator
!= null){
130 // disable for now because of transaction problems.
131 duplicateArbitrator
.arbitrate();
134 // commit the conversation and start a new transaction immediately
135 conversation
.commit(true);
137 this.setDirty(false);
140 private void setDirty(boolean dirty
) {
142 firePropertyChange(PROP_DIRTY
);
146 * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty()
148 public boolean isDirty() {
153 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
156 public void editorDirtyStateChanged() {
158 super.editorDirtyStateChanged();
162 * Checks whether nested editors are calling <code>firePropertyChange(PROP_DIRTY)</code>
163 * to signal an edit has taken place before passing property change along to
164 * <code>super.handlePropertyChange(int propertyId)</code>.
167 * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
169 protected void handlePropertyChange(int propertyId
) {
170 if (propertyId
== PROP_DIRTY
) {
173 super.handlePropertyChange(propertyId
);
177 public void doSaveAs() {}
180 public boolean isSaveAsAllowed() {
185 public void init(IEditorSite site
, IEditorInput input
) throws PartInitException
{
187 if (!(input
instanceof TaxonEditorInput
))
188 throw new PartInitException(
189 "Invalid Input: Must be TaxonEditorInput");
191 // FIXME looks like we do it differently now
192 // Get taxon from editor input
193 // if (input.getAdapter(Taxon.class) != null) {
194 // taxon = (Taxon) input.getAdapter(Taxon.class);
199 this.input
= (TaxonEditorInput
) input
;
202 // Listen for name changes,
203 // change tab for this taxon editor accordingly
204 getTaxon().addPropertyChangeListener("name",
205 new PropertyChangeListener() {
206 public void propertyChange(PropertyChangeEvent e
) {
210 } catch (NullPointerException e
) {
211 logger
.warn("Caught an NPE while initing an editor. This is most " +
212 "likely due to the unsuccesful attempt to restore the former " +
213 "state of the application. We ignore this because the workbench " +
214 "will simply be reset.");
218 super.init(site
, input
);
222 * Calls <code>MultiPageEditorPart.setPartName(String partName)</code>
223 * with text appropriate to the state of the taxon: any taxon that has
224 * been saved will by necessity have a name to display; a new taxon
225 * should display "New taxon" in the editor tab.
227 protected void setPartName() {
229 String partName
= null;
230 TaxonNameBase
<?
, ?
> name
= getTaxon().getName();
233 partName
= name
.getTitleCache();
236 if (partName
== null || partName
.equals("")) {
237 partName
= ("New taxon");
240 setPartName(partName
);
244 * Editor pages call this in their postOperation to notify the MultiPageTaxonEditor
247 public void setDirty() {
251 public Taxon
getTaxon(){
252 return input
.getTaxon();
257 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
259 public ConversationHolder
getConversationHolder() {
263 public void setConversationHolder(ConversationHolder conversation
){
264 this.conversation
= conversation
;
268 public IUndoContext
getUndoContext() {
272 public void setUndoContext(IUndoContext undoContext
) {
273 this.undoContext
= undoContext
;
277 public void setFocus(){
278 // bind the conversation
279 getConversationHolder().bind();
280 // pass focus to the active editor page
281 getActiveEditor().setFocus();
286 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
288 public void update(CdmDataChangeMap events
) {
289 if(dataChangeBehavior
== null){
290 dataChangeBehavior
= new MultiPageTaxonEditorDataChangeBehaviour(this);
293 DataChangeBridge
.handleDataChange(events
, dataChangeBehavior
);
299 * @see eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation()
301 public boolean postOperation(CdmBase objectAffectedByOperation
) {
304 for(IEditorPart editor
: this.getPages()){
305 if (editor
instanceof IPostOperationEnabled
) {
306 ((IPostOperationEnabled
) editor
).postOperation(objectAffectedByOperation
);
308 logger
.warn("postOperation not enabled for editor " + editor
);
311 logger
.warn("postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
317 * Returns an <code>AbstractTaxonEditor</code> implementation by type
319 * @param page the page type
322 public IEditorPart
getPage(Page page
){
323 for(IEditorPart editor
: this.getPages()){
324 if(editor
.getClass().equals(page
.getClazz())){
332 * Return a list of <code>AbstractTaxonEditor</code>s registered with this
333 * <code>MultiPageTaxonEditor</code>.
337 public List
<IEditorPart
> getPages(){
338 ArrayList
<IEditorPart
> editors
= new ArrayList
<IEditorPart
>();
339 for(int i
= 0; i
< this.getPageCount(); i
++){
340 editors
.add(this.getEditor(i
));