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