Esempio n. 1
0
 @Override
 public List<String> completionCandidates(String partOfLine, Session session) {
   String lastWord = TextUtil.lastWordOrQuoteOf(partOfLine, false);
   if (lastWord.startsWith("-")) {
     return super.completionCandidates(partOfLine, session);
   }
   try {
     TreeSet<String> result = new TreeSet<String>();
     NodeOrRelationship current = getCurrent(session);
     if (current.isNode()) {
       // TODO Check if -r is supplied
       Node node = current.asNode();
       for (Node otherNode : RelationshipToNodeIterable.wrap(node.getRelationships(), node)) {
         long otherNodeId = otherNode.getId();
         String title = findTitle(getServer(), session, otherNode);
         if (title != null) {
           if (!result.contains(title)) {
             maybeAddCompletionCandidate(result, title + "," + otherNodeId, lastWord);
           }
         }
         maybeAddCompletionCandidate(result, "" + otherNodeId, lastWord);
       }
     } else {
       maybeAddCompletionCandidate(result, START_ALIAS, lastWord);
       maybeAddCompletionCandidate(result, END_ALIAS, lastWord);
       Relationship rel = current.asRelationship();
       maybeAddCompletionCandidate(result, "" + rel.getStartNode().getId(), lastWord);
       maybeAddCompletionCandidate(result, "" + rel.getEndNode().getId(), lastWord);
     }
     return new ArrayList<String>(result);
   } catch (ShellException e) {
     e.printStackTrace();
     return super.completionCandidates(partOfLine, session);
   }
 }
Esempio n. 2
0
  private long findNodeWithTitle(Node node, String match, Session session) {
    Object[] matchParts = splitNodeTitleAndId(match);
    if (matchParts[1] != null) {
      return (Long) matchParts[1];
    }

    String titleMatch = (String) matchParts[0];
    for (Node otherNode : RelationshipToNodeIterable.wrap(node.getRelationships(), node)) {
      String title = findTitle(getServer(), session, otherNode);
      if (titleMatch.equals(title)) {
        return otherNode.getId();
      }
    }
    return -1;
  }