6e54b1c04af17d71325113b3ca9c1b6d24dc4f33
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / feature / OnlyApplicableIfEntityCollectionSectionForNode.java
1 /**
2 * Copyright (C) 2018 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 package eu.etaxonomy.taxeditor.ui.section.feature;
10
11 import java.util.Collection;
12 import java.util.Comparator;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.jface.wizard.WizardDialog;
16
17 import eu.etaxonomy.cdm.model.description.FeatureState;
18 import eu.etaxonomy.cdm.model.term.TermNode;
19 import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
20 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
23 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
24
25 /**
26 * @author pplitzner
27 * @date 06.03.2018
28 */
29 public class OnlyApplicableIfEntityCollectionSectionForNode extends AbstractEntityCollectionSection<TermNode, FeatureState>{
30
31 public OnlyApplicableIfEntityCollectionSectionForNode(CdmFormFactory formFactory,
32 ICdmFormElement parentElement, int style) {
33 super(formFactory, parentElement, "Only applicable if", style);
34 }
35
36 @Override
37 public Collection<FeatureState> getCollection(TermNode entity) {
38 return entity.getOnlyApplicableIf();
39 }
40
41 @Override
42 public Comparator<FeatureState> getComparator() {
43 return new DefaultCdmBaseComparator<>();
44 }
45
46 @Override
47 public FeatureState createNewElement() {
48 FeatureStateWizard wizard = new FeatureStateWizard(TermNodeDto.fromNode(getEntity(), null), formFactory);
49 WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
50 int status = dialog.open();
51 if(status == IStatus.OK) {
52 return wizard.getFeatureState();
53 }
54 return null;
55 }
56
57 @Override
58 public void addElement(FeatureState element) {
59 getEntity().getOnlyApplicableIf().add(element);
60 }
61
62 @Override
63 public FeatureState addExisting() {
64 return null;
65 }
66
67 @Override
68 public boolean allowAddExisting() {
69 return false;
70 }
71
72 @Override
73 public void removeElement(FeatureState element) {
74 getEntity().getOnlyApplicableIf().remove(element);
75 }
76
77 @Override
78 public String getEmptyString() {
79 return "No feature state added yet.";
80 }
81
82 @Override
83 protected String getTooltipString() {
84 return "Add a feature state";
85 }
86 }