Project

General

Profile

Download (5.13 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.editor.key.e4;
5

    
6
import javax.inject.Inject;
7

    
8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.eclipse.e4.ui.di.Focus;
10
import org.eclipse.e4.ui.di.Persist;
11
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
12
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
13
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
14
import org.eclipse.jface.action.IToolBarManager;
15
import org.eclipse.jface.viewers.IBaseLabelProvider;
16
import org.eclipse.jface.viewers.IContentProvider;
17
import org.eclipse.jface.viewers.ISelectionChangedListener;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.zest.core.viewers.AbstractZoomableViewer;
21
import org.eclipse.zest.core.viewers.GraphViewer;
22
import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
23
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
24
import org.eclipse.zest.layouts.LayoutAlgorithm;
25
import org.eclipse.zest.layouts.LayoutStyles;
26
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
27

    
28
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
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
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
37

    
38
/**
39
 *
40
 * @author pplitzner
41
 * @since Sep 28, 2017
42
 *
43
 * @param <T>
44
 */
45
public abstract class AbstractGraphKeyEditorE4<T extends IIdentificationKey>
46
implements IConversationEnabled, IE4SavablePart,
47
		IZoomableWorkbenchPart, IPostOperationEnabled,
48
		IDirtyMarkable {
49

    
50
	protected CdmFormFactory formFactory;
51
	protected Composite container;
52
	protected GraphViewer viewer;
53

    
54
	private LayoutAlgorithm layoutAlgoritm;
55
	private ZoomContributionViewItem zoomContributionViewItem;
56

    
57
	private IToolBarManager toolBarManager;
58

    
59
    private PolytomousKeyEditorInput input;
60

    
61
    @Inject
62
    protected ESelectionService selService;
63

    
64
    @Inject
65
    private MDirtyable dirty;
66

    
67
    protected ISelectionChangedListener selectionChangedListener;
68

    
69
    @Inject
70
    private MPart thisPart;
71

    
72
	@Persist
73
	public void save(IProgressMonitor monitor) {
74
		getConversationHolder().commit(true);
75
		setDirty(false);
76
		viewer.refresh();
77
	}
78

    
79
	public void init(PolytomousKeyEditorInput input) {
80
		this.input = input;
81

    
82

    
83
        viewer.setInput(getKey());
84
        if(getKey()!=null){
85
            thisPart.setLabel(getKey().toString());
86
        }
87
	}
88

    
89
	public boolean isDirty() {
90
		return dirty.isDirty();
91
	}
92

    
93
    public PolytomousKeyEditorInput getEditorInput() {
94
        return input;
95
    }
96

    
97
	//FIXME E4 migrate
98
//	private void createToolbar() {
99
//		getToolBarManager().add(getZoomContributionViewItem());
100
//	}
101

    
102
	protected abstract IBaseLabelProvider getLabelProvider();
103

    
104
	protected abstract IContentProvider getContentProvider();
105

    
106
	/**
107
	 * Return the key that this editor
108
	 *
109
	 * @return
110
	 */
111
	public abstract T getKey();
112

    
113
	@Focus
114
	public void setFocus() {
115
	    if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()) {
116
            viewer.getControl().setFocus();
117
        }
118
	}
119

    
120
	public void refresh() {
121
		viewer.refresh();
122
	}
123

    
124
	@Override
125
	public void update(CdmDataChangeMap changeEvents) {
126

    
127
	}
128

    
129
	@Override
130
	public AbstractZoomableViewer getZoomableViewer() {
131
		return viewer;
132
	}
133

    
134
	protected LayoutAlgorithm getLayoutAlgoritm() {
135
		if (layoutAlgoritm == null) {
136
			// layoutAlgoritm = new CompositeLayoutAlgorithm(
137
			// LayoutStyles.NO_LAYOUT_NODE_RESIZING,
138
			// new LayoutAlgorithm[] {
139
			// new TreeLayoutAlgorithm(
140
			// LayoutStyles.NO_LAYOUT_NODE_RESIZING),
141
			// new HorizontalShift(
142
			// LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
143

    
144
			layoutAlgoritm = new TreeLayoutAlgorithm(
145
					LayoutStyles.NO_LAYOUT_NODE_RESIZING);
146
			layoutAlgoritm.setEntityAspectRatio(0.5);
147
		}
148
		return layoutAlgoritm;
149
	}
150

    
151
	private ZoomContributionViewItem getZoomContributionViewItem() {
152
		if (zoomContributionViewItem == null) {
153
			zoomContributionViewItem = new ZoomContributionViewItem(this);
154
		}
155
		return new ZoomContributionViewItem(this);
156
	}
157

    
158
	@Override
159
	public boolean postOperation(Object objectAffectedByOperation) {
160
		setDirty(true);
161
		refresh();
162

    
163
		if (objectAffectedByOperation instanceof PolytomousKeyNode) {
164
			viewer.setSelection(new StructuredSelection(
165
					objectAffectedByOperation), true);
166
		}
167

    
168
		return true;
169
	}
170

    
171
	//FIXME E4 migrate
172
//	private IToolBarManager getToolBarManager() {
173
//		if (toolBarManager == null) {
174
//			toolBarManager = getEditorSite().getActionBars()
175
//					.getToolBarManager();
176
//		}
177
//		return toolBarManager;
178
//	}
179

    
180
	public void applyLayout() {
181
		viewer.applyLayout();
182
	}
183

    
184
	@Override
185
	public boolean onComplete() {
186
		return true;
187
	}
188

    
189
	public void setDirty(boolean dirty) {
190
		this.dirty.setDirty(dirty);
191
	}
192

    
193
	@Override
194
	public void changed(Object element) {
195
		setDirty(true);
196
		viewer.update(element, null);
197
	}
198

    
199
	@Override
200
	public void forceDirty() {
201
	    changed(null);
202
	}
203

    
204
}
(1-1/2)