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