Changeset 98
- Timestamp:
- 07/08/13 23:04:56 (11 years ago)
- Location:
- java/main/src
- Files:
-
- 7 added
- 4 deleted
- 71 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r97 r98 176 176 177 177 private <C> void sendImplementation(Request request, Dispatcher<C> dispatcher, ClientSideResponseFuture callback) { 178 callback.setRequest(request); 178 179 179 180 if (getState().ordinal() > JoinableState.RUNNING.ordinal()) { -
java/main/src/main/java/com/framsticks/communication/ClientSideResponseFuture.java
r97 r98 11 11 } 12 12 13 protected Request request; 14 13 15 protected abstract void processOk(Response response); 14 16 … … 18 20 processOk(response); 19 21 } else { 20 handle(new FramsticksException().msg("invalid response").arg("comment", response.getComment()) );22 handle(new FramsticksException().msg("invalid response").arg("comment", response.getComment()).arg("request", request)); 21 23 } 22 24 } 23 25 26 /** 27 * @return the request 28 */ 29 public Request getRequest() { 30 return request; 31 } 32 33 /** 34 * @param request the request to set 35 */ 36 public void setRequest(Request request) { 37 this.request = request; 38 } 39 24 40 } -
java/main/src/main/java/com/framsticks/communication/Request.java
r96 r98 48 48 @Override 49 49 public String toString() { 50 return getCommand() + " request"; 50 // return getCommand(); 51 return "request " + stringRepresentation(); 51 52 } 52 53 -
java/main/src/main/java/com/framsticks/communication/RequestHandler.java
r97 r98 2 2 3 3 import com.framsticks.communication.queries.ApplicationRequest; 4 import com.framsticks.util.dispatching.ExceptionResultHandler; 4 5 5 6 /** 6 7 * @author Piotr Sniegowski 7 8 */ 8 public interface RequestHandler {9 public interface RequestHandler extends ExceptionResultHandler { 9 10 public void handle(ApplicationRequest request, ServerSideResponseFuture responseCallback); 10 11 } -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r97 r98 12 12 import java.net.Socket; 13 13 import com.framsticks.util.dispatching.RunAt; 14 import com.framsticks.util.dispatching.ThrowExceptionHandler;15 14 16 15 /** … … 21 20 private final static Logger log = Logger.getLogger(ServerSideManagedConnection.class); 22 21 23 RequestHandler requestHandler;22 protected final RequestHandler requestHandler; 24 23 25 24 public ServerSideManagedConnection(Socket socket, RequestHandler requestHandler) { … … 70 69 71 70 protected final void respond(final Response response, final Integer id) { 72 //TODO TEH: pass it the hosted tree 73 senderThread.dispatch(new RunAt<Connection>(ThrowExceptionHandler.getInstance()) { 71 senderThread.dispatch(new RunAt<Connection>(requestHandler) { 74 72 @Override 75 73 protected void runAt() { -
java/main/src/main/java/com/framsticks/communication/Subscription.java
r97 r98 73 73 74 74 public void dispatchCall(final List<File> files) { 75 //TODO TEH76 75 Dispatching.dispatchIfNotActive(dispatcher, new RunAt<C>(ThrowExceptionHandler.getInstance()) { 77 76 @Override -
java/main/src/main/java/com/framsticks/core/AbstractTree.java
r97 r98 1 1 package com.framsticks.core; 2 import java.util.HashSet;3 import java.util.Set;4 2 5 3 import javax.annotation.Nonnull; … … 10 8 import com.framsticks.params.CompositeParam; 11 9 import com.framsticks.params.FramsClass; 12 import com.framsticks.params.Param;13 10 import com.framsticks.params.ParamsPackage; 14 11 import com.framsticks.params.Registry; 15 12 import com.framsticks.params.annotations.AutoAppendAnnotation; 16 13 import com.framsticks.params.annotations.FramsClassAnnotation; 14 import com.framsticks.params.annotations.ParamAnnotation; 15 import com.framsticks.util.FramsticksException; 16 import com.framsticks.util.dispatching.AbstractJoinable; 17 import com.framsticks.util.dispatching.Dispatcher; 17 18 import com.framsticks.util.dispatching.Dispatching; 19 import com.framsticks.util.dispatching.ExceptionResultHandler; 20 import com.framsticks.util.dispatching.Joinable; 21 import com.framsticks.util.dispatching.JoinableDispatcher; 22 import com.framsticks.util.dispatching.JoinableParent; 23 import com.framsticks.util.dispatching.JoinableState; 18 24 import com.framsticks.util.dispatching.RunAt; 19 25 import com.framsticks.util.dispatching.Thread; … … 24 30 */ 25 31 @FramsClassAnnotation 26 public abstract class AbstractTree extends Thread<Tree> implements Tree{32 public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>, Tree, JoinableParent { 27 33 28 34 private static final Logger log = Logger.getLogger(Tree.class); 29 35 30 private Node root; 31 32 @Override 33 public void setRoot(Node node) { 34 root = node; 35 } 36 37 @Override 38 public @Nonnull Node getRoot() { 39 assert root != null; 36 private Node root = null; 37 private ExceptionResultHandler handler = ThrowExceptionHandler.getInstance(); 38 39 private JoinableDispatcher<Tree> dispatcher; 40 41 @Override 42 public void assignRootParam(CompositeParam param) { 43 if (root != null) { 44 throw new FramsticksException().msg("root has already specified type"); 45 } 46 root = new Node(this, param, null); 47 log.info("assigned root type: " + root); 48 } 49 50 @Override 51 public void assignRootObject(Object object) { 52 if (root == null) { 53 throw new FramsticksException().msg("root is has no type specified"); 54 } 55 if (root.getObject() != null) { 56 throw new FramsticksException().msg("root has already object assigned").arg("current", root.getObject()).arg("candidate", object); 57 } 58 root = new Node(this, root.getParam(), object); 59 log.info("assigned root object: " + root); 60 } 61 62 @Override 63 public @Nonnull Node getAssignedRoot() { 64 if (root == null) { 65 throw new FramsticksException().msg("root has no type specified yet"); 66 } 40 67 return root; 41 68 } … … 46 73 } 47 74 48 protected S et<TreeListener> listeners = new HashSet<TreeListener>();75 protected String name; 49 76 50 77 public AbstractTree() { 51 setName(" entity");78 setName("tree"); 52 79 } 53 80 … … 55 82 56 83 } 57 58 59 protected void fireRun(Exception e) {60 for (TreeListener l : this.listeners) {61 l.onRun(e);62 }63 }64 65 protected void fireStop(Exception e) {66 for (TreeListener l : this.listeners) {67 l.onStop(e);68 }69 }70 71 @Override72 public void addListener(final TreeListener listener) {73 assert Dispatching.isThreadSafe();74 Dispatching.dispatchIfNotActive(this, new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {75 @Override76 protected void runAt() {77 listeners.add(listener);78 }79 });80 }81 82 @Override83 public void removeListener(final TreeListener listener) {84 assert Dispatching.isThreadSafe();85 Dispatching.dispatchIfNotActive(this, new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {86 @Override87 protected void runAt() {88 listeners.remove(listener);89 }90 });91 }92 93 protected void fireListChange(Path path, ListChange change) {94 assert isActive();95 for (TreeListener l : this.listeners) {96 l.onListChange(path, change);97 }98 }99 100 @Override101 public void notifyOfFetch(Path path) {102 fireFetch(path);103 }104 105 protected void fireFetch(Path path) {106 assert isActive();107 for (TreeListener l : this.listeners) {108 l.onFetch(path);109 }110 }111 112 84 113 85 @Override … … 142 114 } 143 115 144 @Override145 protected void joinableStart() {146 dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {147 @Override148 protected void runAt() {149 if (!isRootAssigned()) {150 setRoot(new Node(Param.build().name("Tree").id(getName()).type("o").finish(CompositeParam.class), null));151 }152 }153 });154 super.joinableStart();155 }156 116 157 117 @Override … … 159 119 registry.putFramsClass(framclass); 160 120 } 121 122 123 /** 124 * @return the handler 125 */ 126 @Override 127 public ExceptionResultHandler getExceptionHandler() { 128 return handler; 129 } 130 131 /** 132 * @param handler the handler to set 133 */ 134 @Override 135 public void setExceptionHandler(ExceptionResultHandler handler) { 136 this.handler = handler; 137 } 138 139 @Override 140 public void handle(FramsticksException exception) { 141 handler.handle(exception); 142 } 143 144 /** 145 * @return the dispatcher 146 */ 147 @Override 148 public JoinableDispatcher<Tree> getDispatcher() { 149 return dispatcher; 150 } 151 152 /** 153 * @param dispatcher the dispatcher to set 154 */ 155 @Override 156 public void setDispatcher(JoinableDispatcher<Tree> dispatcher) { 157 if (this.dispatcher != null) { 158 throw new FramsticksException().msg("dispatcher is already set").arg("tree", this).arg("dispatcher", dispatcher); 159 } 160 this.dispatcher = dispatcher; 161 } 162 163 /** 164 * @return the name 165 */ 166 @ParamAnnotation 167 public String getName() { 168 return name; 169 } 170 171 /** 172 * @param name the name to set 173 */ 174 @ParamAnnotation 175 public void setName(String name) { 176 this.name = name; 177 } 178 179 @Override 180 protected void joinableStart() { 181 if (dispatcher == null) { 182 dispatcher = new Thread<Tree>(); 183 } 184 Dispatching.use(dispatcher, this); 185 } 186 187 @Override 188 protected void joinableInterrupt() { 189 Dispatching.drop(dispatcher, this); 190 } 191 192 @Override 193 protected void joinableFinish() { 194 195 } 196 197 @Override 198 protected void joinableJoin() throws InterruptedException { 199 Dispatching.join(dispatcher); 200 } 201 202 @Override 203 public void childChangedState(Joinable joinable, JoinableState state) { 204 if (joinable == dispatcher) { 205 proceedToState(state); 206 } 207 } 208 209 @Override 210 public boolean isActive() { 211 if (dispatcher == null) { 212 throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this); 213 } 214 return dispatcher.isActive(); 215 } 216 217 @Override 218 public void dispatch(RunAt<? extends Tree> runnable) { 219 if (dispatcher == null) { 220 throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this); 221 } 222 dispatcher.dispatch(runnable); 223 } 224 161 225 } 162 226 -
java/main/src/main/java/com/framsticks/core/Node.java
r90 r98 5 5 6 6 import com.framsticks.params.CompositeParam; 7 import com.framsticks.params.ParamBuilder; 7 import com.framsticks.util.FramsticksException; 8 // import com.framsticks.params.ParamBuilder; 9 import com.framsticks.util.lang.Strings; 8 10 9 11 /** … … 13 15 public class Node { 14 16 17 protected final Tree tree; 15 18 protected final CompositeParam param; 16 19 protected final Object object; 17 //protected final Map<String, Node> children = new HashMap<String, Node>();18 20 19 public Node() { 20 param = null; 21 object = null; 22 } 23 24 public Node(@Nonnull CompositeParam param, Object object) { 21 public Node(Tree tree, @Nonnull CompositeParam param, Object object) { 25 22 assert param != null; 23 assert tree != null; 24 this.tree = tree; 26 25 this.param = param; 27 26 this.object = object; 28 27 } 29 28 30 public Node(@Nonnull ParamBuilder builder, Object object) { 31 this(builder.finish(CompositeParam.class), object); 29 30 public final Tree getTree() { 31 return tree; 32 32 } 33 33 … … 40 40 } 41 41 42 @Override 43 public String toString() { 44 return param.toString() + ":" + Strings.toStringNullProof(object, "<null>"); 45 } 46 47 public final boolean isResolved() { 48 return object != null; 49 } 50 51 public Node assureResolved() { 52 if (!isResolved()) { 53 throw new FramsticksException().msg("path is not resolved").arg("node", this); 54 } 55 return this; 56 } 57 42 58 } -
java/main/src/main/java/com/framsticks/core/ObjectTree.java
r97 r98 8 8 import com.framsticks.params.Param; 9 9 import com.framsticks.params.PrimitiveParam; 10 import com.framsticks.params.ValueParam; 10 11 import com.framsticks.params.annotations.AutoAppendAnnotation; 11 12 import com.framsticks.params.annotations.FramsClassAnnotation; 12 import com.framsticks.util.UnsupportedOperationException;13 13 import com.framsticks.params.types.ProcedureParam; 14 14 import com.framsticks.util.FramsticksException; 15 15 import com.framsticks.util.dispatching.Future; 16 16 17 import static com.framsticks.core.TreeOperations.*; 17 18 … … 24 25 registry.registerAndBuild(object.getClass()); 25 26 AccessInterface access = registry.createAccess(object.getClass()); 26 setRoot(new Node(Param.build().forAccess(access).id(getName()).finish(CompositeParam.class), object)); 27 assignRootParam(Param.build().forAccess(access).id(getName()).finish(CompositeParam.class)); 28 assignRootObject(object); 27 29 } 28 30 29 31 public Object getRootObject() { 30 return get Root().getObject();32 return getAssignedRoot().getObject(); 31 33 } 32 34 … … 43 45 44 46 @Override 45 public void get( final Path path, Mode mode, Future<Object> future) {47 public void get(Path path, Mode mode, Future<Path> future) { 46 48 assert isActive(); 47 49 log.debug("requesting: " + path); 48 fireFetch(path);49 future.pass(path .getTopObject());50 path = resolveTopSync(path); 51 future.pass(path); 50 52 } 51 53 52 54 @Override 53 public void get(Path path, PrimitiveParam<?>param, Mode mode, Future<Object> future) {55 public void get(Path path, ValueParam param, Mode mode, Future<Object> future) { 54 56 assert isActive(); 55 fireFetch(path);57 path = resolveTopSync(path); 56 58 future.pass(bindAccess(path).get(param, Object.class)); 57 59 } … … 80 82 } 81 83 82 @Override 83 public void resolve(Path path, Future<Path> future) { 84 protected Path resolveTopSync(Path path) { 84 85 assert isActive(); 85 86 assert path.isOwner(this); 86 87 if (path.getTop().getObject() != null) { 87 future.pass(path); 88 return; 88 return path; 89 89 } 90 AccessInterface access = bindAccess( this,path.getUnder());90 AccessInterface access = bindAccess(path.getUnder()); 91 91 Object object = access.get(path.getTop().getParam(), Object.class); 92 92 if (object == null) { 93 future.pass(path); 94 return; 93 return path; 95 94 } 96 future.pass(path.appendResolution(object));95 return path.appendResolution(object); 97 96 } 97 98 98 99 99 @Override … … 103 103 } 104 104 105 @Override106 public Path create(Path path) {107 assert isActive();108 assert !path.isResolved();109 throw new UnsupportedOperationException();110 }111 112 105 } -
java/main/src/main/java/com/framsticks/core/Path.java
r97 r98 58 58 public Path appendParam(CompositeParam param) { 59 59 assert isResolved(); 60 return appendNode(new Node( param, null));60 return appendNode(new Node(tree, param, null)); 61 61 } 62 62 … … 99 99 public PathBuilder setLast(Object object) { 100 100 Node n = nodes.pollLast(); 101 nodes.add(new Node(n.get Param(), object));101 nodes.add(new Node(n.getTree(), n.getParam(), object)); 102 102 return this; 103 103 } … … 130 130 } 131 131 132 132 133 public PathBuilder resolve(@Nonnull Tree tree, String textual) { 133 134 … … 136 137 this.tree = tree; 137 138 138 nodes.add(tree.getRoot());139 Node current = tree.getRoot();139 Node current = tree.getAssignedRoot(); 140 nodes.add(current); 140 141 141 142 StringBuilder b = new StringBuilder(); 142 143 Iterator<String> i = splitPath(textual); 143 144 while (i.hasNext() && current.getObject() != null) { 144 AccessInterface access = tree.prepareAccess(current.getParam()); 145 if (access == null) { 146 break; 147 } 145 AccessInterface access = TreeOperations.bindAccess(current);// tree.prepareAccess(current.getParam()); 148 146 String e = i.next(); 149 147 Param p = access.getParam(e); … … 155 153 b.append("/").append(e); 156 154 access.select(current.getObject()); 157 current = new Node(c , getKnownChild(tree, access, c));155 current = new Node(current.getTree(), c, getKnownChild(tree, access, c)); 158 156 nodes.add(current); 159 157 } … … 218 216 assert Dispatching.isThreadSafe(); 219 217 return this.textual.equals(textual); 218 } 219 220 public final boolean isTheSameTextually(Path path) { 221 assert Dispatching.isThreadSafe(); 222 return (tree == path.getTree()) && textual.equals(path.getTextual()); 220 223 } 221 224 … … 242 245 return Path.build().resolve(tree, "/").finish(); 243 246 } 244 Object child = getKnownChild(tree, TreeOperations.bindAccess( tree,getUnder()), getTop().getParam());247 Object child = getKnownChild(tree, TreeOperations.bindAccess(getUnder()), getTop().getParam()); 245 248 if (child == null) { 246 249 return this; … … 249 252 } 250 253 251 public boolean matches(Path p) {252 assert Dispatching.isThreadSafe();253 assert tree == p.tree;254 Iterator<Node> a = nodes.iterator();255 Iterator<Node> b = p.nodes.iterator();256 while (a.hasNext() && b.hasNext()) {257 Node an = a.next();258 Node bn = b.next();259 if (an.object != bn.object) {260 return false;261 }262 }263 return a.hasNext() == b.hasNext();264 }265 254 266 255 public String getLastElement() { … … 278 267 } 279 268 280 public voidassureResolved() {269 public Path assureResolved() { 281 270 if (!isResolved()) { 282 271 throw new FramsticksException().msg("path is not resolved").arg("path", this); 283 272 } 273 return this; 284 274 } 285 275 … … 287 277 return Path.build().resolve(tree, textual).finish(); 288 278 } 279 280 public boolean isTheSameObjects(Path path) { 281 if (tree != path.getTree()) { 282 return false; 283 } 284 if (size() != path.size()) { 285 return false; 286 } 287 if (!getTextual().equals(path.getTextual())) { 288 return false; 289 } 290 Iterator<Node> a = nodes.iterator(); 291 Iterator<Node> b = path.getNodes().iterator(); 292 while (a.hasNext()) { 293 assert b.hasNext(); 294 if (a.next() != b.next()) { 295 return false; 296 } 297 } 298 return true; 299 } 300 301 302 // public boolean isEmpty() { 303 // return nodes.isEmpty(); 304 // } 289 305 } 290 306 -
java/main/src/main/java/com/framsticks/core/Tree.java
r97 r98 8 8 import com.framsticks.params.PrimitiveParam; 9 9 import com.framsticks.params.Registry; 10 import com.framsticks.params.ValueParam; 10 11 import com.framsticks.params.types.ProcedureParam; 11 12 import com.framsticks.util.dispatching.Dispatcher; 13 import com.framsticks.util.dispatching.ExceptionResultHandler; 12 14 import com.framsticks.util.dispatching.Future; 13 15 import com.framsticks.util.dispatching.Joinable; 16 import com.framsticks.util.dispatching.JoinableDispatcher; 14 17 15 public interface Tree extends Dispatcher<Tree>, Joinable {18 public interface Tree extends Dispatcher<Tree>, Joinable, ExceptionResultHandler { 16 19 17 public @Nonnull Node getRoot(); 18 public @Nonnull void setRoot(Node node); 20 public @Nonnull Node getAssignedRoot(); 21 public void assignRootParam(CompositeParam param); 22 public void assignRootObject(Object object); 19 23 20 24 public @Nonnull AccessInterface prepareAccess(CompositeParam param); 21 25 public void takeAllFrom(Registry source); 22 23 public void addListener(TreeListener listener);24 public void removeListener(TreeListener listener);25 26 public void notifyOfFetch(Path path);27 26 28 27 public FramsClass getInfoFromCache(String id); … … 30 29 public void putInfoIntoCache(FramsClass framclass); 31 30 32 public void resolve(Path path, Future<Path> future); 31 /** 32 * 33 * Functions accepts ValueParam, because it is also possible to get number of List elements. 34 * 35 */ 36 public void get(Path path, ValueParam param, Mode mode, Future<Object> future); 33 37 34 public void get(Path path, PrimitiveParam<?> param, Mode mode, Future<Object> future); 35 36 public void get(Path path, Mode mode, Future<Object> future); 38 public void get(Path path, Mode mode, Future<Path> future); 37 39 38 40 public void call(Path path, ProcedureParam param, Object[] arguments, Future<Object> future); 39 41 42 /** 43 * 44 * Functions accepts PrimitiveParam<?>, because it is not possible to set number of List elements. 45 * 46 */ 40 47 public void set(Path path, PrimitiveParam<?> param, Object value, Future<Integer> future); 41 48 42 49 public void info(Path path, Future<FramsClass> future); 43 50 44 public Path create(Path path); 51 public void setExceptionHandler(ExceptionResultHandler handler); 52 53 public ExceptionResultHandler getExceptionHandler(); 54 55 public void setDispatcher(JoinableDispatcher<Tree> dispatcher); 56 57 public JoinableDispatcher<Tree> getDispatcher(); 58 45 59 } -
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r97 r98 1 1 package com.framsticks.core; 2 2 3 3 4 import java.util.List; … … 14 15 import com.framsticks.params.Param; 15 16 import com.framsticks.params.PrimitiveParam; 16 import com.framsticks.params.ValueParam;17 17 import com.framsticks.params.types.ObjectParam; 18 18 import com.framsticks.params.types.ProcedureParam; … … 28 28 public final class TreeOperations { 29 29 30 private static final Logger log = Logger.getLogger(TreeOperations.class .getName());30 private static final Logger log = Logger.getLogger(TreeOperations.class); 31 31 32 32 private TreeOperations() { … … 36 36 assert tree.isActive(); 37 37 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); 38 if ("/".equals(file.getPath())) { 39 if (tree.getRoot().getParam().getContainedTypeName() == null) { 40 tree.setRoot(new Node(Param.build().name("Tree").id(tree.getName()).type("o " + framsClass.getId()).finish(CompositeParam.class), tree.getRoot().getObject())); 41 } 42 } 38 log.debug("process fetched info for " + tree + ": " + framsClass); 43 39 tree.putInfoIntoCache(framsClass); 44 40 return framsClass; 45 41 } 46 42 43 public static void processFetchedValues(Path path, List<File> files) { 44 Tree tree = path.getTree(); 45 assert tree.isActive(); 46 assert files.size() == 1; 47 assert path.isTheSame(files.get(0).getPath()); 48 49 if (!path.isResolved()) { 50 AccessInterface access = tree.prepareAccess(path.getTop().getParam()); 51 Object child = access.createAccessee(); 52 assert child != null; 53 if (path.size() == 1) { 54 tree.assignRootObject(child); 55 } else { 56 bindAccess(path.getUnder()).set(path.getTop().getParam(), child); 57 } 58 path = path.appendResolution(child); 59 } 60 61 log.debug("process fetched values: " + path); 62 Node node = path.getTop(); 63 MultiParamLoader loader = new MultiParamLoader(); 64 loader.setNewSource(files.get(0).getContent()); 65 loader.addBreakCondition(MultiParamLoader.Status.AfterObject); 66 67 try { 68 if (node.getParam() instanceof ObjectParam) { 69 loader.addAccessInterface(bindAccess(node)); 70 loader.go(); 71 return; 72 } 73 74 ListAccess listAccess = (ListAccess) bindAccess(node); 75 listAccess.clearValues(); 76 77 AccessInterface elementAccess = listAccess.getElementAccess(); 78 loader.addAccessInterface(elementAccess); 79 MultiParamLoader.Status status; 80 while ((status = loader.go()) != MultiParamLoader.Status.Finished) { 81 if (status == MultiParamLoader.Status.AfterObject) { 82 AccessInterface accessInterface = loader.getLastAccessInterface(); 83 84 String id = listAccess.computeIdentifierFor(accessInterface.getSelected()); 85 //TODO listAccessParam 86 CompositeParam param = Param.build().forAccess(accessInterface).id(id).finish(CompositeParam.class); 87 Object child = accessInterface.getSelected(); 88 accessInterface.select(null); 89 assert child != null; 90 bindAccess(node).set(param, child); 91 } 92 } 93 94 } catch (FramsticksException e) { 95 throw new FramsticksException().msg("exception occurred while loading").cause(e); 96 } 97 } 98 47 99 public static FramsClass getInfo(Path path) { 48 100 Tree tree = path.getTree(); 49 101 assert tree.isActive(); 102 log.debug("get info for: " + path); 50 103 final String name = path.getTop().getParam().getContainedTypeName(); 51 104 return tree.getInfoFromCache(name); … … 53 106 54 107 public static void findInfo(final Path path, final Future<FramsClass> future) { 108 log.debug("find info for: " + path); 55 109 try { 56 110 Tree tree = path.getTree(); … … 67 121 } 68 122 69 public static void processFetchedValues(Path path, List<File> files) { 70 Tree tree = path.getTree(); 71 assert tree.isActive(); 72 assert files.size() == 1; 73 assert path.isTheSame(files.get(0).getPath()); 74 Node node = path.getTop(); 75 MultiParamLoader loader = new MultiParamLoader(); 76 loader.setNewSource(files.get(0).getContent()); 77 loader.addBreakCondition(MultiParamLoader.Status.AfterObject); 78 79 try { 80 if (node.getParam() instanceof ObjectParam) { 81 loader.addAccessInterface(TreeOperations.bindAccess(tree, node)); 82 loader.go(); 83 tree.notifyOfFetch(path); 84 return; 85 } 86 87 ListAccess listAccess = ((ListAccess) TreeOperations.bindAccess(tree, node)); 88 assert listAccess != null; 89 listAccess.clearValues(); 90 91 AccessInterface elementAccess = listAccess.getElementAccess(); 92 loader.addAccessInterface(elementAccess); 93 MultiParamLoader.Status status; 94 while ((status = loader.go()) != MultiParamLoader.Status.Finished) { 95 if (status == MultiParamLoader.Status.AfterObject) { 96 AccessInterface accessInterface = loader.getLastAccessInterface(); 97 98 String id = listAccess.computeIdentifierFor(accessInterface.getSelected()); 99 //TODO listAccessParam 100 Param param = Param.build().forAccess(accessInterface).id(id).finish(); 101 Object child = accessInterface.getSelected(); 102 accessInterface.select(null); 103 assert child != null; 104 TreeOperations.bindAccess(tree, node).set((ValueParam) param, child); 105 } 106 } 107 108 tree.notifyOfFetch(path); 109 } catch (Exception e) { 110 log.error("exception occurred while loading: " + e); 111 } 112 113 } 114 115 public static void resolveAndGet(final Tree tree, final String targetPath, final Future<Path> future) { 116 resolve(tree, targetPath, new FutureHandler<Path>(future) { 117 @Override 118 protected void result(final Path path) { 119 assert path.isResolved(targetPath); 120 //TODO Future 121 tree.get(path, Mode.FETCH, new FutureHandler<Object>(future) { 122 @Override 123 protected void result(Object object) { 124 future.pass(path); 125 } 126 }); 127 } 128 }); 129 } 130 131 132 public static void resolve(final Path path, final Future<Path> future) { 133 final Tree tree = path.getTree(); 134 assert tree.isActive(); 135 if (path.getTop().getObject() != null) { 136 if (getInfoFromCache(path) != null) { 137 future.pass(path); 138 return; 139 } 140 TreeOperations.findInfo(path, new FutureHandler<FramsClass>(future) { 141 @Override 142 protected void result(FramsClass result) { 143 future.pass(path); 144 } 145 }); 146 return; 147 } 148 TreeOperations.findInfo(path, new FutureHandler<FramsClass>(future) { 149 @Override 150 protected void result(FramsClass result) { 151 assert tree.isActive(); 152 assert path.getTop().getParam().isMatchingContainedName(result.getId()); 153 Path p = (path.getTop().getParam().getContainedTypeName() != null ? path : path.tryFindResolution()); 154 future.pass(TreeOperations.createIfNeeded(p)); 155 } 156 }); 157 } 158 159 public static Path createIfNeeded(Tree tree, String path) { 160 assert tree.isActive(); 161 Path p; 162 while (!(p = Path.to(tree, path)).isResolved(path)) { 163 tree.create(p); 164 } 165 return p; 166 } 167 168 public static Path createIfNeeded(Path path) { 169 Tree tree = path.getTree(); 170 assert tree.isActive(); 171 if (path.isResolved()) { 172 return path; 173 } 174 return tree.create(path); 175 } 123 176 124 177 125 public static @Nonnull AccessInterface bindAccess(Tree tree, String path) { 126 log.debug("bind access for textual: " + path + " in " + tree); 178 127 return bindAccess(Path.to(tree, path)); 179 128 } 180 129 181 public static @Nonnull AccessInterface bindAccess(Tree tree, Node node) { 130 public static @Nonnull AccessInterface bindAccess(Node node) { 131 Tree tree = node.getTree(); 182 132 assert tree.isActive(); 183 133 assert node.getObject() != null; … … 194 144 assert path.getTree().isActive(); 195 145 path.assureResolved(); 196 return bindAccess(path.getTree(), path.getTop()); 146 log.debug("bind access for: " + path); 147 return bindAccess(path.getTop()); 197 148 } 198 149 … … 219 170 } 220 171 172 221 173 /** This might not be correct. */ 222 public static void resolve(final Tree tree, final String targetPath, final Future<Path> future) { 174 public static void tryGet(final Tree tree, final String targetPath, final Future<Path> future) { 175 log.debug("resolve textual: " + targetPath + " for " + tree); 223 176 dispatchIfNotActive(tree, new RunAt<Tree>(future) { 224 177 225 178 @Override 226 179 protected void runAt() { 227 tree.resolve(Path.to(tree, targetPath), new FutureHandler<Path>(future) { 180 final Path path = Path.to(tree, targetPath); 181 if (path.isResolved()) { 182 future.pass(path); 183 return; 184 } 185 186 tree.get(path, Mode.FETCH, new FutureHandler<Path>(future) { 228 187 @Override 229 188 protected void result(Path result) { 230 assert result.getTree().isActive(); 231 if (result.isResolved(targetPath)) { 232 future.pass(result); 233 return; 234 } 235 resolve(tree, targetPath, future); 189 tryGet(tree, targetPath, future); 236 190 } 237 191 }); -
java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java
r97 r98 1 1 package com.framsticks.diagnostics; 2 2 3 import java.util.Date;4 import java.io.File;5 import java.io.FileOutputStream;6 import java.io.IOException;7 import java.io.OutputStreamWriter;8 import java.io.PrintWriter;9 import java.text.SimpleDateFormat;10 3 11 import org.apache.log4j.Logger;12 13 import com.framsticks.core.AbstractTreeListener;14 4 import com.framsticks.core.Tree; 15 import com.framsticks.core.Path;16 import com.framsticks.dumping.PrintWriterSink;17 import com.framsticks.dumping.SaveStream;18 5 import com.framsticks.params.annotations.AutoAppendAnnotation; 19 import com.framsticks.remote.RecursiveFetcher;20 import com.framsticks.util.FramsticksException;21 import com.framsticks.util.PeriodicTask;22 import com.framsticks.util.dispatching.ExceptionResultHandler;23 import com.framsticks.util.dispatching.FutureHandler;24 6 import com.framsticks.util.dispatching.JoinableCollection; 25 import com.framsticks.util.dispatching.ThrowExceptionHandler;26 import com.framsticks.util.io.Encoding;27 7 28 8 /** … … 30 10 */ 31 11 public class Diagnostics extends JoinableCollection<Tree> { 32 private static final Logger log = Logger.getLogger(Diagnostics.class);33 12 34 13 … … 48 27 super.add(tree); 49 28 50 tree.addListener(new AbstractTreeListener() {51 @Override52 public void onRun(Exception e) {53 if (e != null) {54 return;55 }29 // tree.addListener(new AbstractTreeListener() { 30 // @Override 31 // public void onRun(Exception e) { 32 // if (e != null) { 33 // return; 34 // } 56 35 57 if (dumpsInterval != null) {58 new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), tree, dumpsInterval * 1000) {59 protected final ExceptionResultHandler repeater = new ExceptionResultHandler() {36 // if (dumpsInterval != null) { 37 // new PeriodicTask<Tree>(ThrowExceptionHandler.getInstance(), tree, dumpsInterval * 1000) { 38 // protected final ExceptionResultHandler repeater = new ExceptionResultHandler() { 60 39 61 @Override62 public void handle(FramsticksException exception) {63 log.error("caught error during diagnostics fetching (repeating): " + exception);64 again();65 }40 // @Override 41 // public void handle(FramsticksException exception) { 42 // log.error("caught error during diagnostics fetching (repeating): " + exception); 43 // again(); 44 // } 66 45 67 };68 @Override69 protected void runAt() {46 // }; 47 // @Override 48 // protected void runAt() { 70 49 71 log.info("starting periodic dump");72 new RecursiveFetcher(tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) {50 // log.info("starting periodic dump"); 51 // new RecursiveFetcher(tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 73 52 74 @Override75 protected void result(Void result) {76 log.info("tree resolved, saving");77 try {78 final String fileName = dumpsPath + "/" + tree + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param";79 File file = new File(fileName);80 new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) {53 // @Override 54 // protected void result(Void result) { 55 // log.info("tree resolved, saving"); 56 // try { 57 // final String fileName = dumpsPath + "/" + tree + "_" + new SimpleDateFormat(dumpsFormat).format(new Date()) + ".param"; 58 // File file = new File(fileName); 59 // new SaveStream(new PrintWriterSink(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Encoding.getFramsticksCharset()))), tree, Path.to(tree, "/"), new FutureHandler<Void>(repeater) { 81 60 82 @Override83 protected void result(Void result) {84 again();85 }86 });87 } catch (IOException e) {88 throw new FramsticksException().msg("failed to initiate dump").cause(e);89 }90 }91 });92 }93 };94 }95 }96 });61 // @Override 62 // protected void result(Void result) { 63 // again(); 64 // } 65 // }); 66 // } catch (IOException e) { 67 // throw new FramsticksException().msg("failed to initiate dump").cause(e); 68 // } 69 // } 70 // }); 71 // } 72 // }; 73 // } 74 // } 75 // }); 97 76 98 77 -
java/main/src/main/java/com/framsticks/dumping/LoadStream.java
r97 r98 59 59 if (line.equals("ok")) { 60 60 if (query.first.equals("get")) { 61 Path path = TreeOperations.createIfNeeded(tree, query.second); 62 TreeOperations.processFetchedValues(path, files); 61 // Path path = null; 62 throw new UnimplementedException().msg("rework load stream"); 63 // Path path = TreeOperations.createIfNeeded(tree, query.second); 64 // TreeOperations.processFetchedValues(path, files); 63 65 } else if (query.first.equals("info")) { 64 66 assert files.size() == 1; -
java/main/src/main/java/com/framsticks/dumping/SaveStream.java
r97 r98 14 14 import com.framsticks.util.dispatching.Dispatching; 15 15 import com.framsticks.util.dispatching.Future; 16 import com.framsticks.util.dispatching.ThrowExceptionHandler;17 16 18 17 import org.apache.log4j.Logger; … … 48 47 protected void dispatchWrite(final Path path) { 49 48 ++dispatched; 50 //TODO TEH 51 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 49 tree.dispatch(new RunAt<Tree>(tree) { 52 50 @Override 53 51 protected void runAt() { … … 89 87 } 90 88 for (CompositeParam p : filterInstanceof(access.getParams(), CompositeParam.class)) { 91 final Path childPath = path.appendNode(new Node(p , access.get(p, Object.class)));89 final Path childPath = path.appendNode(new Node(path.getTree(), p, access.get(p, Object.class))); 92 90 if (childPath.isResolved() && getInfoFromCache(childPath) != null) { 93 91 dispatchWrite(childPath); -
java/main/src/main/java/com/framsticks/gui/Browser.java
r97 r98 14 14 import com.framsticks.util.dispatching.ExceptionResultHandler; 15 15 import com.framsticks.util.dispatching.Future; 16 import com.framsticks.util.dispatching.FutureHandler;17 16 import com.framsticks.util.dispatching.Joinable; 18 17 import com.framsticks.util.dispatching.JoinableCollection; … … 46 45 47 46 protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>(); 47 // protected final SwingDispatcher 48 48 49 49 protected final MainFrame mainFrame; … … 63 63 64 64 mainFrame = new MainFrame(Browser.this); 65 66 // mainFrame.getStatusBar().setExceptionHandler(ThrowExceptionHandler.getInstance()); 67 65 68 addFrame(mainFrame); 66 69 … … 120 123 public void addTree(Tree tree) { 121 124 log.info("adding tree: " + tree); 125 tree.setDispatcher(new SwingDispatcher<Tree>()); 122 126 trees.add(tree); 123 127 } 124 128 125 129 public void autoResolvePath(final String path, final Future<Path> future) { 126 final Tree i = trees.get("localhost");127 i.dispatch(new RunAt<Tree>(future) {128 @Override129 protected void runAt() {130 TreeOperations.resolveAndGet(i, path, new FutureHandler<Path>(future) {131 @Override132 protected void result(final Path p) {133 future.pass(p);134 mainFrame.dispatch(new RunAt<Frame>(future) {135 @Override136 protected void runAt() {137 mainFrame.goTo(p);138 }139 });140 }141 });142 }143 });130 // final Tree i = trees.get("localhost"); 131 // i.dispatch(new RunAt<Tree>(future) { 132 // @Override 133 // protected void runAt() { 134 // TreeOperations.tryGet(i, path, new FutureHandler<Path>(future) { 135 // @Override 136 // protected void result(final Path p) { 137 // future.pass(p); 138 // mainFrame.dispatch(new RunAt<Frame>(future) { 139 // @Override 140 // protected void runAt() { 141 // mainFrame.goTo(p); 142 // } 143 // }); 144 // } 145 // }); 146 // } 147 // }); 144 148 } 145 149 … … 284 288 } 285 289 286 // @Override 287 // public boolean isDone() { 288 // return frames.isDone() && trees.isDone(); 290 // final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>(); 291 // public boolean hasSubscribed(EventParam param) { 292 // assert frame.isActive(); 293 // return userSubscriptions.containsKey(param); 289 294 // } 295 296 // public void unsubscribe(EventParam eventParam) { 297 // assert frame.isActive(); 298 // if (!hasSubscribed(eventParam)) { 299 // log.error("could not unsubscribe from " + eventParam); 300 // return; 301 // } 302 // userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam)); 303 // userSubscriptions.remove(eventParam); 304 // } 305 306 307 308 290 309 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r97 r98 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.util. HashMap;13 import java.util.IdentityHashMap; 14 14 import java.util.Map; 15 15 … … 28 28 import javax.swing.ToolTipManager; 29 29 import javax.swing.UIManager; 30 import javax.swing.event.Tree ModelEvent;31 import javax.swing.event.Tree ModelListener;30 import javax.swing.event.TreeExpansionEvent; 31 import javax.swing.event.TreeExpansionListener; 32 32 import javax.swing.event.TreeSelectionEvent; 33 33 import javax.swing.event.TreeSelectionListener; 34 import javax.swing.tree.DefaultMutableTreeNode;35 import javax.swing.tree.DefaultTreeModel;36 34 import javax.swing.tree.DefaultTreeSelectionModel; 37 35 import javax.swing.tree.TreePath; … … 40 38 import org.apache.log4j.Logger; 41 39 40 import com.framsticks.core.Mode; 42 41 import com.framsticks.core.Path; 43 42 import com.framsticks.core.Tree; 43 import com.framsticks.core.TreeOperations; 44 44 import com.framsticks.gui.view.TreeCellRenderer; 45 import com.framsticks. util.FramsticksException;45 import com.framsticks.params.AccessInterface; 46 46 import com.framsticks.util.dispatching.Dispatching; 47 import com.framsticks.util.dispatching. ExceptionResultHandler;47 import com.framsticks.util.dispatching.FutureHandler; 48 48 import com.framsticks.util.dispatching.Joinable; 49 49 import com.framsticks.util.dispatching.JoinableCollection; 50 50 import com.framsticks.util.dispatching.JoinableParent; 51 51 import com.framsticks.util.dispatching.JoinableState; 52 import com.framsticks.util.dispatching.RunAt;53 import com.framsticks.util.lang.ScopeEnd;54 52 import com.framsticks.util.swing.KeyboardModifier; 55 53 import com.framsticks.util.swing.MenuConstructor; … … 72 70 protected JScrollPane treeScrollPane; 73 71 protected JTree jtree; 74 protected DefaultTreeModel treeModel; 75 protected javax.swing.tree.MutableTreeNode rootNode; 72 protected TreeModel treeModel; 73 74 protected MetaNode rootNode; 75 76 76 protected JPanel treePanel; 77 77 protected JPopupMenu treePopupMenu; 78 78 protected JMenuItem treePopupMenuHeader; 79 79 80 TreeNode currentlyPoppedTreeNode;81 80 protected JPanel mainPanel; 82 81 protected JPanel leftPanel; … … 91 90 protected JMenu helpMenu; 92 91 93 protected final Map<Tree, TreeAtFrame> treeAtFrames = new HashMap<Tree, TreeAtFrame>();94 protected JoinableCollection<Tree> trees = new JoinableCollection< Tree>();92 protected final Map<Tree, TreeAtFrame> treeAtFrames = new IdentityHashMap<>(); 93 protected JoinableCollection<Tree> trees = new JoinableCollection<>(); 95 94 96 95 public Frame(Browser browser) { … … 106 105 log.debug("creating " + this); 107 106 108 109 107 Container contentPane = getSwing().getContentPane(); 110 108 treePopupMenu = new JPopupMenu("title"); … … 114 112 treePanel.setLayout(new BorderLayout()); 115 113 116 treeModel = new DefaultTreeModel(null); 117 treeModel.addTreeModelListener(new TreeModelListener() { 118 119 @Override 120 public void treeNodesChanged(TreeModelEvent arg0) { 121 log.trace("treeNodesChanged: " + arg0); 122 } 123 124 @Override 125 public void treeNodesInserted(TreeModelEvent arg0) { 126 // log.trace("treeNodesInserted: " + arg0); 127 } 128 129 @Override 130 public void treeNodesRemoved(TreeModelEvent arg0) { 131 log.trace("treeNodesRemoved: " + arg0); 132 } 133 134 @Override 135 public void treeStructureChanged(TreeModelEvent arg0) { 136 log.trace("treeStructureChanged: " + arg0); 137 } 138 }); 114 rootNode = new MetaNode(); 115 rootNode.setName("root"); 116 treeModel = new TreeModel(this); 139 117 140 118 jtree = new JTree(treeModel); … … 152 130 }); 153 131 132 jtree.addTreeExpansionListener(new TreeExpansionListener() { 133 134 @Override 135 public void treeCollapsed(TreeExpansionEvent e) { 136 137 } 138 139 @Override 140 public void treeExpanded(TreeExpansionEvent e) { 141 loadChildren(treeModel.convertToPath(e.getPath()), false); 142 } 143 }); 144 154 145 jtree.setExpandsSelectedPaths(true); 155 146 jtree.setEditable(false); 156 jtree.setDoubleBuffered(true);157 147 jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 158 148 jtree.setShowsRootHandles(true); … … 173 163 }); 174 164 175 new KeyboardModifier(jtree, JComponent.WHEN_FOCUSED).join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)).join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)).join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)).join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 165 new KeyboardModifier(jtree, JComponent.WHEN_FOCUSED) 166 .join(KeyStroke.getKeyStroke('h'), KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)) 167 .join(KeyStroke.getKeyStroke('j'), KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)) 168 .join(KeyStroke.getKeyStroke('k'), KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)) 169 .join(KeyStroke.getKeyStroke('l'), KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); 176 170 177 171 jtree.setCellRenderer(new TreeCellRenderer()); … … 182 176 treePanel.add(treeScrollPane); 183 177 184 rootNode = new DefaultMutableTreeNode();185 rootNode.setUserObject("root");186 treeModel.setRoot(rootNode);187 178 188 179 normalWorkPanel = new JPanel(); … … 248 239 }); 249 240 241 new MenuConstructor(fileMenu).add(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK), new AbstractAction("Reload current") { 242 @Override 243 public void actionPerformed(ActionEvent actionEvent) { 244 245 loadPath(treeModel.convertToPath(jtree.getSelectionPath()), true); 246 } 247 }); 248 250 249 } 251 250 … … 254 253 } 255 254 256 public void addRootPath( Path path) {255 public void addRootPath(final Path path) { 257 256 assert isActive(); 257 258 258 Tree tree = path.getTree(); 259 260 log.info("trying mount: " + path); 261 if (!tree.getAssignedRoot().isResolved()) { 262 tree.get(path, Mode.FETCH, new FutureHandler<Path>(this) { 263 264 @Override 265 protected void result(Path result) { 266 addRootPath(result); 267 } 268 }); 269 return; 270 } 271 259 272 assert browser.getTrees().contains(tree); 260 273 261 274 TreeAtFrame e = new TreeAtFrame(tree, this); 262 tree.addListener(e);263 275 treeAtFrames.put(tree, e); 264 TreeNode node = new TreeNode(e, path); 265 e.rootTreeNode = node; 266 treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount()); 267 jtree.expandPath(new TreePath(rootNode)); 276 277 rootNode.getChildren().add(new TreeNode(tree.getAssignedRoot())); 278 e.rootNode = tree.getAssignedRoot(); 279 treeModel.nodeStructureChanged(new TreePath(rootNode)); 280 // jtree.expandPath(new TreePath(rootNode)); 268 281 } 269 282 … … 275 288 } 276 289 290 277 291 private void showPopup(MouseEvent e) { 278 292 assert isActive(); … … 280 294 return; 281 295 } 282 currentlyPoppedTreeNode = findTreeNodeByTreePath(jtree.getPathForLocation(e.getX(), e.getY())); 283 if (currentlyPoppedTreeNode == null) { 284 return; 285 } 286 287 Path path = currentlyPoppedTreeNode.getTreePath(); 296 TreePath treePath = jtree.getPathForLocation(e.getX(), e.getY()); 297 298 Path path = treeModel.convertToPath(treePath); 288 299 treePopupMenu.removeAll(); 289 300 … … 291 302 provider.provide(treePopupMenu, path); 292 303 } 293 // treePopupMenuHeader.setText(path.getTree().getName() + path.getTextual());294 304 treePopupMenu.show(e.getComponent(), e.getX(), e.getY()); 295 //currentlyPoppedPanel.getNode().getFramsClass().getName()296 }297 298 public TreeNode getCurrentlyPoppedTreeNode() {299 assert isActive();300 return currentlyPoppedTreeNode;301 305 } 302 306 303 307 public void clear() { 304 treeModel.setRoot(null);305 308 cardPanel.removeAll(); 306 309 cardPanel.updateUI(); … … 308 311 } 309 312 310 public ScopeEnd startChange(final DefaultMutableTreeNode node) { 311 assert isActive(); 312 final TreePath selection = jtree.getSelectionPath(); 313 return new ScopeEnd() { 314 @Override 315 public void close() { 316 assert isActive(); 317 treeModel.nodeChanged(node); 318 jtree.setSelectionPath(selection); 319 } 320 }; 321 } 322 323 public void selectTreeNode(final TreeNode treeNode) { 324 assert isActive(); 325 /* final Panel panel = treeNode.getOrCreatePanel(); 326 if (panel == null) { 327 return; 328 } 329 panel.setCurrentTreeNode(treeNode); 330 treeNode.updateData(); 331 showPanel(panel);*/ 332 } 333 334 public TreeNode findTreeNodeByTreePath(TreePath treePath) { 313 public void loadChildren(Path path, boolean reload) { 314 if (path == null) { 315 return; 316 } 317 AccessInterface access = TreeOperations.bindAccess(path); 318 319 int count = access.getCompositeParamCount(); 320 for (int i = 0; i < count; ++i) { 321 Path childPath = path.appendParam(access.getCompositeParam(i)).tryFindResolution(); 322 loadPath(childPath, reload); 323 } 324 325 } 326 327 public void loadPath(Path path, boolean reload) { 328 if (path == null) { 329 return; 330 } 331 if (path.isResolved() && !reload) { 332 return; 333 } 334 path.getTree().get(path, Mode.FETCH, new FutureHandler<Path>(this) { 335 @Override 336 protected void result(Path result) { 337 final TreePath treePath = treeModel.convertToTreePath(result); 338 339 treeModel.nodeStructureChanged(treePath); 340 if (treePath.equals(jtree.getSelectionPath())) { 341 treeAtFrames.get(result.getTree()).useOrCreatePanel(treePath); 342 } 343 } 344 }); 345 } 346 347 public void chooseTreeNode(final TreePath treePath) { 335 348 assert isActive(); 336 349 if (treePath == null) { 337 return null; 338 } 339 if (!(treePath.getLastPathComponent() instanceof TreeNode)) { 340 return null; 341 } 342 return (TreeNode) treePath.getLastPathComponent(); 343 } 344 345 public void chooseTreeNode(TreePath treePath) { 346 assert isActive(); 347 final TreeNode treeNode = findTreeNodeByTreePath(treePath); 348 if (treeNode == null) { 349 return; 350 } 351 treeNode.select(); 352 } 353 354 protected final ExceptionResultHandler dialogHandler = new ExceptionResultHandler() { 355 356 @Override 357 public void handle(FramsticksException exception) { 358 //TODO TEH 359 throw exception; 360 361 } 362 }; 363 364 public void goTo(Path path) { 365 assert isActive(); 366 final TreePath treePath = treeAtFrames.get(path.getTree()).getTreePath(path, false); 367 log.info("go to path: " + path + "(" + treePath + ")"); 368 369 this.dispatch(new RunAt<Frame>(dialogHandler) { 370 @Override 371 protected void runAt() { 372 log.info("executed"); 373 jtree.setSelectionPath(treePath); 374 jtree.makeVisible(treePath); 375 assert jtree.isVisible(treePath); 376 } 377 }); 378 379 } 380 381 public void addNode(TreeNode child, DefaultMutableTreeNode parent) { 382 assert isActive(); 383 384 try (ScopeEnd e = startChange(parent)) { 385 treeModel.insertNodeInto(child, parent, parent.getChildCount()); 386 } 387 } 350 return; 351 } 352 if (treeModel.isChanging()) { 353 return; 354 } 355 356 Path path = treeModel.convertToPath(treePath); 357 if (path == null) { 358 return; 359 } 360 path = path.assureResolved(); 361 final Tree tree = path.getTree(); 362 363 treeAtFrames.get(tree).useOrCreatePanel(treePath); 364 loadChildren(path, false); 365 366 } 367 368 369 // public void goTo(Path path) { 370 // assert isActive(); 371 // final TreePath treePath = treeModel.convertToTreePath(path); 372 // log.info("go to path: " + path + "(" + treePath + ")"); 373 374 // this.dispatch(new RunAt<Frame>(this) { 375 // @Override 376 // protected void runAt() { 377 // log.info("executed"); 378 // jtree.setSelectionPath(treePath); 379 // jtree.makeVisible(treePath); 380 // assert jtree.isVisible(treePath); 381 // } 382 // }); 383 384 // } 388 385 389 386 @Override … … 422 419 } 423 420 421 /** 422 * @return the treeModel 423 */ 424 public TreeModel getTreeModel() { 425 return treeModel; 426 } 427 424 428 } -
java/main/src/main/java/com/framsticks/gui/ImageProvider.java
r90 r98 7 7 8 8 import javax.swing.*; 9 9 10 import java.util.HashMap; 10 import java.util. LinkedHashMap;11 import java.util.Map; 11 12 12 13 /** … … 21 22 * HashMap stores icons. Key is icon path, Value is icon. 22 23 */ 23 private static HashMap<String, ImageIcon> icons = new LinkedHashMap<String, ImageIcon>();24 private static Map<String, ImageIcon> icons = new HashMap<String, ImageIcon>(); 24 25 25 26 public static final String IMAGE = "image.png"; 26 27 public static final String LOGO = "logo.png"; 27 28 28 //public static final String FOLDER_OPEN = "folder_open.png";29 //public static final String FOLDER_CLOSED = "folder_close.png";30 //public static final String NODE = "node.png";29 public static final String FOLDER_OPEN = "folder_open.png"; 30 public static final String FOLDER_CLOSED = "folder_close.png"; 31 public static final String NODE = "node.png"; 31 32 32 33 public static final String SERVER = "server.png"; -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r97 r98 2 2 3 3 import org.apache.log4j.Logger; 4 4 5 5 6 import javax.swing.*; … … 65 66 } 66 67 67 @Override68 public void setCurrentTreeNode(TreeNode node) {69 super.setCurrentTreeNode(node);70 }71 72 68 protected abstract void applyChanges(); 73 69 -
java/main/src/main/java/com/framsticks/gui/MultiPanel.java
r97 r98 4 4 5 5 import javax.swing.*; 6 import javax.swing.tree.TreePath; 7 6 8 import java.awt.*; 7 9 import java.util.List; … … 46 48 47 49 @Override 48 public void setCurrentTree Node(TreeNode currentTreeNode) {49 super.setCurrentTree Node(currentTreeNode);50 public void setCurrentTreePath(TreePath currentTreePath) { 51 super.setCurrentTreePath(currentTreePath); 50 52 for (Panel p : panels) { 51 p.setCurrentTree Node(currentTreeNode);53 p.setCurrentTreePath(currentTreePath); 52 54 } 53 55 } -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r97 r98 12 12 13 13 import javax.swing.*; 14 import javax.swing.tree.TreePath; 14 15 15 16 import java.util.Collection; 16 import java.util. HashMap;17 import java.util.IdentityHashMap; 17 18 import java.util.Map; 18 19 import static com.framsticks.util.lang.Containers.filterInstanceof; 19 20 20 21 import com.framsticks.util.FramsticksException; 21 import com.framsticks.util.dispatching.RunAt;22 22 23 23 @SuppressWarnings("serial") 24 24 public class ObjectPanel extends ModifiablePanel implements ControlOwner { 25 25 26 private static final Logger log = Logger.getLogger(ObjectPanel.class .getName());26 private static final Logger log = Logger.getLogger(ObjectPanel.class); 27 27 28 final protected Map<Param, Control> components = new HashMap<Param, Control>();29 final protected Map<ValueParam, ValueControl> valueControls = new HashMap<ValueParam, ValueControl>();28 final protected Map<Param, Control> components = new IdentityHashMap<Param, Control>(); 29 final protected Map<ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>(); 30 30 31 31 public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) { … … 37 37 for (final ValueControl c : filterInstanceof(components.values(), ValueControl.class)) { 38 38 valueControls.put(c.getParam(), c); 39 c.setUserEnabled(true); 39 40 c.setListener(new ValueControlListener() { 40 41 @Override 41 42 public boolean onChange(Object newValue) { 42 if (currentTree Node== null) {43 if (currentTreePath == null) { 43 44 return true; 44 45 } 45 boolean result = currentTreeNode.changeValue(c, newValue);46 boolean result = treeAtFrame.changeValue(currentTreePath, c, newValue); 46 47 refreshControlButtons(); 47 48 return result; … … 57 58 protected void applyChanges() { 58 59 assert frame.isActive(); 59 assert currentTree Node!= null;60 currentTreeNode.pushLocalChanges();60 assert currentTreePath != null; 61 treeAtFrame.pushLocalChanges(currentTreePath); 61 62 } 62 63 63 64 protected void refreshControlButtons() { 64 65 assert frame.isActive(); 65 applyButton.setEnabled( currentTreeNode.localChanges != null);66 applyButton.setEnabled(treeAtFrame.hasLocalChanges(currentTreePath)); 66 67 } 67 68 … … 71 72 @Override 72 73 public void pullValuesFromLocalToUser(AccessInterface access) { 73 assert currentTreeNode != null; 74 assert currentTreeNode.path.getTree().isActive(); 74 assert currentTreePath != null; 75 75 log.debug("refreshing components"); 76 76 77 final Map<ValueControl, Object> values = new HashMap<ValueControl, Object>();77 final Map<ValueControl, Object> values = new IdentityHashMap<ValueControl, Object>(); 78 78 for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) { 79 79 values.put(e.getValue(), access.get(e.getKey().getId(), Object.class)); 80 80 } 81 81 82 frame.dispatch(new RunAt<Frame>(frame) { 83 @Override 84 protected void runAt() { 85 if (currentTreeNode.localChanges != null) { 86 for (Map.Entry<ValueControl, Object> e : currentTreeNode.localChanges.entrySet()) { 87 values.put(e.getKey(), e.getValue()); 88 } 89 } 90 for (Map.Entry<ValueControl, Object> e : values.entrySet()) { 91 e.getKey().pushValueToUserInterface(e.getValue()); 92 } 93 refreshControlButtons(); 94 ObjectPanel.this.revalidate(); 82 83 NodeAtFrame nodeAtFrame = treeAtFrame.getLocalInfo(currentTreePath); 84 if (nodeAtFrame != null) { 85 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 86 values.put(e.getKey(), e.getValue()); 95 87 } 96 }); 88 } 89 90 for (Map.Entry<ValueControl, Object> e : values.entrySet()) { 91 e.getKey().pushValueToUserInterface(e.getValue()); 92 } 93 refreshControlButtons(); 94 ObjectPanel.this.revalidate(); 97 95 98 96 } … … 109 107 110 108 @Override 111 public TreeNode getCurrentTreeNode() {112 return super.getCurrentTreeNode();113 }114 115 @Override116 109 public void handle(FramsticksException exception) { 117 110 frame.handle(exception); 118 111 } 119 112 120 // public void updateValue() { 121 // //assert panel.getFrame().isActive(); 113 @Override 114 public TreePath getCurrentTreePath() { 115 return super.getCurrentTreePath(); 116 } 122 117 123 // final Node n = panel.getCurrentNode();124 // panel.getBrowser().getManager().invokeLater(new Runnable() {125 // @Override126 // public void run() {127 // Object v = n.getAccess().get(param, Object.class);128 // if (v == null) {129 // v = param.getDef(Object.class);130 // }131 // final Object fv = v;132 // panel.getBrowser().invokeLater(new Runnable() {133 // @Override134 // public void run() {135 // setValueImpl(fv);136 // }137 // });138 // }139 // });140 // }141 118 142 119 } -
java/main/src/main/java/com/framsticks/gui/Panel.java
r97 r98 4 4 import com.framsticks.params.CompositeParam; 5 5 import com.framsticks.params.FramsClass; 6 // import org.apache.log4j.Logger;7 6 8 7 import javax.swing.*; 8 import javax.swing.tree.TreePath; 9 10 import org.apache.log4j.Logger; 9 11 10 12 /** … … 13 15 @SuppressWarnings("serial") 14 16 public abstract class Panel extends JPanel { 17 18 private static final Logger log = Logger.getLogger(Panel.class); 19 15 20 16 21 public static class Parameters { … … 28 33 // private static final Logger log = Logger.getLogger(Panel.class.getName()); 29 34 30 protected Tree Node currentTreeNode;35 protected TreePath currentTreePath; 31 36 protected final TreeAtFrame treeAtFrame; 32 37 protected final Frame frame; … … 43 48 this.className = parameters.param.getContainedTypeName(); 44 49 this.setName(parameters.param.getFramsTypeName()); 50 log.debug("created panel: " + this); 45 51 } 46 52 47 public void setCurrentTreeNode(TreeNode currentTreeNode) {48 this.currentTreeNode = currentTreeNode;49 }50 53 51 public TreeNode getCurrentTreeNode() {52 return currentTreeNode;53 }54 54 55 55 public final Frame getFrame() { 56 56 return frame; 57 } 58 59 /** 60 * @return the currentTreePath 61 */ 62 public TreePath getCurrentTreePath() { 63 return currentTreePath; 64 } 65 66 /** 67 * @param currentTreePath the currentTreePath to set 68 */ 69 public void setCurrentTreePath(TreePath currentTreePath) { 70 this.currentTreePath = currentTreePath; 57 71 } 58 72 … … 70 84 @Override 71 85 public String toString() { 72 return uniqueName;86 return param.toString() + "(" + uniqueName + ")"; 73 87 } 74 88 -
java/main/src/main/java/com/framsticks/gui/StatusBar.java
r97 r98 22 22 protected JTextField statusBar; 23 23 protected JPanel swing; 24 protected ExceptionResultHandler exceptionHandler; 24 25 25 26 /** … … 35 36 @Override 36 37 protected void runAt() { 37 log.error("error: " +exception);38 log.error("error: ", exception); 38 39 statusBar.setText(exception.getShortMessage(new StringBuilder()).toString()); 40 if (exceptionHandler != null) { 41 exceptionHandler.handle(exception); 42 } 39 43 } 40 44 }); … … 70 74 } 71 75 76 /** 77 * @return the exceptionHandler 78 */ 79 public ExceptionResultHandler getExceptionHandler() { 80 return exceptionHandler; 81 } 82 83 /** 84 * @param exceptionHandler the exceptionHandler to set 85 */ 86 public void setExceptionHandler(ExceptionResultHandler exceptionHandler) { 87 this.exceptionHandler = exceptionHandler; 88 } 89 72 90 } -
java/main/src/main/java/com/framsticks/gui/SwingDispatcher.java
r97 r98 1 1 package com.framsticks.gui; 2 2 3 import java.awt.event.ActionEvent; 4 import java.awt.event.ActionListener; 5 6 import com.framsticks.util.dispatching.AbstractJoinable; 3 7 import com.framsticks.util.dispatching.Dispatcher; 8 import com.framsticks.util.dispatching.JoinableDispatcher; 4 9 import com.framsticks.util.dispatching.Task; 5 10 import com.framsticks.util.dispatching.ThrowExceptionHandler; … … 11 16 * @author Piotr Sniegowski 12 17 */ 13 public class SwingDispatcher<C> implementsDispatcher<C> {18 public class SwingDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> { 14 19 15 20 @SuppressWarnings("rawtypes") … … 37 42 @Override 38 43 public final void dispatch(RunAt<? extends C> runnable) { 39 assert !(runnable instanceof Task); 44 if (runnable instanceof Task) { 45 final Task<?> task = (Task<?>) runnable; 46 Timer timer = new Timer(0, null); 47 timer.addActionListener(new ActionListener() { 48 49 @Override 50 public void actionPerformed(ActionEvent event) { 51 task.run(); 52 } 53 54 }); 55 timer.setInitialDelay((int) (task.getMoment() - System.currentTimeMillis())); 56 timer.setRepeats(false); 57 timer.start(); 58 return; 59 } 40 60 SwingUtilities.invokeLater(runnable); 41 61 } 42 62 63 @Override 64 public String getName() { 65 return "gui"; 66 } 67 68 @Override 69 protected void joinableStart() { 70 71 } 72 73 @Override 74 protected void joinableInterrupt() { 75 finish(); 76 } 77 78 @Override 79 protected void joinableFinish() { 80 81 } 82 83 @Override 84 protected void joinableJoin() throws InterruptedException { 85 86 } 87 43 88 } -
java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java
r97 r98 4 4 5 5 import com.framsticks.core.Tree; 6 import com.framsticks.core.TreeListener;7 import com.framsticks.core.ListChange;8 6 import com.framsticks.core.Node; 9 7 import com.framsticks.core.Path; 8 import com.framsticks.core.TreeOperations; 9 import com.framsticks.gui.controls.ValueControl; 10 10 import com.framsticks.params.CompositeParam; 11 11 import com.framsticks.params.FramsClass; … … 14 14 15 15 import javax.swing.tree.TreePath; 16 import com.framsticks.util.dispatching.RunAt; 16 17 18 import com.framsticks.util.dispatching.FutureHandler; 19 import com.framsticks.util.lang.Casting; 17 20 18 21 /** 19 22 * @author Piotr Sniegowski 20 23 */ 21 public class TreeAtFrame implements TreeListener{24 public class TreeAtFrame { 22 25 23 26 private static final Logger log = Logger.getLogger(TreeAtFrame.class); … … 26 29 protected final Tree tree; 27 30 protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>(); 28 protected TreeNode rootTreeNode; 31 protected Node rootNode; 32 33 protected Map<TreeNode, NodeAtFrame> nodesStorage = new WeakHashMap<>(); 29 34 30 35 public TreeAtFrame(Tree tree, Frame frame) { … … 90 95 } 91 96 92 @Override 93 public void onListChange(Path path, ListChange change) { 97 public boolean hasLocalChanges(TreePath treePath) { 98 NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent()); 99 if (nodeAtFrame == null) { 100 return false; 101 } 102 return !nodeAtFrame.localChanges.isEmpty(); 103 } 104 105 public NodeAtFrame assureLocalInfo(TreePath treePath) { 106 assert frame.isActive(); 107 NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent()); 108 109 if (nodeAtFrame == null) { 110 nodeAtFrame = new NodeAtFrame(); 111 nodesStorage.put(Casting.throwCast(TreeNode.class, treePath.getLastPathComponent()), nodeAtFrame); 112 } 113 return nodeAtFrame; 114 } 115 116 public NodeAtFrame getLocalInfo(TreePath treePath) { 117 return nodesStorage.get(treePath.getLastPathComponent()); 118 } 119 120 public boolean changeValue(TreePath treePath, ValueControl component, Object newValue) { 121 log.debug("changing value of " + component + " to '" + newValue + "'"); 122 123 assureLocalInfo(treePath).localChanges.put(component, newValue); 124 125 return true; 126 } 127 128 public void pushLocalChanges(TreePath treePath) { 129 assert frame.isActive(); 130 131 NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent()); 132 if (nodeAtFrame == null) { 133 return; 134 } 135 Path path = frame.treeModel.convertToPath(treePath); 136 137 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 138 TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) { 139 @Override 140 protected void result(Integer flag) { 141 } 142 }); 143 } 144 } 145 146 public void fillPanelWithValues(TreePath treePath) { 147 NodeAtFrame nodeAtFrame = assureLocalInfo(treePath); 148 if (nodeAtFrame == null) { 149 return; 150 } 151 152 if (nodeAtFrame.panel == null) { 153 return; 154 } 155 Node node = TreeNode.tryGetNode(treePath); 156 if (node == null) { 157 return; 158 } 159 nodeAtFrame.panel.setCurrentTreePath(treePath); 160 nodeAtFrame.panel.pullValuesFromLocalToUser(TreeOperations.bindAccess(node)); 161 162 frame.showPanel(nodeAtFrame.panel); 94 163 95 164 } 96 165 97 public TreePath getTreePath(Path path, boolean create) { 98 assert frame.isActive(); 99 TreeNode t = rootTreeNode; 100 TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode); 101 List<Node> nodes = path.getNodes(); 102 Iterator<Node> i = nodes.iterator(); 103 i.next(); 104 // Node first = i.next(); 166 public void useOrCreatePanel(TreePath treePath) { 167 // node.assureResolved(); 168 Node node = TreeNode.tryGetNode(treePath); 105 169 106 // if (!t.path.isResolved()) { 107 // t.path = new Path(path.getInstance(), nodes, first); 108 // } 109 while (i.hasNext()) { 110 Node n = i.next(); 111 TreeNode r = null; 112 for (TreeNode c : t.childrenIterable()) { 113 if (c.param.getId().equals(n.getParam().getId())) { 114 r = c; 115 break; 116 } 170 NodeAtFrame nodeAtFrame = assureLocalInfo(treePath); 171 172 if (nodeAtFrame.panel == null) { 173 CompositeParam param = node.getParam(); 174 nodeAtFrame.panel = findPanel(param.computeAccessId()); 175 if (nodeAtFrame.panel == null) { 176 FramsClass framsClass = node.getTree().getInfoFromCache(param.getContainedTypeName()); 177 nodeAtFrame.panel = preparePanel(param, framsClass); 117 178 } 118 if (r == null) {119 log.debug("missing " + n.getParam().getId() + " in " + t);120 if (!create) {121 return result;122 }123 Path p = Path.build().tree(path.getTree()).buildUpTo(nodes, n).finish();124 125 126 log.debug("forced resolution: creating treenode for " + p);127 TreeNode childNode = new TreeNode(TreeAtFrame.this, p);128 129 frame.addNode(childNode, t);130 // frame.treeModel.reload();131 // t.add(childNode);132 // frame.treeModel.nodeStructureChanged(t);133 134 r = childNode;135 } else {136 // if (!r.path.isResolved()) {137 // r.path = new Path(path.getInstance(), nodes, n);138 // }139 }140 result = result.pathByAddingChild(r);141 t = r;142 179 } 143 return result; 144 } 145 146 @Override 147 public void onFetch(final Path path) { 148 assert tree.isActive(); 149 log.trace("fetched " + path); 150 151 frame.dispatch(new RunAt<Frame>(frame) { 152 @Override 153 protected void runAt() { 154 155 TreePath treePath = getTreePath(path, true); 156 assert treePath.getPathCount() == path.size() + 1; 157 158 final TreeNode result = (TreeNode) treePath.getLastPathComponent(); 159 // log.trace("found " + result + " == " + path); 160 tree.dispatch(new RunAt<Tree>(frame) { 161 @Override 162 protected void runAt() { 163 result.reactForFetchResult(path, null); 164 } 165 }); 166 } 167 }); 168 } 169 170 @Override 171 public void onRun(Exception e) { 172 173 } 174 175 @Override 176 public void onStop(Exception e) { 177 180 fillPanelWithValues(treePath); 178 181 } 179 182 } -
java/main/src/main/java/com/framsticks/gui/TreeNode.java
r97 r98 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.communication.Subscription; 4 import com.framsticks.communication.util.LoggingStateCallback; 5 import com.framsticks.core.Mode; 3 import java.lang.ref.WeakReference; 4 import java.util.Iterator; 5 import java.util.LinkedList; 6 import java.util.List; 7 import java.util.concurrent.atomic.AtomicInteger; 8 9 import javax.swing.tree.TreePath; 10 11 import org.apache.log4j.Logger; 12 13 import com.framsticks.core.Node; 6 14 import com.framsticks.core.Tree; 7 import com.framsticks.core.TreeOperations;8 import com.framsticks.core.ListChange;9 import com.framsticks.core.Path;10 import com.framsticks.gui.controls.ValueControl;11 15 import com.framsticks.gui.view.TreeCellRenderer; 12 16 import com.framsticks.params.AccessInterface; 13 17 import com.framsticks.params.CompositeParam; 14 import com.framsticks.params.FramsClass; 15 import com.framsticks.params.types.*; 16 import com.framsticks.remote.*; 18 import com.framsticks.params.types.StringParam; 19 import com.framsticks.util.FramsticksException; 17 20 import com.framsticks.util.lang.Casting; 18 import com.framsticks.util.lang. Holder;21 import com.framsticks.util.lang.Pair; 19 22 import com.framsticks.util.swing.TooltipConstructor; 20 import com.framsticks.util.dispatching.ExceptionResultHandler; 21 import com.framsticks.util.dispatching.FutureHandler; 22 import com.framsticks.util.FramsticksException; 23 import com.framsticks.util.Logging; 24 import org.apache.log4j.Logger; 25 import com.framsticks.util.dispatching.RunAt; 26 27 import javax.swing.tree.DefaultMutableTreeNode; 28 import java.util.HashMap; 29 import java.util.LinkedList; 30 import java.util.List; 31 import java.util.Map; 32 import static com.framsticks.util.lang.Containers.filterInstanceof; 33 import com.framsticks.util.swing.TreeNodeUtils; 34 import static com.framsticks.core.TreeOperations.*; 35 36 /** 37 * @author Piotr Sniegowski 38 */ 39 @SuppressWarnings("serial") 40 public class TreeNode extends DefaultMutableTreeNode implements NodeListener, ExceptionResultHandler { 41 42 private static final Logger log = Logger.getLogger(TreeNode.class.getName()); 43 44 Panel panel; 45 46 final protected Frame frame; 47 final protected TreeAtFrame treeAtFrame; 48 49 final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>(); 50 protected Map<ValueControl, Object> localChanges = null; 51 protected String tooltip; 52 protected String name; 23 24 public class TreeNode extends AbstractNode { 25 private static final Logger log = Logger.getLogger(TreeNode.class); 26 27 28 protected static final AtomicInteger counter = new AtomicInteger(); 29 30 protected final WeakReference<Object> reference; 53 31 protected final CompositeParam param; 54 protected String iconName; 55 protected Path path; 56 57 public TreeNode(TreeAtFrame treeAtFrame, final Path path) { 58 this.frame = treeAtFrame.getFrame(); 59 assert frame.isActive(); 60 this.param = path.getTop().getParam(); 61 this.name = this.param.getId(); 62 log.debug("creating treenode " + name + ": " + path); 63 this.path = path; 64 this.treeAtFrame = treeAtFrame; 65 66 iconName = TreeCellRenderer.findIconName(name, path.getTextual()); 67 tooltip = "?"; 68 path.getTree().dispatch(new RunAt<Tree>(this) { 69 @Override 70 protected void runAt() { 71 updateDescriptions(path); 72 } 73 }); 74 } 75 76 public void fetch(final Path p) { 77 assert p.getTree().isActive(); 78 log.debug("fetching: " + p); 79 p.getTree().get(p, Mode.FETCH, new FutureHandler<Object>(this) { 80 @Override 81 protected void result(Object result) { 82 83 } 84 }); 85 } 86 87 protected void reactForFetchResult(final Path p, Exception e) { 88 assert p.getTree().isActive(); 89 if (Logging.log(log, "fetch", TreeNode.this, e)) { 90 frame.dispatch(new RunAt<Frame>(this) { 91 @Override 92 protected void runAt() { 93 log.debug("removing node from tree: " + p); 94 frame.treeModel.removeNodeFromParent(TreeNode.this); 95 } 96 }); 97 return; 98 } 99 updateChildren(p); 100 frame.dispatch(new RunAt<Frame>(this) { 101 @Override 102 protected void runAt() { 103 //TODO maybe this should be called from some better place 104 useOrCreatePanel(); 105 } 106 }); 107 } 108 109 protected void postUpdatePath(final Path newPath) { 110 assert !frame.isActive(); 111 /** TODO those two actions could be merged into single closure */ 112 frame.dispatch(new RunAt<Frame>(this) { 113 @Override 114 protected void runAt() { 115 updatePath(newPath); 116 } 117 }); 118 updateDescriptions(newPath); 119 } 120 121 protected void updatePath(Path newPath) { 122 assert frame.isActive(); 123 if (!path.isResolved()) { 124 path = newPath; 125 log.debug("updated treenode's path: " + path); 126 return; 127 } 128 if (path.matches(newPath)) { 129 return; 130 } 131 log.debug("removing all children due to path update"); 132 this.removeAllChildren(); 133 frame.treeModel.nodeStructureChanged(this); 134 } 135 136 public Iterable<TreeNode> childrenIterable() { 137 return filterInstanceof(TreeNodeUtils.children(TreeNode.this, frame.treeModel), TreeNode.class); 138 } 139 140 /** Update children, by removing non existing and adding new ones. 32 protected final Tree tree; 33 protected final List<Pair<WeakReference<Object>, WeakReference<TreeNode>>> children = new LinkedList<>(); 34 protected final int number; 35 36 public TreeNode(Tree tree, CompositeParam param, Object object) { 37 this.tree = tree; 38 this.param = param; 39 reference = new WeakReference<Object>(object); 40 number = counter.getAndIncrement(); 41 } 42 43 public TreeNode(Node node) { 44 this(node.getTree(), node.getParam(), node.assureResolved().getObject()); 45 } 46 47 public Node tryCreateNode() { 48 Object child = lock(); 49 if (child == null) { 50 return null; 51 } 52 return new Node(tree, param, child); 53 } 54 55 @Override 56 public int getChildCount() { 57 Object referent = lock(); 58 if (referent == null) { 59 return 0; 60 } 61 AccessInterface access = tree.prepareAccess(param).select(referent); 62 final int count = access.getCompositeParamCount(); 63 return count; 64 } 65 66 public TreeNode getTreeNodeForChild(Object child) { 67 Iterator<Pair<WeakReference<Object>, WeakReference<TreeNode>>> i = children.iterator(); 68 while (i.hasNext()) { 69 Pair<WeakReference<Object>, WeakReference<TreeNode>> p = i.next(); 70 Object object = p.first.get(); 71 if (object == null) { 72 i.remove(); 73 continue; 74 } 75 TreeNode treeNode = p.second.get(); 76 if (treeNode == null) { 77 i.remove(); 78 continue; 79 } 80 if (object == child) { 81 return treeNode; 82 } 83 } 84 return null; 85 86 // WeakReference<GuiTreeNode> resultReference = children.get(child); 87 // if (resultReference == null) { 88 // return null; 89 // } 90 // return resultReference.get(); 91 } 92 93 @Override 94 public AbstractNode getChild(int number) { 95 Object referent = lock(); 96 if (referent == null) { 97 throw new FramsticksException().msg("invalid state - missing referent"); 98 } 99 AccessInterface access = tree.prepareAccess(param).select(referent); 100 101 final int count = access.getCompositeParamCount(); 102 if (number >= count) { 103 throw new FramsticksException().msg("invalid state - no child"); 104 } 105 106 CompositeParam childParam = access.getCompositeParam(number); 107 Object child = access.get(childParam, Object.class); 108 if (child == null) { 109 log.debug("returing dummy node for " + childParam + " in " + referent); 110 return new EmptyNode(childParam); 111 } 112 113 TreeNode result = getTreeNodeForChild(child); 114 if (result != null) { 115 return result; 116 } 117 result = new TreeNode(tree, childParam, child); 118 119 children.add(Pair.make(new WeakReference<Object>(child), new WeakReference<TreeNode>(result))); 120 121 return result; 122 123 } 124 125 public Object lock() { 126 return reference.get(); 127 } 128 129 @Override 130 public int getIndexOfChild(AbstractNode child) { 131 final TreeNode treeChild = Casting.tryCast(TreeNode.class, child); 132 if (treeChild == null) { 133 return -1; 134 } 135 final Object childObject = treeChild.lock(); 136 final Object parentObject = lock(); 137 if (childObject == null || parentObject == null) { 138 return -1; 139 } 140 final AccessInterface access = tree.prepareAccess(param).select(parentObject); 141 142 final int count = access.getCompositeParamCount(); 143 for (int i = 0; i < count; ++i) { 144 Object c = access.get(access.getCompositeParam(i), Object.class); 145 if (c == childObject) { 146 return i; 147 } 148 } 149 log.debug(child + " not found in " + this); 150 return -1; 151 } 152 153 /** 154 * @return the param 141 155 */ 142 protected void updateChildren(final Path p) { 143 assert p.getTree().isActive(); 144 log.debug("updating children of " + this); 145 AccessInterface access = TreeOperations.bindAccess(p.getTree(), p.getTop()); 146 final List<Path> childrenPaths = new LinkedList<Path>(); 147 /**Prepare path for each child.*/ 148 for (CompositeParam param : filterInstanceof(access.getParams(), CompositeParam.class)) { 149 childrenPaths.add(p.appendParam(param).tryFindResolution()); 150 } 151 152 /**If some child were found, update in frame context.*/ 153 if (childrenPaths.size() > 0) { 154 frame.dispatch(new RunAt<Frame>(this) { 155 @Override 156 protected void runAt() { 157 // TreePath treePath = frame.startChange(); 158 updatePath(p); 159 Map<String, TreeNode> current = new HashMap<String, TreeNode>(); 160 for (TreeNode n : childrenIterable()) { 161 current.put(n.path.getLastElement(), n); 162 } 163 assert current.size() == TreeNode.this.getChildCount(); 164 assert TreeNode.this.getChildCount() == frame.treeModel.getChildCount(TreeNode.this); 165 log.trace("current " + TreeNode.this.getChildCount() + " children: " + current.values()); 166 for (Path childPath : childrenPaths) { 167 String e = childPath.getLastElement(); 168 if (current.containsKey(e)) { 169 current.remove(e); 170 continue; 171 } 172 log.debug("update: treenode for " + p); 173 TreeNode childNode = new TreeNode(treeAtFrame, childPath); 174 175 frame.addNode(childNode, TreeNode.this); 176 } 177 for (TreeNode n : current.values()) { 178 frame.treeModel.removeNodeFromParent(n); 179 } 180 log.debug("updated children of " + TreeNode.this + ": " + TreeNode.this.getChildCount()); 181 } 182 }); 156 public CompositeParam getParam() { 157 return param; 158 } 159 160 /** 161 * @return the tree 162 */ 163 public Tree getTree() { 164 return tree; 165 } 166 167 168 @Override 169 public String toString() { 170 return param.toString(); 171 } 172 173 public static Node tryGetNode(TreePath treePath) { 174 return Casting.throwCast(TreeNode.class, treePath.getLastPathComponent()).tryCreateNode(); 175 } 176 177 @Override 178 public boolean isLeaf() { 179 Object referent = lock(); 180 if (referent == null) { 181 return true; 182 } 183 AccessInterface access = tree.prepareAccess(param).select(referent); 184 return access.getCompositeParamCount() == 0; 185 } 186 187 188 @Override 189 public void render(TreeCellRenderer renderer) { 190 String name = param.getId(); 191 192 Object child = lock(); 193 if (child != null) { 194 AccessInterface access = tree.prepareAccess(param).select(child); 195 196 StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name")); 197 198 if (nameParam != null) { 199 name = access.get(nameParam, String.class); 200 } 201 202 renderer.setToolTipText(new TooltipConstructor() 203 .append("frams", access.getId()) 204 .append("java", child.getClass().getCanonicalName()) 205 .append("access", access.getClass().getSimpleName()) 206 .append("name", name) 207 .append("id", param.getId()) 208 .append("object", Integer.toHexString(System.identityHashCode(child))) 209 .append("number", number) 210 .build()); 183 211 } else { 184 log.debug("no children in " + TreeNode.this); 185 } 186 } 187 188 public void select() { 189 final Path p = path; 190 191 p.getTree().dispatch(new RunAt<Tree>(this) { 192 @Override 193 protected void runAt() { 194 final Path updated = (p.isResolved()) ? p : p.tryFindResolution(); 195 if (updated.isResolved()) { 196 Logging.log(log, "update", updated, null); 197 fetch(updated); 198 postUpdatePath(updated); 199 return; 200 } 201 p.getTree().resolve(updated, new FutureHandler<Path>(Logging.logger(log, "resolve and select", TreeNode.this)) { 202 @Override 203 protected void result(Path result) { 204 fetch(result); 205 postUpdatePath(result); 206 } 207 }); 208 } 209 }); 210 211 } 212 213 @Override 214 public String toString() { 215 return path.toString(); 216 } 217 218 public final Panel getPanel() { 219 assert frame.isActive(); 220 return panel; 221 } 222 223 protected void updateDescriptions(Path p) { 224 assert p.getTree().isActive(); 225 226 if (!p.isResolved()) { 227 return; 228 } 229 AccessInterface access = TreeOperations.bindAccess(p); 230 231 final String tooltip = new TooltipConstructor().append("frams", access.getId()).append("java", p.getTopObject().getClass().getCanonicalName()).append("access", access.getClass().getSimpleName()).append("name", name).append("id", param.getId()).append("object", Integer.toHexString(System.identityHashCode(this))).build(); 232 233 StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name")); 234 final String name = (nameParam != null ? access.get(nameParam, String.class) : path.getTop().getParam().getId()); 235 236 frame.dispatch(new RunAt<Frame>(this) { 237 @Override 238 protected void runAt() { 239 TreeNode.this.tooltip = tooltip; 240 TreeNode.this.name = name; 241 242 log.debug("updated descriptions for " + path + ": " + name); 243 } 244 }); 245 } 246 247 public void showPanel() { 248 assert frame.isActive(); 249 assert panel != null; 250 frame.showPanel(panel); 251 } 252 253 public void fillPanelWithValues() { 254 assert frame.isActive(); 255 if (panel == null) { 256 return; 257 } 258 final Path p = path; 259 assert p.isResolved(); 260 panel.setCurrentTreeNode(this); 261 p.getTree().dispatch(new RunAt<Tree>(this) { 262 @Override 263 protected void runAt() { 264 AccessInterface access = TreeOperations.bindAccess(p); 265 panel.pullValuesFromLocalToUser(access); 266 267 frame.dispatch(new RunAt<Frame>(this) { 268 @Override 269 protected void runAt() { 270 showPanel(); 271 } 272 }); 273 } 274 }); 275 276 } 277 278 public void useOrCreatePanel() { 279 assert frame.isActive(); 280 if (panel != null) { 281 log.trace("panel is already attached: " + path); 282 fillPanelWithValues(); 283 return; 284 } 285 if (!path.isResolved()) { 286 log.trace("path is not resolved: " + path); 287 return; 288 } 289 290 CompositeParam param = path.getTop().getParam(); 291 panel = treeAtFrame.findPanel(param.computeAccessId()); 292 if (panel != null) { 293 log.debug("found prepared panel for: " + path); 294 fillPanelWithValues(); 295 return; 296 } 297 final Path p = path; 298 log.debug("preparing panel: " + p); 299 p.getTree().dispatch(new RunAt<Tree>(this) { 300 @Override 301 protected void runAt() { 302 assert p.getTree().isActive(); 303 final CompositeParam param = p.getTop().getParam(); 304 final FramsClass framsClass = p.getTree().getInfoFromCache(param.getContainedTypeName()); 305 frame.dispatch(new RunAt<Frame>(this) { 306 @Override 307 protected void runAt() { 308 panel = treeAtFrame.preparePanel(param, framsClass); 309 fillPanelWithValues(); 310 } 311 }); 312 } 313 }); 314 } 315 316 public String getTooltip() { 317 assert frame.isActive(); 318 return tooltip; 319 } 320 321 /*public void subscribe(final EventParam eventParam) { 322 assert browser.isActive(); 323 if (hasSubscribed(eventParam)) { 324 log.error(eventParam + " is already subscribed for " + this); 325 return; 326 } 327 Node node = getNode(); 328 node.getConnection().subscribe(node.getPath() + "/" + eventParam.getId(), new SubscriptionCallback() { 329 @Override 330 public EventCallback subscribed(final Subscription subscription) { 331 if (subscription == null) { 332 log.error("subscription failed"); 333 return null; 334 } 335 if (hasSubscribed(eventParam)) { 336 //abort subscription 337 return null; 338 } 339 userSubscriptions.put(eventParam, subscription); 340 log.debug("subscription succeeded: " + subscription); 341 subscription.setDispatcher(browser); 342 return new EventCallback() { 343 @Override 344 public void call(SourceInterface content) { 345 assert browser.isActive(); 346 log.info("event " + subscription + " occurred"); 347 } 348 }; 349 } 350 }); 351 352 }*/ 353 354 public boolean hasSubscribed(EventParam param) { 355 assert frame.isActive(); 356 return userSubscriptions.containsKey(param); 357 } 358 359 public void unsubscribe(EventParam eventParam) { 360 assert frame.isActive(); 361 if (!hasSubscribed(eventParam)) { 362 log.error("could not unsubscribe from " + eventParam); 363 return; 364 } 365 userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam)); 366 userSubscriptions.remove(eventParam); 367 } 368 369 // @Override 370 // public void onChildChange(final Child child, ListChange.Action action) { 371 // assert browser.manager.isActive(); 372 373 // switch (action) { 374 // case Remove: { 375 // Dispatching.invokeDispatch(browser, browser.manager, new Runnable() { 376 // @Override 377 // public void run() { 378 // assert browser.manager.isActive(); 379 // final TreeNode treeNode = (TreeNode) child.getUserObject(); 380 // if (treeNode == null) { 381 // log.error("child " + child + " had no tree node attached"); 382 // return; 383 // } 384 // browser.invokeLater(new Runnable() { 385 // @Override 386 // public void run() { 387 // assert browser.isActive(); 388 // TreePath path = browser.startChange(); 389 // //assert treeNode.getParent() == TreeNode.this; 390 // if (treeNode.getParent() != null) { 391 // browser.treeModel.removeNodeFromParent(treeNode); 392 // } 393 // //remove(treeNode); 394 // browser.markNodeChanged(TreeNode.this, path); 395 // } 396 // }); 397 // } 398 // }); 399 // break; 400 // } 401 // } 402 403 // } 404 405 public String getName() { 406 return name; 407 } 408 409 public String getIconName() { 410 return iconName; 411 } 412 413 @Override 414 public void onUpgrade(Path path) { 415 } 416 417 @Override 418 public void onChange(Path path) { 419 } 420 421 @Override 422 public void onChildChange(Path path, ListChange.Action action) { 423 } 424 425 public final Frame getFrame() { 426 return frame; 427 } 428 429 public boolean changeValue(ValueControl component, Object newValue) { 430 log.debug("changing value of " + component + " to '" + newValue + "'"); 431 432 if (localChanges == null) { 433 localChanges = new HashMap<ValueControl, Object>(); 434 } 435 localChanges.put(component, newValue); 436 437 return true; 438 } 439 440 public Path getTreePath() { 441 assert frame.isActive(); 442 return path; 443 } 444 445 public void pushLocalChanges() { 446 assert frame.isActive(); 447 if (localChanges == null) { 448 return; 449 } 450 Map<ValueControl, Object> changes = localChanges; 451 localChanges = null; 452 final Holder<Integer> counter = new Holder<>(changes.size()); 453 final Path p = path; 454 455 for (Map.Entry<ValueControl, Object> e : changes.entrySet()) { 456 set(p, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(this) { 457 @Override 458 protected void result(Integer flag) { 459 counter.set(counter.get() - 1); 460 if (counter.get() != 0) { 461 return; 462 } 463 log.debug("applied changes for: " + p); 464 frame.dispatch(new RunAt<Frame>(this) { 465 @Override 466 protected void runAt() { 467 fillPanelWithValues(); 468 } 469 }); 470 } 471 472 }); 473 } 474 } 475 476 @Override 477 public void handle(FramsticksException exception) { 478 frame.handle(exception); 479 } 212 renderer.setToolTipText("?"); 213 } 214 renderer.setText(name); 215 renderer.setIcon(ImageProvider.loadImage(TreeCellRenderer.findIconName(param))); 216 217 } 218 480 219 } -
java/main/src/main/java/com/framsticks/gui/console/InteractiveConsole.java
r97 r98 109 109 } 110 110 }); 111 112 113 111 } 114 112 -
java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.java
r97 r98 3 3 import java.util.LinkedList; 4 4 import java.util.List; 5 6 5 7 6 import com.framsticks.communication.ClientSideManagedConnection; … … 11 10 import com.framsticks.communication.Response; 12 11 import com.framsticks.communication.queries.ApplicationRequest; 12 import com.framsticks.core.Mode; 13 13 import com.framsticks.core.Path; 14 14 import static com.framsticks.core.TreeOperations.*; … … 17 17 import com.framsticks.params.annotations.AutoAppendAnnotation; 18 18 import com.framsticks.params.annotations.FramsClassAnnotation; 19 import com.framsticks.params.types.ListParam; 19 20 import com.framsticks.remote.RemoteTree; 20 21 import com.framsticks.util.FramsticksException; 22 import com.framsticks.util.dispatching.Dispatching; 21 23 import com.framsticks.util.dispatching.FutureHandler; 24 import com.framsticks.util.dispatching.RunAt; 22 25 import com.framsticks.util.lang.Casting; 23 26 import com.framsticks.util.lang.Containers; … … 27 30 @FramsClassAnnotation 28 31 public class ManagedConsole extends InteractiveConsole { 32 29 33 30 34 protected RemoteTree tree; … … 70 74 } 71 75 76 72 77 @Override 73 78 protected void findCompletionPropositions(final String prefix) { 74 79 Pair<CharSequence, CharSequence> command = Request.takeIdentifier(prefix); 80 if (command == null) { 81 return; 82 } 75 83 76 84 Casting.throwCast(ApplicationRequest.class, Request.createRequestByTypeString(command.first.toString())); … … 90 98 // final Iterator<String> iterator = Path.splitPath(textual); 91 99 92 resolve(tree, textual, new FutureHandler<Path>(this) {100 tryGet(tree, textual, new FutureHandler<Path>(this) { 93 101 94 102 @Override 95 protected void result( Path path) {103 protected void result(final Path path) { 96 104 if (!textual.startsWith(path.getTextual())) { 97 105 throw new FramsticksException().msg("invalid state").arg("line", prefix).arg("path", path); 98 106 } 107 assert path.getTree().isActive(); 99 108 100 List<String> propositions = new LinkedList<String>(); 101 String remaining = textual.substring(path.getTextual().length()); 102 remaining = Path.PathBuilder.splitPath(remaining).next(); 109 final Runnable finalizeCompletion = new Runnable() { 110 @Override 111 public void run() { 112 String remaining = textual.substring(path.getTextual().length()); 103 113 104 for (CompositeParam p : Containers.filterInstanceof(bindAccess(path).getParams(), CompositeParam.class)) { 105 if (p.getId().startsWith(remaining)) { 106 propositions.add(p.getId()); 114 String base = prefix.substring(0, prefix.length() - (textual.length() - path.getTextual().length())); 115 if (path.size() > 1) { 116 base = base + "/"; 117 } 118 119 if (remaining.startsWith("/")) { 120 remaining = remaining.substring(1); 121 } 122 123 if (remaining.indexOf('/') != -1) { 124 /** It is to long. */ 125 return; 126 } 127 final List<String> propositions = new LinkedList<String>(); 128 for (CompositeParam p : Containers.filterInstanceof(bindAccess(path).getParams(), CompositeParam.class)) { 129 if (remaining.equals("") || p.getId().startsWith(remaining)) { 130 propositions.add(base + p.getId()); 131 } 132 } 133 134 dispatch(new RunAt<ManagedConsole>(ManagedConsole.this) { 135 136 @Override 137 protected void runAt() { 138 processCompletionResult(prefix, propositions); 139 } 140 }); 107 141 } 142 }; 143 144 if (path.getTop().getParam() instanceof ListParam) { 145 tree.get(path, Mode.FETCH, new FutureHandler<Path>(ManagedConsole.this) { 146 @Override 147 protected void result(Path result) { 148 finalizeCompletion.run(); 149 } 150 }); 151 return; 108 152 } 109 processCompletionResult(prefix, propositions); 153 finalizeCompletion.run(); 154 110 155 } 111 156 }); … … 119 164 connection = tree.getConnection(); 120 165 } 166 167 @Override 168 protected void joinableStart() { 169 super.joinableStart(); 170 Dispatching.use(tree, this); 171 } 172 173 @Override 174 protected void joinableInterrupt() { 175 Dispatching.drop(tree, this); 176 super.joinableInterrupt(); 177 } 178 179 @Override 180 protected void joinableJoin() throws InterruptedException { 181 Dispatching.join(tree); 182 super.joinableJoin(); 183 } 121 184 } -
java/main/src/main/java/com/framsticks/gui/console/TrackConsole.java
r97 r98 1 1 package com.framsticks.gui.console; 2 3 import java.awt.BorderLayout; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 7 import javax.swing.Box; 8 import javax.swing.BoxLayout; 9 import javax.swing.JCheckBox; 2 10 3 11 import com.framsticks.communication.Connection; … … 8 16 @FramsClassAnnotation 9 17 public class TrackConsole extends Console implements ConnectionListener { 18 19 volatile boolean writeOut = true; 20 volatile boolean writeIn = true; 10 21 11 22 public TrackConsole() { … … 30 41 } 31 42 32 33 43 @Override 34 44 public void connectionOutgoing(String line) { 35 dispatchWrite(line); 45 if (writeOut) { 46 dispatchWrite(line); 47 } 36 48 } 37 49 38 50 @Override 39 51 public void connectionIncomming(String line) { 40 dispatchWrite(line); 52 if (writeIn) { 53 dispatchWrite(line); 54 } 55 } 56 57 @Override 58 protected void initializeGui() { 59 super.initializeGui(); 60 61 final Box box = new Box(BoxLayout.LINE_AXIS); 62 63 final JCheckBox outCheckbox = new JCheckBox(); 64 outCheckbox.setText("Show out"); 65 outCheckbox.setSelected(true); 66 outCheckbox.addActionListener(new ActionListener() { 67 @Override 68 public void actionPerformed(ActionEvent arg0) { 69 writeOut = outCheckbox.isSelected(); 70 } 71 }); 72 73 final JCheckBox inCheckbox = new JCheckBox(); 74 inCheckbox.setText("Show in"); 75 inCheckbox.setSelected(true); 76 inCheckbox.addActionListener(new ActionListener() { 77 @Override 78 public void actionPerformed(ActionEvent arg0) { 79 writeIn = inCheckbox.isSelected(); 80 } 81 }); 82 83 box.add(outCheckbox); 84 box.add(Box.createHorizontalStrut(10)); 85 box.add(inCheckbox); 86 87 panel.add(box, BorderLayout.PAGE_END); 41 88 } 42 89 -
java/main/src/main/java/com/framsticks/gui/controls/CheckBoxControl.java
r84 r98 21 21 super(booleanParam); 22 22 checkBox = new JCheckBox(); 23 checkBox.setEnabled(!isReadOnly());24 23 checkBox.addActionListener(new ActionListener() { 25 24 … … 52 51 } 53 52 53 @Override 54 protected void updateEnabled(boolean enabled) { 55 checkBox.setEnabled(enabled); 56 } 57 54 58 } -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r97 r98 24 24 protected ControlOwner owner; 25 25 26 protected abstract void updateEnabled(boolean enabled); 27 28 private boolean userEnabled = true; 29 26 30 public Control(Param param) { 27 31 this.param = param; 28 32 setName(param.getId()); 29 30 this.setEnabled(!param.hasFlag(Flags.READONLY));31 // TODO: take care of textField exception: setEditable32 33 } 33 34 … … 38 39 public void setOwner(ControlOwner owner) { 39 40 this.owner = owner; 41 } 42 43 /** 44 * @return the userEnabled 45 */ 46 public final boolean isUserEnabled() { 47 return userEnabled; 48 } 49 50 /** 51 * @param userEnabled the userEnabled to set 52 */ 53 public final void setUserEnabled(boolean userEnabled) { 54 this.userEnabled = userEnabled; 55 updateEnabled(!isReadonly()); 56 } 57 58 public final boolean isReadonly() { 59 return !userEnabled || param.hasFlag(Flags.READONLY); 40 60 } 41 61 -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r97 r98 2 2 3 3 import javax.swing.JPanel; 4 import javax.swing.tree.TreePath; 4 5 5 import com.framsticks.gui. TreeNode;6 import com.framsticks.gui.Frame; 6 7 import com.framsticks.util.dispatching.ExceptionResultHandler; 7 8 … … 9 10 10 11 public JPanel getPanel(); 11 public TreeNode getCurrentTreeNode(); 12 public TreePath getCurrentTreePath(); 13 public Frame getFrame(); 12 14 13 15 } -
java/main/src/main/java/com/framsticks/gui/controls/EnumControl.java
r85 r98 28 28 } 29 29 list.setEditable(false); 30 list.setEnabled(!isReadOnly());31 30 list.addItemListener(new ItemListener() { 32 31 @Override … … 61 60 } 62 61 62 @Override 63 protected void updateEnabled(boolean enabled) { 64 list.setEnabled(enabled); 65 66 } 67 63 68 } -
java/main/src/main/java/com/framsticks/gui/controls/EventControl.java
r84 r98 39 39 } 40 40 41 @Override 42 protected void updateEnabled(boolean enabled) { 43 button.setEnabled(enabled); 44 } 45 41 46 /* 42 47 @Override -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r97 r98 3 3 import com.framsticks.core.Tree; 4 4 import com.framsticks.core.Path; 5 import com.framsticks.gui.Frame; 5 6 import com.framsticks.gui.Gui; 6 import com.framsticks.gui.TreeNode;7 7 import com.framsticks.params.Param; 8 8 import com.framsticks.params.ValueParam; … … 15 15 import javax.swing.*; 16 16 import javax.swing.border.BevelBorder; 17 import javax.swing.tree.TreePath; 17 18 18 19 import org.apache.log4j.Logger; … … 20 21 import java.awt.event.ActionEvent; 21 22 import java.awt.event.ActionListener; 22 import java.util. HashMap;23 import java.util.IdentityHashMap; 23 24 import java.util.LinkedList; 24 25 import java.util.List; … … 32 33 protected final JButton procedureButton; 33 34 34 final protected Map<ValueParam, ValueControl> components = new HashMap<>();35 final protected Map<ValueParam, ValueControl> components = new IdentityHashMap<>(); 35 36 36 37 public ProcedureControl(ProcedureParam procedureParam) { … … 54 55 @Override 55 56 public void actionPerformed(ActionEvent e) { 56 TreeNode treeNode = owner.getCurrentTreeNode();57 assert treeNode != null;58 57 59 log.debug("calling " + getParam() + " on " + treeNode); 60 final Path path = treeNode.getTreePath(); 58 final Path path = getFrame().getTreeModel().convertToPath(getCurrentTreePath()); 61 59 62 60 final List<Object> arguments = new LinkedList<Object>(); … … 93 91 94 92 @Override 95 public TreeNode getCurrentTreeNode() {96 return owner.getCurrentTreeNode();97 }98 99 @Override100 93 public ProcedureParam getParam() { 101 94 return (ProcedureParam) param; 102 95 } 103 96 97 @Override 98 protected void updateEnabled(boolean enabled) { 99 procedureButton.setEnabled(enabled); 100 for (ValueControl vc : components.values()) { 101 vc.setUserEnabled(enabled); 102 } 103 } 104 105 @Override 106 public Frame getFrame() { 107 return owner.getFrame(); 108 } 109 110 @Override 111 public TreePath getCurrentTreePath() { 112 return owner.getCurrentTreePath(); 113 } 114 104 115 } -
java/main/src/main/java/com/framsticks/gui/controls/SliderControl.java
r97 r98 17 17 import org.apache.log4j.Logger; 18 18 19 import com.framsticks.params.Flags;20 19 import com.framsticks.params.types.DecimalParam; 21 20 import com.framsticks.params.types.FloatParam; … … 55 54 slider = new JSlider(); 56 55 57 slider.setEnabled(!isReadOnly());58 56 slider.setPaintLabels(false); 59 57 if (param instanceof DecimalParam) { … … 110 108 text.setHorizontalAlignment(JSlider.CENTER); 111 109 112 text.setEnabled(!param.hasFlag(Flags.READONLY));113 110 114 111 slider.addChangeListener(new ChangeListener() { … … 206 203 } 207 204 205 @Override 206 protected void updateEnabled(boolean enabled) { 207 slider.setEnabled(enabled); 208 text.setEnabled(enabled); 209 } 210 208 211 } -
java/main/src/main/java/com/framsticks/gui/controls/TextAreaControl.java
r97 r98 18 18 textArea.setLineWrap(true); 19 19 textArea.setWrapStyleWord(true); 20 textArea.setEditable(!isReadOnly());21 20 addDefaultDocumentListener(textArea); 22 21 … … 47 46 } 48 47 48 @Override 49 protected void updateEnabled(boolean enabled) { 50 textArea.setEditable(enabled); 51 } 52 49 53 } -
java/main/src/main/java/com/framsticks/gui/controls/TextFieldControl.java
r90 r98 31 31 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); 32 32 33 textField.setEditable(!isReadOnly());34 35 33 addDefaultDocumentListener(textField); 36 34 … … 48 46 } 49 47 48 @Override 49 protected void updateEnabled(boolean enabled) { 50 textField.setEnabled(enabled); 51 } 52 50 53 } -
java/main/src/main/java/com/framsticks/gui/controls/ValueControl.java
r97 r98 97 97 } 98 98 99 public final boolean isReadOnly() {100 return (param.getFlags() & Flags.READONLY) != 0;101 }102 103 104 99 105 100 } -
java/main/src/main/java/com/framsticks/gui/view/TreeCellRenderer.java
r90 r98 1 1 package com.framsticks.gui.view; 2 2 3 import com.framsticks.gui.ImageProvider; 4 import com.framsticks.gui.TreeNode; 3 import java.awt.Component; 5 4 6 import javax.swing. *;5 import javax.swing.JTree; 7 6 import javax.swing.tree.DefaultTreeCellRenderer; 8 7 9 import org.apache.log4j.Logger;10 11 import java.awt.*;8 import com.framsticks.gui.AbstractNode; 9 import com.framsticks.gui.ImageProvider; 10 import com.framsticks.params.CompositeParam; 12 11 13 12 /** … … 16 15 @SuppressWarnings("serial") 17 16 public class TreeCellRenderer extends DefaultTreeCellRenderer { 18 private static final Logger log =19 Logger.getLogger(TreeCellRenderer.class);20 21 17 22 18 public TreeCellRenderer() { 23 setOpenIcon(null); 24 setClosedIcon(null); 25 setLeafIcon(null); 19 20 // setOpenIcon(ImageProvider.loadImage(ImageProvider.FOLDER_OPEN)); 21 // setClosedIcon(ImageProvider.loadImage(ImageProvider.FOLDER_CLOSED)); 22 // setLeafIcon(ImageProvider.loadImage(ImageProvider.NODE)); 26 23 } 27 24 … … 31 28 boolean hasFocus) { 32 29 33 //super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,34 // row, hasFocus); 30 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 31 35 32 if (value == null) { 33 setText("!null value"); 36 34 return this; 37 35 } 38 if (!(value instanceof TreeNode)) { 36 37 if (!(value instanceof AbstractNode)) { 39 38 setIcon(ImageProvider.loadImage(ImageProvider.SERVER)); 40 39 setText("framsticks"); 41 40 return this; 42 41 } 43 TreeNode treeNode = (TreeNode)value; 44 assert treeNode.getFrame().isActive(); 45 setToolTipText(treeNode.getTooltip()); 46 setIcon(ImageProvider.loadImage(treeNode.getIconName())); 47 setText(treeNode.getName()); 42 ((AbstractNode) value).render(this); 43 48 44 return this; 49 45 } 50 46 51 public static String findIconName(String nodeName, String path) { 52 if (nodeName == null || path == null) { 53 log.warn("given invalid parameters: " + nodeName + " " + path); 54 // return null; 55 return ImageProvider.SERVER; 47 public static String findIconName(CompositeParam param) { 48 switch (param.getFramsTypeName()) { 49 case "o Server": return ImageProvider.SERVER; 50 case "o Simulator": return ImageProvider.SIMULATOR; 51 case "o CLI": return ImageProvider.CLI; 52 case "o World": return ImageProvider.WORLD; 53 case "o GenePools": return ImageProvider.GENEPOOLS; 54 case "l GenePool": return ImageProvider.SIMULATOR; //HERE 55 case "o GenePool": return ImageProvider.GENEPOOLS_GROUP; //HERE 56 57 case "o Populations": return ImageProvider.POPULATIONS; 58 case "l Population": return ImageProvider.SIMULATOR; ///HERE 59 case "o Population": return ImageProvider.POPULATION_GROUP; 60 case "o ExpParams": return ImageProvider.EXPERIMENT; 61 case "o stats": return ImageProvider.STATISTIC; 62 case "l Genotype uid": return ImageProvider.GENOTYPES_GROUP; 63 case "o Genotype": return ImageProvider.GENOTYPES; 64 65 case "o Part": return ImageProvider.PART; 66 case "o Joint": return ImageProvider.JOINT; 67 case "o NeuroDef": return ImageProvider.NEURON_DEF; 68 case "o NeuroConn": return ImageProvider.NEURON_DEF; 69 70 case "o MechPart": return ImageProvider.MECH_PART; 71 case "o MechJoint": return ImageProvider.MECH_JOINT; 72 case "o Neuro": return ImageProvider.NEURON; 73 74 case "l Part": return ImageProvider.PART_GROUP; 75 case "l Joint": return ImageProvider.JOINT_GROUP; 76 case "l NeuroDef": return ImageProvider.NEURON_DEF_GROUP; 77 case "l NeuroConn": return ImageProvider.NEURON_DEF_GROUP; 78 79 case "l MechPart": return ImageProvider.MECH_PART_GROUP; 80 case "l MechJoint": return ImageProvider.MECH_JOINT_GROUP; 81 case "l Neuro": return ImageProvider.NEURON_GROUP; 82 83 case "o Creature": return ImageProvider.CREATURE; 84 case "l Creature uid": return ImageProvider.CREATURES_GROUP; 85 case "l Event id": return ImageProvider.EVENT; 86 case "o Event": return ImageProvider.EVENT; 87 56 88 } 57 if (path.equals("/")) { 58 return ImageProvider.SERVER; 59 } 60 if (path.endsWith("simulator")) { 61 return ImageProvider.SIMULATOR; 62 } 63 if (path.endsWith("cli")) { 64 return ImageProvider.CLI; 65 } 66 if (path.endsWith("world")) { 67 return ImageProvider.WORLD; 68 } 69 if (path.endsWith("genepools")) { 70 return ImageProvider.GENEPOOLS; 71 } 72 if (path.endsWith("populations")) { 73 return ImageProvider.POPULATIONS; 74 } 75 if (path.endsWith("experiment")) { 76 return ImageProvider.EXPERIMENT; 77 } 78 if (path.endsWith("stats")) { 79 return ImageProvider.STATISTIC; 80 } 81 if (nodeName.equals("creatures") || path.endsWith("creatures")) { 82 return ImageProvider.CREATURES_GROUP; 83 } 84 if (nodeName.equals("Favourite Fields")) { 85 return ImageProvider.FAVORITE_FIELDS; 86 } 87 if (nodeName.equals("genotypes") || path.endsWith("creatures")) { 88 return ImageProvider.GENOTYPES_GROUP; 89 } 90 if (nodeName.equals("parts") || path.endsWith("parts")) { 91 return ImageProvider.PART_GROUP; 92 } 93 if (nodeName.equals("joints") || path.endsWith("joints")) { 94 return ImageProvider.JOINT_GROUP; 95 } 96 if (nodeName.equals("neurodefs") || path.endsWith("neurodefs")) { 97 return ImageProvider.NEURON_DEF_GROUP; 98 } 99 if (nodeName.equals("neuroconns") || path.endsWith("neuroconns")) { 100 return ImageProvider.NEURON_DEF_GROUP; 101 } 102 if (nodeName.equals("mechparts") || path.endsWith("mechparts")) { 103 return ImageProvider.MECH_PART_GROUP; 104 } 105 if (nodeName.equals("mechjoints") || path.endsWith("mechjoints")) { 106 return ImageProvider.MECH_JOINT_GROUP; 107 } 108 if (nodeName.equals("neurons") || path.endsWith("neurons")) { 109 return ImageProvider.NEURON_GROUP; 110 } 111 if (path.matches("^.*parts/[0-9]+$")) { 112 return ImageProvider.PART; 113 } 114 if (path.matches("^.*joints/[0-9]+$")) { 115 return ImageProvider.JOINT; 116 } 117 if (path.matches("^.*neurodefs/[0-9]+$")) { 118 return ImageProvider.NEURON_DEF; 119 } 120 if (path.matches("^.*neuroconns/[0-9]+$")) { 121 return ImageProvider.NEURON_DEF; 122 } 123 if (path.matches("^.*mechparts/[0-9]+$")) { 124 return ImageProvider.MECH_PART; 125 } 126 if (path.matches("^.*mechjoints/[0-9]+$")) { 127 return ImageProvider.MECH_JOINT; 128 } 129 if (path.matches("^.*neurons/[0-9]+$")) { 130 return ImageProvider.NEURON; 131 } 132 if (path.matches("^.*creatures/c[0-9]+$")) { 133 return ImageProvider.CREATURE; 134 } 135 if (path.matches("^.*genotypes/g[0-9]+$")) { 136 return ImageProvider.GENOTYPES; 137 } 138 if (path.matches("^.*populations/groups/[0-9]+$")) { 139 return ImageProvider.POPULATION_GROUP; 140 } 141 if (path.matches("^.*genepools/groups/[0-9]+$")) { 142 return ImageProvider.GENEPOOLS_GROUP; 143 } 144 if (path.matches("^.*events/e[0-9]+$")) { 145 return ImageProvider.EVENT; 146 } 147 return ImageProvider.SIMULATOR; 89 90 91 return ImageProvider.SERVER; 148 92 } 149 93 150 94 95 151 96 } -
java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java
r97 r98 9 9 import com.framsticks.communication.queries.InfoRequest; 10 10 import com.framsticks.communication.queries.SetRequest; 11 import com.framsticks.core.Mode;12 11 import com.framsticks.core.Tree; 13 12 import com.framsticks.core.Path; … … 18 17 import com.framsticks.util.dispatching.AbstractJoinable; 19 18 import com.framsticks.util.dispatching.Dispatching; 19 import com.framsticks.util.dispatching.ExceptionResultHandler; 20 20 import com.framsticks.util.dispatching.FutureHandler; 21 21 import com.framsticks.util.dispatching.Joinable; … … 31 31 * @author Piotr Sniegowski 32 32 */ 33 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent {33 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, ExceptionResultHandler { 34 34 35 35 protected final Server server; … … 52 52 assureNotEmpty(request.getPath()); 53 53 54 resolve(tree, request.getPath(), new FutureHandler<Path>(responseCallback) {54 tryGet(tree, request.getPath(), new FutureHandler<Path>(responseCallback) { 55 55 @Override 56 56 protected void result(final Path path) { 57 58 if (!path.getTextual().equals(request.getPath())) { 59 throw new FramsticksException().msg("invalid path").arg("path", request.getPath()); 60 } 57 61 58 62 // final AccessInterface access = tree.prepareAccess(path); … … 73 77 74 78 if (request instanceof GetRequest) { 75 tree.get(path, Mode.FETCH, new FutureHandler<Object>(responseCallback) { 76 77 @Override 78 protected void result(Object result) { 79 if (result != access.getSelected()) { 80 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path); 81 } 82 // TODO Auto-generated method stub 83 List<File> files = new LinkedList<File>(); 84 ListSink sink = new ListSink(); 85 access.save(sink); 86 files.add(new File(path.getTextual(), new ListSource(sink.getOut()))); 87 responseCallback.pass(new Response(true, "", files)); 88 } 89 }); 79 Object result = path.getTopObject(); 80 if (result != access.getSelected()) { 81 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path); 82 } 83 List<File> files = new LinkedList<File>(); 84 ListSink sink = new ListSink(); 85 access.save(sink); 86 files.add(new File(path.getTextual(), new ListSource(sink.getOut()))); 87 responseCallback.pass(new Response(true, "", files)); 90 88 91 89 return; … … 148 146 } 149 147 148 @Override 149 public void handle(FramsticksException exception) { 150 tree.handle(exception); 151 } 150 152 151 153 } -
java/main/src/main/java/com/framsticks/hosting/Server.java
r97 r98 124 124 return; 125 125 } 126 //TODO TEH 127 acceptThread.dispatch(new RunAt<Accept>(ThrowExceptionHandler.getInstance()) { 126 acceptThread.dispatch(new RunAt<Accept>(hosted) { 128 127 @Override 129 128 protected void runAt() { -
java/main/src/main/java/com/framsticks/params/AccessInterface.java
r97 r98 1 1 package com.framsticks.params; 2 2 3 import java.util.Collection;4 3 5 4 import com.framsticks.params.types.ProcedureParam; … … 71 70 Object createAccessee(); 72 71 73 Collection<Param> getParams();72 Iterable<Param> getParams(); 74 73 75 74 FramsClass getFramsClass(); … … 77 76 void tryAutoAppend(Object object); 78 77 78 int getCompositeParamCount(); 79 80 CompositeParam getCompositeParam(int number); 81 79 82 80 83 } -
java/main/src/main/java/com/framsticks/params/ArrayListAccess.java
r90 r98 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.util.UnimplementedException; 3 4 import com.framsticks.util.lang.Numbers; 4 5 5 6 import java.util.ArrayList; 6 import java.util.Collection; 7 import java.util.LinkedList; 7 import java.util.Iterator; 8 8 import java.util.List; 9 import java.util.ListIterator; 9 10 10 11 /** … … 30 31 31 32 @Override 32 public Param getParam(int i) { 33 //TODO listAccessParam 34 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(); 33 public CompositeParam getParam(int i) { 34 if ((i < 0) || (i >= list.size())) { 35 return null; 36 } 37 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class); 35 38 } 36 39 37 40 @Override 38 public Param getParam(String id) {41 public CompositeParam getParam(String id) { 39 42 Integer i = Numbers.parse(id, Integer.class); 40 43 return (i == null ? null : getParam(i)); … … 53 56 @Override 54 57 public <T> T get(int i, Class<T> type) { 55 if ( i < list.size()) {56 return type.cast(list.get(i));58 if ((i < 0) || (i >= list.size())) { 59 return null; 57 60 } 58 return null;61 return type.cast(list.get(i)); 59 62 } 60 63 … … 112 115 113 116 @Override 114 public Collection<Param> getParams() { 115 List<Param> result = new LinkedList<Param>(); 116 if (list == null) { 117 return result; 118 } 119 for (int i = 0; i < list.size(); ++i) { 120 result.add(getParam(i)); 121 } 122 return result; 117 public Iterable<Param> getParams() { 118 return new Iterable<Param>() { 119 120 @Override 121 public Iterator<Param> iterator() { 122 return new Iterator<Param>() { 123 124 protected ListIterator<Object> internal = list.listIterator(); 125 126 @Override 127 public boolean hasNext() { 128 return internal.hasNext(); 129 } 130 131 @Override 132 public Param next() { 133 Param param = Param.build().id(Integer.toString(internal.nextIndex())).forAccess(elementAccess).finish(); 134 internal.next(); 135 return param; 136 } 137 138 @Override 139 public void remove() { 140 throw new UnimplementedException().msg("remove element from list").arg("list", ArrayListAccess.this); 141 142 } 143 }; 144 } 145 }; 146 } 147 148 @Override 149 public int getCompositeParamCount() { 150 return list.size(); 151 } 152 153 @Override 154 public CompositeParam getCompositeParam(int number) { 155 return getParam(number); 123 156 } 124 157 -
java/main/src/main/java/com/framsticks/params/CompositeParam.java
r87 r98 36 36 } 37 37 38 @Override 39 public String toString() { 40 return getId() + ":" + this.getClass().getSimpleName() + "(" + containedTypeName + ")"; 41 } 42 38 43 } -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r96 r98 43 43 protected final List<Param> paramList; 44 44 45 protected final List<CompositeParam> compositeParamList = new ArrayList<>(); 46 45 47 /** 46 48 * The param entry map <parameterId, param> (for fast accessing of parameters 47 49 * by their name) 48 50 */ 49 protected Map<String, Param> paramEntryMap = new LinkedHashMap<String, Param>(); 50 51 // /** The param getId map (for fast lookup of offset based on name */ 52 // protected Map<String, Integer> paramIdMap = new HashMap<String, Integer>(); 51 protected Map<String, Param> paramEntryMap = new HashMap<>(); 52 53 53 54 54 @ParamAnnotation(id = "props", name = "props") … … 67 67 for (Param param : paramList) { 68 68 paramEntryMap.put(param.getId(), param); 69 if (param instanceof CompositeParam) { 70 compositeParamList.add((CompositeParam) param); 71 } 69 72 } 70 73 … … 182 185 } 183 186 187 public final int getCompositeParamCount() { 188 return compositeParamList.size(); 189 } 190 191 public final CompositeParam getCompositeParam(int i) { 192 return compositeParamList.get(i); 193 } 194 184 195 @Override 185 196 public String toString() { … … 190 201 return new FramsClassBuilder(); 191 202 } 203 192 204 } -
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r96 r98 9 9 import java.util.ArrayList; 10 10 import java.util.Collections; 11 import java.util. HashMap;11 import java.util.IdentityHashMap; 12 12 import java.util.LinkedList; 13 13 import java.util.List; … … 197 197 } 198 198 199 public static final Map<Class<?>, FramsClass> synchronizedCacheForBasedOnForJavaClass = Collections.synchronizedMap(new HashMap<Class<?>, FramsClass>());199 public static final Map<Class<?>, FramsClass> synchronizedCacheForBasedOnForJavaClass = Collections.synchronizedMap(new IdentityHashMap<Class<?>, FramsClass>()); 200 200 201 201 public FramsClass forClass(Class<?> javaClass) throws ConstructionException { -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r96 r98 8 8 import java.util.Comparator; 9 9 import java.util.HashMap; 10 import java.util.IdentityHashMap; 10 11 import java.util.List; 11 12 import java.util.Map; … … 56 57 } 57 58 58 protected final Map<ValueParam, ReflectedSetter> setters = new HashMap<>();59 protected final Map<ValueParam, ReflectedGetter> getters = new HashMap<>();60 protected final Map<ProcedureParam, ReflectedCaller> callers = new HashMap<>();59 protected final Map<ValueParam, ReflectedSetter> setters = new IdentityHashMap<>(); 60 protected final Map<ValueParam, ReflectedGetter> getters = new IdentityHashMap<>(); 61 protected final Map<ProcedureParam, ReflectedCaller> callers = new IdentityHashMap<>(); 61 62 protected final List<Method> autoAppendMethods = new ArrayList<>(); 62 63 -
java/main/src/main/java/com/framsticks/params/Registry.java
r96 r98 7 7 import com.framsticks.util.DoubleMap; 8 8 import com.framsticks.util.FramsticksException; 9 import com.framsticks.util.lang.Strings; 9 10 10 import java.util. HashMap;11 import java.util.IdentityHashMap; 11 12 import java.util.Map; 12 13 import java.util.Set; … … 23 24 protected final DoubleMap<String, Class<?>> javaClasses = new DoubleMap<>(); 24 25 protected final DoubleMap<String, FramsClass> framsClasses = new DoubleMap<>(); 25 protected final Map<Class<?>, FramsClass> javaToFramsAssociation = new HashMap<>();26 protected final Map<Class<?>, FramsClass> javaToFramsAssociation = new IdentityHashMap<>(); 26 27 27 28 /** … … 108 109 public @Nonnull AccessInterface createAccess(@Nonnull String name) throws ConstructionException { 109 110 try { 111 Strings.assureNotEmpty(name); 110 112 FramsClass framsClass = getFramsClass(name); 111 113 if (framsClass == null) { -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r97 r98 1 1 package com.framsticks.params; 2 2 3 import java.util.Collection;4 3 5 4 import static com.framsticks.util.lang.Containers.filterInstanceof; … … 113 112 ReassignResult<?> result = param.reassign(value, oldValue); 114 113 Object casted = result.getValue(); 115 if ( !casted.equals(oldValue)) {114 if (casted != null && !casted.equals(oldValue)) { 116 115 internalSet(param, casted); 117 116 } … … 273 272 274 273 @Override 275 public Collection<Param> getParams() {274 public Iterable<Param> getParams() { 276 275 return framsClass.getParamEntries(); 276 } 277 278 @Override 279 public int getCompositeParamCount() { 280 return framsClass.getCompositeParamCount(); 281 } 282 283 @Override 284 public CompositeParam getCompositeParam(int number) { 285 return framsClass.getCompositeParam(number); 277 286 } 278 287 -
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r90 r98 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.UnimplementedException; 5 import com.framsticks.util.UnsupportedOperationException; 3 6 import com.framsticks.util.lang.Casting; 4 7 import com.framsticks.util.lang.Numbers; … … 12 15 public class UniqueListAccess extends ListAccess { 13 16 14 private static final Logger log = Logger.getLogger(UniqueListAccess.class .getName());17 private static final Logger log = Logger.getLogger(UniqueListAccess.class); 15 18 16 19 Map<String, Object> map; … … 23 26 } 24 27 28 public static Integer getUidNumber(String uid) { 29 try { 30 return Integer.valueOf(uid.substring(1)); 31 } catch (NumberFormatException e) { 32 return null; 33 } 34 } 35 36 public static class UidComparator implements Comparator<String> { 37 38 protected String name; 39 40 /** 41 * @param name 42 */ 43 public UidComparator(String name) { 44 this.name = name; 45 } 46 47 @Override 48 public int compare(String a, String b) { 49 if (a.equals(b)) { 50 return 0; 51 } 52 int diff = a.length() - b.length(); 53 if (diff != 0) { 54 return diff; 55 } 56 Integer au = getUidNumber(a); 57 Integer bu = getUidNumber(b); 58 if (au == null || bu == null) { 59 throw new FramsticksException().msg("comparator failure").arg("left", a).arg("right", b).arg("in", this); 60 } 61 return au - bu; 62 } 63 64 @Override 65 public String toString() { 66 return "comparator " + name; 67 } 68 69 70 } 71 25 72 @Override 26 73 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 Param.build().setId(Integer.toString(i)).setName(elementAccess.getId()).type("o " + elementAccess.getId()).build(); 38 } 39 40 @Override 41 public Param getParam(String id) { 74 return new TreeMap<String, Object>(new UidComparator(elementAccess.toString())); 75 } 76 77 @Override 78 public CompositeParam getParam(int i) { 79 if ((i < 0) || (i >= map.size())) { 80 return null; 81 } 82 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class); 83 } 84 85 @Override 86 public CompositeParam getParam(String id) { 42 87 Integer i = Numbers.parse(id, Integer.class); 43 88 if (i != null) { 44 89 return getParam(i); 45 90 } 46 //TODO list access here 47 return Param.build().id(id).forAccess(elementAccess).finish(); 91 Integer uidNumber = getUidNumber(id); 92 if (uidNumber == null) { 93 return null; 94 } 95 if (!map.containsKey(id)) { 96 return null; 97 } 98 return Param.build().id(id).forAccess(elementAccess).finish(CompositeParam.class); 48 99 } 49 100 … … 60 111 @Override 61 112 public <T> T get(int i, Class<T> type) { 62 log.error("accesing unique list through index"); 63 assert false; 64 return null; 65 //Object[] values = map.values().toArray(); 66 //return Casting.tryCast(i < values.length ? values[i] : null, type); 113 Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator(); 114 while (i > 0 && iterator.hasNext()) { 115 iterator.next(); 116 --i; 117 } 118 if (i > 0) { 119 return null; 120 } 121 if (!iterator.hasNext()) { 122 return null; 123 } 124 return Casting.tryCast(type, iterator.next().getValue()); 67 125 } 68 126 … … 73 131 return get(i, type); 74 132 } 75 return Casting.tryCast(type, map.containsKey(id) ? map.get(id) : null); 133 Integer uidNumber = getUidNumber(id); 134 if (uidNumber == null) { 135 return null; 136 } 137 return Casting.tryCast(type, map.get(id)); 76 138 } 77 139 … … 110 172 @Override 111 173 public <T> int set(int i, T value) { 112 log.error("accesing unique list through index"); 113 //return setByUid(value, null); 114 return 0; 174 throw new UnsupportedOperationException().msg("accesing unique list through index"); 115 175 } 116 176 … … 184 244 185 245 @Override 186 public Collection<Param> getParams() { 187 List<Param> result = new LinkedList<Param>(); 188 if (map == null) { 189 return result; 190 } 191 for (String k : map.keySet()) { 192 result.add(getParam(k)); 193 } 194 return result; 246 public Iterable<Param> getParams() { 247 return new Iterable<Param>() { 248 249 @Override 250 public Iterator<Param> iterator() { 251 return new Iterator<Param>() { 252 253 protected Iterator<Map.Entry<String, Object>> internal = map.entrySet().iterator(); 254 255 @Override 256 public boolean hasNext() { 257 return internal.hasNext(); 258 } 259 260 @Override 261 public Param next() { 262 return Param.build().id(internal.next().getKey()).forAccess(elementAccess).finish(); 263 } 264 265 @Override 266 public void remove() { 267 throw new UnimplementedException().msg("remove element from list").arg("list", UniqueListAccess.this); 268 269 } 270 }; 271 } 272 }; 273 } 274 275 @Override 276 public int getCompositeParamCount() { 277 return map.size(); 278 } 279 280 @Override 281 public CompositeParam getCompositeParam(int number) { 282 return getParam(number); 195 283 } 196 284 } -
java/main/src/main/java/com/framsticks/params/types/ObjectParam.java
r90 r98 50 50 } 51 51 52 52 53 } -
java/main/src/main/java/com/framsticks/params/types/UniqueListParam.java
r87 r98 6 6 import com.framsticks.params.ReassignResult; 7 7 import com.framsticks.params.UniqueListAccess; 8 import com.framsticks.util.lang.Casting; 8 9 import com.framsticks.util.lang.Numbers; 9 10 10 import java.util.HashMap;11 11 import java.util.Map; 12 12 … … 54 54 information about it's elements is available, which would break resolution flow 55 55 */ 56 if (oldValue != null) { 57 return new ReassignResult<Map<?,?>>((Map<?,?>) oldValue); 58 } 59 return ReassignResult.create(new HashMap<Object, Object>()); 56 return new ReassignResult<Map<?,?>>(Casting.tryCast(Map.class, oldValue)); 57 // return ReassignResult.create(new TreeMap<Object, Object>()); 60 58 } 61 59 -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r97 r98 7 7 import java.text.ParseException; 8 8 import java.util.ArrayList; 9 import java.util.Collection;10 9 import java.util.List; 11 10 … … 176 175 List<Exception> exceptions = new ArrayList<Exception>(); 177 176 178 Collection<Param> paramsC = access.getParams(); 179 Param[] params = paramsC.toArray(new Param[] {null}); 177 List<Param> paramsL = new ArrayList<>(); 178 179 for (Param param : access.getParams()) { 180 paramsL.add(param); 181 } 182 183 Param[] params = paramsL.toArray(new Param[] {null}); 180 184 if (params.length == 0) { 181 185 return exceptions; 182 186 } 183 for (PrimitiveParam<?> p : Containers.filterInstanceof(params C, PrimitiveParam.class)) {187 for (PrimitiveParam<?> p : Containers.filterInstanceof(paramsL, PrimitiveParam.class)) { 184 188 Object def = p.getDef(Object.class); 185 189 if (def != null) { -
java/main/src/main/java/com/framsticks/portals/Portal.java
r97 r98 2 2 3 3 4 import com.framsticks.core.AbstractTreeListener;5 4 import com.framsticks.core.Tree; 6 import com.framsticks.core.TreeOperations;7 import com.framsticks.core.Path;8 5 import com.framsticks.params.annotations.FramsClassAnnotation; 9 6 import com.framsticks.params.annotations.ParamAnnotation; 10 import com.framsticks.util.Logging;11 import com.framsticks.util.dispatching.Dispatching;12 import com.framsticks.util.dispatching.FutureHandler;13 7 import com.framsticks.util.dispatching.JoinableCollection; 14 import com.framsticks.util.dispatching.RunAt;15 import com.framsticks.util.dispatching.ThrowExceptionHandler;16 17 import org.apache.log4j.Logger;18 8 19 9 … … 23 13 @FramsClassAnnotation 24 14 public class Portal extends JoinableCollection<Tree> { 25 26 private final static Logger log = Logger.getLogger(Portal.class.getName());27 15 28 16 @ParamAnnotation … … 49 37 public void add(final Tree tree) { 50 38 super.add(tree); 51 tree.addListener(new AbstractTreeListener() {52 @Override53 public void onRun(Exception e) {54 assert Dispatching.isThreadSafe();39 // tree.addListener(new AbstractTreeListener() { 40 // @Override 41 // public void onRun(Exception e) { 42 // assert Dispatching.isThreadSafe(); 55 43 56 super.onRun(e);44 // super.onRun(e); 57 45 58 if (e != null) {59 return;60 }61 final String path = "/simulator/genepools/groups/0/genotypes";62 tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) {63 @Override64 protected void runAt() {65 TreeOperations.resolve(tree, path, new FutureHandler<Path>(Logging.logger(log, "resolve", path)) {66 @Override67 public void result(Path result) {68 Logging.log(log, "resolve", path, null);69 }70 });71 }72 });73 }74 });46 // if (e != null) { 47 // return; 48 // } 49 // final String path = "/simulator/genepools/groups/0/genotypes"; 50 // tree.dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 51 // @Override 52 // protected void runAt() { 53 // tryGet(tree, path, new FutureHandler<Path>(Logging.logger(log, "resolve", path)) { 54 // @Override 55 // public void result(Path result) { 56 // Logging.log(log, "resolve", path, null); 57 // } 58 // }); 59 // } 60 // }); 61 // } 62 // }); 75 63 } 76 64 -
java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.java
r97 r98 55 55 for (CompositeParam p : filterInstanceof(access.getParams(), CompositeParam.class)) { 56 56 Object child = access.get(p, Object.class); 57 final Path childPath = path.appendNode(new Node(p , child));57 final Path childPath = path.appendNode(new Node(path.getTree(), p, child)); 58 58 if (childPath.isResolved() && getInfoFromCache(childPath) != null) { 59 59 ++dispatched; … … 67 67 } 68 68 ++dispatched; 69 tree. resolve(childPath, new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {69 tree.get(childPath, Mode.FETCH, new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) { 70 70 @Override 71 71 protected void result(Path result) { … … 83 83 84 84 protected void fetch(final Path path) { 85 tree.get(path, Mode.FETCH, new Future< Object>() {85 tree.get(path, Mode.FETCH, new Future<Path>() { 86 86 87 87 @Override … … 92 92 93 93 @Override 94 protected void result( Object object) {95 process( path);94 protected void result(Path result) { 95 process(result); 96 96 } 97 97 }); -
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r97 r98 8 8 import com.framsticks.core.AbstractTree; 9 9 import com.framsticks.core.Mode; 10 import com.framsticks.core.TreeOperations;11 10 import com.framsticks.core.ListChange; 12 import com.framsticks.core.Node;13 11 import com.framsticks.core.Path; 14 12 import com.framsticks.params.*; … … 22 20 import com.framsticks.util.*; 23 21 import com.framsticks.util.dispatching.Dispatching; 22 import com.framsticks.util.dispatching.Dispatching.DispatcherWaiter; 24 23 import com.framsticks.util.dispatching.Future; 25 24 import com.framsticks.util.dispatching.FutureHandler; … … 27 26 import com.framsticks.util.dispatching.JoinableParent; 28 27 import com.framsticks.util.dispatching.JoinableState; 28 import com.framsticks.util.dispatching.ThrowExceptionHandler; 29 29 import com.framsticks.util.lang.Casting; 30 30 import com.framsticks.util.lang.Pair; … … 52 52 public Pair<Path, Subscription<?>> getSubscription(Path path) { 53 53 for (Pair<Path, Subscription<?>> s : subscriptions) { 54 if (s.first. matches(path)) {54 if (s.first.isTheSameObjects(path)) { 55 55 return s; 56 56 } … … 75 75 public void setConnection(final ClientSideManagedConnection connection) { 76 76 this.connection = connection; 77 // final ExceptionResultHandler failure = new ExceptionResultHandler() { 78 // @Override 79 // public void handle(FramsticksException exception) { 80 // log.fatal("failed to establish connection: ", exception); 81 // // log.fatal("unsupported protocol version!\n minimal version is: " + "\nmanager protocol is: " + connection.getProtocolVersion()); 82 // Dispatching.drop(connection, RemoteTree.this); 83 // fireRun(exception); 84 // } 85 // }; 86 77 } 78 79 public final ClientSideManagedConnection getConnection() { 80 return connection; 87 81 } 88 82 … … 93 87 } 94 88 95 public final ClientSideManagedConnection getConnection() { 96 return connection; 97 } 98 99 @Override 100 public void get(final Path path, final PrimitiveParam<?> param, Mode mode, final Future<Object> future) { 89 @Override 90 public void get(final Path path, final ValueParam param, Mode mode, final Future<Object> future) { 101 91 assert isActive(); 102 92 assert param != null; 103 assert path.isResolved();93 // assert path.isResolved(); 104 94 //TODO only do that if needed 105 95 connection.send(new GetRequest().field(param.getId()).path(path.getTextual()), this, new ClientSideResponseFuture(future) { … … 107 97 protected void processOk(Response response) { 108 98 assert isActive(); 109 TreeOperations.processFetchedValues(path, response.getFiles());110 future.pass(bindAccess(path ).get(param, Object.class));99 processFetchedValues(path, response.getFiles()); 100 future.pass(bindAccess(path.tryResolveIfNeeded()).get(param, Object.class)); 111 101 } 112 102 }); … … 164 154 throw new FramsticksException().msg("path mismatch").arg("returned path", response.getFiles().get(0).getPath()); 165 155 } 166 FramsClass framsClass = TreeOperations.processFetchedInfo(RemoteTree.this, response.getFiles().get(0));156 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 167 157 168 158 CompositeParam thisParam = path.getTop().getParam(); … … 176 166 177 167 @Override 178 public void get(final Path path, Mode mode, final Future<Object> future) { 179 assert isActive(); 180 assert path.getTop().getObject() != null; 168 public void get(final Path path, final Mode mode, final Future<Path> future) { 169 assert isActive(); 181 170 182 171 log.trace("fetching values for " + path); 183 connection.send(new GetRequest().path(path.getTextual()), this, new ClientSideResponseFuture(future) { 184 @Override 185 protected void processOk(Response response) { 186 assert isActive(); 187 TreeOperations.processFetchedValues(path, response.getFiles()); 188 future.pass(path.getTopObject()); 189 } 190 }); 191 } 192 193 @Override 194 public void resolve(final Path path, final Future<Path> future) { 195 TreeOperations.resolve(path, future); 196 } 172 findInfo(path, new FutureHandler<FramsClass>(future) { 173 @Override 174 protected void result(FramsClass result) { 175 176 connection.send(new GetRequest().path(path.getTextual()), RemoteTree.this, new ClientSideResponseFuture(future) { 177 @Override 178 protected void processOk(Response response) { 179 assert isActive(); 180 Path p = path.tryResolveIfNeeded(); 181 processFetchedValues(p, response.getFiles()); 182 future.pass(p.tryResolveIfNeeded().assureResolved()); 183 } 184 }); 185 } 186 }); 187 } 188 197 189 198 190 @Override 199 191 protected void tryRegisterOnChangeEvents(final Path path) { 200 192 assert isActive(); 201 AccessInterface access = TreeOperations.bindAccess(path);193 AccessInterface access = bindAccess(path); 202 194 if (!(access instanceof ListAccess)) { 203 195 return; … … 274 266 protected void result(Path result) { 275 267 log.debug(listChange + ": " + result); 276 fireListChange(result, listChange);277 268 } 278 269 }; … … 282 273 assert isActive(); 283 274 log.debug("reacting to change " + listChange + " in " + path); 284 AccessInterface access = TreeOperations.bindAccess(path);275 AccessInterface access = bindAccess(path); 285 276 assert access != null; 286 277 287 278 if ((listChange.getAction() == ListChange.Action.Modify) && (listChange.getPosition() == -1)) { 288 279 final String p = path.getTextual(); 289 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));280 tryGet(this, p, futureListChanger(listChange, p)); 290 281 return; 291 282 } … … 296 287 case Add: { 297 288 final String p = path.getTextual() + "/" + childParam.getId(); 298 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));289 tryGet(this, p, futureListChanger(listChange, p)); 299 290 break; 300 291 } 301 292 case Remove: { 302 293 access.set(childParam, null); 303 fireListChange(path, listChange);304 294 break; 305 295 } 306 296 case Modify: { 307 297 final String p = path.getTextual() + "/" + childParam.getId(); 308 TreeOperations.resolveAndGet(this, p, futureListChanger(listChange, p));298 tryGet(this, p, futureListChanger(listChange, p)); 309 299 break; 310 300 } … … 315 305 public void set(final Path path, final PrimitiveParam<?> param, final Object value, final Future<Integer> future) { 316 306 assert isActive(); 317 final Integer flag = TreeOperations.bindAccess(path).set(param, value);307 final Integer flag = bindAccess(path).set(param, value); 318 308 319 309 log.trace("storing value " + param + " for " + path); … … 331 321 Dispatching.use(connection, this); 332 322 super.joinableStart(); 323 324 dispatch(new RunAt<RemoteTree>(ThrowExceptionHandler.getInstance()) { 325 @Override 326 protected void runAt() { 327 final DispatcherWaiter<Tree, Tree> waiter = new DispatcherWaiter<Tree, Tree>(RemoteTree.this); 328 329 connection.send(new InfoRequest().path("/"), waiter, new ClientSideResponseFuture(this) { 330 @Override 331 protected void processOk(Response response) { 332 FramsClass framsClass = processFetchedInfo(RemoteTree.this, response.getFiles().get(0)); 333 assignRootParam(Param.build().name("Tree").id(RemoteTree.this.getName()).type("o " + framsClass.getId()).finish(CompositeParam.class)); 334 } 335 }); 336 337 waiter.waitFor(); 338 } 339 }); 333 340 } 334 341 … … 373 380 } 374 381 375 @Override 376 public Path create(Path path) { 377 assert isActive(); 378 assert !path.isResolved(); 379 Path resolved = path.tryFindResolution(); 380 if (!resolved.isResolved()) { 381 log.debug("creating: " + path); 382 AccessInterface access = registry.prepareAccess(path.getTop().getParam()); 383 assert access != null; 384 Object child = access.createAccessee(); 385 assert child != null; 386 if (path.size() == 1) { 387 setRoot(new Node(getRoot().getParam(), child)); 388 } else { 389 bindAccess(this, path.getUnder()).set(path.getTop().getParam(), child); 390 } 391 resolved = path.appendResolution(child); 392 } 393 tryRegisterOnChangeEvents(resolved); 394 return resolved; 395 } 382 // @Override 383 // public Path create(Path path) { 384 // assert isActive(); 385 // assert !path.isResolved(); 386 // Path resolved = path.tryFindResolution(); 387 // if (!resolved.isResolved()) { 388 // log.debug("creating: " + path); 389 // //TODO: access parent here, check if it is valid, only then create 390 // AccessInterface access = registry.prepareAccess(path.getTop().getParam()); 391 // assert access != null; 392 // Object child = access.createAccessee(); 393 // assert child != null; 394 // if (path.size() == 1) { 395 // setRoot(new Node(getRoot().getParam(), child)); 396 // } else { 397 // bindAccess(this, path.getUnder()).set(path.getTop().getParam(), child); 398 // } 399 // resolved = path.appendResolution(child); 400 // } 401 // tryRegisterOnChangeEvents(resolved); 402 // return resolved; 403 // } 396 404 397 405 } -
java/main/src/main/java/com/framsticks/remote/SimulatorTree.java
r97 r98 80 80 @Override 81 81 protected void runAt() { 82 resolveAndGet(SimulatorTree.this, "/simulator", new FutureHandler<Path>(Logging.logger(log, "failed to resolve simulator node", SimulatorTree.this)) {82 tryGet(SimulatorTree.this, "/simulator", new FutureHandler<Path>(Logging.logger(log, "failed to resolve simulator node", SimulatorTree.this)) { 83 83 @Override 84 84 protected void result(Path path) { 85 85 assert isActive(); 86 86 simulator = path; 87 fireRun(null);88 87 log.info("resolved simulator node"); 89 88 … … 94 93 @Override 95 94 public void call(List<File> files) { 96 //TODO TEH 97 dispatch(new RunAt<Tree>(ThrowExceptionHandler.getInstance()) { 95 dispatch(new RunAt<Tree>(getExceptionHandler()) { 98 96 @Override 99 97 protected void runAt() { … … 103 101 } 104 102 })); 105 new PeriodicTask<Tree>( ThrowExceptionHandler.getInstance(), SimulatorTree.this, 1000) {103 new PeriodicTask<Tree>(getExceptionHandler(), SimulatorTree.this, 1000) { 106 104 @Override 107 105 protected void runAt() { -
java/main/src/main/java/com/framsticks/util/FramsticksException.java
r97 r98 4 4 import java.util.List; 5 5 6 import com.framsticks.util.dispatching.ExceptionResultHandler; 6 7 import com.framsticks.util.lang.Delimeted; 7 8 import com.framsticks.util.lang.Pair; … … 75 76 } 76 77 78 79 public static ExceptionResultHandler addArgumentHandler(final ExceptionResultHandler innerHandler, final String header, final Object argument) { 80 return new ExceptionResultHandler() { 81 @Override 82 public void handle(FramsticksException exception) { 83 innerHandler.handle(exception.arg(header, argument)); 84 } 85 }; 86 } 87 77 88 } -
java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java
r97 r98 1 1 package com.framsticks.util.dispatching; 2 2 3 3 4 /** … … 24 25 } 25 26 26 27 27 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r97 r98 86 86 87 87 public static void childChangedState(final JoinableParent parent, final Joinable joinable, final JoinableState state) { 88 if (state.ordinal() <= JoinableState.RUNNING.ordinal()) { 89 return; 90 } 88 91 dispatcherGuardedInvoke(joinable, new RunAt<Object>(ThrowExceptionHandler.getInstance()) { 89 92 @Override … … 118 121 } 119 122 120 public interface Query<T> {123 public interface Query<T> extends ExceptionResultHandler { 121 124 T get(); 125 } 126 127 public static abstract class QueryHandler<T> implements Query<T> { 128 ExceptionResultHandler handler; 129 130 /** 131 * @param handler 132 */ 133 public QueryHandler(ExceptionResultHandler handler) { 134 this.handler = handler; 135 } 136 137 @Override 138 public void handle(FramsticksException exception) { 139 handler.handle(exception); 140 } 122 141 } 123 142 … … 131 150 */ 132 151 public QueryRunner(Query<T> query) { 133 //TODO TEH 134 super(ThrowExceptionHandler.getInstance()); 152 super(query); 135 153 this.query = query; 136 154 } … … 164 182 } 165 183 184 public static class DispatcherWaiter<C, T extends Dispatcher<C> & Joinable> implements Dispatcher<C> { 185 // protected boolean done = false; 186 protected final T dispatcher; 187 protected RunAt<? extends C> runnable; 188 189 /** 190 * @param joinable 191 */ 192 public DispatcherWaiter(T dispatcher) { 193 this.dispatcher = dispatcher; 194 } 195 196 public synchronized void waitFor() { 197 while ((runnable == null) && (dispatcher.getState().ordinal() <= JoinableState.RUNNING.ordinal())) { 198 try { 199 this.wait(); 200 } catch (InterruptedException e) { 201 } 202 } 203 if (runnable != null) { 204 runnable.run(); 205 } 206 207 } 208 209 @Override 210 public boolean isActive() { 211 return dispatcher.isActive(); 212 } 213 214 @Override 215 public synchronized void dispatch(RunAt<? extends C> runnable) { 216 this.runnable = runnable; 217 this.notifyAll(); 218 } 219 220 } 221 166 222 public static class Waiter { 167 223 protected boolean done = false; -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r97 r98 13 13 * @author Piotr Sniegowski 14 14 */ 15 public class Thread<C> extends AbstractJoinable implements Dispatcher<C> {15 public class Thread<C> extends AbstractJoinable implements JoinableDispatcher<C> { 16 16 17 17 private static final Logger log = Logger.getLogger(Thread.class); -
java/main/src/main/resources/configs/framsticks.xml
r97 r98 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Framsticks> 3 < import class="com.framsticks.gui.console.ManagedConsole" />4 < import class="com.framsticks.remote.RemoteTree" />5 < ManagedConsole>6 <RemoteTree name="remote" address="localhost:9009" />7 < /ManagedConsole>3 <!-- <import class="com.framsticks.gui.console.ManagedConsole" /> --> 4 <!-- <import class="com.framsticks.remote.RemoteTree" /> --> 5 <!-- <ManagedConsole> --> 6 <!-- <RemoteTree name="remote" address="localhost:9009" /> --> 7 <!-- </ManagedConsole> --> 8 8 9 9 <!-- <import class="com.framsticks.gui.console.DirectConsole" /> --> … … 13 13 <!-- </DirectConsole> --> 14 14 15 < !-- <import class="com.framsticks.gui.Browser" /> -->16 < !-- <import class="com.framsticks.remote.RemoteTree" /> -->17 < !-- <import class="com.framsticks.remote.SimulatorTree" /> -->18 < !-- <import class="com.framsticks.model.ModelPackage" /> -->19 < !-- <import class="com.framsticks.model.ModelBuilder" /> -->20 < !-- <import class="com.framsticks.model.f0.SchemaBuilder" /> -->21 < !-- <import class="com.framsticks.core.ObjectTree" /> -->22 < !-- <import class="com.framsticks.hosting.Server" /> -->23 < !-- <import class="com.framsticks.test.TestClass" /> -->24 < !-- <Browser> -->25 <!-- <SimulatorTree name="localhost:9009" address="localhost:9009"> -->26 <!-- <ModelPackage /> -->27 <!-- </SimulatorTree> -->28 <!--<ObjectTree name="model"> -->29 <!--<ModelBuilder resource="/examples/f0_example.txt" /> -->30 <!--</ObjectTree> -->31 <!--<ObjectTree name="f0schema"> -->32 <!--<SchemaBuilder /> -->33 <!--</ObjectTree> -->34 <!--<RemoteTree name="remote" address="localhost:9007" /> -->35 < !-- </Browser> -->15 <import class="com.framsticks.gui.Browser" /> 16 <import class="com.framsticks.remote.RemoteTree" /> 17 <import class="com.framsticks.remote.SimulatorTree" /> 18 <import class="com.framsticks.model.ModelPackage" /> 19 <import class="com.framsticks.model.ModelBuilder" /> 20 <import class="com.framsticks.model.f0.SchemaBuilder" /> 21 <import class="com.framsticks.core.ObjectTree" /> 22 <import class="com.framsticks.hosting.Server" /> 23 <import class="com.framsticks.test.TestClass" /> 24 <Browser> 25 <SimulatorTree name="localhost:9009" address="localhost:9009"> 26 <ModelPackage /> 27 </SimulatorTree> 28 <!-- <ObjectTree name="model"> --> 29 <!-- <ModelBuilder resource="/examples/f0_example.txt" /> --> 30 <!-- </ObjectTree> --> 31 <!-- <ObjectTree name="f0schema"> --> 32 <!-- <SchemaBuilder /> --> 33 <!-- </ObjectTree> --> 34 <!-- <RemoteTree name="remote" address="localhost:9007" /> --> 35 </Browser> 36 36 <!-- <Server name="server" port="9007"> --> 37 37 <!-- <ObjectTree name="test"> --> -
java/main/src/main/resources/configs/log4j.properties
r97 r98 29 29 30 30 log4j.logger.com.framsticks=INFO 31 # log4j.logger.com.framsticks.core.Framsticks=DEBUG 31 # log4j.logger.com.framsticks.gui.Panel=DEBUG 32 # log4j.logger.com.framsticks.remote.RemoteTree=DEBUG 32 33 # log4j.logger.com.framsticks.gui.Frame=DEBUG 33 34 # log4j.logger.com.framsticks.gui.controls.ProcedureControl=DEBUG -
java/main/src/test/java/com/framsticks/core/ObjectTreeTest.java
r97 r98 58 58 monitor.use(); 59 59 60 assertThat(Dispatching.get(tree, new Dispatching.Query <String>() {60 assertThat(Dispatching.get(tree, new Dispatching.QueryHandler<String>(failOnException) { 61 61 @Override 62 62 public String get() { -
java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java
r97 r98 12 12 import org.fest.swing.edt.GuiActionRunner; 13 13 14 import com.framsticks.util.dispatching.Dispatching; 14 15 import com.framsticks.util.dispatching.Joinable; 15 16 … … 26 27 protected Joinable createSubject() { 27 28 configureBrowser(); 29 // browser.getMainFrame().getStatusBar().setExceptionHandler(failOnException); 28 30 return browser; 29 31 } … … 47 49 48 50 protected void clickAndExpandPath(String path) { 49 tree.clickPath(path).expandPath(path); 51 tree.clickPath(path); 52 Dispatching.sleep(1.0); 53 tree.expandPath(path); 50 54 robot.waitForIdle(); 51 55 } -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r97 r98 36 36 @Test(timeOut = 30000) 37 37 public void testShow() { 38 Dispatching.synchronize(localhost, 1.0); 39 // Dispatching.sleep(0.5); 38 40 log.info("testing"); 39 41 tree.clickRow(0).expandRow(0); … … 56 58 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes"); 57 59 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); 58 Dispatching.sleep(2.0);59 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes/genotypes");60 // Dispatching.sleep(2.0); 61 // clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); 60 62 robot.pressAndReleaseKey(KeyEvent.VK_J); 61 63 waitForIdle(); -
java/main/src/test/java/com/framsticks/gui/console/TrackConsoleTest.java
r97 r98 41 41 @Test 42 42 public void testCommunication() { 43 //Dispatching.sleep(2.0);43 Dispatching.sleep(2.0); 44 44 final Waiter waiter = produceWaiter(1.0); 45 45 46 resolveAndGet(tree, "/simulator/genepools/groups/0", new FutureHandler<Path>(failOnException) {46 tryGet(tree, "/simulator/genepools/groups/0", new FutureHandler<Path>(failOnException) { 47 47 48 48 @Override -
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r97 r98 84 84 assertThat(path.isResolved()).isFalse(); 85 85 86 remote. resolve(path, new FutureHandler<Path>(failOnException) {86 remote.get(path, Mode.FETCH, new FutureHandler<Path>(failOnException) { 87 87 @Override 88 protected void result(final Path result) { 89 assertThat(result.isResolved()).isTrue(); 90 remotePath = result; 91 remote.get(result, Mode.FETCH, new FutureHandler<Object>(failOnException) { 92 @Override 93 protected void result(Object object) { 94 AccessInterface access = bindAccess(result); 95 assertThat(access).isInstanceOf(PropertiesAccess.class); 96 assertThat(access.get("name", String.class)).isEqualTo("a test name"); 97 waiter.pass(); 98 } 99 }); 88 protected void result(Path path) { 89 assertThat(path.isResolved()).isTrue(); 90 remotePath = path; 91 AccessInterface access = bindAccess(path); 92 assertThat(access).isInstanceOf(PropertiesAccess.class); 93 assertThat(access.get("name", String.class)).isEqualTo("a test name"); 94 waiter.pass(); 100 95 } 101 96 }); -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r97 r98 91 91 @Override 92 92 public void handle(FramsticksException e) { 93 e.printStackTrace(); 93 94 assertThat(e).isNull(); 94 95 } -
java/main/src/test/resources/log4j.properties
r97 r98 28 28 log4j.logger.com.framsticks=WARN 29 29 log4j.logger.com.framsticks.test.TestConfiguration=INFO 30 # log4j.logger.com.framsticks.core.TreeOperations=DEBUG 31 # log4j.logger.com.framsticks.core.AbstractTree=DEBUG 32 # log4j.logger.com.framsticks.remote.RemoteTree=DEBUG 30 33 # log4j.logger.com.framsticks.gui.console.TrackConsole=DEBUG 31 34 # log4j.logger.com.framsticks.gui.controls.ProcedureControl=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.