Project

General

Profile

« Previous | Next » 

Revision f13a970a

Added by Patrick Plitzner almost 7 years ago

ref #6596 Refactored selection handling to support e3 and e4 parts

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewPart.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.view.detail;
11 11

  
12
import java.util.Collection;
13

  
12 14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.workbench.modeling.EPartService;
13 17
import org.eclipse.jface.viewers.ISelection;
14 18
import org.eclipse.jface.viewers.IStructuredSelection;
15 19
import org.eclipse.jface.viewers.TreeNode;
......
30 34
import eu.etaxonomy.taxeditor.model.IContextListener;
31 35
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
32 36
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
37
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
33 38
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
34 39

  
35 40
/**
......
46 51

  
47 52
	private DetailsViewer viewer;
48 53

  
54
	//FIXME E4: this can be removed when working with E4 event system
55
	private Object selectionProvidingPart;
56

  
49 57
	/** {@inheritDoc} */
50 58
	@Override
51 59
	public void createViewer(Composite parent) {
......
55 63
	}
56 64

  
57 65
	@Override
58
    protected void selectionChanged_internal(IWorkbenchPart part, ISelection selection){
59
	    if(AbstractUtility.getActiveEditor() == null && !(AbstractUtility.getActivePart() instanceof IConversationEnabled)){
66
    protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
67
	    Object part = workbenchPart;
68
	    Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
69
	    if(wrappedPart!=null){
70
	        part = wrappedPart;
71
	    }
72
	    if(AbstractUtility.getActiveE4Editor() == null && !(AbstractUtility.getActiveE4Part() instanceof IConversationEnabled)){
60 73
            showEmptyPage();
61 74
            return;
62 75
        }
63 76

  
64
	    if(AbstractUtility.getActiveEditor() == null &&
65
	            selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() !=null){
66
	        //special case where the details view still open with details about the closed object #5495
67
	        showEmptyPage();
77
	    //special case where the details view still open with details about the closed object #5495
78
	    try{
79
	        boolean isSelectionProvidingPartStillActive = false;
80
	        if(selectionProvidingPart!=null){
81
	            EPartService partService = TaxeditorStorePlugin.getDefault().getWorkbench().getService(EPartService.class);
82
	            Collection<MPart> parts = partService.getParts();
83
	            for (MPart mPart : parts) {
84
	                if(selectionProvidingPart.equals(mPart.getObject())){
85
	                    isSelectionProvidingPartStillActive = true;
86
	                    break;
87
	                }
88
	            }
89
	            if(!isSelectionProvidingPartStillActive &&
90
	                    selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() !=null){
91
	                showEmptyPage();
92
	                return;
93
	            }
94
	        }
95
	    }catch(IllegalStateException e){
96
	        //nothing
97
	    }
98

  
99
	    if(part == this){
68 100
	        return;
69 101
	    }
70
        if(part == this){
71
            return;
72
        }
73 102

  
74 103
        if(!(selection instanceof IStructuredSelection)){
75 104
            return;
......
92 121
                    return;
93 122
                }
94 123
            }
124
            selectionProvidingPart = part;
95 125
            showViewer(part, structuredSelection);
96 126
        }else{
97 127
            showEmptyPage();
......
122 152

  
123 153
	@Override
124 154
	public void showEmptyPage() {
155
	    selectionProvidingPart = null;
125 156
	    viewer.setSelection(null);
126 157
	    super.showEmptyPage();
127 158
	}

Also available in: Unified diff