Project

General

Profile

« Previous | Next » 

Revision 5eece89f

Added by Patrick Plitzner over 7 years ago

ref #5458 Split settings window into two

  • one for distribution/taxonomy settings and one for other setting

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
11 11

  
12
import java.util.Set;
13

  
14
import com.vaadin.data.Container;
15 12
import com.vaadin.data.Property;
16 13
import com.vaadin.data.Property.ValueChangeEvent;
17 14
import com.vaadin.data.Property.ValueChangeListener;
......
22 19
import com.vaadin.ui.Button.ClickEvent;
23 20
import com.vaadin.ui.Button.ClickListener;
24 21
import com.vaadin.ui.CheckBox;
25
import com.vaadin.ui.ComboBox;
26 22
import com.vaadin.ui.CustomComponent;
27 23
import com.vaadin.ui.HorizontalLayout;
28
import com.vaadin.ui.Label;
29
import com.vaadin.ui.ListSelect;
30
import com.vaadin.ui.Notification;
31
import com.vaadin.ui.Tree;
32 24
import com.vaadin.ui.TwinColSelect;
33 25
import com.vaadin.ui.VerticalLayout;
34 26
import com.vaadin.ui.Window;
35 27

  
36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
37
import eu.etaxonomy.cdm.model.location.NamedArea;
38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
40
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
41 28
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
42 29
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
43 30

  
......
51 38
	private static final long serialVersionUID = -8220442386869594032L;
52 39
    private VerticalLayout mainLayout;
53 40
    private TwinColSelect distStatusSelect;
54
    private ComboBox classificationBox;
55
    private ComboBox distAreaBox;
56
    private ListSelect namedAreaList;
57
    private Tree taxonTree;
58
    private Label labelNoClassification;
59 41
    private CheckBox boxToggleAbbreviatedLabels;
60 42
    private Button okButton;
61 43
    private Button cancelButton;
62 44
    private final SettingsPresenter presenter;
63 45
	private Window window;
46
	private DistributionTableView distributionTableView;
64 47

  
65 48
    /**
66 49
     * The constructor should first build the main layout, set the
......
68 51
     *
69 52
     * The constructor will not be automatically regenerated by the
70 53
     * visual editor.
54
     * @param distributionTableView 
71 55
     */
72
    public SettingsConfigWindow() {
56
    public SettingsConfigWindow(DistributionTableView distributionTableView) {
57
    	this.distributionTableView = distributionTableView;
73 58
        buildMainLayout();
74 59
        presenter = new SettingsPresenter();
75 60
        init();
76 61
    }
77 62

  
78 63
    private void init() {
79
        Container distributionContainer = presenter.getDistributionContainer();
80
        TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
81
        
82
        classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
83
        classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
84
		classificationBox.setImmediate(true);
85
        TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
86
		classificationBox.addValueChangeListener(this);
87
        if(chosenTaxonNode!=null){
88
        	classificationBox.setValue(chosenTaxonNode.getClassification().getRootNode());
89
        	taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue()));
90
        	taxonTree.setValue(chosenTaxonNode);
91
        }
92
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
93
        distAreaBox.setContainerDataSource(distributionContainer);
94
        distAreaBox.setValue(chosenArea);
95
        distAreaBox.addValueChangeListener(this);
96
        
97
        if(chosenArea!=null){
98
        	NamedAreaContainer container = new NamedAreaContainer(chosenArea);
99
        	namedAreaList.setContainerDataSource(container);
100
        }
101
        Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
102
        namedAreaList.setValue(selectedAreas);
103
        
104 64
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
105 65
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
106 66

  
......
126 86
        mainLayout.setMargin(true);
127 87
        mainLayout.setSpacing(true);
128 88

  
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
        //distribution area box
143
        distAreaBox = new ComboBox("Distribution Area:");
144
        distAreaBox.setImmediate(true);
145
        distAreaBox.setWidth("100%");
146

  
147
        // named areas
148
        namedAreaList = new ListSelect();
149
        namedAreaList.setCaption("Areas");
150
        namedAreaList.setWidth("100%");
151
        namedAreaList.setMultiSelect(true);
152

  
153 89
        //distribution status
154 90
        distStatusSelect = new TwinColSelect("Distribution Status:");
