1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 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.cdm.vaadin.component;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
|
18
|
import com.vaadin.annotations.AutoGenerated;
|
19
|
import com.vaadin.data.Container;
|
20
|
import com.vaadin.data.Property;
|
21
|
import com.vaadin.data.Property.ValueChangeEvent;
|
22
|
import com.vaadin.data.util.IndexedContainer;
|
23
|
import com.vaadin.data.util.sqlcontainer.RowId;
|
24
|
import com.vaadin.event.ItemClickEvent;
|
25
|
import com.vaadin.ui.Alignment;
|
26
|
import com.vaadin.ui.Button;
|
27
|
import com.vaadin.ui.CheckBox;
|
28
|
import com.vaadin.ui.ComboBox;
|
29
|
import com.vaadin.ui.Component;
|
30
|
import com.vaadin.ui.CustomComponent;
|
31
|
import com.vaadin.ui.GridLayout;
|
32
|
import com.vaadin.ui.HorizontalLayout;
|
33
|
import com.vaadin.ui.Table;
|
34
|
import com.vaadin.ui.Table.ColumnHeaderMode;
|
35
|
import com.vaadin.ui.TextField;
|
36
|
import com.vaadin.ui.VerticalLayout;
|
37
|
import com.vaadin.ui.themes.Reindeer;
|
38
|
|
39
|
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
|
40
|
|
41
|
/**
|
42
|
* @author cmathew
|
43
|
* @date 11 Mar 2015
|
44
|
*
|
45
|
*/
|
46
|
public class StatusComposite extends CustomComponent implements IStatusComposite {
|
47
|
|
48
|
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
|
49
|
|
50
|
@AutoGenerated
|
51
|
private GridLayout mainLayout;
|
52
|
@AutoGenerated
|
53
|
private Table taxaTreeTable;
|
54
|
@AutoGenerated
|
55
|
private HorizontalLayout addRemovehorizontalLayout;
|
56
|
@AutoGenerated
|
57
|
private Button removeButton;
|
58
|
@AutoGenerated
|
59
|
private ComboBox addComboBox;
|
60
|
@AutoGenerated
|
61
|
private TextField searchTextField;
|
62
|
@AutoGenerated
|
63
|
private VerticalLayout filterVerticalLayout;
|
64
|
@AutoGenerated
|
65
|
private Table filterTable;
|
66
|
@AutoGenerated
|
67
|
private ComboBox filterComboBox;
|
68
|
@AutoGenerated
|
69
|
private ComboBox classificationComboBox;
|
70
|
private static final Logger logger = Logger.getLogger(StatusComposite.class);
|
71
|
private StatusComponentListener listener;
|
72
|
|
73
|
private static final String SELECT_FILTER = "Select filter ...";
|
74
|
private static final String SELECT_CLASSIFICATION = "Select classification ...";
|
75
|
private static final String ADD_TAXON_SYNONYM = "Add ...";
|
76
|
/**
|
77
|
* The constructor should first build the main layout, set the
|
78
|
* composition root and then do any custom initialization.
|
79
|
*
|
80
|
* The constructor will not be automatically regenerated by the
|
81
|
* visual editor.
|
82
|
*/
|
83
|
public StatusComposite() {
|
84
|
buildMainLayout();
|
85
|
setCompositionRoot(mainLayout);
|
86
|
|
87
|
addUIListeners();
|
88
|
initFilterNativeSelect();
|
89
|
initFilterTable();
|
90
|
initAddComboBox();
|
91
|
setEnabledAll(false);
|
92
|
}
|
93
|
|
94
|
public void init() {
|
95
|
initClassificationComboBox();
|
96
|
|
97
|
}
|
98
|
|
99
|
public void setEnabledAll(boolean enable) {
|
100
|
filterComboBox.setEnabled(enable);
|
101
|
filterTable.setEnabled(enable);
|
102
|
taxaTreeTable.setEnabled(enable);
|
103
|
addComboBox.setEnabled(enable);
|
104
|
removeButton.setEnabled(enable);
|
105
|
}
|
106
|
|
107
|
private void initTaxaTable(int classificationId) {
|
108
|
|
109
|
if(listener != null) {
|
110
|
List<String> columnIds = new ArrayList<String>();
|
111
|
columnIds.add("Name");
|
112
|
taxaTreeTable.setColumnExpandRatio("Name", 1);
|
113
|
columnIds.add("Pb");
|
114
|
taxaTreeTable.setColumnWidth("Pb", 10);
|
115
|
taxaTreeTable.addGeneratedColumn("Pb", new BooleanCheckBoxGenerator());
|
116
|
try {
|
117
|
taxaTreeTable.setContainerDataSource(listener.loadTaxa(classificationId), columnIds);
|
118
|
} catch (SQLException e) {
|
119
|
// TODO Auto-generated catch block
|
120
|
e.printStackTrace();
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
private void initClassificationComboBox() {
|
126
|
|
127
|
classificationComboBox.setNewItemsAllowed(false);
|
128
|
classificationComboBox.setNullSelectionAllowed(false);
|
129
|
classificationComboBox.setImmediate(true);
|
130
|
classificationComboBox.setItemCaptionPropertyId("titleCache");
|
131
|
classificationComboBox.setInputPrompt(SELECT_CLASSIFICATION);
|
132
|
if(listener != null) {
|
133
|
try {
|
134
|
classificationComboBox.setContainerDataSource(listener.loadClassifications());
|
135
|
} catch (SQLException e) {
|
136
|
// TODO Auto-generated catch block
|
137
|
e.printStackTrace();
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
|
142
|
|
143
|
private void initFilterNativeSelect() {
|
144
|
filterComboBox.setNullSelectionAllowed(false);
|
145
|
filterComboBox.setImmediate(true);
|
146
|
filterComboBox.addItem(SELECT_FILTER);
|
147
|
filterComboBox.addItem("unplaced");
|
148
|
filterComboBox.addItem("not finished");
|
149
|
filterComboBox.addItem("published");
|
150
|
filterComboBox.setValue(SELECT_FILTER);
|
151
|
}
|
152
|
|
153
|
|
154
|
private void initFilterTable() {
|
155
|
filterTable.setNullSelectionAllowed(false);
|
156
|
Container container = new IndexedContainer();
|
157
|
container.addContainerProperty("filter", String.class, "");
|
158
|
|
159
|
filterTable.setContainerDataSource(container);
|
160
|
filterTable.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
|
161
|
filterTable.addStyleName(Reindeer.TABLE_BORDERLESS);
|
162
|
filterTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
|
163
|
|
164
|
private static final long serialVersionUID = -3363906932807556720L;
|
165
|
|
166
|
@Override
|
167
|
public String getStyle(Table source, Object itemId, Object propertyId) {
|
168
|
return "removable";
|
169
|
}
|
170
|
});
|
171
|
}
|
172
|
|
173
|
private void initAddComboBox() {
|
174
|
addComboBox.setNullSelectionAllowed(false);
|
175
|
addComboBox.setImmediate(true);
|
176
|
addComboBox.addItem(ADD_TAXON_SYNONYM);
|
177
|
addComboBox.addItem("New Accepted Taxon");
|
178
|
addComboBox.addItem("New Synonym");
|
179
|
addComboBox.setValue(ADD_TAXON_SYNONYM);
|
180
|
|
181
|
}
|
182
|
private void addUIListeners() {
|
183
|
addClassificationComboBoxListener();
|
184
|
addFilterComboBoxListener();
|
185
|
addFilterTableListener();
|
186
|
}
|
187
|
|
188
|
private void addClassificationComboBoxListener() {
|
189
|
|
190
|
classificationComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
191
|
|
192
|
private static final long serialVersionUID = 4196786323147791606L;
|
193
|
|
194
|
@Override
|
195
|
public void valueChange(ValueChangeEvent event) {
|
196
|
if (classificationComboBox.getValue() != null) {
|
197
|
Object selected = classificationComboBox.getValue();
|
198
|
logger.info("selected : " + selected);
|
199
|
int classificationId = (Integer)((RowId)selected).getId()[0];
|
200
|
initTaxaTable(classificationId);
|
201
|
setEnabledAll(true);
|
202
|
}
|
203
|
}
|
204
|
});
|
205
|
}
|
206
|
|
207
|
private void addFilterComboBoxListener() {
|
208
|
filterComboBox.addValueChangeListener(new Property.ValueChangeListener() {
|
209
|
|
210
|
private static final long serialVersionUID = 1314542578509878256L;
|
211
|
|
212
|
@Override
|
213
|
public void valueChange(ValueChangeEvent event) {
|
214
|
if (filterComboBox.getValue() != null) {
|
215
|
String selected = (String)filterComboBox.getValue();
|
216
|
logger.info("selected : " + selected);
|
217
|
if(!selected.equals(SELECT_FILTER)) {
|
218
|
filterTable.addItem(new Object[]{selected}, filterTable.getItemIds().size() + 1);
|
219
|
filterComboBox.setValue(SELECT_FILTER);
|
220
|
}
|
221
|
}
|
222
|
}
|
223
|
});
|
224
|
}
|
225
|
|
226
|
private void addFilterTableListener() {
|
227
|
filterTable.addItemClickListener(new ItemClickEvent.ItemClickListener() {
|
228
|
|
229
|
private static final long serialVersionUID = -4722168300711497739L;
|
230
|
|
231
|
@Override
|
232
|
public void itemClick(ItemClickEvent event) {
|
233
|
filterTable.removeItem(event.getItemId());
|
234
|
}}
|
235
|
);
|
236
|
}
|
237
|
|
238
|
|
239
|
/* (non-Javadoc)
|
240
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComponent#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComponent.StatusComponentListener)
|
241
|
*/
|
242
|
@Override
|
243
|
public void setListener(StatusComponentListener listener) {
|
244
|
this.listener = listener;
|
245
|
}
|
246
|
|
247
|
|
248
|
class BooleanCheckBoxGenerator implements Table.ColumnGenerator {
|
249
|
/**
|
250
|
* Generates the cell containing an open image when boolean is true
|
251
|
*/
|
252
|
@Override
|
253
|
public Component generateCell(Table source, Object itemId, Object columnId) {
|
254
|
Property prop = source.getItem(itemId).getItemProperty(columnId);
|
255
|
return new CheckBox(null, prop);
|
256
|
}
|
257
|
}
|
258
|
|
259
|
|
260
|
@AutoGenerated
|
261
|
private GridLayout buildMainLayout() {
|
262
|
// common part: create layout
|
263
|
mainLayout = new GridLayout();
|
264
|
mainLayout.setImmediate(false);
|
265
|
mainLayout.setWidth("320px");
|
266
|
mainLayout.setHeight("840px");
|
267
|
mainLayout.setMargin(true);
|
268
|
mainLayout.setSpacing(true);
|
269
|
mainLayout.setRows(6);
|
270
|
|
271
|
// top-level component properties
|
272
|
setWidth("320px");
|
273
|
setHeight("840px");
|
274
|
|
275
|
// classificationComboBox
|
276
|
classificationComboBox = new ComboBox();
|
277
|
classificationComboBox.setImmediate(false);
|
278
|
classificationComboBox.setWidth("100.0%");
|
279
|
classificationComboBox.setHeight("-1px");
|
280
|
mainLayout.addComponent(classificationComboBox, 0, 0);
|
281
|
|
282
|
// filterVerticalLayout
|
283
|
filterVerticalLayout = buildFilterVerticalLayout();
|
284
|
mainLayout.addComponent(filterVerticalLayout, 0, 1);
|
285
|
mainLayout.setComponentAlignment(filterVerticalLayout, new Alignment(20));
|
286
|
|
287
|
// searchTextField
|
288
|
searchTextField = new TextField();
|
289
|
searchTextField.setImmediate(false);
|
290
|
searchTextField.setWidth("100.0%");
|
291
|
searchTextField.setHeight("-1px");
|
292
|
mainLayout.addComponent(searchTextField, 0, 2);
|
293
|
mainLayout.setComponentAlignment(searchTextField, new Alignment(20));
|
294
|
|
295
|
// addRemovehorizontalLayout
|
296
|
addRemovehorizontalLayout = buildAddRemovehorizontalLayout();
|
297
|
mainLayout.addComponent(addRemovehorizontalLayout, 0, 4);
|
298
|
mainLayout.setComponentAlignment(addRemovehorizontalLayout, new Alignment(48));
|
299
|
|
300
|
// taxaTreeTable
|
301
|
taxaTreeTable = new Table();
|
302
|
taxaTreeTable.setImmediate(false);
|
303
|
taxaTreeTable.setWidth("100.0%");
|
304
|
taxaTreeTable.setHeight("536px");
|
305
|
mainLayout.addComponent(taxaTreeTable, 0, 5);
|
306
|
mainLayout.setComponentAlignment(taxaTreeTable, new Alignment(20));
|
307
|
|
308
|
return mainLayout;
|
309
|
}
|
310
|
|
311
|
@AutoGenerated
|
312
|
private VerticalLayout buildFilterVerticalLayout() {
|
313
|
// common part: create layout
|
314
|
filterVerticalLayout = new VerticalLayout();
|
315
|
filterVerticalLayout.setImmediate(false);
|
316
|
filterVerticalLayout.setWidth("100.0%");
|
317
|
filterVerticalLayout.setHeight("-1px");
|
318
|
filterVerticalLayout.setMargin(false);
|
319
|
|
320
|
// filterComboBox
|
321
|
filterComboBox = new ComboBox();
|
322
|
filterComboBox.setImmediate(false);
|
323
|
filterComboBox.setWidth("100.0%");
|
324
|
filterComboBox.setHeight("-1px");
|
325
|
filterVerticalLayout.addComponent(filterComboBox);
|
326
|
filterVerticalLayout.setComponentAlignment(filterComboBox, new Alignment(20));
|
327
|
|
328
|
// filterTable
|
329
|
filterTable = new Table();
|
330
|
filterTable.setImmediate(false);
|
331
|
filterTable.setWidth("100.0%");
|
332
|
filterTable.setHeight("86px");
|
333
|
filterVerticalLayout.addComponent(filterTable);
|
334
|
filterVerticalLayout.setComponentAlignment(filterTable, new Alignment(48));
|
335
|
|
336
|
return filterVerticalLayout;
|
337
|
}
|
338
|
|
339
|
@AutoGenerated
|
340
|
private HorizontalLayout buildAddRemovehorizontalLayout() {
|
341
|
// common part: create layout
|
342
|
addRemovehorizontalLayout = new HorizontalLayout();
|
343
|
addRemovehorizontalLayout.setImmediate(false);
|
344
|
addRemovehorizontalLayout.setWidth("100.0%");
|
345
|
addRemovehorizontalLayout.setHeight("-1px");
|
346
|
addRemovehorizontalLayout.setMargin(false);
|
347
|
addRemovehorizontalLayout.setSpacing(true);
|
348
|
|
349
|
// addComboBox
|
350
|
addComboBox = new ComboBox();
|
351
|
addComboBox.setImmediate(false);
|
352
|
addComboBox.setWidth("100.0%");
|
353
|
addComboBox.setHeight("-1px");
|
354
|
addRemovehorizontalLayout.addComponent(addComboBox);
|
355
|
addRemovehorizontalLayout.setExpandRatio(addComboBox, 3.0f);
|
356
|
|
357
|
// removeButton
|
358
|
removeButton = new Button();
|
359
|
removeButton.setCaption("Remove");
|
360
|
removeButton.setImmediate(true);
|
361
|
removeButton.setWidth("100.0%");
|
362
|
removeButton.setHeight("-1px");
|
363
|
addRemovehorizontalLayout.addComponent(removeButton);
|
364
|
addRemovehorizontalLayout.setExpandRatio(removeButton, 2.0f);
|
365
|
|
366
|
return addRemovehorizontalLayout;
|
367
|
}
|
368
|
|
369
|
}
|