- Timestamp:
- 07/08/13 23:04:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.