Project

General

Profile

« Previous | Next » 

Revision 8f6b3c3a

Added by Andreas Kohlbecker about 7 years ago

ref #6169 allowing to toggle item list and grid

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/presenter/phycobank/ListPresenter.java
34 34
    @Override
35 35
    public void onViewEnter() {
36 36
        super.onViewEnter();
37
        //getView().populateTable(listRegistrations());
38
        getView().populateList(listRegistrations());
37
        getView().populate(listRegistrations());
39 38
    }
40 39

  
41 40
    /**
src/main/java/eu/etaxonomy/cdm/vaadin/view/phycobank/ListView.java
24 24
    /**
25 25
     * @param page
26 26
     */
27
    void populateTable(Collection<RegistrationDTO> registrations);
28

  
29
    /**
30
     * @param page
31
     */
32
    void populateList(Collection<RegistrationDTO> registrations);
27
    void populate(Collection<RegistrationDTO> registrations);
33 28

  
34 29

  
35 30
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/phycobank/ListViewBean.java
20 20
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
21 21
import com.vaadin.shared.ui.grid.HeightMode;
22 22
import com.vaadin.spring.annotation.SpringView;
23
import com.vaadin.ui.Button;
24
import com.vaadin.ui.Button.ClickEvent;
23 25
import com.vaadin.ui.Component;
24 26
import com.vaadin.ui.CssLayout;
25 27
import com.vaadin.ui.Grid;
......
49 51

  
50 52
    public static final String NAME = "list";
51 53

  
52
    CssLayout listContainer;
54
    private CssLayout listContainer;
53 55

  
54 56
    private Grid grid;
55 57

  
58
    private CssLayout toolBar;
59

  
56 60
    public ListViewBean() {
57 61

  
58 62
        super();
59 63

  
60
        CssLayout toolBar = new CssLayout();
61
        // toolBar.addComponent(new Button);
62

  
63
//        grid = buildGrid();
64
//        layout.addComponent(grid);
65
//        layout.setExpandRatio(grid, 1);
64
        toolBar = new CssLayout();
65
        toolBar.setWidth(100, Unit.PERCENTAGE);
66
        toolBar.addComponent(new Button("As grid", e -> toggleListType(e)));
67
        getLayout().addComponent(toolBar);
66 68

  
67
        listContainer = new CssLayout();
68
        listContainer.setId("registration-list");
69
        listContainer.setWidth(100, Unit.PERCENTAGE);
70
        listContainer.setHeight(100, Unit.PERCENTAGE);
71

  
72
        getLayout().addComponent(listContainer);
69
        buildList();
70
        buildGrid();
73 71

  
72
        showList();
74 73
    }
75 74

  
76 75
    @Override
......
83 82
        return "This is the list of all your registrations in progress.";
84 83
    }
85 84

  
86
    private Grid buildGrid() {
87
        Grid grid = new Grid();
85
    private void buildList() {
86
        listContainer = new CssLayout();
87
        listContainer.setId("registration-list");
88
        listContainer.setWidth(100, Unit.PERCENTAGE);
89
        listContainer.setHeight(100, Unit.PERCENTAGE);
90
    }
91

  
92
    private void buildGrid() {
93
        grid = new Grid();
88 94
        grid.setSizeFull();
89 95
        grid.setEditorEnabled(false);
90 96
        grid.setId("registration-list");
......
93 99
        grid.setHeightMode(HeightMode.CSS);
94 100
        // add status as class  attribute to the rows to allow styling with css
95 101
        grid.setRowStyleGenerator(rowRef -> {return "status-" + rowRef.getItem().getItemProperty("status").getValue().toString();});
96
        return grid;
97 102
    }
98 103

  
104
    /**
105
     * @param e
106
     * @return
107
     */
108
    private Object toggleListType(ClickEvent e) {
109
        Button button = e.getButton();
110
        if(button.getCaption().equals("As grid")){
111
            button.setCaption("As list");
112
            showGrid();
113
        } else {
114
            button.setCaption("As grid");
115
            showList();
116
        }
117
        return null;
118
    }
119

  
120
    private void showList() {
121
        if(grid != null){
122
            getLayout().removeComponent(grid);
123
        }
124
        getLayout().addComponent(listContainer);
125
    }
126

  
127
    private void showGrid() {
128
        if(listContainer != null){
129
            getLayout().removeComponent(listContainer);
130
        }
131
        getLayout().addComponent(grid);
132
    }
133

  
134

  
99 135
    /**
100 136
     * {@inheritDoc}
101 137
     */
102 138
    @Override
103 139
    public void enter(ViewChangeEvent event) {
104 140
        getPresenter().onViewEnter();
105

  
106 141
    }
107 142

  
108 143
    /**
......
112 147
    @Autowired
113 148
    protected void injectPresenter(ListPresenter presenter) {
114 149
        setPresenter(presenter);
115

  
116 150
    }
117 151

  
118
    static final String[] visiblCols = new String[]{"status, summary", "registrationId"};
119
    /**
120
     * {@inheritDoc}
121
     */
122 152
    @Override
123
    public void populateTable(Collection<RegistrationDTO> registrations) {
153
    public void populate(Collection<RegistrationDTO> registrations) {
154
        populateGrid(registrations);
155
        populateList(registrations);
156
    }
157

  
158

  
159
    public void populateGrid(Collection<RegistrationDTO> registrations) {
124 160

  
125 161
        BeanContainer<String, RegistrationDTO> registrationItems = new BeanContainer<String, RegistrationDTO>(RegistrationDTO.class);
126 162
        registrationItems.setBeanIdProperty("specificIdentifier");
......
170 206

  
171 207
    }
172 208

  
173
    /**
174
     * {@inheritDoc}
175
     */
176
    @Override
209

  
177 210
    public void populateList(Collection<RegistrationDTO> registrations) {
178 211

  
179 212
        for(RegistrationDTO regDto : registrations) {
180

  
181 213
            Component lazyItem = new RegistrationItem(regDto, this); //new LazyLoadWrapper(new RegistrationItem(regDto, this));
182 214
            lazyItem.setWidth(100, Unit.PERCENTAGE);
183 215
            listContainer.addComponent(lazyItem);
184
//            if(list.getComponentCount() > 10){
185
//                break;
186
//            }
187 216
        }
188
        // panel.setContent(listContainer);
189

  
190 217
    }
191 218

  
192 219
    /**

Also available in: Unified diff