Revision 65514c8c
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import org.apache.commons.lang.StringUtils; |
22 | 22 |
import org.eclipse.core.commands.operations.IUndoContext; |
23 |
import org.eclipse.core.commands.operations.UndoContext; |
|
23 | 24 |
import org.eclipse.core.runtime.IProgressMonitor; |
24 | 25 |
import org.eclipse.core.runtime.OperationCanceledException; |
25 | 26 |
import org.eclipse.e4.ui.di.Focus; |
... | ... | |
27 | 28 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable; |
28 | 29 |
import org.eclipse.e4.ui.services.EMenuService; |
29 | 30 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
30 |
import org.eclipse.jface.action.MenuManager;
|
|
31 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
31 | 32 |
import org.eclipse.jface.viewers.ISelection; |
32 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
33 | 33 |
import org.eclipse.jface.viewers.ISelectionProvider; |
34 | 34 |
import org.eclipse.jface.viewers.StructuredSelection; |
35 | 35 |
import org.eclipse.swt.graphics.Color; |
36 | 36 |
import org.eclipse.swt.widgets.Composite; |
37 |
import org.eclipse.swt.widgets.Menu; |
|
38 | 37 |
import org.eclipse.ui.ISelectionListener; |
39 |
import org.eclipse.ui.ISelectionService; |
|
40 | 38 |
import org.eclipse.ui.IWorkbenchPart; |
41 | 39 |
import org.eclipse.ui.IWorkbenchPartReference; |
42 | 40 |
import org.eclipse.ui.PartInitException; |
... | ... | |
58 | 56 |
import eu.etaxonomy.taxeditor.editor.ISecuredEditor; |
59 | 57 |
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4; |
60 | 58 |
import eu.etaxonomy.taxeditor.editor.l10n.Messages; |
61 |
import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer; |
|
62 | 59 |
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupE4; |
63 | 60 |
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainerE4; |
64 | 61 |
import eu.etaxonomy.taxeditor.editor.name.e4.container.AcceptedGroupE4; |
... | ... | |
70 | 67 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
71 | 68 |
import eu.etaxonomy.taxeditor.model.IPartChangeListener; |
72 | 69 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
70 |
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData; |
|
71 |
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia; |
|
72 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
|
73 | 73 |
import eu.etaxonomy.taxeditor.model.TaxeditorPartService; |
74 | 74 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
75 | 75 |
import eu.etaxonomy.taxeditor.preference.Resources; |
76 | 76 |
import eu.etaxonomy.taxeditor.security.RequiredPermissions; |
77 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
78 | 77 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
79 | 78 |
|
80 | 79 |
/** |
... | ... | |
83 | 82 |
* @date Aug 24, 2017 |
84 | 83 |
* |
85 | 84 |
*/ |
86 |
public class TaxonNameEditorE4 implements |
|
87 |
IConversationEnabled, IDirtyMarkable, |
|
88 |
IPartContentHasDetails, IPartChangeListener, |
|
89 |
ISelectionListener, ISecuredEditor, IPostOperationEnabled { |
|
85 |
public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable, IPartContentHasDetails, |
|
86 |
IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener, |
|
87 |
ISelectionListener, ISecuredEditor, IPostOperationEnabled { |
|
90 | 88 |
|
91 | 89 |
private Taxon taxon; |
92 | 90 |
|
... | ... | |
99 | 97 |
|
100 | 98 |
private ConversationHolder conversation; |
101 | 99 |
|
102 |
private MenuManager menuManager; |
|
103 |
private Menu menu; |
|
104 |
|
|
105 | 100 |
private AcceptedGroupE4 acceptedGroup; |
106 | 101 |
private List<HomotypicalSynonymGroupE4> heterotypicSynonymGroups = new ArrayList<>(); |
107 | 102 |
private MisappliedGroupE4 misappliedGroup; |
... | ... | |
109 | 104 |
//FIXME E4 migrate dnd |
110 | 105 |
// private DropTarget target; |
111 | 106 |
|
112 |
private ISelectionService selectionService; |
|
113 |
|
|
114 | 107 |
private TaxonBase objectAffectedByLastOperation; |
115 | 108 |
|
116 |
private ICdmEntitySession cdmEntitySession; |
|
109 |
@Inject |
|
110 |
private EMenuService menuService; |
|
117 | 111 |
|
118 | 112 |
@Inject |
119 | 113 |
private ESelectionService selService; |
... | ... | |
121 | 115 |
@Inject |
122 | 116 |
private MDirtyable dirty; |
123 | 117 |
|
124 |
private ISelectionChangedListener selectionChangedListener; |
|
125 |
|
|
126 | 118 |
private TaxonEditorInputE4 input; |
127 | 119 |
|
120 |
private UndoContext undoContext; |
|
121 |
|
|
128 | 122 |
@Inject |
129 | 123 |
public TaxonNameEditorE4() { |
124 |
undoContext = new UndoContext(); |
|
130 | 125 |
} |
131 | 126 |
|
132 | 127 |
|
133 | 128 |
@PostConstruct |
134 |
public void createPartControl(Composite parent, EMenuService menuService) {
|
|
129 |
public void createPartControl(Composite parent) { |
|
135 | 130 |
if (CdmStore.isActive()){ |
136 | 131 |
if(conversation == null){ |
137 | 132 |
conversation = CdmStore.createConversation(); |
... | ... | |
143 | 138 |
|
144 | 139 |
createManagedForm(parent); |
145 | 140 |
|
146 |
//propagate selection |
|
147 |
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event))); |
|
148 |
//FIXME E4 migrate |
|
149 |
// viewer.addSelectionChangedListener(selectionChangedListener); |
|
150 |
|
|
151 |
//create context menu |
|
152 |
menuService.registerContextMenu(managedForm, "eu.etaxonomy.taxeditor.editor.popupmenu.nameeditor"); |
|
153 |
|
|
154 | 141 |
TaxeditorPartService.getInstance().addListener( |
155 | 142 |
TaxeditorPartService.PART_ACTIVATED, this); |
156 | 143 |
|
... | ... | |
169 | 156 |
|
170 | 157 |
@Override |
171 | 158 |
public boolean setInput(Object input) { |
172 |
if (input instanceof AbstractGroupedContainer) { |
|
173 |
selection = ((AbstractGroupedContainer) input).getData(); |
|
159 |
if (input instanceof AbstractGroupedContainerE4) {
|
|
160 |
selection = ((AbstractGroupedContainerE4) input).getData();
|
|
174 | 161 |
|
175 |
selectionChangedListener = (event -> selService.setSelection(new StructuredSelection(selection)));
|
|
162 |
selService.setSelection(new StructuredSelection(selection));
|
|
176 | 163 |
}else if(input == null){ |
177 | 164 |
selection = null; |
178 |
selectionChangedListener = (event -> selService.setSelection(new StructuredSelection()));
|
|
165 |
selService.setSelection(new StructuredSelection());
|
|
179 | 166 |
} |
180 | 167 |
|
181 | 168 |
|
... | ... | |
200 | 187 |
parent.setLayout(layout); |
201 | 188 |
parent.setBackground(AbstractUtility |
202 | 189 |
.getColor(Resources.COLOR_COMPOSITE_BACKGROUND)); |
190 |
|
|
191 |
//FIXME E4 migrate |
|
192 |
// viewer.addSelectionChangedListener(selectionChangedListener); |
|
193 |
|
|
203 | 194 |
} |
204 | 195 |
|
205 | 196 |
public void createOrUpdateNameComposites() { |
... | ... | |
223 | 214 |
|
224 | 215 |
@Focus |
225 | 216 |
public void setFocus() { |
217 |
//make sure to bind again if maybe in another view the conversation was unbound |
|
218 |
if(conversation!=null && !conversation.isBound()){ |
|
219 |
conversation.bind(); |
|
220 |
} |
|
226 | 221 |
if(input!=null){ |
227 | 222 |
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus(); |
228 | 223 |
if (getSelectedContainer() == null) { |
... | ... | |
298 | 293 |
return managedForm; |
299 | 294 |
} |
300 | 295 |
|
301 |
public Menu getMenu() { |
|
302 |
if (menu == null || menu.isDisposed()) { |
|
303 |
// Creating the menu because it was either not initialised or |
|
304 |
// disposed while refreshing the editor |
|
305 |
menu = menuManager.createContextMenu(parent); |
|
306 |
} |
|
307 |
return menu; |
|
308 |
} |
|
309 | 296 |
|
310 | 297 |
/** |
311 | 298 |
* <p> |
... | ... | |
341 | 328 |
@Persist |
342 | 329 |
public void doSave(IProgressMonitor monitor) { |
343 | 330 |
|
344 |
monitor.beginTask(Messages.TaxonNameEditor_SAVING_NAMES, getGroupedContainers().size()); |
|
331 |
monitor.beginTask(Messages.TaxonNameEditor_SAVING_NAMES, getGroupedContainers().size()); |
|
332 |
if (!conversation.isBound()) { |
|
333 |
conversation.bind(); |
|
334 |
} |
|
335 |
monitor.worked(1); |
|
345 | 336 |
|
346 |
try { |
|
347 |
// check for empty names |
|
348 |
for (AbstractGroupedContainerE4 container : getGroupedContainers()) { |
|
337 |
// check for empty names |
|
338 |
if (checkForEmptyNames()) { |
|
339 |
MessageDialog.openWarning(AbstractUtility.getShell(), Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED, |
|
340 |
Messages.MultiPageTaxonEditor_NO_NAME_SPECIFIED_MESSAGE); |
|
341 |
return; |
|
342 |
} |
|
343 |
for (AbstractGroupedContainerE4 container : getGroupedContainers()) { |
|
349 | 344 |
|
350 |
monitor.subTask(Messages.TaxonNameEditor_SAVING_COMPOSITES
|
|
351 |
+ container.getTaxonBase().getTitleCache());
|
|
352 |
container.persistName();
|
|
345 |
monitor.subTask(Messages.TaxonNameEditor_SAVING_COMPOSITES
|
|
346 |
+ container.getTaxonBase().getTitleCache());
|
|
347 |
container.persistName();
|
|
353 | 348 |
|
354 |
// In case the progress monitor was canceled throw an exception. |
|
355 |
if (monitor.isCanceled()) { |
|
356 |
throw new OperationCanceledException(); |
|
357 |
} |
|
349 |
// In case the progress monitor was canceled throw an exception. |
|
350 |
if (monitor.isCanceled()) { |
|
351 |
throw new OperationCanceledException(); |
|
352 |
} |
|
353 |
// commit the conversation and start a new transaction immediately |
|
354 |
input.merge(); |
|
358 | 355 |
|
359 |
// Otherwise declare this step as done. |
|
360 |
monitor.worked(1); |
|
361 |
} |
|
362 |
} finally { |
|
356 |
conversation.commit(true); |
|
363 | 357 |
|
364 |
// Stop the progress monitor. |
|
365 |
monitor.done(); |
|
366 |
} |
|
358 |
// Otherwise declare this step as done. |
|
359 |
monitor.worked(1); |
|
360 |
|
|
361 |
dirty.setDirty(false); |
|
362 |
} |
|
367 | 363 |
|
364 |
// Stop the progress monitor. |
|
365 |
monitor.done(); |
|
368 | 366 |
} |
369 | 367 |
|
370 | 368 |
public void init(TaxonEditorInputE4 input) |
... | ... | |
467 | 465 |
|
468 | 466 |
@PreDestroy |
469 | 467 |
public void dispose() { |
470 |
conversation.unregisterForDataStoreChanges(this); |
|
468 |
if(conversation!=null){ |
|
469 |
conversation.unregisterForDataStoreChanges(this); |
|
470 |
conversation.close(); |
|
471 |
} |
|
471 | 472 |
} |
472 | 473 |
|
473 | 474 |
/** {@inheritDoc} */ |
... | ... | |
614 | 615 |
|
615 | 616 |
|
616 | 617 |
public IUndoContext getUndoContext() { |
617 |
//FIXME E4 is this needed |
|
618 |
return null; |
|
618 |
return undoContext; |
|
619 | 619 |
} |
620 | 620 |
|
621 | 621 |
public Composite getControl(){ |
622 | 622 |
return managedForm.getForm().getBody(); |
623 | 623 |
} |
624 | 624 |
|
625 |
public EMenuService getMenuService() { |
|
626 |
return menuService; |
|
627 |
} |
|
628 |
|
|
629 |
public ESelectionService getSelectionService() { |
|
630 |
return selService; |
|
631 |
} |
|
632 |
|
|
633 |
|
|
634 |
/** |
|
635 |
* {@inheritDoc} |
|
636 |
*/ |
|
637 |
@Override |
|
638 |
public boolean canAttachMedia() { |
|
639 |
return true; |
|
640 |
} |
|
641 |
|
|
625 | 642 |
} |
Also available in: Unified diff
ref #6595 further migration of name editor