1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor;
|
11
|
|
12
|
import java.util.Vector;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
|
20
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
21
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
|
22
|
import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
|
23
|
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
|
24
|
|
25
|
/**
|
26
|
* Implementation if {@link eu.etaxonomy.taxeditor.store.model.IDataChangeBehaviour}
|
27
|
* for the {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor}.
|
28
|
*
|
29
|
* TODO make this class a bean and thus configurable by Spring
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created 01.04.2009
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class MultiPageTaxonEditorDataChangeBehaviour extends AbstractDataChangeBehaviour implements
|
36
|
IDataChangeBehavior {
|
37
|
private static final Logger logger = Logger
|
38
|
.getLogger(MultiPageTaxonEditorDataChangeBehaviour.class);
|
39
|
|
40
|
private MultiPageTaxonEditor source;
|
41
|
|
42
|
private TaxonEditorInput input;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for MultiPageTaxonEditorDataChangeBehaviour.</p>
|
46
|
*
|
47
|
* @param multiPageTaxonEditor a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor} object.
|
48
|
*/
|
49
|
public MultiPageTaxonEditorDataChangeBehaviour(
|
50
|
MultiPageTaxonEditor multiPageTaxonEditor) {
|
51
|
source = multiPageTaxonEditor;
|
52
|
}
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see eu.etaxonomy.taxeditor.store.model.IDataChangeBehavior#reactOnDataChange()
|
56
|
*/
|
57
|
/** {@inheritDoc} */
|
58
|
public void reactOnDataChange(CdmDataChangeMap changeEvents) {
|
59
|
input = (TaxonEditorInput) source.getEditorInput();
|
60
|
|
61
|
// I don't know when this happens but ...
|
62
|
if(input.getTaxon() == null)
|
63
|
return;
|
64
|
|
65
|
if(changeEvents.sizeByEventType(EventType.UPDATE) > 0){
|
66
|
reactOnUpdate(changeEvents.getEvents(EventType.UPDATE));
|
67
|
}
|
68
|
if(changeEvents.sizeByEventType(EventType.INSERT) > 0){
|
69
|
reactOnInsert(changeEvents.getEvents(EventType.INSERT));
|
70
|
}
|
71
|
if(changeEvents.sizeByEventType(EventType.DELETE) > 0){
|
72
|
reactOnDelete(changeEvents.getEvents(EventType.DELETE));
|
73
|
}
|
74
|
}
|
75
|
|
76
|
|
77
|
/** {@inheritDoc} */
|
78
|
@Override
|
79
|
public void reactOnDelete(Vector<CdmDataChangeEvent> events){
|
80
|
for(CdmDataChangeEvent event : events){
|
81
|
// close open editors
|
82
|
if(event.getEntity() instanceof TaxonNode){
|
83
|
logger.warn("taxon node");
|
84
|
}
|
85
|
if((event.getEntity() instanceof TaxonNode)
|
86
|
&& input.getTaxonNode().equals(event.getEntity())){
|
87
|
EditorUtil.close(source);
|
88
|
logger.debug("Closing open editor for deleted taxon.");
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/** {@inheritDoc} */
|
94
|
@Override
|
95
|
public void reactOnUpdate(Vector<CdmDataChangeEvent> events){
|
96
|
|
97
|
for(CdmDataChangeEvent event : events){
|
98
|
|
99
|
// update editor title
|
100
|
if(event.getEntity() instanceof TaxonNameBase){
|
101
|
if(input.getTaxon().getName().equals(event.getEntity())){
|
102
|
// set the name of the editor window
|
103
|
source.setPartName();
|
104
|
logger.debug("Updating title of taxons editor.");
|
105
|
}
|
106
|
}
|
107
|
// TODO other stuff to happen
|
108
|
|
109
|
}
|
110
|
}
|
111
|
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
public void reactOnInsert(Vector<CdmDataChangeEvent> events){
|
115
|
boolean doRedraw = false;
|
116
|
for(CdmDataChangeEvent event : events){
|
117
|
// refresh on synonym changes
|
118
|
if(input.getTaxon().hasSynonyms() && event.getEntity() instanceof Synonym){
|
119
|
Synonym synonym = (Synonym) event.getEntity();
|
120
|
|
121
|
if(synonym.isSynonymOf(input.getTaxon())){
|
122
|
doRedraw = true;
|
123
|
break;
|
124
|
}
|
125
|
}
|
126
|
}
|
127
|
// if(doRedraw)
|
128
|
// source.redraw(Page.NAME);
|
129
|
}
|
130
|
}
|