minor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / DescriptiveDataSetComposite.java
1 /**
2 * Copyright (C) 2017 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.editor.descriptiveDataSet;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.stream.Collectors;
14
15 import org.eclipse.jface.viewers.TreeViewer;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
23 import org.eclipse.swt.widgets.Tree;
24
25 import eu.etaxonomy.cdm.model.common.TermType;
26 import eu.etaxonomy.cdm.model.description.FeatureTree;
27 import eu.etaxonomy.cdm.model.name.Rank;
28 import eu.etaxonomy.cdm.persistence.dto.TermDto;
29 import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
30 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
31 import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
32 import eu.etaxonomy.taxeditor.model.ImageResources;
33 import eu.etaxonomy.taxeditor.ui.combo.TermUuidComboViewer;
34 import eu.etaxonomy.taxeditor.util.TaxonTreeNodeContentProvider;
35 import eu.etaxonomy.taxeditor.util.TaxonTreeNodeLabelProvider;
36
37 /**
38 * @author pplitzner
39 * @since Nov 21, 2017
40 *
41 */
42 public class DescriptiveDataSetComposite extends Composite {
43 private Text txtDescriptiveDataSet;
44 private TermUuidComboViewer comboRankMin;
45 private TermUuidComboViewer comboRankMax;
46 private FeatureTreeEditorComposite featureTreeEditorComposite;
47 private TreeViewer taxonNodeTree;
48 private List<TermDto> areas = new ArrayList<>();
49 private Text textAreaText;
50 private Button btnChooseArea;
51 private Button btnRemoveRankMin;
52 private Button btnRemoveRankMax;
53
54 public DescriptiveDataSetComposite(Composite parent, int style) {
55 super(parent, style);
56
57 setLayout(new GridLayout(3, false));
58
59 Label lblNewLabel = new Label(this, SWT.NONE);
60 lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
61 lblNewLabel.setText(Messages.DescriptiveDataSetComposite_LABEL);
62
63 txtDescriptiveDataSet = new Text(this, SWT.BORDER);
64 txtDescriptiveDataSet.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
65
66 Label lblNewLabel_1 = new Label(this, SWT.NONE);
67 lblNewLabel_1.setText(Messages.DescriptiveDataSetComposite_TAXON_FILTER);
68
69 Label lblNewLabel_2 = new Label(this, SWT.NONE);
70 lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
71 lblNewLabel_2.setText(Messages.DescriptiveDataSetComposite_RANK_MIN);
72
73 Composite composite_1 = new Composite(this, SWT.NONE);
74 composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
75 GridLayout gl_composite_1 = new GridLayout(2, false);
76 gl_composite_1.horizontalSpacing = 0;
77 gl_composite_1.verticalSpacing = 0;
78 gl_composite_1.marginWidth = 0;
79 gl_composite_1.marginHeight = 0;
80 composite_1.setLayout(gl_composite_1);
81
82 comboRankMin = new TermUuidComboViewer(composite_1, SWT.NONE);
83 comboRankMin.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
84 comboRankMin.setInput(TermType.Rank);
85
86 btnRemoveRankMin = new Button(composite_1, SWT.NONE);
87 btnRemoveRankMin.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
88
89 Tree tree = new Tree(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
90 tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4));
91 taxonNodeTree = new TreeViewer(tree);
92
93 taxonNodeTree.setContentProvider(new TaxonTreeNodeContentProvider());
94 taxonNodeTree.setLabelProvider(new TaxonTreeNodeLabelProvider());
95
96 Label lblNewLabel_3 = new Label(this, SWT.NONE);
97 lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
98 lblNewLabel_3.setText(Messages.DescriptiveDataSetComposite_RANK_MAX);
99
100 Composite composite_2 = new Composite(this, SWT.NONE);
101 composite_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
102 GridLayout gl_composite_2 = new GridLayout(2, false);
103 gl_composite_2.horizontalSpacing = 0;
104 gl_composite_2.verticalSpacing = 0;
105 gl_composite_2.marginWidth = 0;
106 gl_composite_2.marginHeight = 0;
107 composite_2.setLayout(gl_composite_2);
108
109 comboRankMax = new TermUuidComboViewer(composite_2, SWT.NONE);
110 comboRankMax.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
111 comboRankMax.setInput(TermType.Rank);
112
113 btnRemoveRankMax = new Button(composite_2, SWT.NONE);
114 btnRemoveRankMax.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
115
116 Label lblNewLabel_4 = new Label(this, SWT.NONE);
117 lblNewLabel_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
118 lblNewLabel_4.setText(Messages.DescriptiveDataSetComposite_AREA);
119
120 Composite composite = new Composite(this, SWT.NONE);
121 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
122 GridLayout gl_composite = new GridLayout(2, false);
123 gl_composite.horizontalSpacing = 0;
124 gl_composite.verticalSpacing = 0;
125 gl_composite.marginHeight = 0;
126 gl_composite.marginWidth = 0;
127 composite.setLayout(gl_composite);
128
129 textAreaText = new Text(composite, SWT.BORDER);
130 textAreaText.setEditable(false);
131 textAreaText.setText(Messages.DescriptiveDataSetComposite_CHOOSE);
132 textAreaText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
133
134 btnChooseArea = new Button(composite, SWT.NONE);
135 btnChooseArea.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
136
137 featureTreeEditorComposite = new FeatureTreeEditorComposite(this, SWT.NONE);
138 featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
139 }
140
141 @Override
142 protected void checkSubclass() {
143 // Disable the check that prevents subclassing of SWT components
144 }
145 public Text getTxt_label() {
146 return txtDescriptiveDataSet;
147 }
148
149 public TermUuidComboViewer getRankMin() {
150 return comboRankMin;
151 }
152 public TermUuidComboViewer getRankMax() {
153 return comboRankMax;
154 }
155
156 public void setRankMin(Rank min) {
157 comboRankMin.setElement(min);
158 }
159 public void setRankMax(Rank max) {
160 comboRankMax.setElement(max);
161 }
162
163 public FeatureTreeEditorComposite getFeatureTreeEditorComposite() {
164 return featureTreeEditorComposite;
165 }
166
167 public FeatureTree getCharacters(){
168 return featureTreeEditorComposite.getFeatureTree();
169 }
170 public void setCharacters(FeatureTree characters) {
171 featureTreeEditorComposite.setSelectedTree(characters);
172 }
173
174 public TreeViewer getTaxonNodeTree() {
175 return taxonNodeTree;
176 }
177 public List<TermDto> getAreas() {
178 return areas;
179 }
180 public void setAreas(List<TermDto> areas) {
181 this.areas = areas;
182 textAreaText.setText(areas.stream().map(area->{
183 area.localize(new TermRepresentation_L10n());
184 return area.getRepresentation_L10n();
185 }).collect(Collectors.joining(", ")));
186 }
187 public Button getBtnChooseArea() {
188 return btnChooseArea;
189 }
190 public Button getBtnRemoveRankMin() {
191 return btnRemoveRankMin;
192 }
193 public Button getBtnRemoveRankMax() {
194 return btnRemoveRankMax;
195 }
196 }