Project

General

Profile

Download (22.3 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.view.derivate;
2

    
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.Collection;
6
import java.util.Collections;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Set;
12
import java.util.UUID;
13

    
14
import javax.annotation.PostConstruct;
15
import javax.annotation.PreDestroy;
16
import javax.inject.Inject;
17
import javax.inject.Named;
18

    
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.e4.core.di.annotations.Optional;
21
import org.eclipse.e4.ui.di.Focus;
22
import org.eclipse.e4.ui.di.Persist;
23
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
24
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
25
import org.eclipse.e4.ui.services.EMenuService;
26
import org.eclipse.e4.ui.services.IServiceConstants;
27
import org.eclipse.e4.ui.workbench.modeling.EPartService;
28
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
29
import org.eclipse.jface.util.LocalSelectionTransfer;
30
import org.eclipse.jface.viewers.AbstractTreeViewer;
31
import org.eclipse.jface.viewers.ISelection;
32
import org.eclipse.jface.viewers.ISelectionChangedListener;
33
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.StructuredSelection;
35
import org.eclipse.jface.viewers.TreeNode;
36
import org.eclipse.jface.viewers.TreeSelection;
37
import org.eclipse.jface.viewers.TreeViewer;
38
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.dnd.DND;
40
import org.eclipse.swt.dnd.Transfer;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.layout.GridLayout;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Tree;
45
import org.eclipse.ui.IMemento;
46

    
47
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
48
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
49
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
50
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
51
import eu.etaxonomy.cdm.model.common.CdmBase;
52
import eu.etaxonomy.cdm.model.molecular.SingleRead;
53
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
54
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
55
import eu.etaxonomy.cdm.model.taxon.Taxon;
56
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
57
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
58
import eu.etaxonomy.taxeditor.editor.EditorUtil;
59
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
60
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
61
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
62
import eu.etaxonomy.taxeditor.model.AbstractUtility;
63
import eu.etaxonomy.taxeditor.model.IContextListener;
64
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
65
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
66
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
67
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
68
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
69
import eu.etaxonomy.taxeditor.model.MessagingUtils;
70
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
71
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
72
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
73
import eu.etaxonomy.taxeditor.store.CdmStore;
74
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
75
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
76
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
77

    
78
/**
79
 * Displays the derivate hierarchy of the specimen specified in the editor input.
80
 *
81
 */
82
public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
83
        ICdmEntitySessionEnabled, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
84
        IContextListener, IE4SavablePart {
85

    
86
    private static final String SPECIMEN_EDITOR = Messages.DerivateView_SPECIMEN_EDITOR;
87

    
88
    public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
89
    public static final String INPUT_ID = ID+".editorInput"; //$NON-NLS-1$
90

    
91
    public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
92
    public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
93

    
94
    private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
95
            "descriptions", //$NON-NLS-1$
96
            "annotations", //$NON-NLS-1$
97
            "markers", //$NON-NLS-1$
98
            "credits", //$NON-NLS-1$
99
            "extensions", //$NON-NLS-1$
100
            "rights", //$NON-NLS-1$
101
            "sources", //$NON-NLS-1$
102
            "derivationEvents.derivatives.annotations", //$NON-NLS-1$
103
            "derivationEvents.derivatives.markers", //$NON-NLS-1$
104
            "derivationEvents.derivatives.credits", //$NON-NLS-1$
105
            "derivationEvents.derivatives.extensions", //$NON-NLS-1$
106
            "derivationEvents.derivatives.rights", //$NON-NLS-1$
107
            "derivationEvents.derivatives.sources" //$NON-NLS-1$
108
    });
109

    
110
	private static final int WARN_THRESHOLD = 200;
111

    
112

    
113
	private ConversationHolder conversation;
114

    
115
	private TreeViewer viewer;
116

    
117
    private final int dndOperations = DND.DROP_MOVE;
118

    
119
    private DerivateLabelProvider labelProvider;
120

    
121
    private DerivateContentProvider contentProvider;
122

    
123
    private DerivateSearchCompositeController derivateSearchCompositeController;
124

    
125
    /**
126
     * A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
127
     * and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
128
     */
129
    private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
130

    
131
    /**
132
     * The set of root elements
133
     */
