Project

General

Profile

Download (6.53 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 java.util.HashSet;
13

    
14
import com.vaadin.data.Container;
15
import com.vaadin.data.Property.ValueChangeEvent;
16
import com.vaadin.data.Property.ValueChangeListener;
17
import com.vaadin.ui.AbstractLayout;
18
import com.vaadin.ui.Alignment;
19
import com.vaadin.ui.Button;
20
import com.vaadin.ui.Button.ClickEvent;
21
import com.vaadin.ui.Button.ClickListener;
22
import com.vaadin.ui.ComboBox;
23
import com.vaadin.ui.CustomComponent;
24
import com.vaadin.ui.HorizontalLayout;
25
import com.vaadin.ui.Tree;
26
import com.vaadin.ui.TwinColSelect;
27
import com.vaadin.ui.VerticalLayout;
28
import com.vaadin.ui.Window;
29

    
30
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
31
import eu.etaxonomy.cdm.model.common.TermVocabulary;
32
import eu.etaxonomy.cdm.model.location.NamedArea;
33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
35
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
36
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
37

    
38
/**
39
 * @author alex
40
 * @date 22.04.2015
41
 *
42
 */
43
public class SettingsConfigWindow extends CustomComponent {
44

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

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

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

    
124
    private AbstractLayout buildMainLayout() {
125

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

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

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

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

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

    
177
        // okButton
178
        okButton = new Button();
179
        okButton.setCaption("OK");
180
        okButton.setImmediate(true);
181
        buttonToolBar.addComponent(okButton);
182

    
183
        mainLayout.addComponent(topContainer);
184
        mainLayout.addComponent(buttonToolBar);
185
        mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
186

    
187
        return mainLayout;
188
    }
189

    
190
}
(5-5/5)