PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/page/entry/editor/mock/MockAdminFieldSet.java

http://sigma-h.googlecode.com/
Java | 75 lines | 51 code | 17 blank | 7 comment | 3 complexity | 48fee600118beccfb4eff3789505fc17 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.client.page.entry.editor.mock;
 7
 8import com.extjs.gxt.ui.client.store.ListStore;
 9import org.sigmah.client.page.entry.editor.AdminFieldSetPresenter;
10import org.sigmah.shared.dto.AdminEntityDTO;
11
12import java.util.HashMap;
13import java.util.HashSet;
14import java.util.Map;
15import java.util.Set;
16
17/**
18 * @author Alex Bertram (akbertram@gmail.com)
19 */
20public class MockAdminFieldSet implements AdminFieldSetPresenter.View {
21
22    AdminFieldSetPresenter presenter;
23
24    Map<Integer, AdminEntityDTO> values =
25            new HashMap<Integer, AdminEntityDTO>();
26    Set<Integer> enabled =
27            new HashSet<Integer>();
28    Map<Integer, ListStore<AdminEntityDTO>> stores =
29            new HashMap<Integer, ListStore<AdminEntityDTO>>();
30
31    @Override
32    public void bindPresenter(AdminFieldSetPresenter presenter) {
33        this.presenter = presenter;
34    }
35
36    @Override
37    public void setStore(int levelId, ListStore<AdminEntityDTO> store) {
38        stores.put(levelId, store);
39    }
40
41    public ListStore<AdminEntityDTO> getStore(int levelId) {
42        return stores.get(levelId);
43    }
44
45    @Override
46    public void setEnabled(int levelId, boolean value) {
47        if(value) {
48            enabled.add(levelId);
49        } else {
50            enabled.remove(levelId);
51        }
52    }
53
54    public boolean getEnabled(int levelId) {
55        return enabled.contains(levelId);
56
57    }
58
59    @Override
60    public void setValue(int levelId, AdminEntityDTO value) {
61        values.put(levelId, value);
62        System.out.println("level " + levelId + " set to " +  (value == null ? "null" : value.getName()));
63    }
64
65    public void setValueAndFire(int levelId, AdminEntityDTO value) {
66        setValue(levelId, value);
67        presenter.onSelectionChanged(levelId, value);
68    }
69
70    public AdminEntityDTO getValue(int levelId) {
71        return values.get(levelId);
72
73    }
74
75}