1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.key.e4;
|
5
|
|
6
|
import javax.inject.Inject;
|
7
|
|
8
|
import org.eclipse.e4.ui.di.Focus;
|
9
|
import org.eclipse.e4.ui.di.Persist;
|
10
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
11
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
12
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
13
|
import org.eclipse.jface.action.IToolBarManager;
|
14
|
import org.eclipse.jface.viewers.IBaseLabelProvider;
|
15
|
import org.eclipse.jface.viewers.IContentProvider;
|
16
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
17
|
import org.eclipse.jface.viewers.StructuredSelection;
|
18
|
import org.eclipse.swt.widgets.Composite;
|
19
|
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
|
20
|
import org.eclipse.zest.core.viewers.GraphViewer;
|
21
|
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
|
22
|
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
|
23
|
import org.eclipse.zest.layouts.LayoutAlgorithm;
|
24
|
import org.eclipse.zest.layouts.LayoutStyles;
|
25
|
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
28
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29
|
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
|
30
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
31
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
32
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
|
33
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
34
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
35
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
36
|
|
37
|
/**
|
38
|
*
|
39
|
* @author pplitzner
|
40
|
* @since Sep 28, 2017
|
41
|
*
|
42
|
* @param <T>
|
43
|
*/
|
44
|
public abstract class AbstractGraphKeyEditorE4<T extends IIdentificationKey>
|
45
|
implements IConversationEnabled,
|
46
|
IZoomableWorkbenchPart, IPostOperationEnabled,
|
47
|
IDirtyMarkable {
|
48
|
|
49
|
protected CdmFormFactory formFactory;
|
50
|
protected Composite container;
|
51
|
protected GraphViewer viewer;
|
52
|
|
53
|
private LayoutAlgorithm layoutAlgoritm;
|
54
|
private ZoomContributionViewItem zoomContributionViewItem;
|
55
|
|
56
|
private IToolBarManager toolBarManager;
|
57
|
|
58
|
private PolytomousKeyEditorInput input;
|
59
|
|
60
|
@Inject
|
61
|
protected ESelectionService selService;
|
62
|
|
63
|
@Inject
|
64
|
private MDirtyable dirty;
|
65
|
|
66
|
protected ISelectionChangedListener selectionChangedListener;
|
67
|
|
68
|
@Inject
|
69
|
private MPart thisPart;
|
70
|
|
71
|
@Persist
|
72
|
public void doSave() {
|
73
|
getConversationHolder().commit(true);
|
74
|
setDirty(false);
|
75
|
viewer.refresh();
|
76
|
}
|
77
|
|
78
|
public void init(PolytomousKeyEditorInput input) {
|
79
|
this.input = input;
|
80
|
|
81
|
|
82
|
viewer.setInput(getKey());
|
83
|
}
|
84
|
|
85
|
public boolean isDirty() {
|
86
|
return dirty.isDirty();
|
87
|
}
|
88
|
|
89
|
public PolytomousKeyEditorInput getEditorInput() {
|
90
|
return input;
|
91
|
}
|
92
|
|
93
|
//FIXME E4 migrate
|
94
|
// private void createToolbar() {
|
95
|
// getToolBarManager().add(getZoomContributionViewItem());
|
96
|
// }
|
97
|
|
98
|
protected abstract IBaseLabelProvider getLabelProvider();
|
99
|
|
100
|
protected abstract IContentProvider getContentProvider();
|
101
|
|
102
|
/**
|
103
|
* Return the key that this editor
|
104
|
*
|
105
|
* @return
|
106
|
*/
|
107
|
public abstract T getKey();
|
108
|
|
109
|
@Focus
|
110
|
public void setFocus() {
|
111
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()) {
|
112
|
viewer.getControl().setFocus();
|
113
|
}
|
114
|
}
|
115
|
|
116
|
public void refresh() {
|
117
|
viewer.refresh();
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public void update(CdmDataChangeMap changeEvents) {
|
122
|
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public AbstractZoomableViewer getZoomableViewer() {
|
127
|
return viewer;
|
128
|
}
|
129
|
|
130
|
protected LayoutAlgorithm getLayoutAlgoritm() {
|
131
|
if (layoutAlgoritm == null) {
|
132
|
// layoutAlgoritm = new CompositeLayoutAlgorithm(
|
133
|
// LayoutStyles.NO_LAYOUT_NODE_RESIZING,
|
134
|
// new LayoutAlgorithm[] {
|
135
|
// new TreeLayoutAlgorithm(
|
136
|
// LayoutStyles.NO_LAYOUT_NODE_RESIZING),
|
137
|
// new HorizontalShift(
|
138
|
// LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
|
139
|
|
140
|
layoutAlgoritm = new TreeLayoutAlgorithm(
|
141
|
LayoutStyles.NO_LAYOUT_NODE_RESIZING);
|
142
|
layoutAlgoritm.setEntityAspectRatio(0.5);
|
143
|
}
|
144
|
return layoutAlgoritm;
|
145
|
}
|
146
|
|
147
|
private ZoomContributionViewItem getZoomContributionViewItem() {
|
148
|
if (zoomContributionViewItem == null) {
|
149
|
zoomContributionViewItem = new ZoomContributionViewItem(this);
|
150
|
}
|
151
|
return new ZoomContributionViewItem(this);
|
152
|
}
|
153
|
|
154
|
@Override
|
155
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
156
|
setDirty(true);
|
157
|
refresh();
|
158
|
|
159
|
if (objectAffectedByOperation instanceof PolytomousKeyNode) {
|
160
|
viewer.setSelection(new StructuredSelection(
|
161
|
objectAffectedByOperation), true);
|
162
|
}
|
163
|
|
164
|
return true;
|
165
|
}
|
166
|
|
167
|
//FIXME E4 migrate
|
168
|
// private IToolBarManager getToolBarManager() {
|
169
|
// if (toolBarManager == null) {
|
170
|
// toolBarManager = getEditorSite().getActionBars()
|
171
|
// .getToolBarManager();
|
172
|
// }
|
173
|
// return toolBarManager;
|
174
|
// }
|
175
|
|
176
|
public void applyLayout() {
|
177
|
viewer.applyLayout();
|
178
|
}
|
179
|
|
180
|
@Override
|
181
|
public boolean onComplete() {
|
182
|
return true;
|
183
|
}
|
184
|
|
185
|
public void setDirty(boolean dirty) {
|
186
|
this.dirty.setDirty(dirty);
|
187
|
}
|
188
|
|
189
|
@Override
|
190
|
public void changed(Object element) {
|
191
|
setDirty(true);
|
192
|
viewer.update(element, null);
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
public void forceDirty() {
|
197
|
changed(null);
|
198
|
}
|
199
|
|
200
|
}
|