/** * Constructor that stores a selection. This is used by the action every time is is run. This also * sets up the text and image of the Action. * * @param selection The selection to use every time this action is run. */ public CopyRuleAction(ModelSelection selection) { if (selection != null && selection.isOnlyRules()) { this.selection = selection; this.setText(ZLang.ZL_Copy); this.setImageFile(ImageFile.COPY); } else { // Should not use this constructor without a valid selection ZDebug.dumpStackTrace("CopyRuleAction created without proper selection."); this.setText("!!"); } }
/** * Return all groups starting with the passed in prefix. * * @param start The start of a groups you want to match. * @return A collection of groups that match the passed string. */ public Collection<FunctionGroup> getGroupsStartingWith(String start) { if (start.length() == 0) { return groupTree; } start = start.toLowerCase(); if (start.length() > maxGroupLength) return new TreeSet<FunctionGroup>(); try { // Uses tree subset to find the groups greater than start or less than return groupTree.subSet(new FunctionGroup(start), new FunctionGroup(getSearchLimit(start))); } catch (IllegalArgumentException e) { ZDebug.printStackTrace(e, "Invalid search limit"); } return new TreeSet<FunctionGroup>(); }
/** * Get a set of possibilities to complete the passed word. * * @param word The word you want to complete * @param types The types of completions you want. * @return A set of possibilities to complete the code. */ public Collection<CodePossibility> getPossiblilities(String word, Type[] types) { ZDebug.print(4, "getPossiblilities( ", word, " )"); // Optimisation if (word.length() > 0 && !Character.isLetter(word.charAt(0))) { return new ArrayList<CodePossibility>(0); } // Get what types of possibility the caller wants boolean listGroups = false, listFunctions = false, listKeywords = false; for (Type type : types) { switch (type) { case FUNCTION: listFunctions = true; break; case GROUP: listGroups = true; break; case KEYWORD: listKeywords = true; break; } } // Split up into parts (for functions and groups) String[] parts = word.split("\\.", -1); if (parts.length < 1) return new HashSet<CodePossibility>(0); String groupName = ""; String funcName = null; for (int i = 0; i < parts.length - 1; i++) { if (i != 0) groupName += "."; groupName += parts[i]; } ZDebug.print(5, "Word Before: '", word, "'"); FunctionGroup currentGroup = this.getGroup(groupName); if (parts.length > 0) { funcName = parts[parts.length - 1]; } TreeSet<CodePossibility> list = new TreeSet<CodePossibility>(); // Suggest some keywords if (listKeywords) { for (String keyword : getKeywordsStartingWith(word)) { list.add(new CodePossibility(keyword, word)); } } // Suggest some groups if (listGroups) { ZDebug.print(5, "Getting groups that start with: ", word); for (FunctionGroup group : getGroupsStartingWith(word)) { list.add(new CodePossibility(group, word)); } } // Suggest some functions if (listFunctions) { if (currentGroup != null) { ZDebug.print(5, "Getting functions in '", currentGroup, "' that start with: ", funcName); for (Function function : currentGroup.getFunctionsStartingWith(funcName)) { list.add(new CodePossibility(function, funcName)); } } } return list; }