Project

General

Profile

Download (5.15 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.view.concept.e4;
11

    
12
import java.util.Map.Entry;
13

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

    
18
import org.eclipse.e4.core.di.annotations.Optional;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.EMenuService;
21
import org.eclipse.e4.ui.services.IServiceConstants;
22
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
23
import org.eclipse.jface.viewers.ISelection;
24
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.ListViewer;
27
import org.eclipse.jface.viewers.StructuredSelection;
28
import org.eclipse.jface.viewers.ViewerSorter;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.ui.IEditorInput;
31

    
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
34
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
35
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
36
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
37
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
38
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider;
39
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
40
import eu.etaxonomy.taxeditor.model.AbstractUtility;
41
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
42
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
43
import eu.etaxonomy.taxeditor.model.LineSelection;
44
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
45
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
46
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
47

    
48
/**
49
 *
50
 * @author pplitzner
51
 * @date 21.08.2017
52
 *
53
 */
54
public class ConceptViewPartE4 extends AbstractCdmEditorPartE4
55
implements IPartContentHasDetails, IPartContentHasSupplementalData{
56

    
57
    private ISelectionChangedListener selectionChangedListener;
58

    
59
    @Inject
60
    private ESelectionService selService;
61

    
62
    @Inject
63
    @Optional
64
    public void selectionChanged(
65
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
66
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
67
            MPart thisPart){
68
        if(activePart==thisPart){
69
            return;
70
        }
71

    
72
        Object partObject = createPartObject(activePart);
73

    
74
        if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4) {
75
            // do not show empty page as these views are also used to edit the
76
            // description selected in this view
77
            return;
78
        }
79
        else if(partObject instanceof BulkEditor && selection instanceof LineSelection){
80
			if(((LineSelection) selection).getFirstElement() instanceof Taxon){
81
				showViewer((LineSelection) selection, activePart, viewer);
82
			}
83
			else{
84
				showEmptyPage();
85
			}
86
			return;
87
		}
88
		else if(partObject instanceof AbstractGraphKeyEditor){
89
			showEmptyPage();
90
		}
91
		else if(partObject instanceof TaxonNameEditorE4){
92
		    IEditorInput input = ((TaxonNameEditorE4) partObject).getEditorInput();
93
		    if(input!=null){
94
		        showViewer(new StructuredSelection(input), activePart, viewer);
95
		    }
96
		}
97
		else {
98
		    showEmptyPage();
99
		}
100

    
101
	}
102

    
103
	@PostConstruct
104
    public void create(Composite parent, EMenuService menuService, MPart thisPart) {
105

    
106
	    this.thisPart = thisPart;
107

    
108
	    ConceptRelationViewer conceptViewer = new ConceptRelationViewer(parent);
109

    
110
	    conceptViewer.setContentProvider(new ConceptContentProvider());
111
	    conceptViewer.setLabelProvider(new ConceptLabelProvider());
112

    
113

    
114
	    conceptViewer.setSorter(new ViewerSorter());
115

    
116
		viewer = conceptViewer;
117

    
118
		// Propagate selection from viewer
119
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
120
        viewer.addSelectionChangedListener(selectionChangedListener);
121

    
122
        //create context menu
123
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
124

    
125
	}
126

    
127
	@Override
128
	public void changed(Object object) {
129
		getViewer().refresh();
130
		super.changed(object);
131
	}
132

    
133
	private class ConceptRelationViewer extends ListViewer {
134

    
135
		public ConceptRelationViewer(Composite parent) {
136
			super(parent);
137
		}
138

    
139
		@Override
140
		public ISelection getSelection() {
141
			ISelection selection = super.getSelection();
142
			if(selection instanceof IStructuredSelection && !selection.isEmpty()){
143
				Object firstElement = ((IStructuredSelection) selection).getFirstElement();
144
				TaxonRelationship taxonRelationship = ((Entry<TaxonRelationship, Taxon>)firstElement).getKey();
145
				return new StructuredSelection(taxonRelationship);
146

    
147
			}
148
			return selection;
149
		}
150

    
151
		@Override
152
		public void setSelection(ISelection selection) {
153
			super.setSelection(selection);
154
		}
155

    
156
	}
157

    
158
	@Override
159
	protected String getViewName() {
160
		return Messages.ConceptViewPart_VIEWER_NAME;
161
	}
162

    
163
}
(1-1/2)