Project

General

Profile

Download (4.56 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.i18n.Messages;
25
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
26
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.DistributionStatusSettingsPresenter;
27

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

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

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

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

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

    
67
    @Override
68
    protected AbstractLayout buildMainLayout() {
69

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

    
76
        //distribution status
77
        distStatusSelect = new ListSelect(Messages.getLocalizedString(Messages.DistributionStatusSettingsConfigWindow_DISTRIBUTION_STATUS));
78
        distStatusSelect.setImmediate(false);
79
        distStatusSelect.setMultiSelect(true);
80
        distStatusSelect.setSizeFull();
81
        distStatusSelect.setWidth("100%"); //$NON-NLS-1$
82

    
83
        //toggle abbreviated labels
84
        boxToggleAbbreviatedLabels = new CheckBox(Messages.getLocalizedString(Messages.DistributionStatusSettingsConfigWindow_SHOW_ABBREVIATED_LABELS), DistributionEditorUtil.isAbbreviatedLabels());
85
        boxToggleAbbreviatedLabels.setImmediate(true);
86

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

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

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

    
98
        return mainLayout;
99
    }
100

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

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

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

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

    
135
}
(2-2/7)