]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java
Playground for Antti.
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / base / PostEventCommand.java
1 package org.simantics.document.swt.core.base;
2
3 import org.simantics.document.server.io.AbstractEventHandler;
4 import org.simantics.document.server.io.CommandContext;
5 import org.simantics.document.server.io.CommandContextMutable;
6 import org.simantics.document.swt.core.SWTDocument;
7
8 public class PostEventCommand extends AbstractEventCommand {
9     
10     private AbstractEventHandler handler;
11     private CommandContextMutable context;
12     
13     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context) {
14         this(document, handler, context, null);
15     }
16     
17     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) {
18         super(document);
19         this.handler = handler;
20         this.context = context;
21         this.next = next;
22     }
23
24     @Override
25     public CommandContext handleCommand(CommandContextMutable context) {
26         document.post(handler, context);
27         return context;
28     }
29
30     @Override
31     public CommandContext commandSuccess(CommandContextMutable context) {
32         if(next != null)
33             return next.handleCommand(context);
34         return context;
35     }
36
37     @Override
38     public void commandError(String errorMessage) {
39         System.err.println(this + " failed: " + errorMessage);
40     }
41
42 }