]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java
Improvements to modelled SWT documents
[simantics/platform.git] / bundles / org.simantics.document.swt.core / src / org / simantics / document / swt / core / base / PostEventCommand.java
1 /*******************************************************************************
2  * Copyright (c) 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.document.swt.core.base;
13
14 import org.simantics.document.server.io.AbstractEventHandler;
15 import org.simantics.document.server.io.CommandContext;
16 import org.simantics.document.server.io.CommandContextMutable;
17 import org.simantics.document.swt.core.SWTDocument;
18
19 public class PostEventCommand extends AbstractEventCommand {
20     
21     private AbstractEventHandler handler;
22     private CommandContextMutable context;
23     
24     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context) {
25         this(document, handler, context, null);
26     }
27     
28     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) {
29         super(document);
30         this.handler = handler;
31         this.context = context;
32         this.next = next;
33     }
34
35     @Override
36     public CommandContext handleCommand(CommandContextMutable context) {
37         document.post(handler, context);
38         return context;
39     }
40
41     @Override
42     public CommandContext commandSuccess(CommandContextMutable context) {
43         if(next != null)
44             return next.handleCommand(context);
45         return context;
46     }
47
48     @Override
49     public void commandError(String errorMessage) {
50         System.err.println(this + " failed: " + errorMessage);
51     }
52
53 }