Project

General

Profile

Download (4.67 KB) Statistics
| Branch: | Tag: | Revision:
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.view.dbstatus;
11

    
12
import com.vaadin.data.Property;
13
import com.vaadin.data.Property.ValueChangeEvent;
14
import com.vaadin.data.Property.ValueChangeListener;
15
import com.vaadin.server.VaadinSession;
16
import com.vaadin.ui.AbstractLayout;
17
import com.vaadin.ui.Alignment;
18
import com.vaadin.ui.Button;
19
import com.vaadin.ui.Button.ClickEvent;
20
import com.vaadin.ui.Button.ClickListener;
21
import com.vaadin.ui.CheckBox;
22
import com.vaadin.ui.CustomComponent;
23
import com.vaadin.ui.HorizontalLayout;
24
import com.vaadin.ui.TwinColSelect;
25
import com.vaadin.ui.VerticalLayout;
26
import com.vaadin.ui.Window;
27

    
28
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
29
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
30

    
31
/**
32
 * @author alex
33
 * @date 22.04.2015
34
 *
35
 */
36
public class SettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
37

    
38
	private static final long serialVersionUID = -8220442386869594032L;
39
    private VerticalLayout mainLayout;
40
    private TwinColSelect distStatusSelect;
41
    private CheckBox boxToggleAbbreviatedLabels;
42
    private Button okButton;
43
    private Button cancelButton;
44
    private final SettingsPresenter presenter;
45
	private Window window;
46
	private DistributionTableView distributionTableView;
47

    
48
    /**
49
     * The constructor should first build the main layout, set the
50
     * composition root and then do any custom initialization.
51
     *
52
     * The constructor will not be automatically regenerated by the
53
     * visual editor.
54
     * @param distributionTableView
55
     */
56
    public SettingsConfigWindow(DistributionTableView distributionTableView) {
57
    	this.distributionTableView = distributionTableView;
58
        buildMainLayout();
59
        presenter = new SettingsPresenter();
60
        init();
61
    }
62

    
63
    private void init() {
64
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
65
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
66

    
67
        okButton.addClickListener(this);
68
        cancelButton.addClickListener(this);
69
    }
70

    
71
    public Window createWindow(){
72
        window = new Window();
73
        window.setModal(true);
74
        window.setWidth("60%");
75
        window.setHeight("80%");
76
        window.setCaption("Settings");
77
        window.setContent(mainLayout);
78
        return window;
79
    }
80

    
81
    private AbstractLayout buildMainLayout() {
82

    
83
    	mainLayout = new VerticalLayout();
84
        mainLayout.setImmediate(false);
85
        mainLayout.setSizeFull();
86
        mainLayout.setMargin(true);
87
        mainLayout.setSpacing(true);
88

    
89
        //distribution status
90
        distStatusSelect = new TwinColSelect("Distribution Status:");
91
        distStatusSelect.setImmediate(false);
92
        distStatusSelect.setSizeFull();
93
        distStatusSelect.setWidth("100%");
94

    
95
        //toggle abbreviated labels
96
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
97
        boxToggleAbbreviatedLabels.setImmediate(true);
98

    
99
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
100
        mainLayout.addComponent(distStatusSelect);
101
        mainLayout.setExpandRatio(distStatusSelect, 1);
102
        mainLayout.setSizeFull();
103

    
104
        //button toolbar
105
        HorizontalLayout buttonContainer = new HorizontalLayout();
106
        // cancelButton
107
        cancelButton = new Button();
108
        cancelButton.setCaption("Cancel");
109
        cancelButton.setImmediate(true);
110
        buttonContainer.addComponent(cancelButton);
111

    
112
        // okButton
113
        okButton = new Button();
114
        okButton.setCaption("OK");
115
        okButton.setImmediate(true);
116
        buttonContainer.addComponent(okButton);
117

    
118
        mainLayout.addComponent(buttonContainer);
119
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
120

    
121
        return mainLayout;
122
    }
123

    
124
	@Override
125
	public void valueChange(ValueChangeEvent event) {
126
		Property property = event.getProperty();
127
		if(property==boxToggleAbbreviatedLabels){
128
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
129
		}
130
	}
131

    
132
	@Override
133
	public void buttonClick(ClickEvent event) {
134
		Object source = event.getSource();
135
		if(source==okButton){
136
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
137
			distributionTableView.enter(null);
138
			window.close();
139
		}
140
		else if(source==cancelButton){
141
			window.close();
142
		}
143
	}
144

    
145
}
(5-5/5)