Project

General

Profile

Download (7.4 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
import java.util.Set;
6

    
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.ListSelect;
22
import com.vaadin.ui.Panel;
23
import com.vaadin.ui.Tree;
24
import com.vaadin.ui.VerticalLayout;
25

    
26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
import eu.etaxonomy.cdm.model.location.NamedArea;
29
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
31
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
32

    
33
public class DistributionSelectionView extends CustomComponent implements IDistributionSelectionComponent, View, ClickListener{
34

    
35
    private VerticalLayout mainLayout;
36
    private Panel panel_1;
37
    private VerticalLayout verticalLayout_2;
38
    private Button button_proceed;
39
    private ComboBox classificationBox;
40
    private ComboBox distributionAreaBox;
41
    private ListSelect namedAreaList;
42
    private Tree taxonTree;
43
    private Label labelInstruction;
44
    private Label labelNoClassification;
45

    
46
    private static final long serialVersionUID = 1L;
47
	private DistributionSelectionComponentListener distListener;
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
	 */
55
	public DistributionSelectionView(){
56
		buildMainLayout();
57
		setCompositionRoot(mainLayout);
58
		setStyleName("login");
59
		button_proceed.addClickListener(this);
60
		button_proceed.setClickShortcut(KeyCode.ENTER, null);
61
	}
62

    
63

    
64
	@Override
65
	public void addListener(DistributionSelectionComponentListener listener) {
66
		distListener = listener;
67
	}
68

    
69
	@Override
70
	public void buttonClick(ClickEvent event) {
71
		TaxonNode taxonNode = (TaxonNode) taxonTree.getValue();
72
		if(taxonNode==null){
73
			taxonNode = (TaxonNode) classificationBox.getValue();
74
		}
75
		TermVocabulary<DefinedTermBase> term = (TermVocabulary<DefinedTermBase>)distributionAreaBox.getValue();
76
		Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
77
		try {
78
			distListener.buttonClick(taxonNode, term, selectedAreas);
79
		} catch (SQLException e) {
80
			e.printStackTrace();
81
		}
82
	}
83

    
84
	public void dataBinding(){
85
		classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
86
		classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
87
		classificationBox.setImmediate(true);
88
		classificationBox.addValueChangeListener(new ValueChangeListener() {
89
			@Override
90
			public void valueChange(ValueChangeEvent event) {
91
				TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
92
				if(parentNode!=null){
93
					taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
94
				}
95
				else{
96
					taxonTree.setContainerDataSource(null);
97
				}
98
				labelNoClassification.setVisible(parentNode==null);
99
			}
100
		});
101
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
102

    
103
        distributionAreaBox.addValueChangeListener(new ValueChangeListener() {
104

    
105
			@Override
106
			public void valueChange(ValueChangeEvent event) {
107
				TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
108
				NamedAreaContainer container = new NamedAreaContainer(vocabulary);
109
				namedAreaList.setContainerDataSource(container);
110
			}
111
		});
112

    
113
		List<TermVocabulary<DefinedTermBase>> namedAreaList = distListener.getNamedAreaList();
114
		Container d = new IndexedContainer(namedAreaList);
115
		distributionAreaBox.setContainerDataSource(d);
116
	}
117

    
118
	@Override
119
	public void enter(ViewChangeEvent event) {
120
	}
121

    
122
    private VerticalLayout buildMainLayout() {
123
        // common part: create layout
124
        mainLayout = new VerticalLayout();
125
        mainLayout.setImmediate(false);
126
        mainLayout.setWidth("100%");
127
        mainLayout.setHeight("100%");
128
        mainLayout.setMargin(false);
129

    
130
        // top-level component properties
131
        setWidth("100.0%");
132
        setHeight("100.0%");
133

    
134
        // panel_1
135
        panel_1 = buildPanel_1();
136
        mainLayout.addComponent(panel_1);
137
        mainLayout.setComponentAlignment(panel_1, new Alignment(48));
138

    
139
        return mainLayout;
140
    }
141

    
142

    
143
    private Panel buildPanel_1() {
144
        // common part: create layout
145
        panel_1 = new Panel();
146
        panel_1.setImmediate(false);
147
        panel_1.setWidth("-1px");
148
        panel_1.setHeight("-1px");
149

    
150
        // verticalLayout_2
151
        verticalLayout_2 = buildVerticalLayout_2();
152
        panel_1.setContent(verticalLayout_2);
153

    
154
        return panel_1;
155
    }
156

    
157

    
158
    private VerticalLayout buildVerticalLayout_2() {
159
        // common part: create layout
160
        verticalLayout_2 = new VerticalLayout();
161
        verticalLayout_2.setImmediate(false);
162
        verticalLayout_2.setWidth("-1px");
163
        verticalLayout_2.setHeight("-1px");
164
        verticalLayout_2.setMargin(true);
165
        verticalLayout_2.setSpacing(true);
166

    
167
        labelInstruction = new Label();
168
        labelInstruction.setImmediate(false);
169
        labelInstruction.setWidth("213px");
170
        labelInstruction.setHeight("-1px");
171
        labelInstruction.setValue("Please choose a Classification and/or taxon and a distribution area to proceed.");
172
        verticalLayout_2.addComponent(labelInstruction);
173

    
174
        // classificationBox
175
        classificationBox = new ComboBox();
176
        classificationBox.setCaption("Classification: ");
177
        classificationBox.setImmediate(false);
178
        classificationBox.setWidth("200px");
179
        classificationBox.setHeight("-1px");
180
        verticalLayout_2.addComponent(classificationBox);
181

    
182
        // distributionAreaBox
183
        distributionAreaBox = new ComboBox();
184
        distributionAreaBox.setCaption("Distribution Area");
185
        distributionAreaBox.setWidth("200px");
186
        distributionAreaBox.setHeight("-1px");
187
        verticalLayout_2.addComponent(distributionAreaBox);
188

    
189
        // named areas
190
        namedAreaList = new ListSelect();
191
        namedAreaList.setCaption("Areas");
192
        namedAreaList.setWidth("200px");
193
        namedAreaList.setHeight("-1px");
194
        namedAreaList.setMultiSelect(true);
195
        verticalLayout_2.addComponent(namedAreaList);
196

    
197
        // taxon tree
198
        taxonTree = new Tree("Taxonomy");
199
        taxonTree.setWidth("200px");
200
        verticalLayout_2.addComponent(taxonTree);
201
        labelNoClassification = new Label(" - Please select a classification - ");
202
        verticalLayout_2.addComponent(labelNoClassification);
203
        verticalLayout_2.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT);
204

    
205
        // button_proceed
206
        button_proceed = new Button();
207
        button_proceed.setCaption("Proceed");
208
        button_proceed.setImmediate(true);
209
        button_proceed.setWidth("-1px");
210
        button_proceed.setHeight("-1px");
211
        verticalLayout_2.addComponent(button_proceed);
212
        verticalLayout_2.setComponentAlignment(button_proceed, new Alignment(10));
213

    
214
        return verticalLayout_2;
215
    }
216

    
217
}
(1-1/5)