View Javadoc
1   package org.vaadin.aceeditor.client;
2   
3   import org.vaadin.aceeditor.AceEditor;
4   import org.vaadin.aceeditor.client.TransportDoc.TransportAnnotation;
5   import org.vaadin.aceeditor.client.TransportDoc.TransportMarkerAnnotation;
6   import org.vaadin.aceeditor.client.TransportDoc.TransportRowAnnotation;
7   import org.vaadin.aceeditor.client.TransportDoc.TransportableAs;
8   
9   /**
10   * An annotation for {@link AceEditor}.
11   *
12   */
13  public class AceAnnotation {
14  	
15  	public enum Type {
16  		error,
17  		warning,
18  		info
19  	}
20  	
21  	private final String message;
22  	private final Type type;
23  	
24  	public AceAnnotation(String message, Type type) {
25  		this.message = message;
26  		this.type = type;
27  	}
28  
29  	public String getMessage() {
30  		return message;
31  	}
32  
33  	public Type getType() {
34  		return type;
35  	}
36  
37  	public TransportAnnotation asTransport() {
38  		return new TransportAnnotation(message, type);
39  	}
40  	
41  	public static AceAnnotation fromTransport(TransportAnnotation ta) {
42  		return new AceAnnotation(ta.message, ta.type);
43  	}
44  	
45  	@Override
46  	public boolean equals(Object o) {
47  		if (o instanceof AceAnnotation) {
48  			AceAnnotation oa = (AceAnnotation)o;
49  			return type.equals(oa.type) && message.equals(oa.message);
50  		}
51  		return false;
52  	}
53  	
54  	@Override
55  	public int hashCode() {
56  		return message.hashCode(); // ?
57  	}
58  	
59  	@Override
60  	public String toString() {
61  		return "<"+message+", "+type+">";
62  	}
63  	
64  	
65  	public static class MarkerAnnotation implements TransportableAs<TransportMarkerAnnotation> {
66  		private final String markerId;
67  		private final AceAnnotation ann;
68  		public MarkerAnnotation(String markerId, AceAnnotation ann) {
69  			this.markerId = markerId;
70  			this.ann = ann;
71  		}
72  		public String getMarkerId() {
73  			return markerId;
74  		}
75  		public AceAnnotation getAnnotation() {
76  			return ann;
77  		}
78  		@Override
79  		public boolean equals(Object o) {
80  			if (o instanceof MarkerAnnotation) {
81  				MarkerAnnotation oma = (MarkerAnnotation)o;
82  				return markerId.equals(oma.markerId) && ann.equals(oma.ann);
83  			}
84  			return false;
85  		}
86  		@Override
87  		public int hashCode() {
88  			return markerId.hashCode(); // ?
89  		}
90  		
91  		@Override
92  		public TransportMarkerAnnotation asTransport() {
93  			return new TransportMarkerAnnotation(markerId, ann.asTransport());
94  		}
95  		
96  		@Override
97  		public String toString() {
98  			return markerId+": " + ann;
99  		}
100 	}
101 	
102 	public static class RowAnnotation implements TransportableAs<TransportRowAnnotation> {
103 		private final int row;
104 		private final AceAnnotation ann;
105 		public RowAnnotation(int row, AceAnnotation ann) {
106 			this.row = row;
107 			this.ann = ann;
108 		}
109 		public int getRow() {
110 			return row;
111 		}
112 		public AceAnnotation getAnnotation() {
113 			return ann;
114 		}
115 		@Override
116 		public boolean equals(Object o) {
117 			if (o instanceof RowAnnotation) {
118 				RowAnnotation ora = (RowAnnotation)o;
119 				return row==ora.row && ann.equals(ora.ann);
120 			}
121 			return false;
122 		}
123 		@Override
124 		public int hashCode() {
125 			return row; // ?
126 		}
127 		@Override
128 		public TransportRowAnnotation asTransport() {
129 			return new TransportRowAnnotation(row, ann.asTransport());
130 		}
131 		@Override
132 		public String toString() {
133 			return row+": " + ann;
134 		}
135 	}
136 }