1 package nl.toolforge.karma.cli.cmd;
2
3 import nl.toolforge.karma.core.cmd.CommandDescriptor;
4 import nl.toolforge.karma.core.cmd.CommandException;
5 import nl.toolforge.karma.core.cmd.CommandResponse;
6 import nl.toolforge.karma.core.cmd.event.MessageEvent;
7 import nl.toolforge.karma.core.cmd.event.SimpleMessage;
8 import nl.toolforge.karma.core.cmd.impl.ViewWorkingContexts;
9 import org.apache.commons.lang.StringUtils;
10
11 import java.util.Iterator;
12
13 /***
14 * Views all working contexts in tabular format.
15 *
16 * @author D.A. Smedes
17 * @version $Id: ViewWorkingContextsImpl.java,v 1.2 2004/11/02 23:57:05 asmedes Exp $
18 */
19 public class ViewWorkingContextsImpl extends ViewWorkingContexts {
20
21 private CommandResponse response = new CommandResponse();
22
23 public ViewWorkingContextsImpl(CommandDescriptor descriptor) {
24 super(descriptor);
25 }
26
27 public void execute() throws CommandException {
28
29 super.execute();
30
31 StringBuffer buffer = new StringBuffer();
32
33 buffer.append("\n");
34 String header = "Available working contexts:";
35 buffer.append(header + "\n");
36 buffer.append(StringUtils.repeat("_", header.length()) + "\n\n");
37
38 for (Iterator i = getWorkingContexts().iterator(); i.hasNext();) {
39 buffer.append((String) i.next() + "\n");
40 }
41
42 response.addEvent(new MessageEvent(new SimpleMessage(buffer.toString())));
43 }
44
45 public CommandResponse getCommandResponse() {
46 return response;
47 }
48 }