24ea70f115b96167c99dd03d563d7a841512f8d8
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / TaxonNameEditor.java
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
10 package eu.etaxonomy.taxeditor.editor.name;
11
12 import java.util.ArrayList;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16
17 import org.apache.commons.lang.StringUtils;
18 import org.eclipse.core.commands.operations.IUndoContext;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.OperationCanceledException;
21 import org.eclipse.jface.action.MenuManager;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.ISelectionProvider;
24 import org.eclipse.jface.viewers.StructuredSelection;
25 import org.eclipse.swt.dnd.DND;
26 import org.eclipse.swt.dnd.DropTarget;
27 import org.eclipse.swt.dnd.Transfer;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Menu;
31 import org.eclipse.ui.IEditorInput;
32 import org.eclipse.ui.IEditorSite;
33 import org.eclipse.ui.ISelectionListener;
34 import org.eclipse.ui.ISelectionService;
35 import org.eclipse.ui.IWorkbenchPart;
36 import org.eclipse.ui.IWorkbenchPartReference;
37 import org.eclipse.ui.PartInitException;
38 import org.eclipse.ui.PlatformUI;
39 import org.eclipse.ui.forms.ManagedForm;
40 import org.eclipse.ui.forms.widgets.FormToolkit;
41 import org.eclipse.ui.forms.widgets.ScrolledForm;
42 import org.eclipse.ui.forms.widgets.TableWrapLayout;
43 import org.eclipse.ui.part.EditorPart;
44
45 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
46 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
47 import eu.etaxonomy.cdm.api.service.ITaxonService;
48 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
49 import eu.etaxonomy.cdm.model.common.CdmBase;
50 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
51 import eu.etaxonomy.cdm.model.taxon.Taxon;
52 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
53 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
54 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
55 import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
56 import eu.etaxonomy.taxeditor.editor.EditorUtil;
57 import eu.etaxonomy.taxeditor.editor.IDropTargetable;
58 import eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage;
59 import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
60 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
61 import eu.etaxonomy.taxeditor.editor.SimpleSelectionProvider;
62 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
63 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup;
64 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
65 import eu.etaxonomy.taxeditor.editor.name.container.AcceptedGroup;
66 import eu.etaxonomy.taxeditor.editor.name.container.AcceptedNameContainer;
67 import eu.etaxonomy.taxeditor.editor.name.container.ContainerFactory;
68 import eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup;
69 import eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup;
70 import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDropTargetListener;
71 import eu.etaxonomy.taxeditor.model.AbstractUtility;
72 import eu.etaxonomy.taxeditor.model.IPartChangeListener;
73 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
74 import eu.etaxonomy.taxeditor.model.TaxeditorPartService;
75 import eu.etaxonomy.taxeditor.preference.Resources;
76 import eu.etaxonomy.taxeditor.security.RequiredPermissions;
77 import eu.etaxonomy.taxeditor.store.CdmStore;
78 import eu.etaxonomy.taxeditor.store.StoreUtil;
79
80 /**
81 * <p>
82 * TaxonNameEditor class.
83 * </p>
84 *
85 * @author p.ciardelli
86 * @author n.hoffmann
87 * @created 15.05.2008
88 * @version 1.0
89 */
90 public class TaxonNameEditor extends EditorPart implements
91 IMultiPageTaxonEditorPage, IConversationEnabled,
92 IPartContentHasDetails, IPartChangeListener,
93 ISelectionListener, IDropTargetable, ISecuredEditor {
94
95 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.taxon.name"</code> */
96 public static final String ID = "eu.etaxonomy.taxeditor.editor.taxon.name";
97
98 private Taxon taxon;
99
100 private ManagedForm managedForm;
101 private ScrolledForm scrolledForm;
102 private Composite parent;
103 private ISelectionProvider simpleSelectionProvider;
104
105 private final MultiPageTaxonEditor editor;
106
107 private TaxonBase selection;
108
109 private final ConversationHolder conversation;
110
111 private MenuManager menuManager;
112 private Menu menu;
113
114 private AcceptedGroup acceptedGroup;
115 private List<HomotypicalSynonymGroup> heterotypicSynonymGroups = new ArrayList<HomotypicalSynonymGroup>();
116 private MisappliedGroup misappliedGroup;
117
118 private DropTarget target;
119
120 private ISelectionService selectionService;
121
122 private TaxonBase objectAffectedByLastOperation;
123
124 /**
125 * <p>
126 * Constructor for TaxonNameEditor.
127 * </p>
128 *
129 * @param editor
130 * a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor}
131 * object.
132 */
133 public TaxonNameEditor(MultiPageTaxonEditor editor) {
134 this.editor = editor;
135 conversation = editor.getConversationHolder();
136 }
137
138 /**
139 * <p>
140 * getUndoContext
141 * </p>
142 *
143 * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
144 * object.
145 */
146 public IUndoContext getUndoContext() {
147 return editor.getUndoContext();
148 }
149
150 /*
151 * (non-Javadoc)
152 *
153 * @see
154 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
155 * .Composite)
156 */
157 /** {@inheritDoc} */
158 @Override
159 public void createPartControl(Composite composite) {
160 selectionService = getSite().getWorkbenchWindow().getSelectionService();
161 selectionService.addSelectionListener(this);
162
163 createManagedForm(composite);
164
165 TaxeditorPartService.getInstance().addListener(
166 TaxeditorPartService.PART_ACTIVATED, this);
167 }
168
169 /**
170 * <p>
171 * createManagedForm
172 * </p>
173 *
174 * @param composite
175 * a {@link org.eclipse.swt.widgets.Composite} object.
176 */
177 protected void createManagedForm(Composite composite) {
178
179 managedForm = new ManagedForm(composite) {
180
181 @Override
182 public void dirtyStateChanged() {
183 firePropertyChange(PROP_DIRTY);
184 }
185
186 @Override
187 public boolean setInput(Object input) {
188 if (input instanceof AbstractGroupedContainer) {
189 selection = ((AbstractGroupedContainer) input).getData();
190 getSite().getSelectionProvider().setSelection(new StructuredSelection(selection));
191 }else if(input == null){
192 selection = null;
193 getSite().getSelectionProvider().setSelection(new StructuredSelection());
194 }
195
196
197 return super.setInput(input);
198 }
199 };
200
201 scrolledForm = managedForm.getForm();
202 parent = scrolledForm.getBody();
203
204 // register the context menu
205 menuManager = new MenuManager();
206 ISelectionProvider selectionProvider = getSite().getSelectionProvider();
207 getSite().registerContextMenu(TaxonNameEditor.ID, menuManager,
208 selectionProvider);
209
210 parent.setData(taxon);
211
212 TableWrapLayout layout = new TableWrapLayout();
213 layout.leftMargin = 0;
214 layout.rightMargin = 0;
215 layout.topMargin = 0;
216 layout.bottomMargin = 0;
217
218 layout.verticalSpacing = 0;
219 layout.horizontalSpacing = 0;
220
221 parent.setLayout(layout);
222 parent.setBackground(AbstractUtility
223 .getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
224
225 createOrUpdateNameComposites();
226
227 createDragSupport();
228
229 setFocus();
230 }
231
232 /**
233 * <p>
234 * createNameComposites
235 * </p>
236 */
237 public void createOrUpdateNameComposites() {
238 this.taxon = (Taxon)CdmStore.getService(ITaxonService.class).load(this.getTaxon().getUuid());
239 ContainerFactory.createOrUpdateAcceptedTaxonsHomotypicGroup(this);
240 ContainerFactory.createOrUpdateHeterotypicSynonymyGroups(this);
241 ContainerFactory.createOrUpdateMisapplicationsGroup(this);
242
243 // Redraw composite
244 managedForm.reflow(true);
245 }
246
247 /**
248 * <p>
249 * Getter for the field <code>taxon</code>.
250 * </p>
251 *
252 * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
253 */
254 public Taxon getTaxon() {
255 return (Taxon) HibernateProxyHelper.deproxy(taxon);
256 }
257
258 /**
259 * <p>
260 * setDirty
261 * </p>
262 */
263 public void setDirty() {
264 managedForm.dirtyStateChanged();
265 }
266
267 /*
268 * (non-Javadoc)
269 *
270 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
271 */
272 /** {@inheritDoc} */
273 @Override
274 public void setFocus() {
275 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
276 if (getSelectedContainer() == null) {
277 throw new IllegalStateException(
278 "There should always be a selected object.");
279 }
280 getSelectedContainer().setSelected();
281
282 // check permissions
283 boolean doEnable = permissionsSatisfied();
284 setEnabled(doEnable);
285 }
286
287 /* (non-Javadoc)
288 * @see eu.etaxonomy.taxeditor.editor.name.ISecuredEditorPart#permissionsSatisfied()
289 */
290 @Override
291 public boolean permissionsSatisfied() {
292 TaxonNode taxonNode = ((TaxonEditorInput)getEditorInput()).getTaxonNode();
293 boolean doEnable = CdmStore.currentAuthentiationHasPermission(taxonNode, RequiredPermissions.TAXONNODE_EDIT);
294 return doEnable;
295 }
296
297 /** {@inheritDoc} */
298 @Override
299 public void setInput(IEditorInput input) {
300 this.setInputWithNotify(input);
301 }
302
303 /*
304 * (non-Javadoc)
305 *
306 * @see
307 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
308 * ()
309 */
310 /**
311 * <p>
312 * getConversationHolder
313 * </p>
314 *
315 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
316 * object.
317 */
318 @Override
319 public ConversationHolder getConversationHolder() {
320 return conversation;
321 }
322
323 /*
324 * (non-Javadoc)
325 *
326 * @see
327 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu
328 * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
329 */
330 /** {@inheritDoc} */
331 @Override
332 public void update(CdmDataChangeMap events) {
333 // redraw();
334 }
335
336 /**
337 * Redraws this editor return true on success
338 *
339 * @return a boolean.
340 */
341 @Override
342 public boolean redraw() {
343 return redraw(true);
344 }
345
346 /**
347 * {@inheritDoc}
348 *
349 * Redraws the editor controls
350 */
351 @Override
352 public boolean redraw(boolean focus) {
353
354 createOrUpdateNameComposites();
355
356 if (focus) {
357 setFocus();
358 }
359
360 return true;
361 }
362
363 /**
364 * <p>
365 * getMultiPageTaxonEditor
366 * </p>
367 *
368 * @return a {@link eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor}
369 * object.
370 */
371 public MultiPageTaxonEditor getMultiPageTaxonEditor() {
372 return editor;
373 }
374
375 /*
376 * (non-Javadoc)
377 *
378 * @see
379 * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation
380 * ()
381 */
382 /** {@inheritDoc} */
383 @Override
384 public boolean postOperation(CdmBase objectAffectedByOperation) {
385
386 editor.changed(objectAffectedByOperation);
387
388 redraw(false);
389
390 if (objectAffectedByOperation instanceof TaxonBase) {
391 objectAffectedByLastOperation = (TaxonBase) objectAffectedByOperation;
392 }
393
394 return true;
395 }
396
397 /**
398 * <p>
399 * Getter for the field <code>managedForm</code>.
400 * </p>
401 *
402 * @return the managedForm
403 */
404 public ManagedForm getManagedForm() {
405 return managedForm;
406 }
407
408 /**
409 * <p>
410 * getControl
411 * </p>
412 *
413 * @return a {@link org.eclipse.swt.widgets.Composite} object.
414 */
415 @Override
416 public Composite getControl() {
417 return this.getManagedForm().getForm().getBody();
418 }
419
420 /**
421 * <p>
422 * Getter for the field <code>menu</code>.
423 * </p>
424 *
425 * @return the menu
426 */
427 public Menu getMenu() {
428 if (menu == null || menu.isDisposed()) {
429 // Creating the menu because it was either not initialised or
430 // disposed while refreshing the editor
431 menu = menuManager.createContextMenu(parent);
432 }
433 return menu;
434 }
435
436 /**
437 * <p>
438 * checkForEmptyNames
439 * </p>
440 *
441 * @return true if there are empty names
442 */
443 public boolean checkForEmptyNames() {
444 for (AbstractGroupedContainer container : getGroupedContainers()) {
445 if (container.getName() == null
446 || StringUtils.isEmpty(container.getName().getTitleCache())) {
447 return true;
448 }
449 }
450 return false;
451 }
452
453 public Set<AbstractGroupedContainer> getEmptyContainers() {
454 Set<AbstractGroupedContainer> containersWithEmptyNames = new HashSet<AbstractGroupedContainer>();
455
456 for (AbstractGroupedContainer container : getGroupedContainers()) {
457 if (container.getName() == null
458 || StringUtils.isEmpty(container.getName().getTitleCache())) {
459 containersWithEmptyNames.add(container);
460 }
461 }
462
463 return containersWithEmptyNames;
464 }
465
466 /** {@inheritDoc} */
467 @Override
468 public void doSave(IProgressMonitor monitor) {
469
470 monitor.beginTask("Saving names", getGroupedContainers().size());
471
472 try {
473 // check for empty names
474 for (AbstractGroupedContainer container : getGroupedContainers()) {
475
476 monitor.subTask("Saving composite: "
477 + container.getTaxonBase().getTitleCache());
478 container.persistName();
479
480 // In case the progress monitor was canceled throw an exception.
481 if (monitor.isCanceled()) {
482 throw new OperationCanceledException();
483 }
484
485 // Otherwise declare this step as done.
486 monitor.worked(1);
487 }
488 } finally {
489
490 // Stop the progress monitor.
491 monitor.done();
492 }
493
494 }
495
496 /** {@inheritDoc} */
497 @Override
498 public void doSaveAs() {
499 }
500
501 /** {@inheritDoc} */
502 @Override
503 public void init(IEditorSite site, IEditorInput input)
504 throws PartInitException {
505
506 if (!(input != null)) {
507 throw new PartInitException("Invalid Input: Must be IEditorInput");
508 }
509
510 if (input.getAdapter(Taxon.class) != null) {
511 taxon = (Taxon) input.getAdapter(Taxon.class);
512 } else {
513 throw new PartInitException("Invalid Input: Taxon cannot be null");
514 }
515
516 setSite(site);
517 setInput(input);
518
519 simpleSelectionProvider = new SimpleSelectionProvider();
520 getSite().setSelectionProvider(simpleSelectionProvider);
521 }
522
523
524 /**
525 *
526 */
527 private void createDragSupport() {
528 // Listen for names being dragged outside of existing homotypic groups -
529 // user wants to create a new group
530 Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
531 int operations = DND.DROP_MOVE;
532 if (target == null) {
533 target = new DropTarget(parent, operations);
534 target.setTransfer(types);
535 target.addDropListener(new NameEditorDropTargetListener(this));
536 }
537 }
538
539 /**
540 * <p>
541 * Getter for the field <code>acceptedNameContainer</code>.
542 * </p>
543 *
544 * @return a
545 * {@link eu.etaxonomy.taxeditor.editor.name.container.AcceptedNameContainer}
546 * object.
547 */
548 public AcceptedNameContainer getAcceptedNameContainer() {
549 return getAcceptedGroup().getAcceptedNameContainer();
550 }
551
552 /**
553 * <p>
554 * getSynonymGroup
555 * </p>
556 *
557 * @param homotypicalGroup
558 * a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
559 * @return a
560 * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup}
561 * object.
562 */
563 public HomotypicalSynonymGroup getHomotypicalGroupContainer(
564 HomotypicalGroup homotypicalGroup) {
565 for (HomotypicalSynonymGroup group : getHeterotypicSynonymGroups()) {
566 if (group.getGroup().equals(homotypicalGroup)) {
567 return group;
568 }
569 }
570
571 return null;
572 }
573
574 /**
575 * <p>
576 * getDirtyNames
577 * </p>
578 *
579 * @return a Set containing all composites that have been edited
580 */
581 public Set<AbstractGroupedContainer> getDirtyNames() {
582 Set<AbstractGroupedContainer> dirtyNames = new HashSet<AbstractGroupedContainer>();
583
584 for (AbstractGroupedContainer composite : getGroupedContainers()) {
585 if (composite.isDirty()) {
586 dirtyNames.add(composite);
587 }
588 }
589
590 return dirtyNames;
591 }
592
593 /**
594 * <p>
595 * getGroupedContainers
596 * </p>
597 *
598 * @return a {@link java.util.List} object.
599 */
600 public List<AbstractGroupedContainer> getGroupedContainers() {
601 List<AbstractGroupedContainer> groupedComposites = new ArrayList<AbstractGroupedContainer>();
602
603 for (AbstractGroup group : getAllGroups()) {
604 groupedComposites.addAll(group.getGroupedContainers());
605 }
606
607 return groupedComposites;
608 }
609
610 /**
611 * <p>
612 * getAllGroups
613 * </p>
614 *
615 * @return a {@link java.util.List} object.
616 */
617 public List<AbstractGroup> getAllGroups() {
618 List<AbstractGroup> allGroups = new ArrayList<AbstractGroup>();
619
620 allGroups.add(getAcceptedGroup());
621
622 // List<HomotypicalSynonymGroup> grps = getHeterotypicSynonymGroups(); // UNUSED => remove
623
624 heterotypicSynonymGroups = getHeterotypicSynonymGroups();
625
626 if (heterotypicSynonymGroups != null) {
627 allGroups.addAll(heterotypicSynonymGroups);
628 }
629
630 if (misappliedGroup != null) {
631 allGroups.add(misappliedGroup);
632 }
633
634 return allGroups;
635 }
636
637 /*
638 * (non-Javadoc)
639 *
640 * @see org.eclipse.ui.part.EditorPart#isDirty()
641 */
642 /** {@inheritDoc} */
643 @Override
644 public boolean isDirty() {
645 return editor.isDirty();
646 }
647
648 /*
649 * (non-Javadoc)
650 *
651 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
652 */
653 /** {@inheritDoc} */
654 @Override
655 public void dispose() {
656 conversation.unregisterForDataStoreChanges(this);
657 super.dispose();
658 }
659
660 /*
661 * (non-Javadoc)
662 *
663 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
664 */
665 /** {@inheritDoc} */
666 @Override
667 public boolean isSaveAsAllowed() {
668 return false;
669 }
670
671 /*
672 * (non-Javadoc)
673 *
674 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.
675 * IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
676 */
677 /** {@inheritDoc} */
678 @Override
679 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
680
681 }
682
683 /**
684 * <p>
685 * getNameEditor
686 * </p>
687 *
688 * @return a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor}
689 * object.
690 */
691 @Override
692 public TaxonNameEditor getEditor() {
693 return this;
694 }
695
696 /**
697 * <p>
698 * Getter for the field <code>selectedObject</code>.
699 * </p>
700 *
701 * @return a
702 * {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer}
703 * object.
704 */
705 public AbstractGroupedContainer getSelectedContainer() {
706
707 TaxonBase selectedTaxonBase = null;
708
709 TaxonEditorInput input = (TaxonEditorInput) editor.getEditorInput();
710 if (input.getInitiallySelectedTaxonBase() != null) {
711 selectedTaxonBase = input.getInitiallySelectedTaxonBase();
712 } else {
713 if (selection != null) {
714 selectedTaxonBase = selection;
715 }
716 }
717
718 return (selectedTaxonBase != null) ? getContainer(selectedTaxonBase)
719 : getAcceptedNameContainer();
720 }
721
722 /**
723 * <p>
724 * dragEntered
725 * </p>
726 */
727 @Override
728 public void dragEntered() {
729 // TODO change this
730 getControl().setBackground(
731 AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
732 }
733
734 /**
735 * <p>
736 * dragLeft
737 * </p>
738 */
739 @Override
740 public void dragLeft() {
741 getControl().setBackground(
742 AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
743 }
744
745
746 /**
747 * <p>
748 * setMisapplicationsGroup
749 * </p>
750 *
751 * @param misappliedGroup
752 * a
753 * {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup}
754 * object.
755 */
756 public void setMisapplicationsGroup(MisappliedGroup misappliedGroup) {
757 this.misappliedGroup = misappliedGroup;
758 }
759
760 /*
761 * (non-Javadoc)
762 *
763 * @see
764 * eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage#isRedrawing()
765 */
766 /**
767 * <p>
768 * isRedrawing
769 * </p>
770 *
771 * @return a boolean.
772 */
773 @Override
774 public boolean isRedrawing() {
775 return false;
776 }
777
778 /**
779 * <p>
780 * getToolkit
781 * </p>
782 *
783 * @return a {@link org.eclipse.ui.forms.widgets.FormToolkit} object.
784 */
785 public FormToolkit getToolkit() {
786 return managedForm.getToolkit();
787 }
788
789 /**
790 * <p>
791 * getHeterotypicSynonymGroups
792 * </p>
793 *
794 * @return a {@link java.util.List} object.
795 */
796 public List<HomotypicalSynonymGroup> getHeterotypicSynonymGroups() {
797 return heterotypicSynonymGroups;
798 }
799
800 /**
801 * <p>
802 * addHeterotypicSynonymGroup
803 * </p>
804 *
805 * @param group
806 * a
807 * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup}
808 * object.
809 */
810 public void addHeterotypicSynonymGroup(HomotypicalSynonymGroup group) {
811 heterotypicSynonymGroups.add(group);
812 }
813
814 /**
815 * <p>
816 * getHomotypicSynonymGroup
817 * </p>
818 *
819 * @return a
820 * {@link eu.etaxonomy.taxeditor.editor.name.container.HomotypicalSynonymGroup}
821 * object.
822 */
823 public AcceptedGroup getAcceptedGroup() {
824 return acceptedGroup;
825 }
826
827 /**
828 *
829 * @param acceptedGroup
830 */
831 public void setAcceptedGroup(AcceptedGroup acceptedGroup) {
832 this.acceptedGroup = acceptedGroup;
833 }
834
835 /**
836 * <p>
837 * Getter for the field <code>misappliedGroup</code>.
838 * </p>
839 *
840 * @return a
841 * {@link eu.etaxonomy.taxeditor.editor.name.container.MisappliedGroup}
842 * object.
843 */
844 public MisappliedGroup getMisappliedGroup() {
845 return misappliedGroup;
846 }
847
848 // TODO not very useful at the moment
849 /**
850 * <p>
851 * isActive
852 * </p>
853 *
854 * @return a boolean.
855 */
856 public boolean isActive() {
857 IWorkbenchPart activePart = AbstractUtility.getActivePart();
858 return editor.equals(activePart);
859 }
860
861 /**
862 * <p>
863 * onComplete
864 * </p>
865 *
866 * @return a boolean.
867 */
868 @Override
869 public boolean onComplete() {
870 getContainer(objectAffectedByLastOperation).setSelected();
871 return true;
872 }
873
874 /** {@inheritDoc} */
875 @Override
876 public void partChanged(Integer eventType, IWorkbenchPartReference partRef) {
877 if (!partRef.getPart(false).equals(editor)) {
878 // getSelectedObject().colorSelected(AbstractGroupedContainer.SELECTED_NO_FOCUS);
879 }
880 }
881
882 /**
883 * @param retainedGroup
884 */
885 public void removeGroup(AbstractGroup group) {
886 if (group != null) {
887 group.dispose();
888
889 //if (heterotypicSynonymGroups != null) {
890 heterotypicSynonymGroups.remove(group);
891 //}
892 }
893 }
894
895 /**
896 * @param element
897 * @return
898 */
899 public AbstractGroupedContainer getContainer(TaxonBase taxonBase) {
900 List<AbstractGroupedContainer> groupedContainers = getGroupedContainers();
901 for (AbstractGroupedContainer container : groupedContainers) {
902 if (container.getData().equals(taxonBase)
903 && container.getNameViewer().getTextWidget() != null) {
904 return container;
905 }
906 }
907 return getAcceptedNameContainer();
908 }
909
910 /* (non-Javadoc)
911 * @see eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage#setOnError()
912 */
913 @Override
914 public void setOnError() {
915 Color disabledColor = AbstractUtility.getColor(Resources.COLOR_EDITOR_ERROR);
916 setEnabled(false, disabledColor);
917 }
918
919 /* (non-Javadoc)
920 * @see eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage#setDisabled()
921 */
922 @Override
923 public void setDisabled(){
924 Color disabledColor = AbstractUtility.getColor(Resources.COLOR_TEXT_DISABLED_BACKGROUND);
925 setEnabled(false);
926 }
927
928 protected void setEnabled(boolean enabled, Color background) {
929
930 for(AbstractGroupedContainer groupedContainer : getGroupedContainers()){
931 groupedContainer.setEnabled(enabled);
932 }
933
934 // send an empty selection to the current provider - TODO only on error ???
935 if (!enabled) {
936 getManagedForm().setInput(null);
937
938 for (AbstractGroupedContainer groupedContainer : getGroupedContainers()) {
939 groupedContainer.setBackground(background);
940 }
941 }
942 getControl().setBackground(background);
943 }
944
945 @Override
946 public void setEnabled(boolean enabled) {
947 Color background = AbstractUtility.getColor(enabled ? Resources.COLOR_COMPOSITE_BACKGROUND : Resources.COLOR_TEXT_DISABLED_BACKGROUND);
948 setEnabled(enabled, background);
949 }
950 }