134
    private Set<SpecimenOrObservationBase<?>> rootElements;
135

    
136
    private ICdmEntitySession cdmEntitySession;
137

    
138
    /**
139
     * <code>true</code> if this view is listening to selection  changes
140
     */
141
    private boolean listenToSelectionChange;
142

    
143
    private Taxon selectedTaxon;
144

    
145
    @Inject
146
    private ESelectionService selService;
147

    
148
    @Inject
149
    private MDirtyable dirty;
150

    
151
    @Inject
152
    private EPartService partService;
153

    
154
    private ISelectionChangedListener selectionChangedListener;
155

    
156
    /**
157
     * Default constructor
158
     */
159
    @Inject
160
    public DerivateView() {
161
    }
162

    
163
    /**
164
     * {@inheritDoc}
165
     */
166
    public void init(DerivateViewEditorInput editorInput){
167
        this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
168
        this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
169

    
170
        //init tree
171
        Collection<UUID> derivativeUuids = editorInput.getDerivativeUuids();
172
        checkWarnThreshold(derivativeUuids);
173
        updateRootEntities(derivativeUuids);
174
        //set taxon filter
175
        derivateSearchCompositeController.setTaxonFilter(editorInput.getTaxonUuid());
176
        //reset status bar
177
        //TODO e4
178
//        getEditorSite().getActionBars().getStatusLineManager().setMessage(""); //$NON-NLS-1$
179
    }
180

    
181
    @PostConstruct
182
    public void createPartControl(Composite parent, EMenuService menuService, MPart thisPart) {
183
        if (CdmStore.isActive()){
184
            if(conversation == null){
185
                conversation = CdmStore.createConversation();
186
            }
187
            cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
188
        }
189
        else{
190
            return;
191
        }
192
        //listen to context changes
193
        CdmStore.getContextManager().addContextListener(this);
194

    
195
        parent.setLayout(new GridLayout());
196

    
197
        //---search and filter---
198
        derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
199
        GridData gridDataSearchBar = new GridData();
200
        gridDataSearchBar.horizontalAlignment = GridData.FILL;
201
        gridDataSearchBar.grabExcessHorizontalSpace = true;
202
        derivateSearchCompositeController.setLayoutData(gridDataSearchBar);
203
        derivateSearchCompositeController.setEnabled(CdmStore.isActive());
204

    
205
        //---tree viewer---
206
        viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
207
        GridData gridDataTree = new GridData();
208
        gridDataTree.horizontalAlignment = GridData.FILL;
209
        gridDataTree.verticalAlignment = GridData.FILL;
210
        gridDataTree.grabExcessVerticalSpace = true;
211
        gridDataTree.grabExcessHorizontalSpace = true;
212
        viewer.getTree().setLayoutData(gridDataTree);
213
        contentProvider = new DerivateContentProvider();
214
        viewer.setContentProvider(contentProvider);
215
        labelProvider = new DerivateLabelProvider();
216
        labelProvider.setConversation(conversation);
217
        viewer.setLabelProvider(labelProvider);
218
        viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
219
        viewer.getTree().setEnabled(CdmStore.isActive());
220

    
221
        //propagate selection
222
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
223
        viewer.addSelectionChangedListener(selectionChangedListener);
224

    
225
        //create context menu
226
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor");
227

    
228
        //add drag'n'drop support
229
        Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),};
230
        viewer.addDragSupport(dndOperations, transfers, new DerivateDragListener(this));
231
        viewer.addDropSupport(dndOperations, transfers, new DerivateDropListener(this));
232
    }
233

    
234
    public void updateRootEntities() {
235
        updateRootEntities((Collection)null);
236
    }
