]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/event/Event.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / event / Event.java
1 /*******************************************************************************\r
2  *  Copyright (c) 2010 Association for Decentralized Information Management in\r
3  *  Industry THTH ry.\r
4  *  All rights reserved. This program and the accompanying materials\r
5  *  are made available under the terms of the Eclipse Public License v1.0\r
6  *  which accompanies this distribution, and is available at\r
7  *  http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  *  Contributors:\r
10  *      VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.databoard.accessor.event;
13
14 import java.io.IOException;\r
15 \r
16 import org.simantics.databoard.Bindings;\r
17 import org.simantics.databoard.accessor.reference.ChildReference;\r
18 import org.simantics.databoard.annotations.Optional;\r
19 import org.simantics.databoard.annotations.Union;\r
20 import org.simantics.databoard.binding.Binding;\r
21 import org.simantics.databoard.binding.error.BindingConstructionException;\r
22 import org.simantics.databoard.binding.error.BindingException;\r
23
24 @Union({\r
25         ArrayElementAdded.class,
26         ArrayElementRemoved.class,
27         MapEntryAdded.class,
28         MapEntryRemoved.class,
29         UnionValueAssigned.class,\r
30         OptionalValueAssigned.class,\r
31         OptionalValueRemoved.class,\r
32         ValueAssigned.class,\r
33         InvalidatedEvent.class//,\r
34         //CustomEvent.class
35 })
36 public abstract class Event {
37         
38         /** Path from the listened Object to the composite, null if same */
39         public @Optional ChildReference reference;
40         
41         /**
42          * Create a clone with new reference
43          * @param newReference
44          * @return clone with a new reference
45          */
46         public abstract Event clone(ChildReference newReference);               
47         
48         @Override
49         public String toString() {
50                 try {
51                         Binding b = Bindings.getBinding(Event.class);
52                         return b.printValueDefinition(this, true);
53                 } catch (BindingConstructionException e) {
54                         return e.getClass().getName()+" "+e.getMessage();
55                 } catch (IOException e) {
56                         return e.getClass().getName()+" "+e.getMessage();
57                 } catch (BindingException e) {
58                         return e.getClass().getName()+" "+e.getMessage();
59                 }
60         }\r
61         \r
62         protected String toRef() {\r
63                 if (reference==null) return "[] ";\r
64                 return "["+reference+"] ";\r
65         }
66         
67 }
68