Project

General

Profile

Download (4.16 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.TwinColSelect;
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 TwinColSelect 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

    
59
        okButton.addClickListener(this);
60
        cancelButton.addClickListener(this);
61
        updateButtons();
62
    }
63

    
64
    @Override
65
    protected AbstractLayout buildMainLayout() {
66

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

    
73
        //distribution status
74
        distStatusSelect = new TwinColSelect("Distribution Status:");
75
        distStatusSelect.setImmediate(false);
76
        distStatusSelect.setSizeFull();
77
        distStatusSelect.setWidth("100%");
78

    
79
        //toggle abbreviated labels
80
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
81
        boxToggleAbbreviatedLabels.setImmediate(true);
82

    
83
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
84
        mainLayout.addComponent(distStatusSelect);
85
        mainLayout.setExpandRatio(distStatusSelect, 1);
86
        mainLayout.setSizeFull();
87

    
88
        //button toolbar
89
        HorizontalLayout buttonContainer = createOkCancelButtons();
90

    
91
        mainLayout.addComponent(buttonContainer);
92
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
93

    
94
        return mainLayout;
95
    }
96

    
97
    @Override
98
    protected boolean isValid() {
99
    	return true;
100
    }
101

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

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

    
123
    /**
124
     * {@inheritDoc}
125
     */
126
    @Override
127
    protected DistributionStatusSettingsPresenter getPresenter() {
128
        return new DistributionStatusSettingsPresenter();
129
    }
130

    
131
}
(2-2/7)