Merge branch 'release/5.18.0'
[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.FeatureState;
20 import eu.etaxonomy.cdm.model.term.TermNode;
21 import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
25 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
26
27 /**
28 * @author pplitzner
29 * @date 06.03.2018
30 *
31 */
32 public class InapplicableIfEntityCollectionSectionForNode extends AbstractEntityCollectionSection<TermNode, FeatureState>{
33
34 public InapplicableIfEntityCollectionSectionForNode(CdmFormFactory formFactory, ConversationHolder conversation,
35 ICdmFormElement parentElement, int style) {
36 super(formFactory, conversation, parentElement, "Inapplicable If", style);
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 @Override
43 public Collection<FeatureState> getCollection(TermNode entity) {
44 return entity.getInapplicableIf();
45 }
46
47 /**
48 * {@inheritDoc}
49 */
50 @Override
51 public Comparator<FeatureState> getComparator() {
52 return new DefaultCdmBaseComparator<>();
53 }
54
55
56 /**
57 * {@inheritDoc}
58 */
59 @Override
60 public FeatureState createNewElement() {
61 FeatureStateWizard wizard = new FeatureStateWizard(TermNodeDto.fromNode(getEntity(), null), formFactory);
62 WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
63 int status = dialog.open();
64 if(status == IStatus.OK) {
65 return wizard.getFeatureState();
66 }
67 return null;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 @Override
74 public void addElement(FeatureState element) {
75 getEntity().getInapplicableIf().add(element);
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 @Override
82 public FeatureState addExisting() {
83 return null;
84 }
85
86 /**
87 * {@inheritDoc}
88 */
89 @Override
90 public boolean allowAddExisting() {
91 return false;
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 @Override
98 public void removeElement(FeatureState element) {
99 getEntity().getInapplicableIf().remove(element);
100 }
101
102 /** {@inheritDoc} */
103 @Override
104 public String getEmptyString() {
105 return "No feature state added yet.";
106 }
107
108 /** {@inheritDoc} */
109 @Override
110 protected String getTooltipString() {
111 return "Add a feature state";
112 }
113
114 }