Project

General

Profile

Download (6.05 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.data.Container;
7
import com.vaadin.data.Property.ValueChangeEvent;
8
import com.vaadin.data.Property.ValueChangeListener;
9
import com.vaadin.data.util.IndexedContainer;
10
import com.vaadin.event.ShortcutAction.KeyCode;
11
import com.vaadin.navigator.View;
12
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
13
import com.vaadin.ui.Alignment;
14
import com.vaadin.ui.Button;
15
import com.vaadin.ui.Button.ClickEvent;
16
import com.vaadin.ui.Button.ClickListener;
17
import com.vaadin.ui.ComboBox;
18
import com.vaadin.ui.CustomComponent;
19
import com.vaadin.ui.Label;
20
import com.vaadin.ui.Panel;
21
import com.vaadin.ui.Tree;
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 Tree taxonTree;
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) taxonTree.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
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
86
			}
87
		});
88

    
89
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
90
        
91
		List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
92
		Container d = new IndexedContainer(namedAreaList);
93
		distributionAreaBox.setContainerDataSource(d);
94
	}
95

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

    
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
    private Panel buildPanel_1() {
122
        // common part: create layout
123
        panel_1 = new Panel();
124
        panel_1.setImmediate(false);
125
        panel_1.setWidth("-1px");
126
        panel_1.setHeight("-1px");
127

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

    
132
        return panel_1;
133
    }
134

    
135

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

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

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

    
161
        // distributionAreaBox
162
        distributionAreaBox = new ComboBox();
163
        distributionAreaBox.setCaption("Distribution Area");
164
        distributionAreaBox.setImmediate(false);
165
        distributionAreaBox.setWidth("200px");
166
        distributionAreaBox.setHeight("-1px");
167
        verticalLayout_2.addComponent(distributionAreaBox);
168

    
169
        // taxon tree
170
        taxonTree = new Tree("Taxonomy");
171
        taxonTree.setWidth("200px");
172
        verticalLayout_2.addComponent(taxonTree);
173

    
174
        // button_proceed
175
        button_proceed = new Button();
176
        button_proceed.setCaption("Proceed");
177
        button_proceed.setImmediate(true);
178
        button_proceed.setWidth("-1px");
179
        button_proceed.setHeight("-1px");
180
        verticalLayout_2.addComponent(button_proceed);
181
        verticalLayout_2.setComponentAlignment(button_proceed, new Alignment(10));
182

    
183
        return verticalLayout_2;
184
    }
185

    
186
}
(1-1/5)