1 |
4ff11da5
|
pplitzner
|
/**
|
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 |
|
|
|
10 |
|
|
package eu.etaxonomy.taxeditor.editor.name.e4;
|
11 |
|
|
|
12 |
|
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.HashSet;
|
14 |
|
|
import java.util.List;
|
15 |
|
|
import java.util.Set;
|
16 |
|
|
|
17 |
|
|
import javax.annotation.PostConstruct;
|
18 |
|
|
import javax.annotation.PreDestroy;
|
19 |
|
|
import javax.inject.Inject;
|
20 |
|
|
|
21 |
|
|
import org.apache.commons.lang.StringUtils;
|
22 |
|
|
import org.eclipse.core.commands.operations.IUndoContext;
|
23 |
65514c8c
|
Patrick Plitzner
|
import org.eclipse.core.commands.operations.UndoContext;
|
24 |
4ff11da5
|
pplitzner
|
import org.eclipse.core.runtime.IProgressMonitor;
|
25 |
|
|
import org.eclipse.core.runtime.OperationCanceledException;
|
26 |
b5b429af
|
Patrick Plitzner
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
27 |
e9fa67ee
|
Patrick Plitzner
|
import org.eclipse.e4.core.services.events.IEventBroker;
|
28 |
4ff11da5
|
pplitzner
|
import org.eclipse.e4.ui.di.Focus;
|
29 |
|
|
import org.eclipse.e4.ui.di.Persist;
|
30 |
|
|
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
31 |
e378d285
|
Patrick Plitzner
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
32 |
4ff11da5
|
pplitzner
|
import org.eclipse.e4.ui.services.EMenuService;
|
33 |
|
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
34 |
65514c8c
|
Patrick Plitzner
|
import org.eclipse.jface.dialogs.MessageDialog;
|
35 |
4ff11da5
|
pplitzner
|
import org.eclipse.jface.viewers.ISelection;
|
36 |
|
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
37 |
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
38 |
24b8f2f1
|
Patrick Plitzner
|
import org.eclipse.swt.dnd.DND;
|
39 |
|
|
import org.eclipse.swt.dnd.DropTarget;
|
40 |
|
|
import org.eclipse.swt.dnd.Transfer;
|
41 |
4ff11da5
|
pplitzner
|
import org.eclipse.swt.graphics.Color;
|
42 |
|
|
import org.eclipse.swt.widgets.Composite;
|
43 |
|
|
import org.eclipse.ui.ISelectionListener;
|
44 |
|
|
import org.eclipse.ui.IWorkbenchPart;
|
45 |
|
|
import org.eclipse.ui.IWorkbenchPartReference;
|
46 |
|
|
import org.eclipse.ui.forms.ManagedForm;
|
47 |
|
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
48 |
|
|
import org.eclipse.ui.forms.widgets.ScrolledForm;
|
49 |
|
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
50 |
|
|
|
51 |
|
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
52 |
|
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
53 |
|
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
54 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
55 |
|
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
56 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
57 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
58 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
59 |
c8cdc672
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
60 |
4ff11da5
|
pplitzner
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
61 |
24b8f2f1
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
|
62 |
4ff11da5
|
pplitzner
|
import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
|
63 |
e9fa67ee
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
64 |
4ff11da5
|
pplitzner
|
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
|
65 |
|
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
66 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupE4;
|
67 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainerE4;
|
68 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedGroupE4;
|
69 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedNameContainerE4;
|
70 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.ContainerFactoryE4;
|
71 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.HomotypicalSynonymGroupE4;
|
72 |
|
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
|
73 |
24b8f2f1
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetListenerE4;
|
74 |
e9fa67ee
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
75 |
4ff11da5
|
pplitzner
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
76 |
|
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
77 |
|
|
import eu.etaxonomy.taxeditor.model.IPartChangeListener;
|
78 |
|
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
79 |
65514c8c
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
80 |
|
|
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
|
81 |
|
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
82 |
22f2d1a4
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
83 |
4ff11da5
|
pplitzner
|
import eu.etaxonomy.taxeditor.model.TaxeditorPartService;
|
84 |
|
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
85 |
|
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
86 |
|
|
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
|
87 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
88 |
c8cdc672
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
89 |
4ff11da5
|
pplitzner
|
|
90 |
|
|
/**
|
91 |
|
|
*
|
92 |
|
|
* @author pplitzner
|
93 |
|
|
* @date Aug 24, 2017
|
94 |
|
|
*
|
95 |
|
|
*/
|
96 |
65514c8c
|
Patrick Plitzner
|
public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable, IPartContentHasDetails,
|
97 |
|
|
IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener,
|
98 |
24b8f2f1
|
Patrick Plitzner
|
ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor, IDropTargetableE4 {
|
99 |
4ff11da5
|
pplitzner
|
|
100 |
|
|
private Taxon taxon;
|
101 |
|
|
|
102 |
|
|
private ManagedForm managedForm;
|
103 |
|
|
private ScrolledForm scrolledForm;
|
104 |
|
|
private Composite parent;
|
105 |
|
|
private ISelectionProvider simpleSelectionProvider;
|
106 |
|
|
|
107 |
|
|
private TaxonBase selection;
|
108 |
|
|
|
109 |
|
|
private ConversationHolder conversation;
|
110 |
|
|
|
111 |
|
|
private AcceptedGroupE4 acceptedGroup;
|
112 |
|
|
private List<HomotypicalSynonymGroupE4> heterotypicSynonymGroups = new ArrayList<>();
|
113 |
|
|
private MisappliedGroupE4 misappliedGroup;
|
114 |
|
|
|
115 |
24b8f2f1
|
Patrick Plitzner
|
private DropTarget target;
|
116 |
033ef209
|
Patrick Plitzner
|
|
117 |
4ff11da5
|
pplitzner
|
private TaxonBase objectAffectedByLastOperation;
|
118 |
|
|
|
119 |
65514c8c
|
Patrick Plitzner
|
@Inject
|
120 |
|
|
private EMenuService menuService;
|
121 |
4ff11da5
|
pplitzner
|
|
122 |
|
|
@Inject
|
123 |
|
|
private ESelectionService selService;
|
124 |
|
|
|
125 |
b5b429af
|
Patrick Plitzner
|
@Inject
|
126 |
|
|
private IEclipseContext context;
|
127 |
|
|
|
128 |
4ff11da5
|
pplitzner
|
@Inject
|
129 |
|
|
private MDirtyable dirty;
|
130 |
|
|
|
131 |
e378d285
|
Patrick Plitzner
|
private MPart thisPart;
|
132 |
|
|
|
133 |
4ff11da5
|
pplitzner
|
private TaxonEditorInputE4 input;
|
134 |
|
|
|
135 |
65514c8c
|
Patrick Plitzner
|
private UndoContext undoContext;
|
136 |
|
|
|
137 |
e9fa67ee
|
Patrick Plitzner
|
@Inject
|
138 |
|
|
private IEventBroker eventBroker;
|
139 |
|
|
|
140 |
4ff11da5
|
pplitzner
|
@Inject
|
141 |
|
|
public TaxonNameEditorE4() {
|
142 |
65514c8c
|
Patrick Plitzner
|
undoContext = new UndoContext();
|
143 |
4ff11da5
|
pplitzner
|
}
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
@PostConstruct
|
147 |
e378d285
|
Patrick Plitzner
|
public void createPartControl(Composite parent, MPart thisPart) {
|
148 |
|
|
this.thisPart = thisPart;
|
149 |
4ff11da5
|
pplitzner
|
|
150 |
033ef209
|
Patrick Plitzner
|
createManagedForm(parent);
|
151 |
4ff11da5
|
pplitzner
|
|
152 |
|
|
TaxeditorPartService.getInstance().addListener(
|
153 |
|
|
TaxeditorPartService.PART_ACTIVATED, this);
|
154 |
|
|
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
protected void createManagedForm(Composite composite) {
|
158 |
|
|
|
159 |
|
|
managedForm = new ManagedForm(composite) {
|
160 |
|
|
|
161 |
|
|
@Override
|
162 |
|
|
public void dirtyStateChanged() {
|
163 |
|
|
dirty.setDirty(true);
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
@Override
|
167 |
|
|
public boolean setInput(Object input) {
|
168 |
65514c8c
|
Patrick Plitzner
|
if (input instanceof AbstractGroupedContainerE4) {
|
169 |
61d94a7a
|
Patrick Plitzner
|
TaxonBase newSelection = ((AbstractGroupedContainerE4) input).getData();
|
170 |
0f199310
|
Patrick Plitzner
|
if(selection!=newSelection || TaxonNameEditorE4.this.isDirty()){
|
171 |
61d94a7a
|
Patrick Plitzner
|
selection = newSelection;
|
172 |
|
|
selService.setSelection(new StructuredSelection(selection));
|
173 |
|
|
}
|
174 |
4ff11da5
|
pplitzner
|
}else if(input == null){
|
175 |
|
|
selection = null;
|
176 |
65514c8c
|
Patrick Plitzner
|
selService.setSelection(new StructuredSelection());
|
177 |
4ff11da5
|
pplitzner
|
}
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
return super.setInput(input);
|
181 |
|
|
}
|
182 |
|
|
};
|
183 |
|
|
|
184 |
|
|
scrolledForm = managedForm.getForm();
|
185 |
|
|
parent = scrolledForm.getBody();
|
186 |
|
|
|
187 |
|
|
parent.setData(taxon);
|
188 |
|
|
|
189 |
|
|
TableWrapLayout layout = new TableWrapLayout();
|
190 |
|
|
layout.leftMargin = 0;
|
191 |
|
|
layout.rightMargin = 0;
|
192 |
|
|
layout.topMargin = 0;
|
193 |
|
|
layout.bottomMargin = 0;
|
194 |
|
|
|
195 |
|
|
layout.verticalSpacing = 0;
|
196 |
|
|
layout.horizontalSpacing = 0;
|
197 |
|
|
|
198 |
|
|
parent.setLayout(layout);
|
199 |
|
|
parent.setBackground(AbstractUtility
|
200 |
|
|
.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
public void createOrUpdateNameComposites() {
|
204 |
|
|
ContainerFactoryE4.createOrUpdateAcceptedTaxonsHomotypicGroup(this);
|
205 |
|
|
ContainerFactoryE4.createOrUpdateHeterotypicSynonymyGroups(this);
|
206 |
|
|
ContainerFactoryE4.createOrUpdateMisapplicationsGroup(this);
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
// Redraw composite
|
210 |
|
|
managedForm.reflow(true);
|
211 |
033ef209
|
Patrick Plitzner
|
managedForm.refresh();
|
212 |
4ff11da5
|
pplitzner
|
}
|
213 |
|
|
|
214 |
e9fa67ee
|
Patrick Plitzner
|
@Override
|
215 |
|
|
public Taxon getTaxon() {
|
216 |
4ff11da5
|
pplitzner
|
return HibernateProxyHelper.deproxy(taxon);
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
public void setDirty() {
|
220 |
|
|
managedForm.dirtyStateChanged();
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
@Focus
|
224 |
|
|
public void setFocus() {
|
225 |
65514c8c
|
Patrick Plitzner
|
//make sure to bind again if maybe in another view the conversation was unbound
|
226 |
|
|
if(conversation!=null && !conversation.isBound()){
|
227 |
|
|
conversation.bind();
|
228 |
|
|
}
|
229 |
4ff11da5
|
pplitzner
|
if(input!=null){
|
230 |
|
|
if (getSelectedContainer() == null) {
|
231 |
|
|
throw new IllegalStateException(
|
232 |
|
|
Messages.TaxonNameEditor_THERE_SHOULD_ALWAYS_BE);
|
233 |
|
|
}
|
234 |
|
|
getSelectedContainer().setSelected();
|
235 |
|
|
|
236 |
|
|
// check permissions
|
237 |
|
|
boolean doEnable = permissionsSatisfied();
|
238 |
|
|
managedForm.getForm().setEnabled(doEnable);
|
239 |
|
|
}
|
240 |
e9fa67ee
|
Patrick Plitzner
|
eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
|
241 |
4ff11da5
|
pplitzner
|
}
|
242 |
|
|
|
243 |
|
|
@Override
|
244 |
|
|
public boolean permissionsSatisfied() {
|
245 |
|
|
TaxonNode taxonNode = input.getTaxonNode();
|
246 |
|
|
boolean doEnable = CdmStore.currentAuthentiationHasPermission(taxonNode, RequiredPermissions.TAXONNODE_EDIT);
|
247 |
|
|
return doEnable;
|
248 |
|
|
}
|
249 |
|
|
|
250 |
|
|
@Override
|
251 |
|
|
public ConversationHolder getConversationHolder() {
|
252 |
|
|
return conversation;
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
/** {@inheritDoc} */
|
256 |
|
|
@Override
|
257 |
|
|
public void update(CdmDataChangeMap events) {
|
258 |
|
|
// redraw();
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
/**
|
262 |
|
|
* Redraws this editor return true on success
|
263 |
|
|
*
|
264 |
|
|
* @return a boolean.
|
265 |
|
|
*/
|
266 |
|
|
public boolean redraw() {
|
267 |
|
|
return redraw(true);
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
/**
|
271 |
|
|
* {@inheritDoc}
|
272 |
|
|
*
|
273 |
|
|
* Redraws the editor controls
|
274 |
|
|
*/
|
275 |
|
|
public boolean redraw(boolean focus) {
|
276 |
|
|
|
277 |
|
|
createOrUpdateNameComposites();
|
278 |
|
|
|
279 |
|
|
if (focus) {
|
280 |
|
|
setFocus();
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
return true;
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
@Override
|
287 |
|
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
288 |
|
|
|
289 |
|
|
changed(objectAffectedByOperation);
|
290 |
|
|
|
291 |
|
|
redraw(false);
|
292 |
|
|
|
293 |
|
|
if (objectAffectedByOperation instanceof TaxonBase) {
|
294 |
|
|
objectAffectedByLastOperation = (TaxonBase) objectAffectedByOperation;
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
return true;
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
public ManagedForm getManagedForm() {
|
301 |
|
|
return managedForm;
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
/**
|
306 |
|
|
* <p>
|
307 |
|
|
* checkForEmptyNames
|
308 |
|
|
* </p>
|
309 |
|
|
*
|
310 |
|
|
* @return true if there are empty names
|
311 |
|
|
*/
|
312 |
|
|
public boolean checkForEmptyNames() {
|
313 |
|
|
for (AbstractGroupedContainerE4 container : getGroupedContainers()) {
|
314 |
|
|
if (container.getName() == null
|
315 |
|
|
|| StringUtils.isEmpty(container.getName().getTitleCache())) {
|
316 |
|
|
return true;
|
317 |
|
|
}
|
318 |
|
|
}
|
319 |
|
|
return false;
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
public Set<AbstractGroupedContainerE4> getEmptyContainers() {
|
323 |
|
|
Set<AbstractGroupedContainerE4> containersWithEmptyNames = new HashSet<>();
|
324 |
|
|
|
325 |
|
|
for (AbstractGroupedContainerE4 container : getGroupedContainers()) {
|
326 |
|
|
if (container.getName() == null
|
327 |
|
|
|| StringUtils.isEmpty(container.getName().getTitleCache())) {
|
328 |
|
|
containersWithEmptyNames.add(container);
|
329 |
|
|
}
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
return containersWithEmptyNames;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
/** {@inheritDoc} */
|
336 |
c8cdc672
|
Patrick Plitzner
|
@Override
|
337 |
|
|
@Persist
|
338 |
|
|
public void save(IProgressMonitor monitor) {
|
339 |
4ff11da5
|
pplitzner
|
|
340 |
65514c8c
|
Patrick Plitzner
|
monitor.beginTask(Messages.TaxonNameEditor_SAVING_NAMES, getGroupedContainers().size());
|
341 |
|
|
if (!conversation.isBound()) {
|
342 |
|
|
conversation.bind();
|
343 |
|
|
}
|
344 |
|
|
monitor.worked(1);
|
345 |
4ff11da5
|
pplitzner
|
|
346 |
65514c8c
|
Patrick Plitzner
|
// check for empty names
|
347 |
|
|
if (checkForEmptyNames()) {
|
348 |
|
|
MessageDialog.openWarning(AbstractUtility.getShell(), Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED,
|
349 |
|
|
Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED_MESSAGE);
|
350 |
|
|
return;
|
351 |
|
|
}
|
352 |
|
|
for (AbstractGroupedContainerE4 container : getGroupedContainers()) {
|
353 |
4ff11da5
|
pplitzner
|
|
354 |
65514c8c
|
Patrick Plitzner
|
monitor.subTask(Messages.TaxonNameEditor_SAVING_COMPOSITES
|
355 |
|
|
+ container.getTaxonBase().getTitleCache());
|
356 |
|
|
container.persistName();
|
357 |
4ff11da5
|
pplitzner
|
|
358 |
65514c8c
|
Patrick Plitzner
|
// In case the progress monitor was canceled throw an exception.
|
359 |
|
|
if (monitor.isCanceled()) {
|
360 |
|
|
throw new OperationCanceledException();
|
361 |
|
|
}
|
362 |
4ff11da5
|
pplitzner
|
|
363 |
a692bc7b
|
Katja Luther
|
// Otherwise declare this step as done.
|
364 |
65514c8c
|
Patrick Plitzner
|
monitor.worked(1);
|
365 |
|
|
|
366 |
|
|
}
|
367 |
a692bc7b
|
Katja Luther
|
input.merge();
|
368 |
|
|
// commit the conversation and start a new transaction immediately
|
369 |
|
|
conversation.commit(true);
|
370 |
|
|
|
371 |
|
|
|
372 |
|
|
dirty.setDirty(false);
|
373 |
4ff11da5
|
pplitzner
|
|
374 |
65514c8c
|
Patrick Plitzner
|
// Stop the progress monitor.
|
375 |
|
|
monitor.done();
|
376 |
4ff11da5
|
pplitzner
|
}
|
377 |
|
|
|
378 |
22f2d1a4
|
Patrick Plitzner
|
public void init(TaxonEditorInputE4 input) {
|
379 |
4ff11da5
|
pplitzner
|
|
380 |
|
|
if (!(input != null)) {
|
381 |
22f2d1a4
|
Patrick Plitzner
|
MessagingUtils.error(this.getClass(), new Exception(Messages.TaxonNameEditor_INVALID_INPUT));
|
382 |
|
|
return;
|
383 |
4ff11da5
|
pplitzner
|
}
|
384 |
|
|
|
385 |
|
|
if (input.getAdapter(Taxon.class) != null) {
|
386 |
|
|
taxon = CdmBase.deproxy(input.getAdapter(Taxon.class), Taxon.class);
|
387 |
|
|
} else {
|
388 |
22f2d1a4
|
Patrick Plitzner
|
MessagingUtils.error(this.getClass(), new Exception(Messages.TaxonNameEditor_INVALID_INPUT_TAXON_NULL));
|
389 |
|
|
return;
|
390 |
4ff11da5
|
pplitzner
|
}
|
391 |
|
|
|
392 |
|
|
this.input = input;
|
393 |
c6d3ffdc
|
Patrick Plitzner
|
conversation = input.getConversationHolder();
|
394 |
4ff11da5
|
pplitzner
|
|
395 |
|
|
createOrUpdateNameComposites();
|
396 |
|
|
|
397 |
24b8f2f1
|
Patrick Plitzner
|
createDragSupport();
|
398 |
|
|
|
399 |
e378d285
|
Patrick Plitzner
|
setPartName();
|
400 |
b4730c9a
|
Patrick Plitzner
|
|
401 |
|
|
//set initial selection
|
402 |
3fd7ed16
|
Patrick Plitzner
|
TaxonBase initiallySelectedTaxonBase = input.getInitiallySelectedTaxonBase();
|
403 |
|
|
if(initiallySelectedTaxonBase!=null){
|
404 |
|
|
selService.setSelection(new StructuredSelection(initiallySelectedTaxonBase));
|
405 |
|
|
getContainer(initiallySelectedTaxonBase).setSelected();
|
406 |
e34c0af1
|
Patrick Plitzner
|
}
|
407 |
4ff11da5
|
pplitzner
|
}
|
408 |
|
|
|
409 |
24b8f2f1
|
Patrick Plitzner
|
private void createDragSupport() {
|
410 |
|
|
// Listen for names being dragged outside of existing homotypic groups -
|
411 |
|
|
// user wants to create a new group
|
412 |
|
|
Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
|
413 |
|
|
int operations = DND.DROP_MOVE;
|
414 |
|
|
if (target == null) {
|
415 |
|
|
target = new DropTarget(parent, operations);
|
416 |
|
|
target.setTransfer(types);
|
417 |
|
|
target.addDropListener(new NameEditorDropTargetListenerE4(this));
|
418 |
|
|
}
|
419 |
|
|
}
|
420 |
4ff11da5
|
pplitzner
|
|
421 |
|
|
public AcceptedNameContainerE4 getAcceptedNameContainer() {
|
422 |
|
|
return getAcceptedGroup().getAcceptedNameContainer();
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
public HomotypicalSynonymGroupE4 getHomotypicalGroupContainer(
|
426 |
|
|
HomotypicalGroup homotypicalGroup) {
|
427 |
|
|
for (HomotypicalSynonymGroupE4 group : getHeterotypicSynonymGroups()) {
|
428 |
|
|
if (group.getGroup().equals(homotypicalGroup)) {
|
429 |
|
|
return group;
|
430 |
|
|
}
|
431 |
|
|
}
|
432 |
|
|
|
433 |
|
|
return null;
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
/**
|
437 |
|
|
* <p>
|
438 |
|
|
* getDirtyNames
|
439 |
|
|
* </p>
|
440 |
|
|
*
|
441 |
|
|
* @return a Set containing all composites that have been edited
|
442 |
|
|
*/
|
443 |
|
|
public Set<AbstractGroupedContainerE4> getDirtyNames() {
|
444 |
|
|
Set<AbstractGroupedContainerE4> dirtyNames = new HashSet<>();
|
445 |
|
|
|
446 |
|
|
for (AbstractGroupedContainerE4 composite : getGroupedContainers()) {
|
447 |
|
|
if (composite.isDirty()) {
|
448 |
|
|
dirtyNames.add(composite);
|
449 |
|
|
}
|
450 |
|
|
}
|
451 |
|
|
|
452 |
|
|
return dirtyNames;
|
453 |
|
|
}
|
454 |
|
|
|
455 |
|
|
public List<AbstractGroupedContainerE4> getGroupedContainers() {
|
456 |
|
|
List<AbstractGroupedContainerE4> groupedComposites = new ArrayList<>();
|
457 |
|
|
|
458 |
|
|
for (AbstractGroupE4 group : getAllGroups()) {
|
459 |
31e5785c
|
Katja Luther
|
if (group!= null){
|
460 |
|
|
groupedComposites.addAll(group.getGroupedContainers());
|
461 |
|
|
}
|
462 |
4ff11da5
|
pplitzner
|
}
|
463 |
|
|
|
464 |
|
|
return groupedComposites;
|
465 |
|
|
}
|
466 |
|
|
|
467 |
|
|
public List<AbstractGroupE4> getAllGroups() {
|
468 |
|
|
List<AbstractGroupE4> allGroups = new ArrayList<>();
|
469 |
|
|
|
470 |
|
|
allGroups.add(getAcceptedGroup());
|
471 |
|
|
|
472 |
|
|
heterotypicSynonymGroups = getHeterotypicSynonymGroups();
|
473 |
|
|
|
474 |
|
|
if (heterotypicSynonymGroups != null) {
|
475 |
|
|
allGroups.addAll(heterotypicSynonymGroups);
|
476 |
|
|
}
|
477 |
|
|
|
478 |
|
|
if (misappliedGroup != null) {
|
479 |
|
|
allGroups.add(misappliedGroup);
|
480 |
|
|
}
|
481 |
|
|
|
482 |
|
|
return allGroups;
|
483 |
|
|
}
|
484 |
|
|
|
485 |
b5b429af
|
Patrick Plitzner
|
@Override
|
486 |
|
|
public IEclipseContext getContext() {
|
487 |
|
|
return context;
|
488 |
|
|
}
|
489 |
|
|
|
490 |
4ff11da5
|
pplitzner
|
public boolean isDirty() {
|
491 |
|
|
return dirty.isDirty();
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
@PreDestroy
|
495 |
|
|
public void dispose() {
|
496 |
65514c8c
|
Patrick Plitzner
|
if(conversation!=null){
|
497 |
|
|
conversation.unregisterForDataStoreChanges(this);
|
498 |
|
|
conversation.close();
|
499 |
|
|
}
|
500 |
d6d945d2
|
Patrick Plitzner
|
eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, null);
|
501 |
4ff11da5
|
pplitzner
|
}
|
502 |
|
|
|
503 |
|
|
/** {@inheritDoc} */
|
504 |
|
|
@Override
|
505 |
|
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
506 |
|
|
|
507 |
|
|
}
|
508 |
|
|
|
509 |
|
|
public AbstractGroupedContainerE4 getSelectedContainer() {
|
510 |
61d94a7a
|
Patrick Plitzner
|
return (selection != null) ? getContainer(selection)
|
511 |
4ff11da5
|
pplitzner
|
: getAcceptedNameContainer();
|
512 |
|
|
}
|
513 |
|
|
|
514 |
24b8f2f1
|
Patrick Plitzner
|
@Override
|
515 |
|
|
public void dragEntered() {
|
516 |
|
|
// TODO change this
|
517 |
|
|
getControl().setBackground(
|
518 |
|
|
AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
|
519 |
|
|
}
|
520 |
|
|
|
521 |
|
|
@Override
|
522 |
|
|
public void dragLeft() {
|
523 |
|
|
getControl().setBackground(
|
524 |
|
|
AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
|
525 |
|
|
}
|
526 |
033ef209
|
Patrick Plitzner
|
|
527 |
|
|
|
528 |
4ff11da5
|
pplitzner
|
public void setMisapplicationsGroup(MisappliedGroupE4 misappliedGroup) {
|
529 |
|
|
this.misappliedGroup = misappliedGroup;
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
public FormToolkit getToolkit() {
|
533 |
|
|
return managedForm.getToolkit();
|
534 |
|
|
}
|
535 |
|
|
|
536 |
|
|
public List<HomotypicalSynonymGroupE4> getHeterotypicSynonymGroups() {
|
537 |
|
|
return heterotypicSynonymGroups;
|
538 |
|
|
}
|
539 |
|
|
|
540 |
|
|
public void addHeterotypicSynonymGroup(HomotypicalSynonymGroupE4 group) {
|
541 |
|
|
heterotypicSynonymGroups.add(group);
|
542 |
|
|
}
|
543 |
|
|
|
544 |
|
|
public AcceptedGroupE4 getAcceptedGroup() {
|
545 |
|
|
return acceptedGroup;
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
public void setAcceptedGroup(AcceptedGroupE4 acceptedGroup) {
|
549 |
|
|
this.acceptedGroup = acceptedGroup;
|
550 |
|
|
}
|
551 |
|
|
|
552 |
|
|
public MisappliedGroupE4 getMisappliedGroup() {
|
553 |
|
|
return misappliedGroup;
|
554 |
|
|
}
|
555 |
|
|
|
556 |
|
|
public boolean isActive() {
|
557 |
cf2f4360
|
Patrick Plitzner
|
return this.equals(AbstractUtility.getActivePart());
|
558 |
4ff11da5
|
pplitzner
|
}
|
559 |
|
|
|
560 |
|
|
@Override
|
561 |
|
|
public boolean onComplete() {
|
562 |
|
|
getContainer(objectAffectedByLastOperation).setSelected();
|
563 |
|
|
return true;
|
564 |
|
|
}
|
565 |
|
|
|
566 |
|
|
/** {@inheritDoc} */
|
567 |
|
|
@Override
|
568 |
|
|
public void partChanged(Integer eventType, IWorkbenchPartReference partRef) {
|
569 |
|
|
if (!partRef.getPart(false).equals(this)) {
|
570 |
|
|
// getSelectedObject().colorSelected(AbstractGroupedContainer.SELECTED_NO_FOCUS);
|
571 |
|
|
}
|
572 |
|
|
}
|
573 |
|
|
|
574 |
|
|
public void removeGroup(AbstractGroupE4 group) {
|
575 |
|
|
if (group != null) {
|
576 |
|
|
group.dispose();
|
577 |
|
|
|
578 |
|
|
//if (heterotypicSynonymGroups != null) {
|
579 |
|
|
heterotypicSynonymGroups.remove(group);
|
580 |
|
|
//}
|
581 |
|
|
}
|
582 |
|
|
}
|
583 |
|
|
|
584 |
|
|
public AbstractGroupedContainerE4 getContainer(TaxonBase taxonBase) {
|
585 |
|
|
List<AbstractGroupedContainerE4> groupedContainers = getGroupedContainers();
|
586 |
|
|
for (AbstractGroupedContainerE4 container : groupedContainers) {
|
587 |
|
|
if (container.getData().equals(taxonBase)
|
588 |
|
|
&& container.getNameViewer().getTextWidget() != null) {
|
589 |
|
|
return container;
|
590 |
|
|
}
|
591 |
|
|
}
|
592 |
|
|
return getAcceptedNameContainer();
|
593 |
|
|
}
|
594 |
|
|
|
595 |
|
|
public void setOnError() {
|
596 |
|
|
Color disabledColor = AbstractUtility.getColor(Resources.COLOR_EDITOR_ERROR);
|
597 |
|
|
setEnabled(false, disabledColor);
|
598 |
|
|
}
|
599 |
|
|
|
600 |
|
|
public void setDisabled(){
|
601 |
|
|
Color disabledColor = AbstractUtility.getColor(Resources.COLOR_TEXT_DISABLED_BACKGROUND);
|
602 |
|
|
setEnabled(false, disabledColor);
|
603 |
|
|
}
|
604 |
|
|
|
605 |
|
|
protected void setEnabled(boolean enabled, Color background) {
|
606 |
|
|
|
607 |
|
|
for(AbstractGroupedContainerE4 groupedContainer : getGroupedContainers()){
|
608 |
|
|
groupedContainer.setEnabled(enabled);
|
609 |
|
|
}
|
610 |
|
|
|
611 |
|
|
// send an empty selection to the current provider - TODO only on error ???
|
612 |
|
|
if (!enabled) {
|
613 |
|
|
getManagedForm().setInput(null);
|
614 |
|
|
|
615 |
|
|
for (AbstractGroupedContainerE4 groupedContainer : getGroupedContainers()) {
|
616 |
|
|
groupedContainer.setBackground(background);
|
617 |
|
|
}
|
618 |
|
|
}
|
619 |
033ef209
|
Patrick Plitzner
|
getControl().setBackground(background);
|
620 |
4ff11da5
|
pplitzner
|
}
|
621 |
|
|
|
622 |
|
|
@Override
|
623 |
|
|
public void changed(Object element) {
|
624 |
c8cdc672
|
Patrick Plitzner
|
// setDirty(true);
|
625 |
|
|
// if the attribute is null then do not set the dirty flag -> hotfix for the problem that for tasks done in service methods the changes are saved automatically
|
626 |
|
|
if (element != null){
|
627 |
|
|
dirty.setDirty(true);
|
628 |
e378d285
|
Patrick Plitzner
|
//refresh part title
|
629 |
|
|
//TODO: refresh taxon node in taxon navigator
|
630 |
|
|
setPartName();
|
631 |
c8cdc672
|
Patrick Plitzner
|
}
|
632 |
4ff11da5
|
pplitzner
|
|
633 |
c8cdc672
|
Patrick Plitzner
|
if (element instanceof TaxonBase) {
|
634 |
|
|
AbstractGroupedContainerE4 container = getContainer((TaxonBase) element);
|
635 |
|
|
if (container != null) {
|
636 |
|
|
container.refresh();
|
637 |
|
|
}
|
638 |
|
|
}
|
639 |
|
|
if (element instanceof TaxonRelationship) {
|
640 |
|
|
AbstractGroupedContainerE4 container = getContainer(((TaxonRelationship) element).getFromTaxon());
|
641 |
|
|
if (container != null) {
|
642 |
|
|
container.refresh();
|
643 |
|
|
}
|
644 |
|
|
}
|
645 |
e378d285
|
Patrick Plitzner
|
}
|
646 |
|
|
|
647 |
|
|
public void setPartName(){
|
648 |
c175c2ff
|
Patrick Plitzner
|
thisPart.setLabel(this.taxon.getName().getFullTitleCache());
|
649 |
4ff11da5
|
pplitzner
|
}
|
650 |
|
|
|
651 |
|
|
@Override
|
652 |
|
|
public void forceDirty() {
|
653 |
|
|
setDirty();
|
654 |
|
|
}
|
655 |
|
|
|
656 |
|
|
|
657 |
|
|
public IUndoContext getUndoContext() {
|
658 |
65514c8c
|
Patrick Plitzner
|
return undoContext;
|
659 |
4ff11da5
|
pplitzner
|
}
|
660 |
|
|
|
661 |
24b8f2f1
|
Patrick Plitzner
|
@Override
|
662 |
033ef209
|
Patrick Plitzner
|
public Composite getControl(){
|
663 |
|
|
return managedForm.getForm().getBody();
|
664 |
|
|
}
|
665 |
|
|
|
666 |
65514c8c
|
Patrick Plitzner
|
public EMenuService getMenuService() {
|
667 |
|
|
return menuService;
|
668 |
|
|
}
|
669 |
|
|
|
670 |
|
|
public ESelectionService getSelectionService() {
|
671 |
|
|
return selService;
|
672 |
|
|
}
|
673 |
|
|
|
674 |
|
|
|
675 |
|
|
/**
|
676 |
|
|
* {@inheritDoc}
|
677 |
|
|
*/
|
678 |
|
|
@Override
|
679 |
|
|
public boolean canAttachMedia() {
|
680 |
|
|
return true;
|
681 |
|
|
}
|
682 |
|
|
|
683 |
a7d1d751
|
Patrick Plitzner
|
public TaxonEditorInputE4 getEditorInput() {
|
684 |
|
|
return input;
|
685 |
|
|
}
|
686 |
|
|
|
687 |
24b8f2f1
|
Patrick Plitzner
|
/**
|
688 |
|
|
* {@inheritDoc}
|
689 |
|
|
*/
|
690 |
|
|
@Override
|
691 |
|
|
public TaxonNameEditorE4 getEditor() {
|
692 |
|
|
return this;
|
693 |
|
|
}
|
694 |
|
|
|
695 |
4ff11da5
|
pplitzner
|
}
|