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.vaadin.mvp;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
|
15
|
import com.vaadin.server.FontAwesome;
|
16
|
import com.vaadin.shared.ui.MarginInfo;
|
17
|
import com.vaadin.ui.Button;
|
18
|
import com.vaadin.ui.Component;
|
19
|
import com.vaadin.ui.Layout;
|
20
|
import com.vaadin.ui.Layout.MarginHandler;
|
21
|
import com.vaadin.ui.themes.ValoTheme;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
import eu.etaxonomy.cdm.vaadin.component.SelectFieldFactory;
|
25
|
import eu.etaxonomy.vaadin.ui.view.PopupEditorFactory;
|
26
|
|
27
|
/**
|
28
|
* @author a.kohlbecker
|
29
|
* @since May 5, 2017
|
30
|
*
|
31
|
*/
|
32
|
public abstract class AbstractCdmPopupEditor<DTO extends CdmBase, P extends AbstractEditorPresenter<DTO, ? extends ApplicationView>>
|
33
|
extends AbstractPopupEditor<DTO, P> {
|
34
|
|
35
|
private static final long serialVersionUID = -5025937489746256070L;
|
36
|
|
37
|
private boolean isAdvancedMode = false;
|
38
|
|
39
|
private List<Component> advancedModeComponents = new ArrayList<>();
|
40
|
|
41
|
private Button advancedModeButton;
|
42
|
|
43
|
/**
|
44
|
* set by the {@link PopupEditorFactory}
|
45
|
*/
|
46
|
protected SelectFieldFactory selectFieldFactory;
|
47
|
|
48
|
/**
|
49
|
* @param layout
|
50
|
* @param dtoType
|
51
|
*/
|
52
|
public AbstractCdmPopupEditor(Layout layout, Class<DTO> dtoType) {
|
53
|
super(layout, dtoType);
|
54
|
if(MarginHandler.class.isAssignableFrom(getFieldLayout().getClass())){
|
55
|
((MarginHandler)getFieldLayout()).setMargin(new MarginInfo(false, true, true, true));
|
56
|
}
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* @return the isAdvancedMode
|
61
|
*/
|
62
|
public boolean isAdvancedMode() {
|
63
|
return isAdvancedMode;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* @param isAdvancedMode the isAdvancedMode to set
|
68
|
*/
|
69
|
public void setAdvancedMode(boolean isAdvancedMode) {
|
70
|
this.isAdvancedMode = isAdvancedMode;
|
71
|
advancedModeComponents.forEach(c -> c.setVisible(isAdvancedMode));
|
72
|
}
|
73
|
|
74
|
public void setAdvancedModeEnabled(boolean activate){
|
75
|
if(activate && advancedModeButton == null){
|
76
|
advancedModeButton = new Button(FontAwesome.WRENCH); // FontAwesome.FLASK
|
77
|
advancedModeButton.setIconAlternateText("Advanced mode");
|
78
|
advancedModeButton.addStyleName(ValoTheme.BUTTON_TINY);
|
79
|
toolBarButtonGroupAdd(advancedModeButton);
|
80
|
advancedModeButton.addClickListener(e -> {
|
81
|
setAdvancedMode(!isAdvancedMode);
|
82
|
}
|
83
|
);
|
84
|
|
85
|
} else if(advancedModeButton != null) {
|
86
|
toolBarButtonGroupRemove(advancedModeButton);
|
87
|
advancedModeButton = null;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
public void registerAdvancedModeComponents(Component ... c){
|
92
|
advancedModeComponents.addAll(Arrays.asList(c));
|
93
|
}
|
94
|
|
95
|
}
|