237

    
238
    public void updateRootEntities(Collection<UUID> derivativeUuids) {
239
        if(conversation!=null){
240
            if (!conversation.isBound()) {
241
                conversation.bind();
242
            }
243
            /*
244
             * If the active session is not the session of the Derivative Editor
245
             * then we will save the active session for later, bind temporarily
246
             * to our session and rebind to the original session when we are
247
             * done. This happens e.g. if a selection change happens in the
248
             * taxon editor and "Link with editor" is enabled. The selection
249
             * change event and thus the loading in updateRootEntities() happens
250
             * in the session of the taxon editor.
251
             */
252
            ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
253
            if(cdmEntitySession != null) {
254
                cdmEntitySession.bind();
255
            }
256

    
257
            List<SpecimenOrObservationBase> derivates = null;
258
            if(derivativeUuids!=null){
259
                this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
260
                this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
261
                derivates = CdmStore.getService(IOccurrenceService.class).load(new ArrayList(derivativeUuids), SPECIMEN_INIT_STRATEGY);
262
            }
263
            updateRootEntities(derivates);
264
            previousCdmEntitySession.bind();
265
        }
266
    }
267

    
268

    
269
    public void updateRootEntities(List<SpecimenOrObservationBase> derivates) {
270
        if(derivates!=null){
271
            this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
272
            this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
273
            for (SpecimenOrObservationBase derivate : derivates) {
274

    
275
                if(derivate instanceof FieldUnit){
276
                    derivateToRootEntityMap.put(derivate, derivate);
277
                }
278
                else {
279
                    SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
280
                    if(topMostDerivate!=null){
281
                        derivateToRootEntityMap.put(derivate, topMostDerivate);
282
                    }
283
                    else{
284
                        derivateToRootEntityMap.put(derivate, derivate);
285
                    }
286
                }
287
            }
288
            for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
289
                rootElements.add(specimen);
290
            }
291
        }
292
        labelProvider.updateLabelCache(rootElements);
293
        viewer.setInput(rootElements);
294

    
295
        //TODO e4
296
        //            getEditorSite().getActionBars().getStatusLineManager().setMessage(String.format(Messages.DerivateView_CNT_DERIVATIVES_FOUND, rootElements.size()));
297

    
298
        //set selection to derivatives if the filter criteria
299
        //taxon assignment or derivative type are set
300
        if(derivates!=null && !derivateSearchCompositeController.isDefaultSearch()){
301
            List<TreeNode> nodesToSelect = new ArrayList<TreeNode>();
302
            for (SpecimenOrObservationBase specimenOrObservationBase : derivates) {
303
                nodesToSelect.add(new TreeNode(specimenOrObservationBase));
304
            }
305
            setSelection(new StructuredSelection(nodesToSelect));
306
        }
307
        else{
308
            setSelection(null);
309
        }
310
    }
311

    
312
    private void setSelection(StructuredSelection selection){
313
        viewer.removeSelectionChangedListener(selectionChangedListener);
314
        viewer.setSelection(selection);
315
        viewer.addSelectionChangedListener(selectionChangedListener);
316
    }
317

    
318
    public void updateLabelCache(){
319
        labelProvider.updateLabelCache(rootElements);
320
    }
321

    
322
    @Persist
323
    @Override
324
    public void save(IProgressMonitor monitor) {
325
        String taskName = Messages.DerivateView_SAVING_HIERARCHY;
326
        monitor.beginTask(taskName, 3);
327
        if (!conversation.isBound()) {
328
            conversation.bind();
329
        }
330
        monitor.worked(1);
331

    
332
        // commit the conversation and start a new transaction immediately
333
        conversation.commit(true);
334

    
335
        CdmStore.getService(IOccurrenceService.class).merge(new ArrayList<SpecimenOrObservationBase>(rootElements), true);
336

    
337
        monitor.worked(1);
338

    
339
        this.setDirty(false);
340
        monitor.worked(1);
341
        monitor.done();
342
        dirty.setDirty(false);
343
        refreshTree();
344
    }
345

    
346
    /**
347
     * @param isDirty the isDirty to set
348
     */
349
    public void setDirty(boolean isDirty) {
350
        dirty.setDirty(isDirty);
351
    }
352

    
353
    @Focus
354
    public void setFocus() {
355
        //make sure to bind again if maybe in another view the conversation was unbound
356
        if(conversation!=null && !conversation.isBound()){
357
            conversation.bind();
358
        }
359
        if(cdmEntitySession != null) {
360
            cdmEntitySession.bind();
361
        }
362
        if(derivateSearchCompositeController!=null) {
363
            derivateSearchCompositeController.setFocusOnSearchField();
364
        }
365
    }
