Project

General

Profile

Download (2.63 KB) Statistics
| Branch: | Tag: | Revision:
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

    
25
/**
26
 * @author a.kohlbecker
27
 * @since May 5, 2017
28
 *
29
 */
30
public abstract class AbstractCdmPopupEditor<DTO extends CdmBase, P extends AbstractEditorPresenter<DTO, ? extends ApplicationView>>
31
    extends AbstractPopupEditor<DTO, P> {
32

    
33
    private static final long serialVersionUID = -5025937489746256070L;
34

    
35
    private boolean isAdvancedMode = false;
36

    
37
    private List<Component> advancedModeComponents = new ArrayList<>();
38

    
39
    private Button advancedModeButton;
40

    
41
    /**
42
     * @param layout
43
     * @param dtoType
44
     */
45
    public AbstractCdmPopupEditor(Layout layout, Class<DTO> dtoType) {
46
        super(layout, dtoType);
47
        if(MarginHandler.class.isAssignableFrom(getFieldLayout().getClass())){
48
            ((MarginHandler)getFieldLayout()).setMargin(new MarginInfo(false, true, true, true));
49
        }
50
    }
51

    
52
    /**
53
     * @return the isAdvancedMode
54
     */
55
    public boolean isAdvancedMode() {
56
        return isAdvancedMode;
57
    }
58

    
59
    /**
60
     * @param isAdvancedMode the isAdvancedMode to set
61
     */
62
    public void setAdvancedMode(boolean isAdvancedMode) {
63
        this.isAdvancedMode = isAdvancedMode;
64
        advancedModeComponents.forEach(c -> c.setVisible(isAdvancedMode));
65
    }
66

    
67
    public void setAdvancedModeEnabled(boolean activate){
68
        if(activate && advancedModeButton == null){
69
            advancedModeButton = new Button(FontAwesome.WRENCH); // FontAwesome.FLASK
70
            advancedModeButton.setIconAlternateText("Advanced mode");
71
            advancedModeButton.addStyleName(ValoTheme.BUTTON_TINY);
72
            toolBarButtonGroupAdd(advancedModeButton);
73
            advancedModeButton.addClickListener(e -> {
74
                setAdvancedMode(!isAdvancedMode);
75
                }
76
            );
77

    
78
        } else if(advancedModeButton != null) {
79
            toolBarButtonGroupRemove(advancedModeButton);
80
            advancedModeButton = null;
81
        }
82
    }
83

    
84
    public void registerAdvancedModeComponents(Component ... c){
85
        advancedModeComponents.addAll(Arrays.asList(c));
86
    }
87

    
88
}
(2-2/8)