]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/event/Event.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / event / Event.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  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  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.accessor.event;
13
14 import java.io.IOException;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.accessor.reference.ChildReference;
18 import org.simantics.databoard.annotations.Optional;
19 import org.simantics.databoard.annotations.Union;
20 import org.simantics.databoard.binding.Binding;
21 import org.simantics.databoard.binding.error.BindingConstructionException;
22 import org.simantics.databoard.binding.error.BindingException;
23
24 @Union({
25         ArrayElementAdded.class,
26         ArrayElementRemoved.class,
27         MapEntryAdded.class,
28         MapEntryRemoved.class,
29         UnionValueAssigned.class,
30         OptionalValueAssigned.class,
31         OptionalValueRemoved.class,
32         ValueAssigned.class,
33         InvalidatedEvent.class//,
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         }
61         
62         protected String toRef() {
63                 if (reference==null) return "[] ";
64                 return "["+reference+"] ";
65         }
66         
67 }
68