366

    
367
    @Override
368
    public void update(CdmDataChangeMap changeEvents) {
369
    }
370

    
371
    @Override
372
    public ConversationHolder getConversationHolder() {
373
        return conversation;
374
    }
375

    
376
    @Override
377
    public void changed(Object element) {
378
        setDirty(true);
379
        //firePropertyChange(IEditorPart.PROP_DIRTY);
380
        viewer.update(new TreeNode(element), null);
381
    }
382

    
383
    @Override
384
    public void forceDirty() {
385
        changed(null);
386
    }
387

    
388
    @Override
389
    public Map<Object, List<String>> getPropertyPathsMap() {
390
        List<String> specimenPropertyPaths = Arrays.asList(new String[] {
391
                "descriptions", //$NON-NLS-1$
392
                "derivationEvents.derivates", //$NON-NLS-1$
393
                "annotations", //$NON-NLS-1$
394
                "markers", //$NON-NLS-1$
395
                "credits", //$NON-NLS-1$
396
                "extensions", //$NON-NLS-1$
397
                "rights", //$NON-NLS-1$
398
                "sources" //$NON-NLS-1$
399
        });
400
        Map<Object, List<String>> specimenPropertyPathMap =
401
                new HashMap<Object, List<String>>();
402
        specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
403
        return specimenPropertyPathMap;
404
    }
405

    
406
    /**
407
     * Refreshes the derivate hierarchy tree and expands the tree
408
     * to show and select the given object.
409
     *
410
     * @param expandTo the object to which the tree should be expanded
411
     */
412
    public void refreshTree(Object expandTo){
413
        refreshTree();
414
        TreeSelection selection = (TreeSelection) viewer.getSelection();
415
        viewer.expandToLevel(selection.getFirstElement(), 1);
416
        viewer.setSelection(new StructuredSelection(new TreeNode(expandTo)));
417
    }
418

    
419
    /**
420
     * Refreshes the derivate hierarchy tree
421
     */
422
    public void refreshTree(){
423
    	if(!viewer.getTree().isDisposed()){
424
    		viewer.refresh();
425
    	}
426
    }
427

    
428
    //FIXME:Remoting hack to make this work for remoting
429
    //This should actually be resolved using remoting post operations
430
    public void remove(Object obj) {
431
        if (obj instanceof TreeNode){
432
            obj = ((TreeNode)obj).getValue();
433
        }
434
        rootElements.remove(obj);
435
        Object o = this.derivateToRootEntityMap.remove(obj);
436
        viewer.setInput(rootElements);
437
    }
438

    
439
    /**
440
     * @return a set of {@link SingleRead}s that have multiple parents
441
     */
442
    public Set<SingleRead> getMultiLinkSingleReads() {
443
        return DerivateLabelProvider.getMultiLinkSingleReads();
444
    }
445

    
446
    public Object getSelectionInput() {
447
        return selectedTaxon;
448
    }
449

    
450
    public DerivateLabelProvider getLabelProvider() {
451
        return labelProvider;
452
    }
453

    
454
    @Override
455
    public boolean postOperation(CdmBase objectAffectedByOperation) {
456
        refreshTree();
457
        if(objectAffectedByOperation!=null){
458
            changed(objectAffectedByOperation);
459
        }
460
        return true;
461
    }
462

    
463
    @Override
464
    public boolean onComplete() {
465
        return true;
466
    }
467

    
468

    
469
    @Override
470
    public boolean canAttachMedia() {
471
        return true;
472
    }
473

    
474
    public void addFieldUnit(FieldUnit fieldUnit) {
475
        rootElements.add(fieldUnit);
476
        derivateToRootEntityMap.put(fieldUnit, fieldUnit);
477
    }
478

    
479
    @Override
480
    public ICdmEntitySession getCdmEntitySession() {
481
        return cdmEntitySession;
482
    }
483

    
484
    @PreDestroy
485
    public void dispose() {
486
        if(conversation!=null){
487
            conversation.close();
488
        }
489
        if(cdmEntitySession != null) {
490
            cdmEntitySession.dispose();
491
        }
492
    }
493

    
494

    
495
    @Inject
496
    @Optional
