Project

General

Profile

Download (6.43 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.Container;
13
import com.vaadin.data.Property.ValueChangeEvent;
14
import com.vaadin.data.Property.ValueChangeListener;
15
import com.vaadin.ui.AbstractLayout;
16
import com.vaadin.ui.Alignment;
17
import com.vaadin.ui.Button;
18
import com.vaadin.ui.Button.ClickEvent;
19
import com.vaadin.ui.Button.ClickListener;
20
import com.vaadin.ui.ComboBox;
21
import com.vaadin.ui.CustomComponent;
22
import com.vaadin.ui.HorizontalLayout;
23
import com.vaadin.ui.Tree;
24
import com.vaadin.ui.TwinColSelect;
25
import com.vaadin.ui.VerticalLayout;
26
import com.vaadin.ui.Window;
27

    
28
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
32
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
33
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
34

    
35
/**
36
 * @author alex
37
 * @date 22.04.2015
38
 *
39
 */
40
public class SettingsConfigWindow extends CustomComponent {
41

    
42
	private static final long serialVersionUID = -8220442386869594032L;
43
    private VerticalLayout mainLayout;
44
    private TwinColSelect distStatusSelect;
45
    private ComboBox classificationBox;
46
    private ComboBox distAreaBox;
47
    private Tree taxonTree;
48
    private Button okButton;
49
    private Button cancelButton;
50
    private final SettingsPresenter presenter;
51
	private Window window;
52
    
53
    /**
54
     * The constructor should first build the main layout, set the
55
     * composition root and then do any custom initialization.
56
     *
57
     * The constructor will not be automatically regenerated by the
58
     * visual editor.
59
     */
60
    public SettingsConfigWindow() {
61
        buildMainLayout();
62
        presenter = new SettingsPresenter();
63
        init();
64
    }
65

    
66
    private void init() {
67
        Container taxonNodeContainer = new TaxonNodeContainer(null);
68
        Container distributionContainer = presenter.getDistributionContainer();
69
        TermVocabulary<?> chosenArea = presenter.getChosenArea();
70
        classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
71
        classificationBox.setContainerDataSource(taxonNodeContainer);
72
        classificationBox.setValue(presenter.getChosenTaxonNode().getClassification().getRootNode());
73
        classificationBox.addValueChangeListener(new ValueChangeListener() {
74
			@Override
75
			public void valueChange(ValueChangeEvent event) {
76
				TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
77
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
78
			}
79
		});
80
        taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue()));
81
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
82
        taxonTree.setValue(presenter.getChosenTaxonNode());
83
        distAreaBox.setContainerDataSource(distributionContainer);
84
        distAreaBox.setValue(chosenArea);
85
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
86
        
87
        okButton.addClickListener(new ClickListener() {
88
			
89
			@Override
90
			public void buttonClick(ClickEvent event) {
91
				TaxonNode taxonNode;
92
				TermVocabulary<DefinedTermBase> term = null;
93
				taxonNode = (TaxonNode) taxonTree.getValue();
94
				if(taxonNode==null){
95
					taxonNode = (TaxonNode) classificationBox.getValue();
96
				}
97
				term = (TermVocabulary<DefinedTermBase>) distAreaBox.getValue();
98
				DistributionEditorUtil.openDistributionView(taxonNode, term);
99
				window.close();
100
			}
101
		});
102
        cancelButton.addClickListener(new ClickListener() {
103
			
104
			@Override
105
			public void buttonClick(ClickEvent event) {
106
				window.close();
107
			}
108
		});
109
    }
110

    
111
    public Window createWindow(){
112
        window = new Window();
113
        window.setModal(true);
114
        window.setWidth("60%");
115
        window.setHeight("80%");
116
        window.setCaption("Settings");
117
        window.setContent(mainLayout);
118
        return window;
119
    }
120

    
121
    private AbstractLayout buildMainLayout() {
122

    
123
    	mainLayout = new VerticalLayout();
124
        mainLayout.setImmediate(false);
125
        mainLayout.setSizeFull();
126
        mainLayout.setMargin(true);
127
        mainLayout.setSpacing(true);
128
        
129
        HorizontalLayout topContainer = new HorizontalLayout();
130
        topContainer.setImmediate(false);
131
        topContainer.setSizeFull();
132
        topContainer.setSpacing(true);
133

    
134
        VerticalLayout verticalLayout = new VerticalLayout();
135
        verticalLayout.setImmediate(false);
136
        
137
        //classification and term
138
        classificationBox = new ComboBox("Classification");
139
        classificationBox.setImmediate(true);
140
        classificationBox.setWidth("100%");
141

    
142
        distAreaBox = new ComboBox("Distribution Area:");
143
        distAreaBox.setImmediate(false);
144
        distAreaBox.setWidth("100%");
145
        
146
        //distribution status
147
        distStatusSelect = new TwinColSelect("Distribution Status:");
148
        distStatusSelect.setImmediate(false);
149
        distStatusSelect.setWidth("100%");
150

    
151
        //taxonomy
152
        taxonTree = new Tree("Taxonomy");
153
        taxonTree.setImmediate(false);
154
        
155
        verticalLayout.addComponent(classificationBox);
156
        verticalLayout.addComponent(distAreaBox);
157
        verticalLayout.addComponent(distStatusSelect);
158
        verticalLayout.setExpandRatio(distStatusSelect, 1);
159
        verticalLayout.setSizeFull();
160
        
161
        topContainer.addComponent(verticalLayout);
162
        topContainer.addComponent(taxonTree);
163
        topContainer.setExpandRatio(taxonTree, 1);
164
        topContainer.setExpandRatio(verticalLayout, 1);
165

    
166
        //button toolbar
167
        HorizontalLayout buttonToolBar = new HorizontalLayout();
168
        // cancelButton
169
        cancelButton = new Button();
170
        cancelButton.setCaption("Cancel");
171
        cancelButton.setImmediate(true);
172
        buttonToolBar.addComponent(cancelButton);
173

    
174
        // okButton
175
        okButton = new Button();
176
        okButton.setCaption("OK");
177
        okButton.setImmediate(true);
178
        buttonToolBar.addComponent(okButton);
179

    
180
        mainLayout.addComponent(topContainer);
181
        mainLayout.addComponent(buttonToolBar);
182
        mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
183

    
184
        return mainLayout;
185
    }
186

    
187
}
(5-5/5)