|
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 * Wrapper class for last known location list |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import java.util.Iterator; |
|
22 |
|
23 import com.nokia.tracebuilder.engine.LocationProperties; |
|
24 import com.nokia.tracebuilder.engine.LastKnownLocation; |
|
25 import com.nokia.tracebuilder.engine.LastKnownLocationList; |
|
26 import com.nokia.tracebuilder.engine.LastKnownLocationListListener; |
|
27 |
|
28 /** |
|
29 * Wrapper class for last known location list |
|
30 * |
|
31 */ |
|
32 final class LastKnownLocationListWrapper extends ListWrapper implements |
|
33 LastKnownLocationListListener { |
|
34 |
|
35 /** |
|
36 * Location list |
|
37 */ |
|
38 private LastKnownLocationList locationList; |
|
39 |
|
40 /** |
|
41 * Constructor |
|
42 * |
|
43 * @param list |
|
44 * the location list |
|
45 * @param parent |
|
46 * the parent wrapper |
|
47 * @param updater |
|
48 * the update notifier |
|
49 */ |
|
50 LastKnownLocationListWrapper(LastKnownLocationList list, |
|
51 WrapperBase parent, WrapperUpdater updater) { |
|
52 super(parent, updater); |
|
53 this.locationList = list; |
|
54 createChildren(); |
|
55 locationList.addLocationListListener(this); |
|
56 } |
|
57 |
|
58 /** |
|
59 * Creates the location wrappers |
|
60 */ |
|
61 private void createChildren() { |
|
62 for (LocationProperties loc : locationList) { |
|
63 LastKnownLocationWrapper wrapper = new LastKnownLocationWrapper( |
|
64 (LastKnownLocation) loc, this, getUpdater()); |
|
65 add(wrapper); |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 * Gets the location list |
|
71 * |
|
72 * @return the location list |
|
73 */ |
|
74 LastKnownLocationList getLocationList() { |
|
75 return locationList; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Updates the location list |
|
80 * |
|
81 * @param list |
|
82 * the new location list |
|
83 */ |
|
84 void updateLocationList(LastKnownLocationList list) { |
|
85 locationList.removeLocationListListener(this); |
|
86 clear(); |
|
87 locationList = list; |
|
88 if (locationList != null) { |
|
89 locationList.addLocationListListener(this); |
|
90 createChildren(); |
|
91 } |
|
92 } |
|
93 |
|
94 /* |
|
95 * (non-Javadoc) |
|
96 * |
|
97 * @see com.nokia.tracebuilder.view.ListWrapper#delete() |
|
98 */ |
|
99 @Override |
|
100 void delete() { |
|
101 super.delete(); |
|
102 locationList.removeLocationListListener(this); |
|
103 } |
|
104 |
|
105 /* |
|
106 * (non-Javadoc) |
|
107 * |
|
108 * @see com.nokia.tracebuilder.engine.LastKnownLocationListListener# |
|
109 * locationAdded(com.nokia.tracebuilder.engine.LastKnownLocation) |
|
110 */ |
|
111 public void locationAdded(LastKnownLocation location) { |
|
112 LastKnownLocationWrapper wrapper = new LastKnownLocationWrapper( |
|
113 location, this, getUpdater()); |
|
114 boolean inView = false; |
|
115 boolean hidden = false; |
|
116 if (!hasChildren()) { |
|
117 hidden = true; |
|
118 } |
|
119 // If one of the existing locations is shown in view, or there are no |
|
120 // existing locations the new one is also marked as shown in view |
|
121 if (isInView()) { |
|
122 if (hasChildren()) { |
|
123 Iterator<WrapperBase> itr = getVisibleWrappers(); |
|
124 if (itr.next().isInView()) { |
|
125 inView = true; |
|
126 } |
|
127 } else { |
|
128 inView = true; |
|
129 } |
|
130 } |
|
131 add(wrapper); |
|
132 wrapper.setInView(inView); |
|
133 if (hidden) { |
|
134 TraceWrapper parent = (TraceWrapper) getParent(); |
|
135 parent.showLastKnownLocationList(); |
|
136 getUpdater().queueUpdate(parent); |
|
137 } else { |
|
138 getUpdater().queueUpdate(this); |
|
139 } |
|
140 } |
|
141 |
|
142 /* |
|
143 * (non-Javadoc) |
|
144 * |
|
145 * @see com.nokia.tracebuilder.engine.LastKnownLocationListListener# |
|
146 * locationRemoved(com.nokia.tracebuilder.engine.LastKnownLocation) |
|
147 */ |
|
148 public void locationRemoved(LastKnownLocation location) { |
|
149 LastKnownLocationWrapper wrapper = (LastKnownLocationWrapper) location |
|
150 .getViewReference(); |
|
151 remove(wrapper); |
|
152 if (!hasChildren()) { |
|
153 TraceWrapper parent = (TraceWrapper) getParent(); |
|
154 parent.hideLastKnownLocationList(); |
|
155 getUpdater().queueUpdate(parent); |
|
156 } else { |
|
157 getUpdater().queueUpdate(this); |
|
158 } |
|
159 } |
|
160 |
|
161 } |