ref #8774: adapt term tree editors to usage of termDtos
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / InapplicableIfEntityCollectionSectionForNode.java
1 // $Id$
2 /**
3 * Copyright (C) 2018 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.ui.section.feature;
11
12 import java.util.Collection;
13 import java.util.Comparator;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jface.wizard.WizardDialog;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.model.description.Feature;
20 import eu.etaxonomy.cdm.model.description.FeatureState;
21 import eu.etaxonomy.cdm.model.term.TermNode;
22 import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
26 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
27
28 /**
29 * @author pplitzner
30 * @date 06.03.2018
31 *
32 */
33 public class InapplicableIfEntityCollectionSectionForNode extends AbstractEntityCollectionSection<TermNode<? extends Feature>, FeatureState>{
34
35 public InapplicableIfEntityCollectionSectionForNode(CdmFormFactory formFactory, ConversationHolder conversation,
36 ICdmFormElement parentElement, int style) {
37 super(formFactory, conversation, parentElement, "Inapplicable If", style);
38 }
39
40 /**
41 * {@inheritDoc}
42 */
43 @Override
44 public Collection<FeatureState> getCollection(TermNode <? extends Feature>entity) {
45 return entity.getInapplicableIf();
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 @Override
52 public Comparator<FeatureState> getComparator() {
53 return new DefaultCdmBaseComparator<>();
54 }
55
56
57 /**
58 * {@inheritDoc}
59 */
60 @Override
61 public FeatureState createNewElement() {
62 FeatureStateWizard wizard = new FeatureStateWizard(new TermNodeDto(getEntity()), formFactory);
63 WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
64 int status = dialog.open();
65 if(status == IStatus.OK) {
66 return wizard.getFeatureState();
67 }
68 return null;
69 }
70
71 /**
72 * {@inheritDoc}
73 */
74 @Override
75 public void addElement(FeatureState element) {
76 getEntity().getInapplicableIf().add(element);
77 }
78
79 /**
80 * {@inheritDoc}
81 */
82 @Override
83 public FeatureState addExisting() {
84 return null;
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 @Override
91 public boolean allowAddExisting() {
92 return false;
93 }
94
95 /**
96 * {@inheritDoc}
97 */
98 @Override
99 public void removeElement(FeatureState element) {
100 getEntity().getInapplicableIf().remove(element);
101 }
102
103 /** {@inheritDoc} */
104 @Override
105 public String getEmptyString() {
106 return "No feature state added yet.";
107 }
108
109 /** {@inheritDoc} */
110 @Override
111 protected String getTooltipString() {
112 return "Add a feature state";
113 }
114
115 }