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 javax.annotation.PreDestroy;
|
12
|
|
13
|
import org.eclipse.e4.ui.di.PersistState;
|
14
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.jface.viewers.StructuredSelection;
|
17
|
import org.eclipse.jface.viewers.Viewer;
|
18
|
import org.eclipse.ui.IEditorPart;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
23
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
24
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
25
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
26
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
27
|
|
28
|
/**
|
29
|
* @author pplitzner
|
30
|
* @since Aug 10, 2017
|
31
|
*
|
32
|
*/
|
33
|
public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, IDirtyMarkable, ISelectionElementEditingPart{
|
34
|
|
35
|
protected Viewer viewer;
|
36
|
|
37
|
protected MPart selectionProvidingPart;
|
38
|
|
39
|
/** {@inheritDoc} */
|
40
|
@Override
|
41
|
public void changed(Object object) {
|
42
|
if(selectionProvidingPart!=null){
|
43
|
Object part = selectionProvidingPart.getObject();
|
44
|
if(part instanceof IDirtyMarkable){
|
45
|
((IDirtyMarkable) part).changed(object);
|
46
|
}
|
47
|
else {
|
48
|
IEditorPart editor = AbstractUtility.getActiveEditor();
|
49
|
if (editor != null && editor instanceof IDirtyMarkable) {
|
50
|
((IDirtyMarkable) editor).changed(object);
|
51
|
}
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
|
56
|
protected void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
|
57
|
if(viewer!=null){
|
58
|
Object element = selection.getFirstElement();
|
59
|
if(selection.getFirstElement()!=null){
|
60
|
viewer.setInput(element);
|
61
|
}
|
62
|
selectionProvidingPart = activePart;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
protected Object createPartObject(MPart activePart) {
|
67
|
Object partObject = activePart;
|
68
|
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
|
69
|
if(wrappedPart!=null){
|
70
|
partObject = wrappedPart;
|
71
|
}
|
72
|
return partObject;
|
73
|
}
|
74
|
|
75
|
protected void showEmptyPage() {
|
76
|
if(viewer!=null){
|
77
|
viewer.setInput(null);
|
78
|
}
|
79
|
selectionProvidingPart = null;
|
80
|
}
|
81
|
|
82
|
protected IStructuredSelection createSelection(Object selection) {
|
83
|
if(selection==null){
|
84
|
return null;
|
85
|
}
|
86
|
IStructuredSelection structuredSelection;
|
87
|
if(!(selection instanceof IStructuredSelection)){
|
88
|
structuredSelection = new StructuredSelection(selection);
|
89
|
}
|
90
|
else{
|
91
|
structuredSelection = (IStructuredSelection) selection;
|
92
|
}
|
93
|
return structuredSelection;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* {@inheritDoc}
|
98
|
*/
|
99
|
@Override
|
100
|
public ConversationHolder getConversationHolder() {
|
101
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof IConversationEnabled) {
|
102
|
return ((IConversationEnabled) selectionProvidingPart).getConversationHolder();
|
103
|
}
|
104
|
return null;
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* {@inheritDoc}
|
109
|
*/
|
110
|
@Override
|
111
|
public Object getSelectionProvidingPart() {
|
112
|
return selectionProvidingPart;
|
113
|
}
|
114
|
|
115
|
@PreDestroy
|
116
|
private void dispose() {
|
117
|
}
|
118
|
|
119
|
@PersistState
|
120
|
private void persistState(){
|
121
|
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* {@inheritDoc}
|
126
|
*/
|
127
|
@Override
|
128
|
public void update(CdmDataChangeMap arg0) {
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* {@inheritDoc}
|
133
|
*/
|
134
|
@Override
|
135
|
public void forceDirty() {
|
136
|
}
|
137
|
|
138
|
protected abstract String getViewName();
|
139
|
|
140
|
}
|