Project

General

Profile

« Previous | Next » 

Revision 49d3c2dd

Added by Katja Luther over 1 year ago

ref #10186: remove conversation holder

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
63 63
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
64 64

  
65 65
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
66
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
67 66
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
68 67
import eu.etaxonomy.cdm.api.service.ITaxonService;
69 68
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
......
102 101
/**
103 102
 * Displays the derivate hierarchy of the specimen specified in the editor input.
104 103
 */
105
public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
104
public class DerivateView implements IPartContentHasFactualData, 
106 105
        ICdmEntitySessionEnabled<SpecimenOrObservationBase<?>>, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
107 106
        IContextListener, IE4SavablePart, ICollapsableExpandable {
108 107

  
......
131 130
    });
132 131

  
133 132
	private static final int WARN_THRESHOLD = 200;
134

  
135

  
136
	private ConversationHolder conversation;
137

  
133
	
138 134
	private TreeViewer viewer;
139 135

  
140 136
    private final int dndOperations = DND.DROP_MOVE;
......
207 203
    public void createPartControl(Composite parent, EMenuService menuService,
208 204
            IEclipseContext context) {
209 205
        if (CdmStore.isActive()){
210
            if(conversation == null){
211
                conversation = CdmStore.createConversation();
212
            }
213 206
            if(cdmEntitySession == null){
214 207
                cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
215 208
            }
......
241 234
        contentProvider = new DerivateContentProvider();
242 235
        viewer.setContentProvider(contentProvider);
243 236
        labelProvider = new DerivateLabelProvider();
244
        labelProvider.setConversation(conversation);
237
        
245 238
        viewer.setLabelProvider(labelProvider);
246 239
        viewer.getTree().setEnabled(CdmStore.isActive());
247 240

  
......
265 258
    }
266 259

  
267 260
    public void updateRootEntities(Collection<UUID> derivativeUuids) {
268
        if(conversation!=null){
269
            if (!conversation.isBound()) {
270
                conversation.bind();
271
            }
272
            /*
273
             * If the active session is not the session of the Derivative Editor
274
             * then we will save the active session for later, bind temporarily
275
             * to our session and rebind to the original session when we are
276
             * done. This happens e.g. if a selection change happens in the
277
             * taxon editor and "Link with editor" is enabled. The selection
278
             * change event and thus the loading in updateRootEntities() happens
279
             * in the session of the taxon editor.
280
             */
281
            ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
282
            if(cdmEntitySession != null) {
283
                cdmEntitySession.bind();
284
            }
285
            eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, null);
286
            List<SpecimenOrObservationBase> derivates = null;
287
            if(derivativeUuids!=null){
288
                this.derivateToRootEntityMap = new HashMap<>();
289
                this.rootElements = new HashSet<>();
290
                derivates = CdmStore.getService(IOccurrenceService.class).load(new ArrayList(derivativeUuids), SPECIMEN_INIT_STRATEGY);
291
            }
292
            updateRootEntities(derivates);
293
            if(previousCdmEntitySession!=null){
294
                previousCdmEntitySession.bind();
295
            }
261
        
262
        /*
263
         * If the active session is not the session of the Derivative Editor
264
         * then we will save the active session for later, bind temporarily
265
         * to our session and rebind to the original session when we are
266
         * done. This happens e.g. if a selection change happens in the
267
         * taxon editor and "Link with editor" is enabled. The selection
268
         * change event and thus the loading in updateRootEntities() happens
269
         * in the session of the taxon editor.
270
         */
271
        ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
272
        if(cdmEntitySession != null) {
273
            cdmEntitySession.bind();
274
        }
275
        eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, null);
276
        List<SpecimenOrObservationBase> derivates = null;
277
        if(derivativeUuids!=null){
278
            this.derivateToRootEntityMap = new HashMap<>();
279
            this.rootElements = new HashSet<>();
280
            derivates = CdmStore.getService(IOccurrenceService.class).load(new ArrayList(derivativeUuids), SPECIMEN_INIT_STRATEGY);
281
        }
282
        updateRootEntities(derivates);
283
        if(previousCdmEntitySession!=null){
284
            previousCdmEntitySession.bind();
296 285
        }
286
        
297 287
    }
298 288

  
299 289
    public void updateRootEntities(List<SpecimenOrObservationBase> derivates) {
......
366 356
    public void save(IProgressMonitor monitor) {
367 357
        String taskName = Messages.DerivateView_SAVING_HIERARCHY;
368 358
        monitor.beginTask(taskName, 3);
369
        if (!conversation.isBound()) {
370
            conversation.bind();
371
            if (!cdmEntitySession.isActive()){
372
                cdmEntitySession.bind();
373
            }
359
        
360
        if (!cdmEntitySession.isActive()){
361
        	cdmEntitySession.bind();
374 362
        }
363
        
375 364
        monitor.worked(1);
376 365

  
377
        // commit the conversation and start a new transaction immediately
378
        conversation.commit(true);
379

  
380 366
        for(AbstractPostOperation entry:operations){
381 367
            IStatus status = Status.CANCEL_STATUS;
382 368
            final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
......
433 419

  
434 420
    @Focus
435 421
    public void setFocus() {
436
        //make sure to bind again if maybe in another view the conversation was unbound
437
        if(conversation!=null && !conversation.isBound()){
438
            conversation.bind();
439
        }
422
        //make sure to bind again if maybe in another view the session was unbound
423
        
440 424
        if(cdmEntitySession != null) {
441 425
            cdmEntitySession.bind();
442 426
        }
......
446 430
        }
447 431
    }
448 432

  
449
    @Override
450
    public void update(CdmDataChangeMap changeEvents) {
451
    }
452

  
453
    @Override
454
    public ConversationHolder getConversationHolder() {
455
        return conversation;
456
    }
457

  
458 433
    @Override
459 434
    public void changed(Object element) {
460 435
        setDirty(true);
......
565 540

  
566 541
    @PreDestroy
567 542
    public void dispose() {
568
        if(conversation!=null){
569
            conversation.close();
570
            conversation = null;
571
        }
572
        if(cdmEntitySession != null) {
543
    	if(cdmEntitySession != null) {
573 544
            cdmEntitySession.dispose();
574 545
            cdmEntitySession = null;
575 546
        }

Also available in: Unified diff