source: java/main/src/main/java/com/framsticks/params/UniqueListAccess.java @ 84

Last change on this file since 84 was 84, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

File size: 4.1 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.util.lang.Casting;
4import com.framsticks.util.lang.Numbers;
5import org.apache.log4j.Logger;
6
7import java.util.*;
8
9/**
10 * @author Piotr Sniegowski
11 */
12public class UniqueListAccess extends ListAccess {
13
14        private static final Logger log = Logger.getLogger(UniqueListAccess.class.getName());
15
16        Map<String, Object> map;
17
18        final String uidName;
19
20        public UniqueListAccess(AccessInterface elementAccess, String uidName) {
21                super(elementAccess);
22                this.uidName = uidName;
23        }
24
25        @Override
26        public Map<String, Object> createAccessee() {
27                return new HashMap<String, Object>();
28        }
29
30        @Override
31        public Param getParam(int i) {
32                log.error("accesing unique list through index");
33                assert false;
34                return null;
35                //log.error("accesing unique list through index");
36                //return null;
37                //return new ParamBuilder().setId(Integer.toString(i)).setName(elementAccess.getId()).setType("o " + elementAccess.getId()).build();
38        }
39
40        @Override
41        public Param getParam(String id) {
42                Integer i = Numbers.parse(id, Integer.class);
43                if (i != null) {
44                        return getParam(i);
45                }
46                return new ParamBuilder().setId(id).setName(elementAccess.getId()).setType("o " + elementAccess.getId()).build();
47        }
48
49        @Override
50        public String getId() {
51                return "l " + elementAccess.getId() + " " + uidName;
52        }
53
54        @Override
55        public int getParamCount() {
56                return map.size();
57        }
58
59        @Override
60        public <T> T get(int i, Class<T> type) {
61                log.error("accesing unique list through index");
62                assert false;
63                return null;
64                //Object[] values = map.values().toArray();
65                //return Casting.tryCast(i < values.length ? values[i] : null, type);
66        }
67
68        @Override
69        public <T> T get(String id, Class<T> type) {
70                Integer i = Numbers.parse(id, Integer.class);
71                if (i != null) {
72                        return get(i, type);
73                }
74                return Casting.tryCast(type, map.containsKey(id) ? map.get(id) : null);
75        }
76
77        @Override
78        public <T> T get(ValueParam param, Class<T> type) {
79                return get(param.getId(), type);
80        }
81
82        public String getUidOf(Object value) {
83                Object tmp = elementAccess.getSelected();
84                elementAccess.select(value);
85                String uid = elementAccess.get(uidName, String.class);
86                elementAccess.select(tmp);
87                if (uid == null) {
88                        return null;
89                }
90                return uid;
91        }
92
93        protected int setByUid(Object object, String uid) {
94                if (uid == null) {
95                        uid = getUidOf(object);
96                        if (uid == null) {
97                                log.error("failed to set - missing uid");
98                                return 0;
99                        }
100                }
101                if (object == null) {
102                        map.remove(uid);
103                } else {
104                        map.put(uid, object);
105                }
106                return 0;
107        }
108
109        @Override
110        public <T> int set(int i, T value) {
111                log.error("accesing unique list through index");
112                //return setByUid(value, null);
113                return 0;
114        }
115
116        @Override
117        public <T> int set(String id, T value) {
118                Integer i = Numbers.parse(id, Integer.class);
119                if (i != null) {
120                        return set(i, value);
121                }
122                if (value == null) {
123                        return setByUid(null, id);
124                }
125                String uid = getUidOf(value);
126                if (uid != null && id != null) {
127                        if (!id.equals(uid)) {
128                                log.error("uid mismatch with set key");
129                                return 0;
130                        }
131                        setByUid(value, uid);
132                        return 0;
133                }
134                if (uid != null) {
135                        setByUid(value, uid);
136                        return 0;
137                }
138                if (id != null) {
139                        setByUid(value, id);
140                        return 0;
141                }
142                log.error("missing both uid and id - failed to set");
143                return 0;
144        }
145
146        @Override
147        public <T> int set(ValueParam param, T value) {
148                return set(param.getId(), value);
149        }
150
151        @Override
152        public void clearValues() {
153                map.clear();
154        }
155
156        @SuppressWarnings("unchecked")
157        @Override
158        public UniqueListAccess select(Object object) {
159                assert (object instanceof Map);
160                map = (Map<String, Object>) object;
161                return this;
162        }
163
164        @Override
165        public Object getSelected() {
166                return map;
167        }
168
169        @Override
170        public UniqueListAccess cloneAccess() {
171                return new UniqueListAccess(elementAccess.cloneAccess(), uidName);
172        }
173
174        @Override
175        public String computeIdentifierFor(Object selected) {
176                String uid = getUidOf(selected);
177                if (uid == null) {
178                        log.error("missing uid field");
179                        return null;
180                }
181                return uid;
182        }
183
184        @Override
185        public Collection<Param> getParams() {
186                List<Param> result = new LinkedList<Param>();
187                if (map == null) {
188                        return result;
189                }
190                for (String k : map.keySet()) {
191                        result.add(getParam(k));
192                }
193                return result;
194        }
195}
Note: See TracBrowser for help on using the repository browser.