- Timestamp:
- 07/10/13 22:41:02 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r98 r99 2 2 3 3 4 import java.util.HashSet; 4 5 import java.util.List; 6 import java.util.Set; 5 7 6 8 import javax.annotation.Nonnull; … … 10 12 import com.framsticks.communication.File; 11 13 import com.framsticks.params.AccessInterface; 12 import com.framsticks.params. CompositeParam;14 import com.framsticks.params.EventListener; 13 15 import com.framsticks.params.FramsClass; 14 16 import com.framsticks.params.ListAccess; 15 17 import com.framsticks.params.Param; 16 18 import com.framsticks.params.PrimitiveParam; 19 import com.framsticks.params.UniqueListAccess; 20 import com.framsticks.params.Util; 21 import com.framsticks.params.types.EventParam; 17 22 import com.framsticks.params.types.ObjectParam; 18 23 import com.framsticks.params.types.ProcedureParam; … … 73 78 74 79 ListAccess listAccess = (ListAccess) bindAccess(node); 75 listAccess.clearValues(); 80 81 Set<String> oldValuesIds = new HashSet<>(); 82 for (Param p : listAccess.getParams()) { 83 oldValuesIds.add(p.getId()); 84 } 85 86 // listAccess.clearValues(); 76 87 77 88 AccessInterface elementAccess = listAccess.getElementAccess(); 89 AccessInterface clonerInterface = elementAccess.cloneAccess(); 90 78 91 loader.addAccessInterface(elementAccess); 79 92 MultiParamLoader.Status status; 93 int number = 0; 80 94 while ((status = loader.go()) != MultiParamLoader.Status.Finished) { 81 95 if (status == MultiParamLoader.Status.AfterObject) { 82 96 AccessInterface accessInterface = loader.getLastAccessInterface(); 83 97 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(); 98 String id; 99 if (listAccess instanceof UniqueListAccess) { 100 id = ((UniqueListAccess) listAccess).computeIdentifierFor(accessInterface.getSelected()); 101 } else { 102 id = Integer.toString(number); 103 } 104 ++number; 105 106 Object childTo = listAccess.get(id, Object.class); 107 boolean newOne; 108 if (childTo == null) { 109 childTo = clonerInterface.createAccessee(); 110 newOne = true; 111 } else { 112 assert oldValuesIds.contains(id); 113 newOne = false; 114 } 115 oldValuesIds.remove(id); 116 clonerInterface.select(childTo); 117 Util.takeAllNonNullValues(clonerInterface, accessInterface); 118 if (newOne) { 119 listAccess.set(id, childTo); 120 } 121 122 // listAccess.set(id, accessInterface.getSelected()); 88 123 accessInterface.select(null); 89 assert child != null; 90 bindAccess(node).set(param, child); 124 91 125 } 126 } 127 /** It looks tricky for ArrayListAccess but should also work. 128 * 129 * They should be sorted. 130 */ 131 for (String id : oldValuesIds) { 132 listAccess.set(id, null); 92 133 } 93 134 … … 170 211 } 171 212 172 173 /** This might not be correct. */ 213 public static <A> void addListener(final Path path, final EventParam param, final EventListener<A> listener, final Class<A> argument, final Future<Void> future) { 214 final Tree tree = path.getTree(); 215 216 dispatchIfNotActive(tree, new RunAt<Tree>(future) { 217 @Override 218 protected void runAt() { 219 tree.addListener(path, param, listener, argument, future); 220 } 221 }); 222 } 223 224 public static void removeListener(final Path path, final EventParam param, final EventListener<?> listener, final Future<Void> future) { 225 final Tree tree = path.getTree(); 226 227 dispatchIfNotActive(tree, new RunAt<Tree>(future) { 228 @Override 229 protected void runAt() { 230 tree.removeListener(path, param, listener, future); 231 } 232 }); 233 } 234 235 236 /** 237 * 238 * If StackOverflow occurs in that loop in LocalTree it is probably caused 239 * the by the fact, that get operation may find the object, but Path resolution 240 * cannot. 241 * */ 174 242 public static void tryGet(final Tree tree, final String targetPath, final Future<Path> future) { 175 243 log.debug("resolve textual: " + targetPath + " for " + tree); … … 178 246 @Override 179 247 protected void runAt() { 180 final Path path = Path.to(tree, targetPath); 248 final Path path = Path.tryTo(tree, targetPath).tryResolveIfNeeded(); 249 log.debug("found: " + path); 181 250 if (path.isResolved()) { 182 251 future.pass(path); … … 184 253 } 185 254 186 tree.get(path, Mode.FETCH,new FutureHandler<Path>(future) {255 tree.get(path, new FutureHandler<Path>(future) { 187 256 @Override 188 257 protected void result(Path result) { 258 // if (result.isResolved(targetPath)) { 259 // future.pass(result); 260 // return; 261 // } 262 log.debug("retrying resolve textual: " + targetPath + " for " + tree + " with " + result); 189 263 tryGet(tree, targetPath, future); 190 264 } … … 198 272 return path.getTree().getInfoFromCache(path.getTop().getParam().getContainedTypeName()); 199 273 } 274 200 275 }
Note: See TracChangeset
for help on using the changeset viewer.