return true;
}
else{
- MessagingUtils.warningDialog("Moving derivate not possible!", derivateView, "Moving \""+DerivateLabelProvider.getDerivateText(draggednode)+"\" to \""+DerivateLabelProvider.getDerivateText(targetNode)+"\" is not possible!");
+ DerivateLabelProvider derivateLabelProvider = new DerivateLabelProvider();
+ derivateLabelProvider.setConversation(derivateView.getConversationHolder());
+ MessagingUtils.warningDialog("Moving derivate not possible!", derivateView, "Moving \""+derivateLabelProvider.getDerivateText(draggednode)+"\" to \""+derivateLabelProvider.getDerivateText(targetNode)+"\" is not possible!");
}
}
}
Object draggedNodeValue = draggedNode.getValue();
Object targetNodeValue = targetNode.getValue();
TreeNode fromParentNode = draggedNode.getParent();
- Object fromParentSpecimen = fromParentNode.getValue();
+ Object fromParentSpecimen = null;
+ if(fromParentNode!=null){
+ fromParentNode.getValue();
+ }
// drag'n'drop for SpecimenOrObservationBase
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
viewer.setContentProvider(new DerivateContentProvider());
labelProvider = new DerivateLabelProvider();
+ labelProvider.setConversation(conversation);
viewer.setLabelProvider(labelProvider);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
// Propagate selection from viewer
if(editorInput instanceof DerivateViewEditorInput){
SpecimenOrObservationBase<?> specimen = ((DerivateViewEditorInput) editorInput).getDerivate();
SpecimenOrObservationBase<?> rootElement = ((DerivateViewEditorInput) editorInput).getRootElement();
- setPartName(DerivateLabelProvider.getDerivateText(rootElement));
+ setPartName(labelProvider.getDerivateText(rootElement));
viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
}
* <b>Note:</b> If you use this label provider you need to assure that you
* created a {@link ConversationHolder} resp. have an open session because
* the labels are generated from various fields of the derivate hierarchy which
- * are lazy loaded and could therefore throw a {@link LazyInitializationException}.
+ * are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br>
+ * Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider.
*/
public class DerivateLabelProvider extends ColumnLabelProvider {
private Set<SingleRead> multiLinkSingleReads;
+ private ConversationHolder conversation;
+
private static DefinedTerm photoTerm = null;
private static DefinedTerm drawingTerm = null;
private static DefinedTerm specimenScanTerm = null;
return getDerivateText(element);
}
+ /**
+ * @param conversation the conversation to set
+ */
+ public void setConversation(ConversationHolder conversation) {
+ this.conversation = conversation;
+ }
+
/**
*
* @param element
* @return
*/
- public static String getDerivateText(Object element){
+ public String getDerivateText(Object element){
if(element instanceof TreeNode){
//unwrap specimen from TreeNode
element = ((TreeNode) element).getValue();
}
+ conversation.bind();
+
String label = "";
if(element instanceof FieldUnit){
FieldUnit fieldUnit = (FieldUnit)element;
- GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
- if(gatheringEvent!=null){
+ if(fieldUnit.getGatheringEvent()!=null){
+ GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+ if(!conversation.getSession().contains(gatheringEvent)){
+ fieldUnit = (FieldUnit) CdmStore.getService(IOccurrenceService.class).load(fieldUnit.getUuid());
+ gatheringEvent = fieldUnit.getGatheringEvent();
+ }
label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+", ":"";
label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+", ":"";
label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.handlers.IHandlerService;
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
private final DerivateSearchComposite derivateSearchComposite;
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>> configurator;
private EnumTermComboController<SpecimenOrObservationType> enumTermComboController;
+ private DerivateLabelProvider labelProvider;
/**
* @param parent
TableViewer resultViewer = derivateSearchComposite.getResultViewer();
resultViewer.setContentProvider(new ArrayContentProvider());
- resultViewer.setLabelProvider(new DerivateLabelProvider());
+ labelProvider = new DerivateLabelProvider();
+ resultViewer.setLabelProvider(labelProvider);
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
derivateSearchComposite.getResultViewer().getControl().setFocus();
}
+ /**
+ * @param conversationHolder
+ */
+ public void setConversation(ConversationHolder conversationHolder) {
+ labelProvider.setConversation(conversationHolder);
+ }
+
}
private void initConversation(){
if(conversationHolder==null){
conversationHolder = CdmStore.createConversation();
+ derivateSearchCompositeController.setConversation(conversationHolder);
}
}