1
|
/**
|
2
|
* Copyright (C) 2015 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.cdm.vaadin.component.distributionStatus;
|
10
|
|
11
|
import com.vaadin.data.Property;
|
12
|
import com.vaadin.data.Property.ValueChangeEvent;
|
13
|
import com.vaadin.data.Property.ValueChangeListener;
|
14
|
import com.vaadin.server.VaadinSession;
|
15
|
import com.vaadin.ui.AbstractLayout;
|
16
|
import com.vaadin.ui.Alignment;
|
17
|
import com.vaadin.ui.Button.ClickEvent;
|
18
|
import com.vaadin.ui.Button.ClickListener;
|
19
|
import com.vaadin.ui.CheckBox;
|
20
|
import com.vaadin.ui.HorizontalLayout;
|
21
|
import com.vaadin.ui.OptionGroup;
|
22
|
import com.vaadin.ui.Panel;
|
23
|
import com.vaadin.ui.VerticalLayout;
|
24
|
|
25
|
import eu.etaxonomy.cdm.i18n.Messages;
|
26
|
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
|
27
|
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.IDistributionTableView;
|
28
|
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.DistributionStatusSettingsPresenter;
|
29
|
|
30
|
/**
|
31
|
*A configuration window to set the available distribution status and toggle the usage of
|
32
|
*abbreviated labels.
|
33
|
* @author alex
|
34
|
* @since 22.04.2015
|
35
|
*
|
36
|
*/
|
37
|
public class DistributionStatusSettingsConfigWindow
|
38
|
extends SettingsDialogWindowBase<DistributionStatusSettingsPresenter>
|
39
|
implements ValueChangeListener, ClickListener{
|
40
|
|
41
|
private static final long serialVersionUID = -8220442386869594032L;
|
42
|
private OptionGroup distStatusSelect;
|
43
|
private CheckBox boxToggleAbbreviatedLabels;
|
44
|
private IDistributionTableView distributionTableView;
|
45
|
|
46
|
/**
|
47
|
* The constructor should first build the main layout, set the
|
48
|
* composition root and then do any custom initialization.
|
49
|
*
|
50
|
* The constructor will not be automatically regenerated by the
|
51
|
* visual editor.
|
52
|
* @param distributionTableView
|
53
|
*/
|
54
|
public DistributionStatusSettingsConfigWindow(IDistributionTableView distributionTableView) {
|
55
|
super();
|
56
|
this.distributionTableView = distributionTableView;
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
*
|
61
|
* {@inheritDoc}
|
62
|
*/
|
63
|
@Override
|
64
|
protected void init() {
|
65
|
boxToggleAbbreviatedLabels.addValueChangeListener(this);
|
66
|
distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
|
67
|
Object selectedStatus = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
|
68
|
distStatusSelect.setValue(selectedStatus);
|
69
|
|
70
|
okButton.addClickListener(this);
|
71
|
cancelButton.addClickListener(this);
|
72
|
updateButtons();
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
*
|
77
|
* {@inheritDoc}
|
78
|
*/
|
79
|
@Override
|
80
|
protected AbstractLayout buildMainLayout() {
|
81
|
|
82
|
mainLayout = new VerticalLayout();
|
83
|
mainLayout.setImmediate(false);
|
84
|
mainLayout.setSizeFull();
|
85
|
mainLayout.setMargin(true);
|
86
|
mainLayout.setSpacing(true);
|
87
|
|
88
|
//distribution status
|
89
|
distStatusSelect = new OptionGroup();
|
90
|
distStatusSelect.setImmediate(false);
|
91
|
distStatusSelect.setMultiSelect(true);
|
92
|
distStatusSelect.setSizeFull();
|
93
|
Panel distStatusPanel = new Panel(Messages.getLocalizedString(Messages.DistributionStatusSettingsConfigWindow_DISTRIBUTION_STATUS));
|
94
|
distStatusPanel.setContent(new VerticalLayout(distStatusSelect));
|
95
|
distStatusPanel.setSizeFull();
|
96
|
|
97
|
//toggle abbreviated labels
|
98
|
boxToggleAbbreviatedLabels = new CheckBox(Messages.getLocalizedString(Messages.DistributionStatusSettingsConfigWindow_SHOW_ABBREVIATED_LABELS), DistributionEditorUtil.isAbbreviatedLabels());
|
99
|
boxToggleAbbreviatedLabels.setImmediate(true);
|
100
|
|
101
|
mainLayout.addComponent(boxToggleAbbreviatedLabels);
|
102
|
mainLayout.addComponent(distStatusPanel);
|
103
|
mainLayout.setExpandRatio(distStatusPanel, 1);
|
104
|
mainLayout.setSizeFull();
|
105
|
|
106
|
//button toolbar
|
107
|
HorizontalLayout buttonContainer = createOkCancelButtons();
|
108
|
|
109
|
mainLayout.addComponent(buttonContainer);
|
110
|
mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
|
111
|
|
112
|
return mainLayout;
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
*
|
117
|
* {@inheritDoc}
|
118
|
*/
|
119
|
@Override
|
120
|
protected boolean isValid() {
|
121
|
return true;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
*
|
126
|
* {@inheritDoc}
|
127
|
*/
|
128
|
@Override
|
129
|
public void valueChange(ValueChangeEvent event) {
|
130
|
Property<?> property = event.getProperty();
|
131
|
if(property==boxToggleAbbreviatedLabels){
|
132
|
VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
|
133
|
}
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
*
|
138
|
* {@inheritDoc}
|
139
|
*/
|
140
|
@Override
|
141
|
public void buttonClick(ClickEvent event) {
|
142
|
Object source = event.getSource();
|
143
|
if(source==okButton){
|
144
|
VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
|
145
|
distributionTableView.enter(null);
|
146
|
window.close();
|
147
|
}
|
148
|
else if(source==cancelButton){
|
149
|
window.close();
|
150
|
}
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* {@inheritDoc}
|
155
|
*/
|
156
|
@Override
|
157
|
protected DistributionStatusSettingsPresenter getPresenter() {
|
158
|
return new DistributionStatusSettingsPresenter();
|
159
|
}
|
160
|
|
161
|
}
|