private static void appendSorted( final List<Command> commandsList, final CommandWrapper wrapper, final Map<String, CommandWrapper> wrappers) { if (!wrapper.afterWrappers.isEmpty()) { final List<CommandWrapper> afterWrappersList = wrapper.afterWrappers; final CommandWrapper[] afterWrappers = afterWrappersList.toArray(new CommandWrapper[afterWrappersList.size()]); for (CommandWrapper afterWrapper : afterWrappers) { for (int j = 0; j < afterWrapper.afterWrappers.size(); j++) { CommandWrapper ownAfterWrapper = afterWrapper.afterWrappers.get(j); if (afterWrappersList.contains(ownAfterWrapper)) { afterWrappersList.remove(afterWrapper); final int insertIndex = afterWrappersList.indexOf(ownAfterWrapper); afterWrappersList.add(insertIndex, afterWrapper); } } } for (CommandWrapper anAfterWrapper : afterWrappersList) { final CommandWrapper cwFromMap = wrappers.get(anAfterWrapper.getName()); if (cwFromMap != null) { commandsList.add(cwFromMap.command); wrappers.remove(cwFromMap.getName()); } } for (CommandWrapper anAfterWrapper : afterWrappersList) { appendSorted(commandsList, anAfterWrapper, wrappers); } } }
@Override public void setPropertyValue(final Object id, final Object value) { final String prop = (String) id; if (prop.equals(COMMAND_DYNAMIC)) { boolean res = (boolean) value; _operation.getCommand().setDynamic(res); } else if (prop.equals(AVERAGE_WINDOW)) { ((SimpleMovingAverageCommand) _operation.getCommand()) .setWindowSize(Integer.parseInt((String) value)); } }
@Override public Object getPropertyValue(final Object id) { final String prop = (String) id; if (prop.equals(COMMAND_NAME)) { return _operation.getCommand().getName(); } else if (prop.equals(COMMAND_DESCRIPTION)) { return _operation.getCommand().getDescription(); } else if (prop.equals(COMMAND_DYNAMIC)) { return _operation.getCommand().getDynamic(); } else if (prop.equals(AVERAGE_WINDOW)) { return "" + ((SimpleMovingAverageCommand) _operation.getCommand()).getWindowSize(); } return null; }
/** @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() */ @Override public IPropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { List<IPropertyDescriptor> list = new ArrayList<IPropertyDescriptor>(); // Create a descriptor and set a category final PropertyDescriptor textDescriptor = new PropertyDescriptor(COMMAND_NAME, "Name"); textDescriptor.setCategory("Label"); list.add(textDescriptor); final PropertyDescriptor descriptionDescriptor = new TextPropertyDescriptor(COMMAND_DESCRIPTION, "Description"); descriptionDescriptor.setCategory("Label"); list.add(descriptionDescriptor); final PropertyDescriptor dynamicDescriptor = new CheckboxPropertyDescriptor(COMMAND_DYNAMIC, "Dynamic updates"); dynamicDescriptor.setCategory("Label"); list.add(dynamicDescriptor); // hmm, is it our moving average? if (_operation.getCommand() instanceof SimpleMovingAverageCommand) { final SliderPropertyDescriptor windowDescriptor = new SliderPropertyDescriptor(AVERAGE_WINDOW, "Window", 1, 20); windowDescriptor.setCategory("Calculation"); list.add(windowDescriptor); } propertyDescriptors = (IPropertyDescriptor[]) list.toArray(new IPropertyDescriptor[] {}); } return propertyDescriptors; }
private void executeCommand(String cmd) { try { command.executeCommand(cmd); } catch (Exception ex) { printException(ex); } if (history.size() == HISTORY_COUNT) { history.remove(0); } history.add(cmd); }
private void exit(int code) { if (command != null) { try { command.close(); } catch (Exception ex) { printException(ex); System.exit(1); } } System.err.println("Goodbye!"); System.exit(code); }
static Command[] sort(final Command[] commands) { final List<Command> sortedCommandsList = new ArrayList<Command>(); if (commands != null) { final Map<String, CommandWrapper> wrappersMap = new HashMap<String, CommandWrapper>(); for (final Command command : commands) { final CommandWrapper wrapper = new CommandWrapper(command); wrappersMap.put(wrapper.getName(), wrapper); } for (final Command command : commands) { final String placeBefore = command.getPlaceBefore(); final String placeAfter = command.getPlaceAfter(); if (placeAfter != null || placeBefore != null) { final CommandWrapper commandWrapper = wrappersMap.get(command.getCommandID()); if (placeAfter != null) { final CommandWrapper beforeCommand = wrappersMap.get(placeAfter); if (beforeCommand != null) { commandWrapper.addBefore(beforeCommand); beforeCommand.addAfter(commandWrapper); } } if (placeBefore != null) { final CommandWrapper afterCommand = wrappersMap.get(placeBefore); if (afterCommand != null) { commandWrapper.addAfter(afterCommand); afterCommand.addBefore(commandWrapper); } } } } while (!wrappersMap.isEmpty()) { CommandWrapper wrapper = wrappersMap.values().iterator().next(); while (!wrapper.beforeWrappers.isEmpty()) { final List linksBefore = wrapper.beforeWrappers; for (Object aLinksBefore : linksBefore) { final CommandWrapper cw = (CommandWrapper) aLinksBefore; final Object o = wrappersMap.get(cw.getName()); if (o != null) { wrapper = (CommandWrapper) o; break; } } } sortedCommandsList.add(wrapper.command); wrappersMap.remove(wrapper.getName()); appendSorted(sortedCommandsList, wrapper, wrappersMap); } } return sortedCommandsList.toArray(new Command[sortedCommandsList.size()]); }
private void promptLoop() { println(""); println("*** Welcome to Temporal Random Indexing (TRI) Shell " + VERSION + " ***"); println("Shell charset: " + charset); println(""); showHelp(); if (reader == null) { try { reader = new BufferedReader(new InputStreamReader(in, charset)); } catch (UnsupportedEncodingException ex) { Logger.getLogger(TriShell.class.getName()).log(Level.SEVERE, null, ex); } } while (true) { try { print(PROMPT + "> "); String line = readLine(); if (line == null) { break; } String trimmed = line.trim(); if (trimmed.length() == 0) { continue; } String cmd = trimmed.replaceAll("\\s+", " "); // remove not necessary whitespaces if ("exit".equals(cmd) || "quit".equals(cmd)) { break; } else if (cmd.matches("(^(help|\\?)$)|(^(help|\\?)\\s+.*$)")) { String[] split = cmd.split("\\s+"); if (split.length == 1) { showHelp(); } else { command.help(split[1]); } } else if ("history".equals(cmd)) { for (int i = 0, size = history.size(); i < size; i++) { String s = history.get(i); s = s.replace('\n', ' ').replace('\r', ' '); println("#" + (1 + i) + ": " + s); } if (history.size() > 0) { println("To re-run a statement, type runh and the number and press enter"); } else { println("No history"); } } else if (cmd.matches("(^runh$)|(^runh\\s+.*$)")) { String[] split = cmd.split("\\s+"); if (split.length > 1) { if (split[1].matches("[0-9]+")) { int hi = Integer.parseInt(split[1]); hi--; if (hi < history.size()) { executeCommand(history.get(hi)); } else { printMessageError("No valid command number"); } } else { printMessageError("No valid command number"); } } else { printMessageError("runh syntax error"); } } else { executeCommand(cmd); } } catch (IOException | NumberFormatException ex) { println("No managed exception sorry..."); printException(ex); exit(1); } } exit(0); }