155 91
        distStatusSelect.setImmediate(false);
......
159 95
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
160 96
        boxToggleAbbreviatedLabels.setImmediate(true);
161 97

  
162
        //taxonomy
163
        taxonTree = new Tree("Taxonomy");
164
        taxonTree.setImmediate(false);
165
        
166
        //no classification selected label
167
        labelNoClassification = new Label(" - Please select a classification - ");
168

  
169
        verticalLayout.addComponent(classificationBox);
170
        verticalLayout.addComponent(distAreaBox);
171
        verticalLayout.addComponent(namedAreaList);
172
        verticalLayout.addComponent(boxToggleAbbreviatedLabels);
173
        verticalLayout.addComponent(distStatusSelect);
174
        verticalLayout.setExpandRatio(distStatusSelect, 1);
175
        verticalLayout.setSizeFull();
176

  
177
        topContainer.addComponent(verticalLayout);
178
        topContainer.addComponent(taxonTree);
179
        topContainer.setExpandRatio(taxonTree, 1);
180
        topContainer.addComponent(labelNoClassification);
181
        topContainer.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT);
182
        topContainer.setExpandRatio(verticalLayout, 1);
98
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
99
        mainLayout.addComponent(distStatusSelect);
100
        mainLayout.setExpandRatio(distStatusSelect, 1);
101
        mainLayout.setSizeFull();
183 102

  
184 103
        //button toolbar
185
        HorizontalLayout buttonToolBar = new HorizontalLayout();
104
        HorizontalLayout buttonContainer = new HorizontalLayout();
186 105
        // cancelButton
187 106
        cancelButton = new Button();
188 107
        cancelButton.setCaption("Cancel");
189 108
        cancelButton.setImmediate(true);
190
        buttonToolBar.addComponent(cancelButton);
109
        buttonContainer.addComponent(cancelButton);
191 110

  
192 111
        // okButton
193 112
        okButton = new Button();
194 113
        okButton.setCaption("OK");
195 114
        okButton.setImmediate(true);
196
        buttonToolBar.addComponent(okButton);
115
        buttonContainer.addComponent(okButton);
197 116

  
198
        mainLayout.addComponent(topContainer);
199
        mainLayout.addComponent(buttonToolBar);
200
        mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
117
        mainLayout.addComponent(buttonContainer);
118
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
201 119

  
202 120
        return mainLayout;
203 121
    }
......
205 123
	@Override
206 124
	public void valueChange(ValueChangeEvent event) {
207 125
		Property property = event.getProperty();
208
		if(property==classificationBox){
209
			TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
210
			if(parentNode!=null){
211
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
212
			}
213
			else{
214
				taxonTree.setContainerDataSource(null);
215
			}
216
			labelNoClassification.setVisible(parentNode==null);
217
		}
218

  
219
		else if(property==distAreaBox){
220
			TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
221
			NamedAreaContainer container = new NamedAreaContainer(vocabulary);
222
			namedAreaList.setContainerDataSource(container);
223
		}
224
		else if(property==boxToggleAbbreviatedLabels){
126
		if(property==boxToggleAbbreviatedLabels){
225 127
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
226 128
		}
227 129
	}
......
230 132
	public void buttonClick(ClickEvent event) {
231 133
		Object source = event.getSource();
232 134
		if(source==okButton){
233
			TaxonNode taxonNode;
234
			TermVocabulary<NamedArea> term = null;
235
			taxonNode = (TaxonNode) taxonTree.getValue();
236
			if(taxonNode==null){
237
				taxonNode = (TaxonNode) classificationBox.getValue();
238
			}
239
			term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
240
			Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
241
			if(taxonNode==null){
242
				Notification.show("Please choose a classification and/or taxon", Notification.Type.HUMANIZED_MESSAGE);
243
				return;
244
			}
245
			if(term==null){
246
				Notification.show("Please choose a distribution area", Notification.Type.HUMANIZED_MESSAGE);
247
				return;
248
			}
249
			DistributionEditorUtil.openDistributionView(taxonNode, term, selectedAreas);
135
			distributionTableView.enter(null);
250 136
			window.close();
251 137
		}
252 138
		else if(source==cancelButton){

Also available in: Unified diff