Project

General

Profile

Revision fcf1cf06

IDfcf1cf0623ea8dd2cb97e43ba79254ef0f24181a
Parent 4a579136
Child 4942e63b

Added by Andreas Kohlbecker over 2 years ago

pulling functionality from AbstractCdmPopupEditor up into AbstractPopupEditor

View differences:

src/main/java/eu/etaxonomy/vaadin/mvp/AbstractCdmPopupEditor.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.mvp;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13 11
import java.util.EnumSet;
14
import java.util.List;
15 12

  
16
import com.vaadin.server.FontAwesome;
17
import com.vaadin.shared.ui.MarginInfo;
18
import com.vaadin.ui.Button;
19
import com.vaadin.ui.Component;
20 13
import com.vaadin.ui.Layout;
21
import com.vaadin.ui.Layout.MarginHandler;
22
import com.vaadin.ui.themes.ValoTheme;
23 14

  
24 15
import eu.etaxonomy.cdm.model.common.CdmBase;
25 16
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
......
33 24
public abstract class AbstractCdmPopupEditor<DTO extends CdmBase, P extends AbstractCdmEditorPresenter<DTO, ? extends ApplicationView>>
34 25
    extends AbstractPopupEditor<DTO, P> implements PerEntityAuthorityGrantingEditor {
35 26

  
36
    private static final long serialVersionUID = -5025937489746256070L;
37

  
38
    private boolean isAdvancedMode = false;
39

  
40
    private List<Component> advancedModeComponents = new ArrayList<>();
41

  
42
    private Button advancedModeButton;
43

  
44 27
    /**
45
     * The supplied layout will be set to full size, to avoid problems with
46
     * automatic resizing of the inner content.
47
     *
48
     *
49 28
     * @param layout
50 29
     * @param dtoType
51 30
     */
52 31
    public AbstractCdmPopupEditor(Layout layout, Class<DTO> dtoType) {
53 32
        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 33
    }
94 34

  
35
    private static final long serialVersionUID = -5025937489746256070L;
95 36

  
96 37
    @Override
97 38
    public void grantToCurrentUser(EnumSet<CRUD> crud){
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java
8 8
*/
9 9
package eu.etaxonomy.vaadin.mvp;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
11 14
import java.util.Map;
12 15
import java.util.Stack;
13 16

  
......
40 43
import com.vaadin.ui.GridLayout.OverlapsException;
41 44
import com.vaadin.ui.HorizontalLayout;
42 45
import com.vaadin.ui.Layout;
46
import com.vaadin.ui.Layout.MarginHandler;
43 47
import com.vaadin.ui.Notification;
44 48
import com.vaadin.ui.Notification.Type;
45 49
import com.vaadin.ui.PopupDateField;
......
98 102

  
99 103
    private boolean isContextUpdated;
100 104

  
105
    private boolean isAdvancedMode = false;
106

  
107
    private List<Component> advancedModeComponents = new ArrayList<>();
108

  
109
    private Button advancedModeButton;
110

  
101 111
    public AbstractPopupEditor(Layout layout, Class<DTO> dtoType) {
102 112

  
103 113
        mainLayout = new VerticalLayout();
......
105 115
        // popup window may have problems with automatic resizing of its
106 116
        // content.
107 117
        mainLayout.setSizeFull();
118

  
108 119
        setCompositionRoot(mainLayout);
109 120

  
110 121
        fieldGroup = new BeanFieldGroup<>(dtoType);
......
122 133
        if(fieldLayout instanceof AbstractOrderedLayout){
123 134
            ((AbstractOrderedLayout)fieldLayout).setSpacing(true);
124 135
        }
136
        if(MarginHandler.class.isAssignableFrom(fieldLayout.getClass())){
137
            ((MarginHandler)fieldLayout).setMargin(new MarginInfo(false, true, true, true));
138
        }
125 139

  
126 140
        buttonLayout = new HorizontalLayout();
127 141
        buttonLayout.setStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
......
255 269
        toolBar.setVisible(true);
256 270
    }
257 271

  
272
    /**
273
     * @return the isAdvancedMode
274
     */
275
    public boolean isAdvancedMode() {
276
        return isAdvancedMode;
277
    }
278

  
279
    /**
280
     * @param isAdvancedMode the isAdvancedMode to set
281
     */
282
    public void setAdvancedMode(boolean isAdvancedMode) {
283
        this.isAdvancedMode = isAdvancedMode;
284
        advancedModeComponents.forEach(c -> c.setVisible(isAdvancedMode));
285
    }
286

  
287
    public void setAdvancedModeEnabled(boolean activate){
288
        if(activate && advancedModeButton == null){
289
            advancedModeButton = new Button(FontAwesome.WRENCH); // FontAwesome.FLASK
290
            advancedModeButton.setIconAlternateText("Advanced mode");
291
            advancedModeButton.addStyleName(ValoTheme.BUTTON_TINY);
292
            toolBarButtonGroupAdd(advancedModeButton);
293
            advancedModeButton.addClickListener(e -> {
294
                setAdvancedMode(!isAdvancedMode);
295
                }
296
            );
297

  
298
        } else if(advancedModeButton != null) {
299
            toolBarButtonGroupRemove(advancedModeButton);
300
            advancedModeButton = null;
301
        }
302
    }
303

  
304
    public void registerAdvancedModeComponents(Component ... c){
305
        advancedModeComponents.addAll(Arrays.asList(c));
306
    }
258 307

  
259 308

  
260 309
    // ------------------------ event handler ------------------------ //

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)