1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * List of trace locations |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.engine; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 |
|
23 import com.nokia.tracecompiler.model.TraceCompilerException; |
|
24 |
|
25 /** |
|
26 * List of trace locations. |
|
27 * |
|
28 */ |
|
29 public class TraceLocationList extends LocationListBase { |
|
30 |
|
31 /** |
|
32 * Location list listeners |
|
33 */ |
|
34 private ArrayList<TraceLocationListListener> listeners = new ArrayList<TraceLocationListListener>(); |
|
35 |
|
36 /** |
|
37 * List title, returned by getTitle |
|
38 */ |
|
39 private String listTitle; |
|
40 |
|
41 /** |
|
42 * Constructor |
|
43 */ |
|
44 TraceLocationList() { |
|
45 } |
|
46 |
|
47 /** |
|
48 * Constructor |
|
49 * |
|
50 * @param listTitle |
|
51 * the title of this location list |
|
52 */ |
|
53 TraceLocationList(String listTitle) { |
|
54 this.listTitle = listTitle; |
|
55 } |
|
56 |
|
57 /** |
|
58 * Adds a location to this list. |
|
59 * |
|
60 * @param location |
|
61 * the location to be added |
|
62 * @throws TraceCompilerException |
|
63 */ |
|
64 void addLocation(TraceLocation location) throws TraceCompilerException { |
|
65 if (TraceCompilerEngineConfiguration.ASSERTIONS_ENABLED) { |
|
66 if (contains(location)) { |
|
67 //this can only happen if there is a programming error |
|
68 TraceCompilerEngineGlobals.getEvents().postCriticalAssertionFailed( |
|
69 "Duplicate trace location", //$NON-NLS-1$ |
|
70 location.getConvertedName()); |
|
71 throw new TraceCompilerException(null); |
|
72 } |
|
73 } |
|
74 location.setLocationList(this); |
|
75 add(location); |
|
76 fireLocationAdded(location); |
|
77 location.runValidityCheck(); |
|
78 } |
|
79 |
|
80 /** |
|
81 * Removes a location from this list. |
|
82 * |
|
83 * @param location |
|
84 * the location to be removed |
|
85 */ |
|
86 void removeLocation(TraceLocation location) { |
|
87 if (remove(location)) { |
|
88 fireLocationRemoved(location); |
|
89 location.setLocationList(null); |
|
90 } |
|
91 } |
|
92 |
|
93 /** |
|
94 * Adds a location list listener to this object |
|
95 * |
|
96 * @param listener |
|
97 * the listener interface |
|
98 */ |
|
99 public void addLocationListListener(TraceLocationListListener listener) { |
|
100 listeners.add(listener); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Removes the location list listener |
|
105 * |
|
106 * @param listener |
|
107 * the listener interface |
|
108 */ |
|
109 public void removeLocationListListener(TraceLocationListListener listener) { |
|
110 listeners.remove(listener); |
|
111 } |
|
112 |
|
113 /** |
|
114 * Creates locationAdded event to location list listeners |
|
115 * |
|
116 * @param location |
|
117 * the location that was added |
|
118 */ |
|
119 private void fireLocationAdded(TraceLocation location) { |
|
120 for (TraceLocationListListener l : listeners) { |
|
121 l.locationAdded(location); |
|
122 } |
|
123 } |
|
124 |
|
125 /** |
|
126 * Creates locationRemoved event to location list listeners |
|
127 * |
|
128 * @param location |
|
129 * the location that was added |
|
130 */ |
|
131 void fireLocationRemoved(TraceLocation location) { |
|
132 for (TraceLocationListListener l : listeners) { |
|
133 l.locationRemoved(location); |
|
134 } |
|
135 } |
|
136 |
|
137 /** |
|
138 * Gets the list title or null |
|
139 * |
|
140 * @return the list title |
|
141 */ |
|
142 public String getListTitle() { |
|
143 return listTitle; |
|
144 } |
|
145 |
|
146 } |
|