Project

General

Profile

Download (4.36 KB) Statistics
| Branch: | Tag: | Revision:
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.view.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.ListSelect;
22
import com.vaadin.ui.VerticalLayout;
23

    
24
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
25
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.DistributionStatusSettingsPresenter;
26

    
27
/**
28
 * @author alex
29
 * @date 22.04.2015
30
 *
31
 */
32
public class DistributionStatusSettingsConfigWindow
33
            extends SettingsDialogWindowBase<DistributionStatusSettingsPresenter>
34
            implements ValueChangeListener, ClickListener{
35

    
36
	private static final long serialVersionUID = -8220442386869594032L;
37
    private ListSelect distStatusSelect;
38
    private CheckBox boxToggleAbbreviatedLabels;
39
    private IDistributionTableView distributionTableView;
40

    
41
    /**
42
     * The constructor should first build the main layout, set the
43
     * composition root and then do any custom initialization.
44
     *
45
     * The constructor will not be automatically regenerated by the
46
     * visual editor.
47
     * @param distributionTableView
48
     */
49
    public DistributionStatusSettingsConfigWindow(IDistributionTableView distributionTableView) {
50
    	super();
51
    	this.distributionTableView = distributionTableView;
52
    }
53

    
54
    @Override
55
    protected void init() {
56
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
57
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
58
        Object selectedStatus = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
59
        distStatusSelect.setValue(selectedStatus);
60

    
61
        okButton.addClickListener(this);
62
        cancelButton.addClickListener(this);
63
        updateButtons();
64
    }
65

    
66
    @Override
67
    protected AbstractLayout buildMainLayout() {
68

    
69
    	mainLayout = new VerticalLayout();
70
        mainLayout.setImmediate(false);
71
        mainLayout.setSizeFull();
72
        mainLayout.setMargin(true);
73
        mainLayout.setSpacing(true);
74

    
75
        //distribution status
76
        distStatusSelect = new ListSelect("Distribution Status:");
77
        distStatusSelect.setImmediate(false);
78
        distStatusSelect.setMultiSelect(true);
79
        distStatusSelect.setSizeFull();
80
        distStatusSelect.setWidth("100%");
81

    
82
        //toggle abbreviated labels
83
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
84
        boxToggleAbbreviatedLabels.setImmediate(true);
85

    
86
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
87
        mainLayout.addComponent(distStatusSelect);
88
        mainLayout.setExpandRatio(distStatusSelect, 1);
89
        mainLayout.setSizeFull();
90

    
91
        //button toolbar
92
        HorizontalLayout buttonContainer = createOkCancelButtons();
93

    
94
        mainLayout.addComponent(buttonContainer);
95
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
96

    
97
        return mainLayout;
98
    }
99

    
100
    @Override
101
    protected boolean isValid() {
102
    	return true;
103
    }
104

    
105
	@Override
106
	public void valueChange(ValueChangeEvent event) {
107
		Property<?> property = event.getProperty();
108
		if(property==boxToggleAbbreviatedLabels){
109
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
110
		}
111
	}
112

    
113
	@Override
114
	public void buttonClick(ClickEvent event) {
115
		Object source = event.getSource();
116
		if(source==okButton){
117
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
118
			distributionTableView.enter(null);
119
			window.close();
120
		}
121
		else if(source==cancelButton){
122
			window.close();
123
		}
124
	}
125

    
126
    /**
127
     * {@inheritDoc}
128
     */
129
    @Override
130
    protected DistributionStatusSettingsPresenter getPresenter() {
131
        return new DistributionStatusSettingsPresenter();
132
    }
133

    
134
}
(2-2/7)