]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.swt.core/src/org/simantics/document/swt/core/base/PostEventCommand.java
Merge "Revert "Support enumerated property types in UC interface""
[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.CommandContextImpl;
17 import org.simantics.document.server.io.CommandContextMutable;
18 import org.simantics.document.swt.core.SWTDocument;
19
20 public class PostEventCommand extends AbstractEventCommand {
21     
22     private AbstractEventHandler handler;
23     private CommandContextMutable context;
24     
25     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context) {
26         this(document, handler, context, null);
27     }
28     
29     public PostEventCommand(SWTDocument document, AbstractEventHandler handler, CommandContextMutable context, PostEventCommand next) {
30         super(document);
31         assert(handler != null);
32         this.handler = handler;
33         this.context = context;
34         this.next = next;
35     }
36
37     @Override
38     public CommandContext handleCommand(CommandContextMutable context) {
39         CommandContextMutable mergedContext = new CommandContextImpl().merge(context)
40                 .merge(this.context);
41         document.post(handler, mergedContext);
42         return context;
43     }
44
45     @Override
46     public CommandContext commandSuccess(CommandContextMutable context) {
47         if(next != null)
48             return next.handleCommand(context);
49         return context;
50     }
51
52     @Override
53     public void commandError(String errorMessage) {
54         System.err.println(this + " failed: " + errorMessage);
55     }
56
57 }