497
    public void selectionChanged(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection,
498
            @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MPart thisPart)
499
    {
500
    	if(activePart == thisPart || viewer==null){
501
            return;
502
        }
503
        if(viewer.getTree().isDisposed()){
504
            return;
505
        }
506
        if(listenToSelectionChange){
507
            selectedTaxon = null;
508
            if(activePart instanceof MultiPageTaxonEditor){
509
                selectedTaxon = ((MultiPageTaxonEditor) activePart).getTaxon();
510
            }
511
            else if(selection instanceof IStructuredSelection){
512
                Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
513
                if(selectedElement instanceof CdmBase){
514
                    if(((CdmBase) selectedElement).isInstanceOf(TaxonNode.class)){
515
                        selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, TaxonNode.class).getTaxon();
516
                    }
517
                    else if(((CdmBase) selectedElement).isInstanceOf(Taxon.class)){
518
                        selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, Taxon.class);
519
                    }
520
                }
521
            }
522
            if(selectedTaxon!=null){
523
                Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(selectedTaxon, null, null);
524
                Collection<UUID> uuids = new HashSet<UUID>();
525
                for (SpecimenOrObservationBase specimenOrObservationBase : fieldUnits) {
526
                    uuids.add(specimenOrObservationBase.getUuid());
527
                }
528
                checkWarnThreshold(uuids);
529
                updateRootEntities(uuids);
530

    
531
                thisPart.setLabel(SPECIMEN_EDITOR+": " + selectedTaxon.getName()); //$NON-NLS-1$
532
            }
533
            else{
534
                updateRootEntities((Collection<UUID>)Collections.EMPTY_LIST);
535
            }
536
        }
537
    }
538

    
539
	private void checkWarnThreshold(Collection<UUID> uuids) {
540
		if(uuids!=null && uuids.size()>WARN_THRESHOLD){
541
			MessagingUtils.warningDialog(Messages.DerivateView_PERF_WARNING, this.getClass(), String.format(Messages.DerivateView_PERF_WARNING_MESSAGE, uuids.size()));
542
			uuids.clear();
543
		}
544
	}
545

    
546
    public TreeViewer getViewer() {
547
        return viewer;
548
    }
549

    
550
    /**
551
     * {@inheritDoc}
552
     */
553
    @Override
554
    public List<SpecimenOrObservationBase<?>> getRootEntities() {
555
        return new ArrayList<SpecimenOrObservationBase<?>>(rootElements);
556
    }
557

    
558
    public void toggleListenToSelectionChange(MPart part) {
559
        listenToSelectionChange = !listenToSelectionChange;
560
        derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
561
        if(!listenToSelectionChange){
562
            selectedTaxon = null;
563
            part.setLabel(SPECIMEN_EDITOR);
564
        }
565
        else if(selectedTaxon==null){
566
            part.setLabel(SPECIMEN_EDITOR+Messages.DerivateView_NO_TAXON_SELECTED);
567
        }
568
    }
569

    
570
    public boolean isListenToSelectionChange(){
571
        return listenToSelectionChange;
572
    }
573

    
574
    /**
575
     * {@inheritDoc}
576
     */
577
    @Override
578
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
579
    }
580

    
581
    /**
582
     * {@inheritDoc}
583
     */
584
    @Override
585
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
586
        derivateSearchCompositeController.setEnabled(false);
587
        if(!viewer.getTree().isDisposed()) {
588
            viewer.getTree().setEnabled(false);
589
            viewer.setInput(null);
590
        }
591
    }
592

    
593
    /**
594
     * {@inheritDoc}
595
     */
596
    @Override
597
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
598
        derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
599
        if(!viewer.getTree().isDisposed()){
600
            viewer.getTree().setEnabled(true);
601
        }
602
        refreshTree();
603
    }
604

    
605
    /**
606
     * {@inheritDoc}
607
     */
608
    @Override
609
    public void contextRefresh(IProgressMonitor monitor) {
610
    }
611

    
612
    /**
613
     * {@inheritDoc}
614
     */
615
    @Override
616
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
617
    }
618

    
619

    
620
    public boolean isDirty() {
621
        return dirty.isDirty();
622
    }
623

    
624
}
(3-3/6)