Project

General

Profile

Revision 725b6f1f

ID725b6f1f9c252e443dc92a8166786d304eaaeb9e
Parent 388cf82b
Child dc46ea13

Added by Andreas Müller about 3 years ago

ref #6903 cleanup and refactor distribution editor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
11 11

  
12 12
import eu.etaxonomy.cdm.model.common.TermVocabulary;
13 13
import eu.etaxonomy.cdm.model.location.NamedArea;
14
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.DistributionTableView;
14
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.IDistributionTableView;
15 15

  
16 16
public class DistributionEditorUtil {
17 17

  
......
31 31

  
32 32
    public static final String SEPARATOR = ";;";
33 33

  
34
    public static void updateDistributionView(DistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc, Set<NamedArea> selectedAreas, UUID classificationUuid) {
34
    public static void updateDistributionView(IDistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc, Set<NamedArea> selectedAreas, UUID classificationUuid) {
35 35
	    VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes);
36 36
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, areaVoc.getUuid());
37 37
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java
1
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
2

  
3
import com.vaadin.ui.AbstractLayout;
4
import com.vaadin.ui.AbstractOrderedLayout;
5
import com.vaadin.ui.Button;
6
import com.vaadin.ui.CustomComponent;
7
import com.vaadin.ui.HorizontalLayout;
8
import com.vaadin.ui.Window;
9

  
10
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.SettingsPresenter;
11

  
12
@SuppressWarnings("serial")
13
public abstract class AbstractSettingsDialogWindow extends CustomComponent {
14

  
15
	protected Button okButton;
16
	protected Button cancelButton;
17
	protected final SettingsPresenter presenter;
18
	protected Window window;
19
	protected AbstractOrderedLayout mainLayout;
20

  
21
	public AbstractSettingsDialogWindow() {
22
        buildMainLayout();
23
        presenter = new SettingsPresenter();
24
        init();
25
	}
26

  
27
	protected abstract AbstractLayout buildMainLayout();
28

  
29
	protected abstract void init();
30

  
31
	protected HorizontalLayout createOkCancelButtons() {
32
		HorizontalLayout buttonToolBar = new HorizontalLayout();
33
	    // cancelButton
34
	    cancelButton = new Button();
35
	    cancelButton.setCaption("Cancel");
36
	    cancelButton.setImmediate(true);
37
	    cancelButton.addStyleName("dialogButton");
38
	    buttonToolBar.addComponent(cancelButton);
39

  
40
	    // okButton
41
	    okButton = new Button();
42
	    okButton.setCaption("OK");
43
	    okButton.setImmediate(true);
44
	    okButton.addStyleName("dialogButton");
45
	    buttonToolBar.addComponent(okButton);
46
		return buttonToolBar;
47
	}
48

  
49
	public Window createWindow(String caption) {
50
	    window = new Window();
51
	    window.setModal(true);
52
	    window.setWidth("60%");
53
	    window.setHeight("80%");
54
	    window.setCaption(caption);
55
	    window.setContent(mainLayout);
56
	    return window;
57
	}
58

  
59
	/**
60
	 * Update OK/Cancel button depending on {@link #isValid()}
61
	 */
62
	protected void updateButtons(){
63
		okButton.setEnabled(isValid());
64
	}
65

  
66
	/**
67
	 * Evaluates if this dialog has all necessary values set in
68
	 * a correct state
69
	 * @return <code>true</code> if the status of this dialog is valid
70
	 */
71
	protected abstract boolean isValid();
72

  
73
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AreaAndTaxonSettingsConfigWindow.java
1
/**
2
 * Copyright (C) 2015 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import com.vaadin.data.Property;
19
import com.vaadin.data.Property.ValueChangeEvent;
20
import com.vaadin.data.Property.ValueChangeListener;
21
import com.vaadin.data.util.BeanItemContainer;
22
import com.vaadin.data.util.sqlcontainer.RowId;
23
import com.vaadin.server.Page;
24
import com.vaadin.server.VaadinSession;
25
import com.vaadin.ui.AbstractLayout;
26
import com.vaadin.ui.Alignment;
27
import com.vaadin.ui.Button.ClickEvent;
28
import com.vaadin.ui.Button.ClickListener;
29
import com.vaadin.ui.ComboBox;
30
import com.vaadin.ui.HorizontalLayout;
31
import com.vaadin.ui.ListSelect;
32
import com.vaadin.ui.Notification;
33
import com.vaadin.ui.Table.ColumnHeaderMode;
34
import com.vaadin.ui.TextField;
35
import com.vaadin.ui.Tree.ExpandEvent;
36
import com.vaadin.ui.Tree.ExpandListener;
37
import com.vaadin.ui.TreeTable;
38
import com.vaadin.ui.UI;
39
import com.vaadin.ui.VerticalLayout;
40

  
41
import eu.etaxonomy.cdm.common.CdmUtils;
42
import eu.etaxonomy.cdm.model.common.TermVocabulary;
43
import eu.etaxonomy.cdm.model.location.NamedArea;
44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
46
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
47
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
48
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
49
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
50
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
51
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
52
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
53
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.AreaAndTaxonSettingsPresenter;
54

  
55
/**
56
 *
57
 * @author pplitzner
58
 *
59
 */
60
public class AreaAndTaxonSettingsConfigWindow
61
            extends SettingsDialogWindowBase<AreaAndTaxonSettingsPresenter>
62
            implements ValueChangeListener, ClickListener, ExpandListener{
63

  
64
    private static final long serialVersionUID = 1439411115014088780L;
65
    private ComboBox classificationBox;
66
    private TextField taxonFilter;
67
    private ComboBox distAreaBox;
68
    private ListSelect namedAreaList;
69
    private TreeTable taxonTree;
70
    IDistributionTableView distributionTableView;
71

  
72
    /**
73
     * The constructor should first build the main layout, set the
74
     * composition root and then do any custom initialization.
75
     *
76
     * The constructor will not be automatically regenerated by the
77
     * visual editor.
78
     * @param distributionTableView
79
     */
80
    public AreaAndTaxonSettingsConfigWindow(IDistributionTableView distributionTableView) {
81
        super();
82
        this.distributionTableView = distributionTableView;
83
    }
84

  
85
    @Override
86
    protected void init() {
87
        //init classification
88
        Classification classification = presenter.getChosenClassification();
89
        try {
90
            classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification")));
91
        } catch (SQLException e) {
92
            DistributionEditorUtil.showSqlError(e);
93
        }
94
        RowId parent = null;
95
        if(classification!=null){
96
        	parent = new RowId(classification.getRootNode().getId());
97
        }
98
        else if(classificationBox.getItemIds().size()==1){
99
            //only one classification exists
100
            parent = (RowId) classificationBox.getItemIds().iterator().next();
101
        }
102
        if(parent!=null){
103
            classificationBox.setValue(new RowId(parent.getId()));
104
            showClassificationTaxa(getUuidAndTitleCacheFromRowId(parent));
105
        }
106

  
107
        classificationBox.addValueChangeListener(this);
108
        taxonFilter.addValueChangeListener(this);
109
        taxonTree.addExpandListener(this);
110

  
111
        //init areas
112
        TermVocabulary<NamedArea> chosenAreaVoc = presenter.getChosenAreaVoc();
113
        distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
114
        distAreaBox.setValue(chosenAreaVoc);
115
        distAreaBox.addValueChangeListener(this);
116

  
117
        if(chosenAreaVoc!=null){
118
            NamedAreaContainer container = new NamedAreaContainer(chosenAreaVoc);
119
            namedAreaList.setContainerDataSource(container);
120
        }
121
        Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
122
        namedAreaList.setValue(selectedAreas);
123

  
124
        okButton.addClickListener(this);
125
        cancelButton.addClickListener(this);
126
        updateButtons();
127
    }
128

  
129
    @Override
130
    protected AbstractLayout buildMainLayout() {
131

  
132
        mainLayout = new VerticalLayout();
133
        mainLayout.setSizeFull();
134

  
135
        HorizontalLayout leftAndRightContainer = new HorizontalLayout();
136
        leftAndRightContainer.setImmediate(false);
137
        leftAndRightContainer.setSizeFull();
138
        leftAndRightContainer.setMargin(true);
139
        leftAndRightContainer.setSpacing(true);
140

  
141
        VerticalLayout leftContainer = new VerticalLayout();
142
        leftContainer.setImmediate(false);
143
        leftContainer.setSpacing(true);
144
        leftContainer.setSizeFull();
145

  
146
        VerticalLayout rightContainer = new VerticalLayout();
147
        rightContainer.setImmediate(false);
148
        rightContainer.setSpacing(true);
149
        rightContainer.setSizeFull();
150

  
151
        //classification
152
        classificationBox = new ComboBox("Classification");
153
        classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
154
        classificationBox.setInputPrompt("Please select a classification...");
155
        classificationBox.setImmediate(true);
156
        classificationBox.setNewItemsAllowed(false);
157
        classificationBox.setNullSelectionAllowed(false);
158
        classificationBox.setSizeFull();
159
        classificationBox.setWidth("100%");
160

  
161
        //taxonFilter
162
        taxonFilter = new TextField("Filter");
163
        taxonFilter.setInputPrompt("Filter taxa by name...");
164
        taxonFilter.setSizeFull();
165
        taxonFilter.setImmediate(true);
166

  
167
        //distribution area box
168
        distAreaBox = new ComboBox("Distribution Area:");
169
        distAreaBox.setInputPrompt("Please select a distribution area...");
170
        distAreaBox.setImmediate(true);
171
        distAreaBox.setNullSelectionAllowed(false);
172
        distAreaBox.setNewItemsAllowed(false);
173
        distAreaBox.setSizeFull();
174
        distAreaBox.setWidth("100%");
175

  
176
        // named areas
177
        namedAreaList = new ListSelect();
178
        namedAreaList.setCaption("Areas");
179
        namedAreaList.setSizeFull();
180
        namedAreaList.setMultiSelect(true);
181

  
182
        //taxonomy
183
        taxonTree = new TreeTable("Taxonomy");
184
        taxonTree.setSelectable(true);
185
        taxonTree.setSizeFull();
186
        taxonTree.setImmediate(true);
187
        taxonTree.setCacheRate(20);
188
        taxonTree.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
189
        taxonTree.setMultiSelect(true);
190

  
191
        leftContainer.addComponent(distAreaBox);
192
        leftContainer.addComponent(namedAreaList);
193
        leftContainer.setExpandRatio(distAreaBox, 0.1f);
194
        leftContainer.setExpandRatio(namedAreaList, 0.9f);
195
        leftContainer.setSizeFull();
196

  
197
        rightContainer.addComponent(classificationBox);
198
        rightContainer.addComponent(taxonFilter);
199
        rightContainer.addComponent(taxonTree);
200
        rightContainer.setExpandRatio(classificationBox, 0.1f);
201
        rightContainer.setExpandRatio(taxonFilter, 0.1f);
202
        rightContainer.setExpandRatio(taxonTree, 0.8f);
203

  
204
        leftAndRightContainer.addComponent(leftContainer);
205
        leftAndRightContainer.addComponent(rightContainer);
206

  
207
        //button toolbar
208
        HorizontalLayout buttonToolBar = createOkCancelButtons();
209

  
210
        mainLayout.addComponent(leftAndRightContainer);
211
        mainLayout.addComponent(buttonToolBar);
212
        mainLayout.setExpandRatio(leftAndRightContainer, 0.9f);
213
        mainLayout.setExpandRatio(buttonToolBar, 0.1f);
214
        mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
215

  
216
        return leftAndRightContainer;
217
    }
218

  
219
    @Override
220
    public void valueChange(ValueChangeEvent event) {
221
        Property<?> property = event.getProperty();
222
        if(property==classificationBox){
223
        	UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
224
            showClassificationTaxa(parent);
225
        }
226
        else if(property==taxonFilter){
227
            String filterText = taxonFilter.getValue();
228
            Property<?> uuidProperty = classificationBox.getContainerProperty(classificationBox.getValue(),"uuid");
229
            if(uuidProperty==null){
230
            	Notification.show("Please select a classification");
231
            }
232
            else{
233
            	if(CdmUtils.isNotBlank(filterText)){
234
            		UUID classificationUuid = UUID.fromString((String) uuidProperty.getValue());
235
            		List<UuidAndTitleCache<TaxonNode>> taxa = CdmSpringContextHelper.getTaxonNodeService().getUuidAndTitleCache(null, filterText, classificationUuid);
236
            		BeanItemContainer<UuidAndTitleCache<TaxonNode>> container = new BeanItemContainer<>(UuidAndTitleCache.class);
237
            		taxonTree.setContainerDataSource(container);
238
            		for (UuidAndTitleCache<TaxonNode> taxon : taxa) {
239
            			container.addItem(taxon);
240
            			taxonTree.setChildrenAllowed(taxon, false);
241
            		}
242
            		taxonTree.setVisibleColumns("titleCache");
243
            	}
244
            	else{
245
            		UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
246
            		showClassificationTaxa(parent);
247
            	}
248
            }
249
        }
250
        else if(property==distAreaBox){
251
            TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
252
            NamedAreaContainer container = new NamedAreaContainer(vocabulary);
253
            namedAreaList.setContainerDataSource(container);
254
        }
255
        updateButtons();
256
    }
257

  
258
    @Override
259
    protected boolean isValid() {
260
        return classificationBox.getValue()!=null && distAreaBox.getValue()!=null;
261
    }
262

  
263
    @Override
264
    public void buttonClick(ClickEvent event) {
265
        Object source = event.getSource();
266
        if(source==okButton){
267
            List<UUID> taxonNodes = new ArrayList<>();
268
            TermVocabulary<NamedArea> areaVoc = null;
269
            String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue();
270
            UUID classificationUuid = UUID.fromString(uuidString);
271
            Set<UuidAndTitleCache<TaxonNode>> treeSelection = (Set<UuidAndTitleCache<TaxonNode>>) taxonTree.getValue();
272
			if(!treeSelection.isEmpty()){
273
				for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : treeSelection) {
274
					taxonNodes.add(uuidAndTitleCache.getUuid());
275
				}
276
            }
277
            areaVoc = (TermVocabulary<NamedArea>) distAreaBox.getValue();
278
            Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
279
            DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, areaVoc, selectedAreas, classificationUuid);
280
            window.close();
281
        }
282
        else if(source==cancelButton){
283
            window.close();
284
        }
285
    }
286

  
287
    @Override
288
    public void nodeExpand(ExpandEvent event) {
289
        UuidAndTitleCache<TaxonNode> parent = (UuidAndTitleCache<TaxonNode>) event.getItemId();
290
        ((TaxonNodeContainer) taxonTree.getContainerDataSource()).addChildItems(parent);
291
    }
292

  
293
    private void showClassificationTaxa(UuidAndTitleCache<TaxonNode> parent) {
294
        final Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
295
        // Enable polling and set frequency to 0.5 seconds
296
        UI.getCurrent().setPollInterval(500);
297
        taxonTree.setEnabled(false);
298
        taxonTree.removeAllItems();
299
        Notification.show("Loading taxa...");
300

  
301
        new TreeUpdater(children).start();
302
    }
303

  
304
    private UuidAndTitleCache<TaxonNode> getUuidAndTitleCacheFromRowId(Object classificationSelection) {
305
        String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue();
306
        Property<?> rootNodeContainerProperty = null;
307

  
308
        Collection<?> ids = classificationBox.getContainerPropertyIds();
309
        //use for loop here because the case of the root node id columns differs between some DBs
310
        for (Object id : ids) {
311
			if(id instanceof String && ((String) id).toLowerCase().equals("rootnode_id")){
312
				rootNodeContainerProperty = classificationBox.getContainerProperty(classificationSelection, id);
313
				break;
314
			}
315
		}
316
		int id = (int) rootNodeContainerProperty.getValue();
317
        String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue();
318
        UUID uuid = UUID.fromString(uuidString);
319
        UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
320
        return parent;
321
    }
322

  
323

  
324
    /**
325
     * {@inheritDoc}
326
     */
327
    @Override
328
    protected AreaAndTaxonSettingsPresenter getPresenter() {
329
        return new AreaAndTaxonSettingsPresenter();
330
    }
331

  
332
    private class TreeUpdater extends Thread{
333

  
334
    	private Collection<UuidAndTitleCache<TaxonNode>> children;
335

  
336

  
337
		public TreeUpdater(Collection<UuidAndTitleCache<TaxonNode>> children) {
338
			this.children = children;
339
		}
340

  
341
		@Override
342
    	public void run() {
343
			UI.getCurrent().access(new Runnable() {
344
				@Override
345
				public void run() {
346
					taxonTree.setContainerDataSource(new TaxonNodeContainer(children));
347

  
348
			        Notification notification = new Notification("Loading complete");
349
			        notification.setDelayMsec(500);
350
			        notification.show(Page.getCurrent());
351
			        taxonTree.setEnabled(true);
352

  
353
			        //disable polling when all taxa are loaded
354
			        UI.getCurrent().setPollInterval(-1);
355
				}
356
			});
357
    	}
358
    }
359

  
360
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java
1
/**
2
 * Copyright (C) 2015 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import com.vaadin.data.Property;
19
import com.vaadin.data.Property.ValueChangeEvent;
20
import com.vaadin.data.Property.ValueChangeListener;
21
import com.vaadin.data.util.BeanItemContainer;
22
import com.vaadin.data.util.sqlcontainer.RowId;
23
import com.vaadin.server.Page;
24
import com.vaadin.server.VaadinSession;
25
import com.vaadin.ui.AbstractLayout;
26
import com.vaadin.ui.Alignment;
27
import com.vaadin.ui.Button.ClickEvent;
28
import com.vaadin.ui.Button.ClickListener;
29
import com.vaadin.ui.ComboBox;
30
import com.vaadin.ui.HorizontalLayout;
31
import com.vaadin.ui.ListSelect;
32
import com.vaadin.ui.Notification;
33
import com.vaadin.ui.Table.ColumnHeaderMode;
34
import com.vaadin.ui.TextField;
35
import com.vaadin.ui.Tree.ExpandEvent;
36
import com.vaadin.ui.Tree.ExpandListener;
37
import com.vaadin.ui.TreeTable;
38
import com.vaadin.ui.UI;
39
import com.vaadin.ui.VerticalLayout;
40

  
41
import eu.etaxonomy.cdm.common.CdmUtils;
42
import eu.etaxonomy.cdm.model.common.TermVocabulary;
43
import eu.etaxonomy.cdm.model.location.NamedArea;
44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
46
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
47
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
48
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
49
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
50
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
51
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
52
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
53

  
54
/**
55
 *
56
 * @author pplitzner
57
 *
58
 */
59
public class DistributionSettingsConfigWindow extends AbstractSettingsDialogWindow implements ValueChangeListener, ClickListener, ExpandListener{
60

  
61
    private static final long serialVersionUID = 1439411115014088780L;
62
    private ComboBox classificationBox;
63
    private TextField taxonFilter;
64
    private ComboBox distAreaBox;
65
    private ListSelect namedAreaList;
66
    private TreeTable taxonTree;
67
    DistributionTableView distributionTableView;
68

  
69
    /**
70
     * The constructor should first build the main layout, set the
71
     * composition root and then do any custom initialization.
72
     *
73
     * The constructor will not be automatically regenerated by the
74
     * visual editor.
75
     * @param distributionTableView
76
     */
77
    public DistributionSettingsConfigWindow(DistributionTableView distributionTableView) {
78
        super();
79
        this.distributionTableView = distributionTableView;
80
    }
81

  
82
    @Override
83
    protected void init() {
84
        //init classification
85
        Classification classification = presenter.getChosenClassification();
86
        try {
87
            classificationBox.setContainerDataSource(new CdmSQLContainer(CdmQueryFactory.generateTableQuery("Classification")));
88
        } catch (SQLException e) {
89
            DistributionEditorUtil.showSqlError(e);
90
        }
91
        RowId parent = null;
92
        if(classification!=null){
93
        	parent = new RowId(classification.getRootNode().getId());
94
        }
95
        else if(classificationBox.getItemIds().size()==1){
96
            //only one classification exists
97
            parent = (RowId) classificationBox.getItemIds().iterator().next();
98
        }
99
        if(parent!=null){
100
            classificationBox.setValue(new RowId(parent.getId()));
101
            showClassificationTaxa(getUuidAndTitleCacheFromRowId(parent));
102
        }
103

  
104
        classificationBox.addValueChangeListener(this);
105
        taxonFilter.addValueChangeListener(this);
106
        taxonTree.addExpandListener(this);
107

  
108
        //init areas
109
        TermVocabulary<NamedArea> chosenAreaVoc = presenter.getChosenAreaVoc();
110
        distAreaBox.setContainerDataSource(presenter.getDistributionContainer());
111
        distAreaBox.setValue(chosenAreaVoc);
112
        distAreaBox.addValueChangeListener(this);
113

  
114
        if(chosenAreaVoc!=null){
115
            NamedAreaContainer container = new NamedAreaContainer(chosenAreaVoc);
116
            namedAreaList.setContainerDataSource(container);
117
        }
118
        Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
119
        namedAreaList.setValue(selectedAreas);
120

  
121
        okButton.addClickListener(this);
122
        cancelButton.addClickListener(this);
123
        updateButtons();
124
    }
125

  
126
    @Override
127
    protected AbstractLayout buildMainLayout() {
128

  
129
        mainLayout = new VerticalLayout();
130
        mainLayout.setSizeFull();
131

  
132
        HorizontalLayout leftAndRightContainer = new HorizontalLayout();
133
        leftAndRightContainer.setImmediate(false);
134
        leftAndRightContainer.setSizeFull();
135
        leftAndRightContainer.setMargin(true);
136
        leftAndRightContainer.setSpacing(true);
137

  
138
        VerticalLayout leftContainer = new VerticalLayout();
139
        leftContainer.setImmediate(false);
140
        leftContainer.setSpacing(true);
141
        leftContainer.setSizeFull();
142

  
143
        VerticalLayout rightContainer = new VerticalLayout();
144
        rightContainer.setImmediate(false);
145
        rightContainer.setSpacing(true);
146
        rightContainer.setSizeFull();
147

  
148
        //classification
149
        classificationBox = new ComboBox("Classification");
150
        classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
151
        classificationBox.setInputPrompt("Please select a classification...");
152
        classificationBox.setImmediate(true);
153
        classificationBox.setNewItemsAllowed(false);
154
        classificationBox.setNullSelectionAllowed(false);
155
        classificationBox.setSizeFull();
156
        classificationBox.setWidth("100%");
157

  
158
        //taxonFilter
159
        taxonFilter = new TextField("Filter");
160
        taxonFilter.setInputPrompt("Filter taxa by name...");
161
        taxonFilter.setSizeFull();
162
        taxonFilter.setImmediate(true);
163

  
164
        //distribution area box
165
        distAreaBox = new ComboBox("Distribution Area:");
166
        distAreaBox.setInputPrompt("Please select a distribution area...");
167
        distAreaBox.setImmediate(true);
168
        distAreaBox.setNullSelectionAllowed(false);
169
        distAreaBox.setNewItemsAllowed(false);
170
        distAreaBox.setSizeFull();
171
        distAreaBox.setWidth("100%");
172

  
173
        // named areas
174
        namedAreaList = new ListSelect();
175
        namedAreaList.setCaption("Areas");
176
        namedAreaList.setSizeFull();
177
        namedAreaList.setMultiSelect(true);
178

  
179
        //taxonomy
180
        taxonTree = new TreeTable("Taxonomy");
181
        taxonTree.setSelectable(true);
182
        taxonTree.setSizeFull();
183
        taxonTree.setImmediate(true);
184
        taxonTree.setCacheRate(20);
185
        taxonTree.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
186
        taxonTree.setMultiSelect(true);
187

  
188
        leftContainer.addComponent(distAreaBox);
189
        leftContainer.addComponent(namedAreaList);
190
        leftContainer.setExpandRatio(distAreaBox, 0.1f);
191
        leftContainer.setExpandRatio(namedAreaList, 0.9f);
192
        leftContainer.setSizeFull();
193

  
194
        rightContainer.addComponent(classificationBox);
195
        rightContainer.addComponent(taxonFilter);
196
        rightContainer.addComponent(taxonTree);
197
        rightContainer.setExpandRatio(classificationBox, 0.1f);
198
        rightContainer.setExpandRatio(taxonFilter, 0.1f);
199
        rightContainer.setExpandRatio(taxonTree, 0.8f);
200

  
201
        leftAndRightContainer.addComponent(leftContainer);
202
        leftAndRightContainer.addComponent(rightContainer);
203

  
204
        //button toolbar
205
        HorizontalLayout buttonToolBar = createOkCancelButtons();
206

  
207
        mainLayout.addComponent(leftAndRightContainer);
208
        mainLayout.addComponent(buttonToolBar);
209
        mainLayout.setExpandRatio(leftAndRightContainer, 0.9f);
210
        mainLayout.setExpandRatio(buttonToolBar, 0.1f);
211
        mainLayout.setComponentAlignment(buttonToolBar, Alignment.BOTTOM_RIGHT);
212

  
213
        return leftAndRightContainer;
214
    }
215

  
216
    @Override
217
    public void valueChange(ValueChangeEvent event) {
218
        Property property = event.getProperty();
219
        if(property==classificationBox){
220
        	UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
221
            showClassificationTaxa(parent);
222
        }
223
        else if(property==taxonFilter){
224
            String filterText = taxonFilter.getValue();
225
            Property uuidProperty = classificationBox.getContainerProperty(classificationBox.getValue(),"uuid");
226
            if(uuidProperty==null){
227
            	Notification.show("Please select a classification");
228
            }
229
            else{
230
            	if(CdmUtils.isNotBlank(filterText)){
231
            		UUID classificationUuid = UUID.fromString((String) uuidProperty.getValue());
232
            		List<UuidAndTitleCache<TaxonNode>> taxa = CdmSpringContextHelper.getTaxonNodeService().getUuidAndTitleCache(null, filterText, classificationUuid);
233
            		BeanItemContainer<UuidAndTitleCache<TaxonNode>> container = new BeanItemContainer<>(UuidAndTitleCache.class);
234
            		taxonTree.setContainerDataSource(container);
235
            		for (UuidAndTitleCache<TaxonNode> taxon : taxa) {
236
            			container.addItem(taxon);
237
            			taxonTree.setChildrenAllowed(taxon, false);
238
            		}
239
            		taxonTree.setVisibleColumns("titleCache");
240
            	}
241
            	else{
242
            		UuidAndTitleCache<TaxonNode> parent = getUuidAndTitleCacheFromRowId(classificationBox.getValue());
243
            		showClassificationTaxa(parent);
244
            	}
245
            }
246
        }
247
        else if(property==distAreaBox){
248
            TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
249
            NamedAreaContainer container = new NamedAreaContainer(vocabulary);
250
            namedAreaList.setContainerDataSource(container);
251
        }
252
        updateButtons();
253
    }
254

  
255
    @Override
256
    protected boolean isValid() {
257
        return classificationBox.getValue()!=null && distAreaBox.getValue()!=null;
258
    }
259

  
260
    @Override
261
    public void buttonClick(ClickEvent event) {
262
        Object source = event.getSource();
263
        if(source==okButton){
264
            List<UUID> taxonNodes = new ArrayList<>();
265
            TermVocabulary<NamedArea> areaVoc = null;
266
            String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue();
267
            UUID classificationUuid = UUID.fromString(uuidString);
268
            Set<UuidAndTitleCache<TaxonNode>> treeSelection = (Set<UuidAndTitleCache<TaxonNode>>) taxonTree.getValue();
269
			if(!treeSelection.isEmpty()){
270
				for (UuidAndTitleCache<TaxonNode> uuidAndTitleCache : treeSelection) {
271
					taxonNodes.add(uuidAndTitleCache.getUuid());
272
				}
273
            }
274
            areaVoc = (TermVocabulary<NamedArea>) distAreaBox.getValue();
275
            Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
276
            DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, areaVoc, selectedAreas, classificationUuid);
277
            window.close();
278
        }
279
        else if(source==cancelButton){
280
            window.close();
281
        }
282
    }
283

  
284
    @Override
285
    public void nodeExpand(ExpandEvent event) {
286
        UuidAndTitleCache<TaxonNode> parent = (UuidAndTitleCache<TaxonNode>) event.getItemId();
287
        ((TaxonNodeContainer) taxonTree.getContainerDataSource()).addChildItems(parent);
288
    }
289

  
290
    private void showClassificationTaxa(UuidAndTitleCache<TaxonNode> parent) {
291
        final Collection<UuidAndTitleCache<TaxonNode>> children = CdmSpringContextHelper.getTaxonNodeService().listChildNodesAsUuidAndTitleCache(parent);
292
        // Enable polling and set frequency to 0.5 seconds
293
        UI.getCurrent().setPollInterval(500);
294
        taxonTree.setEnabled(false);
295
        taxonTree.removeAllItems();
296
        Notification.show("Loading taxa...");
297

  
298
        new TreeUpdater(children).start();
299
    }
300

  
301
    private UuidAndTitleCache<TaxonNode> getUuidAndTitleCacheFromRowId(Object classificationSelection) {
302
        String uuidString = (String) classificationBox.getContainerProperty(classificationSelection, "uuid").getValue();
303
        Property rootNodeContainerProperty = null;
304

  
305
        Collection<?> ids = classificationBox.getContainerPropertyIds();
306
        //use for loop here because the case of the root node id columns differs between some DBs
307
        for (Object id : ids) {
308
			if(id instanceof String && ((String) id).toLowerCase().equals("rootnode_id")){
309
				rootNodeContainerProperty = classificationBox.getContainerProperty(classificationSelection, id);
310
				break;
311
			}
312
		}
313
		int id = (int) rootNodeContainerProperty.getValue();
314
        String titleCache = (String) classificationBox.getContainerProperty(classificationSelection, "titleCache").getValue();
315
        UUID uuid = UUID.fromString(uuidString);
316
        UuidAndTitleCache<TaxonNode> parent = new UuidAndTitleCache<>(uuid, id, titleCache);
317
        return parent;
318
    }
319

  
320
    private class TreeUpdater extends Thread{
321

  
322
    	private Collection<UuidAndTitleCache<TaxonNode>> children;
323

  
324

  
325
		public TreeUpdater(Collection<UuidAndTitleCache<TaxonNode>> children) {
326
			this.children = children;
327
		}
328

  
329
		@Override
330
    	public void run() {
331
			UI.getCurrent().access(new Runnable() {
332
				@Override
333
				public void run() {
334
					taxonTree.setContainerDataSource(new TaxonNodeContainer(children));
335

  
336
			        Notification notification = new Notification("Loading complete");
337
			        notification.setDelayMsec(500);
338
			        notification.show(Page.getCurrent());
339
			        taxonTree.setEnabled(true);
340

  
341
			        //disable polling when all taxa are loaded
342
			        UI.getCurrent().setPollInterval(-1);
343
				}
344
			});
345
    	}
346
    }
347
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionStatusSettingsConfigWindow.java
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import com.vaadin.data.Property;
12
import com.vaadin.data.Property.ValueChangeEvent;
13
import com.vaadin.data.Property.ValueChangeListener;
14
import com.vaadin.server.VaadinSession;
15
import com.vaadin.ui.AbstractLayout;
16
import com.vaadin.ui.Alignment;
17
import com.vaadin.ui.Button.ClickEvent;
18
import com.vaadin.ui.Button.ClickListener;
19
import com.vaadin.ui.CheckBox;
20
import com.vaadin.ui.HorizontalLayout;
21
import com.vaadin.ui.TwinColSelect;
22
import com.vaadin.ui.VerticalLayout;
23

  
24
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
25
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.DistributionStatusSettingsPresenter;
26

  
27
/**
28
 * @author alex
29
 * @date 22.04.2015
30
 *
31
 */
32
public class DistributionStatusSettingsConfigWindow
33
            extends SettingsDialogWindowBase<DistributionStatusSettingsPresenter>
34
            implements ValueChangeListener, ClickListener{
35

  
36
	private static final long serialVersionUID = -8220442386869594032L;
37
    private TwinColSelect distStatusSelect;
38
    private CheckBox boxToggleAbbreviatedLabels;
39
    private IDistributionTableView distributionTableView;
40

  
41
    /**
42
     * The constructor should first build the main layout, set the
43
     * composition root and then do any custom initialization.
44
     *
45
     * The constructor will not be automatically regenerated by the
46
     * visual editor.
47
     * @param distributionTableView
48
     */
49
    public DistributionStatusSettingsConfigWindow(IDistributionTableView distributionTableView) {
50
    	super();
51
    	this.distributionTableView = distributionTableView;
52
    }
53

  
54
    @Override
55
    protected void init() {
56
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
57
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
58

  
59
        okButton.addClickListener(this);
60
        cancelButton.addClickListener(this);
61
        updateButtons();
62
    }
63

  
64
    @Override
65
    protected AbstractLayout buildMainLayout() {
66

  
67
    	mainLayout = new VerticalLayout();
68
        mainLayout.setImmediate(false);
69
        mainLayout.setSizeFull();
70
        mainLayout.setMargin(true);
71
        mainLayout.setSpacing(true);
72

  
73
        //distribution status
74
        distStatusSelect = new TwinColSelect("Distribution Status:");
75
        distStatusSelect.setImmediate(false);
76
        distStatusSelect.setSizeFull();
77
        distStatusSelect.setWidth("100%");
78

  
79
        //toggle abbreviated labels
80
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
81
        boxToggleAbbreviatedLabels.setImmediate(true);
82

  
83
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
84
        mainLayout.addComponent(distStatusSelect);
85
        mainLayout.setExpandRatio(distStatusSelect, 1);
86
        mainLayout.setSizeFull();
87

  
88
        //button toolbar
89
        HorizontalLayout buttonContainer = createOkCancelButtons();
90

  
91
        mainLayout.addComponent(buttonContainer);
92
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
93

  
94
        return mainLayout;
95
    }
96

  
97
    @Override
98
    protected boolean isValid() {
99
    	return true;
100
    }
101

  
102
	@Override
103
	public void valueChange(ValueChangeEvent event) {
104
		Property<?> property = event.getProperty();
105
		if(property==boxToggleAbbreviatedLabels){
106
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
107
		}
108
	}
109

  
110
	@Override
111
	public void buttonClick(ClickEvent event) {
112
		Object source = event.getSource();
113
		if(source==okButton){
114
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
115
			distributionTableView.enter(null);
116
			window.close();
117
		}
118
		else if(source==cancelButton){
119
			window.close();
120
		}
121
	}
122

  
123
    /**
124
     * {@inheritDoc}
125
     */
126
    @Override
127
    protected DistributionStatusSettingsPresenter getPresenter() {
128
        return new DistributionStatusSettingsPresenter();
129
    }
130

  
131
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java
58 58
 */
59 59
@SpringComponent
60 60
@ViewScope
61
public class DistributionTablePresenter extends AbstractPresenter<DistributionTableView> {
61
public class DistributionTablePresenter extends AbstractPresenter<IDistributionTableView> {
62 62

  
63 63
	private static final long serialVersionUID = 3313043335587777217L;
64 64

  
......
179 179
	}
180 180

  
181 181
	public HashMap<DescriptionElementBase, Distribution> getDistribution(DefinedTermBase dt, Taxon taxon) {
182
		Set<Feature> setFeature = new HashSet<Feature>(Arrays.asList(Feature.DISTRIBUTION()));
182
		Set<Feature> setFeature = new HashSet<>(Arrays.asList(Feature.DISTRIBUTION()));
183 183
		List<DescriptionElementBase> listTaxonDescription = CdmSpringContextHelper.getDescriptionService().listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY);
184 184
		HashMap<DescriptionElementBase, Distribution> map = null;
185 185
		for(DescriptionElementBase deb : listTaxonDescription){
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableView.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import com.vaadin.navigator.View;
12

  
13
import eu.etaxonomy.vaadin.mvp.ApplicationView;
14

  
15
/**
16
 * @author freimeier
17
 * @since 18.10.2017
18
 *
19
 */
20
public interface DistributionTableView extends ApplicationView<DistributionTablePresenter>, View {
21

  
22
    /**
23
     * Updates Distribution Table.
24
     */
25
	public void update();
26

  
27
	/**
28
	 * Opens the setting window to change available distribution status.
29
	 */
30
	public void openSettings();
31

  
32
	/**
33
	 * Opens the distribution-setting window to change available areas and chose classification.
34
	 */
35
	public void openDistributionSettings();
36

  
37
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
56 56
 *
57 57
 */
58 58
@SpringView(name=DistributionTableViewBean.NAME)
59
public class DistributionTableViewBean extends AbstractPageView<DistributionTablePresenter> implements DistributionTableView, AccessRestrictedView {
59
public class DistributionTableViewBean
60
            extends AbstractPageView<DistributionTablePresenter>
61
            implements IDistributionTableView, AccessRestrictedView {
60 62

  
61 63
	private static final long serialVersionUID = 1L;
62 64
    public static final String NAME = "distTable";
......
68 70
	private Grid grid;
69 71

  
70 72
    private CdmSQLContainer container;
71
	private DistributionSettingsConfigWindow distributionSettingConfigWindow;
73
	private AreaAndTaxonSettingsConfigWindow distributionSettingConfigWindow;
72 74

  
73 75
	public DistributionTableViewBean() {
74 76
		super();
......
247 249
     */
248 250
	@Override
249 251
	public void openSettings() {
250
		SettingsConfigWindow cw = new SettingsConfigWindow(this);
252
		DistributionStatusSettingsConfigWindow cw = new DistributionStatusSettingsConfigWindow(this);
251 253
		Window window  = cw.createWindow("Status");
252 254
		UI.getCurrent().addWindow(window);
253 255
	}
......
258 260
	@Override
259 261
	public void openDistributionSettings() {
260 262
		if(distributionSettingConfigWindow==null){
261
			distributionSettingConfigWindow = new DistributionSettingsConfigWindow(this);
263
			distributionSettingConfigWindow = new AreaAndTaxonSettingsConfigWindow(this);
262 264
		}
263 265
        Window window  = distributionSettingConfigWindow.createWindow("Areas and Taxa");
264 266
        UI.getCurrent().addWindow(window);
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/IDistributionTableView.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import com.vaadin.navigator.View;
12

  
13
import eu.etaxonomy.vaadin.mvp.ApplicationView;
14

  
15
/**
16
 * @author freimeier
17
 * @since 18.10.2017
18
 *
19
 */
20
public interface IDistributionTableView extends ApplicationView<DistributionTablePresenter>, View {
21

  
22
    /**
23
     * Updates Distribution Table.
24
     */
25
	public void update();
26

  
27
	/**
28
	 * Opens the setting window to change available distribution status.
29
	 */
30
	public void openSettings();
31

  
32
	/**
33
	 * Opens the distribution-setting window to change available areas and chose classification.
34
	 */
35
	public void openDistributionSettings();
36

  
37
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/NoCommitFieldGroup.java
16 16
 *
17 17
 */
18 18
public class NoCommitFieldGroup extends FieldGroup{
19
	@Override
19

  
20
    private static final long serialVersionUID = -1666206997756640330L;
21

  
22
    @Override
20 23
	public boolean isReadOnly() {
21 24
		return false;
22 25
	}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/SettingsConfigWindow.java
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
10

  
11
import com.vaadin.data.Property;
12
import com.vaadin.data.Property.ValueChangeEvent;
13
import com.vaadin.data.Property.ValueChangeListener;
14
import com.vaadin.server.VaadinSession;
15
import com.vaadin.ui.AbstractLayout;
16
import com.vaadin.ui.Alignment;
17
import com.vaadin.ui.Button.ClickEvent;
18
import com.vaadin.ui.Button.ClickListener;
19
import com.vaadin.ui.CheckBox;
20
import com.vaadin.ui.HorizontalLayout;
21
import com.vaadin.ui.TwinColSelect;
22
import com.vaadin.ui.VerticalLayout;
23

  
24
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
25

  
26
/**
27
 * @author alex
28
 * @date 22.04.2015
29
 *
30
 */
31
public class SettingsConfigWindow extends AbstractSettingsDialogWindow implements ValueChangeListener, ClickListener{
32

  
33
	private static final long serialVersionUID = -8220442386869594032L;
34
    private TwinColSelect distStatusSelect;
35
    private CheckBox boxToggleAbbreviatedLabels;
36
    private DistributionTableView distributionTableView;
37

  
38
    /**
39
     * The constructor should first build the main layout, set the
40
     * composition root and then do any custom initialization.
41
     *
42
     * The constructor will not be automatically regenerated by the
43
     * visual editor.
44
     * @param distributionTableView
45
     */
46
    public SettingsConfigWindow(DistributionTableView distributionTableView) {
47
    	super();
48
    	this.distributionTableView = distributionTableView;
49
    }
50

  
51
    @Override
52
    protected void init() {
53
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
54
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
55

  
56
        okButton.addClickListener(this);
57
        cancelButton.addClickListener(this);
58
        updateButtons();
59
    }
60

  
61
    @Override
62
    protected AbstractLayout buildMainLayout() {
63

  
64
    	mainLayout = new VerticalLayout();
65
        mainLayout.setImmediate(false);
66
        mainLayout.setSizeFull();
67
        mainLayout.setMargin(true);
68
        mainLayout.setSpacing(true);
69

  
70
        //distribution status
71
        distStatusSelect = new TwinColSelect("Distribution Status:");
72
        distStatusSelect.setImmediate(false);
73
        distStatusSelect.setSizeFull();
74
        distStatusSelect.setWidth("100%");
75

  
76
        //toggle abbreviated labels
77
        boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
78
        boxToggleAbbreviatedLabels.setImmediate(true);
79

  
80
        mainLayout.addComponent(boxToggleAbbreviatedLabels);
81
        mainLayout.addComponent(distStatusSelect);
82
        mainLayout.setExpandRatio(distStatusSelect, 1);
83
        mainLayout.setSizeFull();
84

  
85
        //button toolbar
86
        HorizontalLayout buttonContainer = createOkCancelButtons();
87

  
88
        mainLayout.addComponent(buttonContainer);
89
        mainLayout.setComponentAlignment(buttonContainer, Alignment.BOTTOM_RIGHT);
90

  
91
        return mainLayout;
92
    }
93

  
94
    @Override
95
    protected boolean isValid() {
96
    	return true;
97
    }
98

  
99
	@Override
100
	public void valueChange(ValueChangeEvent event) {
101
		Property property = event.getProperty();
102
		if(property==boxToggleAbbreviatedLabels){
103
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
104
		}
105
	}
106

  
107
	@Override
108
	public void buttonClick(ClickEvent event) {
109
		Object source = event.getSource();
110
		if(source==okButton){
111
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
112
			distributionTableView.enter(null);
113
			window.close();
114
		}
115
		else if(source==cancelButton){
116
			window.close();
117
		}
118
	}
119

  
120
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/SettingsDialogWindowBase.java
1
package eu.etaxonomy.cdm.vaadin.view.distributionStatus;
2

  
3
import com.vaadin.ui.AbstractLayout;
4
import com.vaadin.ui.AbstractOrderedLayout;
5
import com.vaadin.ui.Button;
6
import com.vaadin.ui.CustomComponent;
7
import com.vaadin.ui.HorizontalLayout;
8
import com.vaadin.ui.Window;
9

  
10
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings.SettingsPresenterBase;
11

  
12
@SuppressWarnings("serial")
13
public abstract class SettingsDialogWindowBase<P extends SettingsPresenterBase> extends CustomComponent {
14

  
15
	protected Button okButton;
16
	protected Button cancelButton;
17
	protected final P presenter;
18
	protected Window window;
19
	protected AbstractOrderedLayout mainLayout;
20

  
21
	public SettingsDialogWindowBase() {
22
        buildMainLayout();
23
        presenter = getPresenter();
24
        init();
25
	}
26

  
27
    protected abstract P getPresenter();
28

  
29
    protected abstract AbstractLayout buildMainLayout();
30

  
31
	protected abstract void init();
32

  
33
	protected HorizontalLayout createOkCancelButtons() {
34
		HorizontalLayout buttonToolBar = new HorizontalLayout();
35
	    // cancelButton
36
	    cancelButton = new Button();
37
	    cancelButton.setCaption("Cancel");
38
	    cancelButton.setImmediate(true);
39
	    cancelButton.addStyleName("dialogButton");
40
	    buttonToolBar.addComponent(cancelButton);
41

  
42
	    // okButton
43
	    okButton = new Button();
44
	    okButton.setCaption("OK");
45
	    okButton.setImmediate(true);
46
	    okButton.addStyleName("dialogButton");
47
	    buttonToolBar.addComponent(okButton);
48
		return buttonToolBar;
49
	}
50

  
51
	public Window createWindow(String caption) {
52
	    window = new Window();
53
	    window.setModal(true);
54
	    window.setWidth("60%");
55
	    window.setHeight("80%");
56
	    window.setCaption(caption);
57
	    window.setContent(mainLayout);
58
	    return window;
59
	}
60

  
61
	/**
62
	 * Update OK/Cancel button depending on {@link #isValid()}
63
	 */
64
	protected void updateButtons(){
65
		okButton.setEnabled(isValid());
66
	}
67

  
68
	/**
69
	 * Evaluates if this dialog has all necessary values set in
70
	 * a correct state
71
	 * @return <code>true</code> if the status of this dialog is valid
72
	 */
73
	protected abstract boolean isValid();
74

  
75
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/AreaAndTaxonSettingsPresenter.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings;
10

  
11
import java.util.Arrays;
12
import java.util.Collections;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import com.vaadin.data.Container;
17
import com.vaadin.data.util.IndexedContainer;
18
import com.vaadin.server.VaadinSession;
19

  
20
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21
import eu.etaxonomy.cdm.model.common.TermType;
22
import eu.etaxonomy.cdm.model.common.TermVocabulary;
23
import eu.etaxonomy.cdm.model.location.NamedArea;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
27
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
28

  
29
/**
30
 * @author a.mueller
31
 * @date 22.10.2017
32
 *
33
 */
34
public class AreaAndTaxonSettingsPresenter extends SettingsPresenterBase {
35

  
36
    private Container distributionContainer;
37
    private UUID areaVocabUUID;
38

  
39
    /**
40
     * @param distributionContainer
41
     * @param vocUUID
42
     */
43
    public AreaAndTaxonSettingsPresenter() {
44
        super();
45
        Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
46
        if(selectedVocabularyUuidString!=null){
47
            areaVocabUUID = UUID.fromString(selectedVocabularyUuidString.toString());
48
        }
49
        distributionContainer = new IndexedContainer(getNamedAreaList());
50
    }
51

  
52
    public Container getDistributionContainer() {
53
        return distributionContainer;
54
    }
55

  
56
    private List<TermVocabulary<DefinedTermBase>> getNamedAreaList() {
57
        List<TermVocabulary<DefinedTermBase>> termList = CdmSpringContextHelper.getVocabularyService().findByTermType(TermType.NamedArea, VOCABULARY_INIT_STRATEGY);
58
        return termList;
59
    }
60

  
61
    public List<TaxonNode> getChosenTaxonNodes(){
62
        List<UUID> nodeUuids = (List<UUID>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
63
        if(nodeUuids!=null){
64
            return CdmSpringContextHelper.getTaxonNodeService().load(nodeUuids, null);
65
        }
66
        return Collections.emptyList();
67
    }
68

  
69
    public Classification getChosenClassification(){
70
        UUID uuid = (UUID) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION);
71
        if(uuid!=null){
72
            return CdmSpringContextHelper.getClassificationService().load(uuid);
73
        }
74
        return null;
75
    }
76

  
77
    public TermVocabulary<NamedArea> getChosenAreaVoc(){
78
        return CdmSpringContextHelper.getVocabularyService().load(areaVocabUUID);
79
    }
80

  
81
    protected static final List<String> VOCABULARY_INIT_STRATEGY = Arrays.asList(new String []{
82
            "$",
83
            "terms",
84
            "terms.*",
85
    });
86

  
87
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/DistributionStatusSettingsPresenter.java
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.view.distributionStatus.settings;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13

  
14
import com.vaadin.data.Container;
15
import com.vaadin.data.util.IndexedContainer;
16

  
17
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
18
import eu.etaxonomy.cdm.model.common.TermType;
19
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
20

  
21
/**
22
 * @author a.mueller
23
 * @date 22.10.2017
24
 *
25
 */
26
public class DistributionStatusSettingsPresenter extends SettingsPresenterBase {
27

  
28
    private Container distributionStatusContainer;
29

  
30
    /**
31
     * @param distributionStatusContainer
32
     */
33
    public DistributionStatusSettingsPresenter() {
34
        super();
35
        distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
36
    }
37

  
38
    private List<DefinedTermBase<?>> getPresenceAbsenceVocabulary(){
39
        return CdmSpringContextHelper.getTermService().listByTermType(
40
                TermType.PresenceAbsenceTerm, null, null, null, DESCRIPTION_INIT_STRATEGY);
41
    }
42

  
43

  
44
    public Container getDistributionStatusContainer() {
45
        return distributionStatusContainer;
46
    }
47

  
48
    protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
49
            "$",
50
            "representations",
51
    });
52
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)