Revision fb5347e6
Added by Patrick Plitzner almost 10 years ago
- added conversation/session support to DerivateLabelProvider
- GUI widgets using the provider need to provide a conversation/session to avoid LazyInitializationException
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java | ||
---|---|---|
301 | 301 |
*/ |
302 | 302 |
@Override |
303 | 303 |
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) { |
304 |
conversation.close(); |
|
304 | 305 |
// if(memento == null){ |
305 | 306 |
// return; |
306 | 307 |
// } |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java | ||
---|---|---|
16 | 16 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
17 | 17 |
import org.eclipse.jface.viewers.TreeNode; |
18 | 18 |
import org.eclipse.swt.graphics.Image; |
19 |
import org.hibernate.LazyInitializationException; |
|
19 | 20 |
|
21 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
20 | 22 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
21 | 23 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
22 | 24 |
import eu.etaxonomy.cdm.model.molecular.Sequence; |
... | ... | |
32 | 34 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
33 | 35 |
|
34 | 36 |
/** |
35 |
* Label provider for the views to show {@link SpecimenOrObservationBase}s. |
|
37 |
* Label provider for the views to show {@link SpecimenOrObservationBase}s.<br> |
|
38 |
* <br> |
|
39 |
* <b>Note:</b> If you use this label provider you need to assure that you |
|
40 |
* created a {@link ConversationHolder} resp. have an open session because |
|
41 |
* the labels are generated from various fields of the derivate hierarchy which |
|
42 |
* are lazy loaded and could therefore throw a {@link LazyInitializationException}. |
|
36 | 43 |
*/ |
37 | 44 |
public class DerivateLabelProvider extends ColumnLabelProvider { |
38 | 45 |
|
... | ... | |
111 | 118 |
if(gatheringEvent!=null){ |
112 | 119 |
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+", ":""; |
113 | 120 |
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+", ":""; |
114 |
// label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";
|
|
121 |
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":""; |
|
115 | 122 |
label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+", ":""; |
116 | 123 |
} |
117 | 124 |
label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():""; |
... | ... | |
136 | 143 |
label += derivedUnit.getBarcode()!=null?derivedUnit.getBarcode():""; |
137 | 144 |
} |
138 | 145 |
else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){ |
139 |
|
|
146 |
// kindofTissue + SampleDesignation |
|
140 | 147 |
} |
141 | 148 |
} |
142 | 149 |
else if(element instanceof MediaSpecimen){ |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateSearchView.java | ||
---|---|---|
14 | 14 |
import org.eclipse.ui.IMemento; |
15 | 15 |
import org.eclipse.ui.part.ViewPart; |
16 | 16 |
|
17 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
17 | 18 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
18 | 19 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
19 | 20 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
26 | 27 |
|
27 | 28 |
public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView"; |
28 | 29 |
private DerivateSearchCompositeController derivateSearchCompositeController; |
30 |
private ConversationHolder conversationHolder; |
|
29 | 31 |
|
30 | 32 |
/** |
31 | 33 |
* Constructs a new DerivateSearchView and registers it to listen to context changes |
... | ... | |
50 | 52 |
@Override |
51 | 53 |
public void setFocus() { |
52 | 54 |
derivateSearchCompositeController.setFocus(); |
55 |
//make sure to bind again if maybe in another view the conversation was unbound |
|
56 |
if(getConversationHolder()!=null && !getConversationHolder().isBound()){ |
|
57 |
getConversationHolder().bind(); |
|
58 |
} |
|
53 | 59 |
} |
54 | 60 |
|
55 | 61 |
/* (non-Javadoc) |
... | ... | |
81 | 87 |
*/ |
82 | 88 |
@Override |
83 | 89 |
public void contextRefresh(IProgressMonitor monitor) { |
90 |
initConversation(); |
|
91 |
} |
|
92 |
|
|
93 |
private void initConversation(){ |
|
94 |
if(conversationHolder==null){ |
|
95 |
conversationHolder = CdmStore.createConversation(); |
|
96 |
} |
|
84 | 97 |
} |
85 | 98 |
|
86 | 99 |
/* (non-Javadoc) |
... | ... | |
88 | 101 |
*/ |
89 | 102 |
@Override |
90 | 103 |
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) { |
104 |
if(getConversationHolder()!=null){ |
|
105 |
getConversationHolder().close(); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* @return the conversationHolder |
|
111 |
*/ |
|
112 |
public ConversationHolder getConversationHolder() { |
|
113 |
if(CdmStore.isActive() && conversationHolder==null){ |
|
114 |
initConversation(); |
|
115 |
} |
|
116 |
return conversationHolder; |
|
91 | 117 |
} |
92 | 118 |
} |
Also available in: Unified diff