1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.taxeditor.view.e4;
|
10
|
|
11
|
import java.util.Set;
|
12
|
|
13
|
import javax.annotation.PreDestroy;
|
14
|
|
15
|
import org.eclipse.e4.ui.di.PersistState;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
import org.eclipse.jface.viewers.StructuredSelection;
|
19
|
import org.eclipse.jface.viewers.Viewer;
|
20
|
import org.eclipse.ui.IEditorPart;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
23
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
24
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
29
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
30
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
31
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
32
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
33
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
34
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
35
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
36
|
|
37
|
/**
|
38
|
* @author pplitzner
|
39
|
* @since Aug 10, 2017
|
40
|
*
|
41
|
*/
|
42
|
public abstract class AbstractCdmEditorPartE4
|
43
|
implements IConversationEnabled, IDirtyMarkable, ISelectionElementEditingPart, IPostOperationEnabled{
|
44
|
|
45
|
protected Viewer viewer;
|
46
|
|
47
|
protected MPart thisPart;
|
48
|
|
49
|
protected MPart selectionProvidingPart;
|
50
|
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
public void changed(Object object) {
|
54
|
if(selectionProvidingPart!=null){
|
55
|
Object part = selectionProvidingPart.getObject();
|
56
|
if(part instanceof IDirtyMarkable){
|
57
|
((IDirtyMarkable) part).changed(object);
|
58
|
}
|
59
|
else {
|
60
|
IEditorPart editor = AbstractUtility.getActiveEditor();
|
61
|
if (editor != null && editor instanceof IDirtyMarkable) {
|
62
|
((IDirtyMarkable) editor).changed(object);
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
if(object!=null){
|
67
|
createPartTitle(object);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
protected void createPartTitle(Object selectedObject){
|
72
|
if(thisPart!=null){
|
73
|
if(selectedObject!=null){
|
74
|
thisPart.setLabel(getViewName()+": "+selectedObject); //$NON-NLS-1$
|
75
|
}
|
76
|
else{
|
77
|
thisPart.setLabel(getViewName());
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
|
82
|
public Viewer getViewer() {
|
83
|
return viewer;
|
84
|
}
|
85
|
|
86
|
protected void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
|
87
|
if(viewer!=null){
|
88
|
Object element = selection.getFirstElement();
|
89
|
if(selection.getFirstElement()!=null){
|
90
|
if (element instanceof Taxon){
|
91
|
Taxon taxon = HibernateProxyHelper.deproxy(element, Taxon.class);
|
92
|
if (taxon.isMisapplication()){
|
93
|
Object part = createPartObject(activePart);
|
94
|
if(part instanceof ITaxonEditor){
|
95
|
Taxon accepted = ((ITaxonEditor) part).getTaxon();
|
96
|
|
97
|
// Taxon accepted= ((ITaxonEditor)activePart).getTaxon();
|
98
|
Set<TaxonRelationship> rels = taxon.getTaxonRelations(accepted);
|
99
|
|
100
|
if (rels.iterator().hasNext()){
|
101
|
TaxonRelationship rel = rels.iterator().next();
|
102
|
if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
|
103
|
viewer.setInput(rel);
|
104
|
|
105
|
return;
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
|
110
|
|
111
|
}
|
112
|
}
|
113
|
viewer.setInput(element);
|
114
|
|
115
|
createPartTitle(element);
|
116
|
|
117
|
}
|
118
|
selectionProvidingPart = activePart;
|
119
|
}
|
120
|
}
|
121
|
|
122
|
protected Object createPartObject(MPart activePart) {
|
123
|
Object partObject = activePart;
|
124
|
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
|
125
|
if(wrappedPart!=null){
|
126
|
partObject = wrappedPart;
|
127
|
}
|
128
|
return partObject;
|
129
|
}
|
130
|
|
131
|
protected void showEmptyPage() {
|
132
|
if(viewer!=null){
|
133
|
viewer.setInput(null);
|
134
|
}
|
135
|
selectionProvidingPart = null;
|
136
|
}
|
137
|
|
138
|
protected IStructuredSelection createSelection(Object selection) {
|
139
|
if(selection==null){
|
140
|
return null;
|
141
|
}
|
142
|
IStructuredSelection structuredSelection;
|
143
|
if(!(selection instanceof IStructuredSelection)){
|
144
|
structuredSelection = new StructuredSelection(selection);
|
145
|
}
|
146
|
else{
|
147
|
structuredSelection = (IStructuredSelection) selection;
|
148
|
}
|
149
|
return structuredSelection;
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* {@inheritDoc}
|
154
|
*/
|
155
|
@Override
|
156
|
public ConversationHolder getConversationHolder() {
|
157
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof IConversationEnabled) {
|
158
|
return ((IConversationEnabled) selectionProvidingPart).getConversationHolder();
|
159
|
}
|
160
|
return null;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* {@inheritDoc}
|
165
|
*/
|
166
|
@Override
|
167
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
168
|
changed(objectAffectedByOperation);
|
169
|
return true;
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* {@inheritDoc}
|
174
|
*/
|
175
|
@Override
|
176
|
public boolean onComplete() {
|
177
|
viewer.refresh();
|
178
|
return true;
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* {@inheritDoc}
|
183
|
*/
|
184
|
@Override
|
185
|
public Object getSelectionProvidingPart() {
|
186
|
return selectionProvidingPart;
|
187
|
}
|
188
|
|
189
|
@PreDestroy
|
190
|
private void dispose() {
|
191
|
}
|
192
|
|
193
|
@PersistState
|
194
|
private void persistState(){
|
195
|
|
196
|
}
|
197
|
|
198
|
/**
|
199
|
* {@inheritDoc}
|
200
|
*/
|
201
|
@Override
|
202
|
public void update(CdmDataChangeMap arg0) {
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* {@inheritDoc}
|
207
|
*/
|
208
|
@Override
|
209
|
public void forceDirty() {
|
210
|
}
|
211
|
|
212
|
protected abstract String getViewName();
|
213
|
|
214
|
}
|