Project

General

Profile

Download (6.21 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2

    
3
import java.sql.SQLException;
4
import java.util.List;
5

    
6
import com.vaadin.annotations.AutoGenerated;
7
import com.vaadin.data.Container;
8
import com.vaadin.data.Property.ValueChangeEvent;
9
import com.vaadin.data.Property.ValueChangeListener;
10
import com.vaadin.data.util.IndexedContainer;
11
import com.vaadin.event.ShortcutAction.KeyCode;
12
import com.vaadin.navigator.View;
13
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
14
import com.vaadin.ui.Alignment;
15
import com.vaadin.ui.Button;
16
import com.vaadin.ui.Button.ClickEvent;
17
import com.vaadin.ui.Button.ClickListener;
18
import com.vaadin.ui.ComboBox;
19
import com.vaadin.ui.CustomComponent;
20
import com.vaadin.ui.Label;
21
import com.vaadin.ui.Panel;
22
import com.vaadin.ui.VerticalLayout;
23

    
24
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
28

    
29
public class DistributionSelectionView extends CustomComponent implements IDistributionSelectionComponent, View, ClickListener{
30

    
31
    private VerticalLayout mainLayout;
32
    private Panel panel_1;
33
    private VerticalLayout verticalLayout_2;
34
    private Button button_proceed;
35
    private ComboBox distributionAreaBox;
36
    private ComboBox classificationBox;
37
    private ComboBox taxonBox;
38
    private Label label_1;
39

    
40
    private static final long serialVersionUID = 1L;
41
	private DistributionSelectionComponentListener distListener;
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
	 */
49
	public DistributionSelectionView(){
50
		buildMainLayout();
51
		setCompositionRoot(mainLayout);
52
		setStyleName("login");
53
		button_proceed.addClickListener(this);
54
		button_proceed.setClickShortcut(KeyCode.ENTER, null);
55
	}
56

    
57

    
58
	@Override
59
	public void addListener(DistributionSelectionComponentListener listener) {
60
		distListener = listener;
61
	}
62

    
63
	@Override
64
	public void buttonClick(ClickEvent event) {
65
		TaxonNode taxonNode = (TaxonNode) taxonBox.getValue();
66
		if(taxonNode==null){
67
			taxonNode = (TaxonNode) classificationBox.getValue();
68
		}
69
		TermVocabulary<DefinedTermBase> term = (TermVocabulary<DefinedTermBase>)distributionAreaBox.getValue();
70
		try {
71
			distListener.buttonClick(taxonNode, term);
72
		} catch (SQLException e) {
73
			e.printStackTrace();
74
		}
75
	}
76

    
77
	public void dataBinding(){
78
		classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
79
		classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
80
		classificationBox.setImmediate(true);
81
		classificationBox.addValueChangeListener(new ValueChangeListener() {
82
			@Override
83
			public void valueChange(ValueChangeEvent event) {
84
				TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
85
				taxonBox.setContainerDataSource(new TaxonNodeContainer(parentNode));
86
			}
87
		});
88
		
89
		taxonBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
90
		List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
91
		Container d = new IndexedContainer(namedAreaList);
92
		distributionAreaBox.setContainerDataSource(d);
93
	}
94

    
95
	@Override
96
	public void enter(ViewChangeEvent event) {
97
	}
98

    
99
	@AutoGenerated
100
    private VerticalLayout buildMainLayout() {
101
        // common part: create layout
102
        mainLayout = new VerticalLayout();
103
        mainLayout.setImmediate(false);
104
        mainLayout.setWidth("100%");
105
        mainLayout.setHeight("100%");
106
        mainLayout.setMargin(false);
107

    
108
        // top-level component properties
109
        setWidth("100.0%");
110
        setHeight("100.0%");
111

    
112
        // panel_1
113
        panel_1 = buildPanel_1();
114
        mainLayout.addComponent(panel_1);
115
        mainLayout.setComponentAlignment(panel_1, new Alignment(48));
116

    
117
        return mainLayout;
118
    }
119

    
120

    
121
    @AutoGenerated
122
    private Panel buildPanel_1() {
123
        // common part: create layout
124
        panel_1 = new Panel();
125
        panel_1.setImmediate(false);
126
        panel_1.setWidth("-1px");
127
        panel_1.setHeight("-1px");
128

    
129
        // verticalLayout_2
130
        verticalLayout_2 = buildVerticalLayout_2();
131
        panel_1.setContent(verticalLayout_2);
132

    
133
        return panel_1;
134
    }
135

    
136

    
137
    @AutoGenerated
138
    private VerticalLayout buildVerticalLayout_2() {
139
        // common part: create layout
140
        verticalLayout_2 = new VerticalLayout();
141
        verticalLayout_2.setImmediate(false);
142
        verticalLayout_2.setWidth("-1px");
143
        verticalLayout_2.setHeight("-1px");
144
        verticalLayout_2.setMargin(true);
145
        verticalLayout_2.setSpacing(true);
146

    
147
        // label_1
148
        label_1 = new Label();
149
        label_1.setImmediate(false);
150
        label_1.setWidth("213px");
151
        label_1.setHeight("-1px");
152
        label_1.setValue("Please choose a Classification and/or taxon and a distribution area to proceed.");
153
        verticalLayout_2.addComponent(label_1);
154

    
155
        // classificationBox
156
        classificationBox = new ComboBox();
157
        classificationBox.setCaption("Classification: ");
158
        classificationBox.setImmediate(false);
159
        classificationBox.setWidth("200px");
160
        classificationBox.setHeight("-1px");
161
        verticalLayout_2.addComponent(classificationBox);
162

    
163
        // taxonBox
164
        taxonBox = new ComboBox();
165
        taxonBox.setCaption("Taxon: ");
166
        taxonBox.setImmediate(false);
167
        taxonBox.setWidth("200px");
168
        taxonBox.setHeight("-1px");
169
        verticalLayout_2.addComponent(taxonBox);
170

    
171
        // distributionAreaBox
172
        distributionAreaBox = new ComboBox();
173
        distributionAreaBox.setCaption("Distribution Area");
174
        distributionAreaBox.setImmediate(false);
175
        distributionAreaBox.setWidth("200px");
176
        distributionAreaBox.setHeight("-1px");
177
        verticalLayout_2.addComponent(distributionAreaBox);
178

    
179
        // button_proceed
180
        button_proceed = new Button();
181
        button_proceed.setCaption("Proceed");
182
        button_proceed.setImmediate(true);
183
        button_proceed.setWidth("-1px");
184
        button_proceed.setHeight("-1px");
185
        verticalLayout_2.addComponent(button_proceed);
186
        verticalLayout_2.setComponentAlignment(button_proceed, new Alignment(10));
187

    
188
        return verticalLayout_2;
189
    }
190

    
191
}
(1-1/5)