source: java/main/src/main/java/com/framsticks/params/FramsClass.java @ 99

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

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File size: 5.0 KB
Line 
1package com.framsticks.params;
2
3import com.framsticks.params.annotations.FramsClassAnnotation;
4import com.framsticks.params.annotations.ParamAnnotation;
5import com.framsticks.util.FramsticksException;
6import com.framsticks.util.lang.Containers;
7import com.framsticks.util.lang.Strings;
8// import com.framsticks.util.FramsticksException;
9
10import java.util.*;
11
12import javax.annotation.Nonnull;
13import javax.annotation.concurrent.Immutable;
14
15import org.apache.log4j.Logger;
16
17/**
18 * The class FramsClass represents the class / schema of connected parameters
19 * (such as parameters within the class). It differs from C++ version by storing
20 * information about the class that parameters belong to.
21 *
22 * Based loosely on c++ class Param located in cpp/gdk/param.*
23 *
24 * @author Jarek Szymczak <name.surname@gmail.com>, Mateusz Jarus (please
25 *         replace name and surname with my personal data)
26 *
27 * @author Piotr Sniegowski
28 */
29@Immutable
30@FramsClassAnnotation(id = "class", name = "class")
31public class FramsClass {
32
33        private final static Logger log = Logger.getLogger(FramsClass.class);
34
35        protected final String id;
36
37        protected final String name;
38
39        protected final String description;
40
41        protected final List<Group> groups;
42
43        /** The param list (for accessing parameters by offset in O(1) time. */
44        protected final List<Param> paramList;
45
46        protected final List<CompositeParam> compositeParamList = new ArrayList<>();
47
48        /**
49         * The param entry map <parameterId, param> (for fast accessing of parameters
50         * by their name)
51         */
52        protected Map<String, Param> paramEntryMap = new HashMap<>();
53
54
55        @ParamAnnotation(id = "props", name = "props")
56        public List<Param> getParamEntries() {
57                return Collections.unmodifiableList(paramList);
58        }
59
60        public FramsClass(FramsClassBuilder builder) {
61
62                this.id = builder.getId();
63                this.name = Strings.toStringEmptyProof(builder.getName(), this.id);
64                this.description = builder.getDescription();
65                this.groups = Containers.build(builder.groupBuilders);
66                this.paramList = builder.params;
67
68                for (Param param : paramList) {
69                        paramEntryMap.put(param.getId(), param);
70                        if (param instanceof CompositeParam) {
71                                compositeParamList.add((CompositeParam) param);
72                        }
73                }
74
75                log.trace("created framsclass " + this);
76
77        }
78
79        @ParamAnnotation(id = "desc")
80        public String getDescription() {
81                return description;
82        }
83
84        public int getGroupCount() {
85                return groups.size();
86        }
87
88        public Group getGroup(int groupNumber) {
89                return Containers.getFromList(groups, groupNumber, "group", this);
90        }
91
92        // /**
93        //  * Gets the group member.
94        //  *
95        //  * @param gi
96        //  *            the offset of group
97        //  * @param pi
98        //  *            the offset of member within a group
99        //  * @return the pi-th member of group gi
100        //  */
101        // public Param getGroupMember(int gi, int pi) {
102        //      if (gi < 0 || pi < 0 || gi >= groups.size()) {
103        //              return null;
104        //      }
105        //      Group group = groups.get(gi);
106        //      return (group != null ? group.getProperty(pi) : null);
107        // }
108
109        // /**
110        //  * Gets the group name.
111        //  *
112        //  * @param gi
113        //  *            the offset of group
114        //  * @return the group name
115        //  */
116        // public String getGroupName(int gi) {
117        //      if (gi < 0 || gi >= groups.size())
118        //              return null;
119        //      return groups.get(gi).name;
120        // }
121
122        @ParamAnnotation
123        public String getId() {
124                return id;
125        }
126
127        @ParamAnnotation
128        public String getName() {
129                return name;
130        }
131
132        public String getNiceName() {
133                return name != null ? name : id;
134        }
135
136        public @Nonnull <T extends Param> T castedParam(@Nonnull final Param param, @Nonnull final Class<T> type, Object name) {
137                if (param == null) {
138                        // return null;
139                        throw new FramsticksException().msg("param is missing").arg("name", name).arg("in", this);
140                }
141                if (!type.isInstance(param)) {
142                        // return null;
143                        throw new FramsticksException().msg("wrong type of param").arg("actual", param.getClass()).arg("requested", type).arg("in", this);
144                }
145                return type.cast(param);
146        }
147
148        /**
149         * Gets the param entry.
150         *
151         * @param i
152         *            the offset of parameter
153         * @return the param entry
154         */
155        public @Nonnull <T extends Param> T getParamEntry(final int i, @Nonnull final Class<T> type) {
156                return castedParam(getParam(i), type, i);
157        }
158
159        /**
160         * Gets the param entry.
161         *
162         * @param id
163         *            the getId of parameter
164         * @return the param entry
165         */
166        public @Nonnull <T extends Param> T getParamEntry(@Nonnull final String id, @Nonnull final Class<T> type) {
167                return castedParam(getParam(id), type, id);
168        }
169
170        public Param getParam(int i) {
171                if (i < 0 || i >= paramList.size()) {
172                        return null;
173                }
174                return paramList.get(i);
175        }
176
177        public Param getParam(String id) {
178                if (!paramEntryMap.containsKey(id)) {
179                        return null;
180                }
181                return paramEntryMap.get(id);
182        }
183
184        public int getParamCount() {
185                return paramList.size();
186        }
187
188        public final int getCompositeParamCount() {
189                return compositeParamList.size();
190        }
191
192        public final CompositeParam getCompositeParam(int i) {
193                return compositeParamList.get(i);
194        }
195
196        @Override
197        public String toString() {
198                return id + "(" + name + ")";
199        }
200
201        public static FramsClassBuilder build() {
202                return new FramsClassBuilder();
203        }
204
205}
Note: See TracBrowser for help on using the repository browser.