|
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 location lists |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Iterator; |
|
23 |
|
24 import com.nokia.tracebuilder.engine.TraceLocationList; |
|
25 import com.nokia.tracebuilder.model.TraceModel; |
|
26 |
|
27 /** |
|
28 * List of location lists |
|
29 * |
|
30 */ |
|
31 final class TraceLocationListsWrapper extends ListWrapper { |
|
32 |
|
33 /** |
|
34 * Location lists that are not visible |
|
35 */ |
|
36 private ArrayList<TraceLocationListWrapper> hiddenWrappers = new ArrayList<TraceLocationListWrapper>(); |
|
37 |
|
38 /** |
|
39 * Constructor |
|
40 * |
|
41 * @param model |
|
42 * the trace model |
|
43 * @param parent |
|
44 * the parent wrapper |
|
45 * @param updater |
|
46 * the updater |
|
47 */ |
|
48 TraceLocationListsWrapper(TraceModel model, WrapperBase parent, |
|
49 WrapperUpdater updater) { |
|
50 super(parent, updater); |
|
51 Iterator<TraceLocationList> itr = model |
|
52 .getExtensions(TraceLocationList.class); |
|
53 while (itr.hasNext()) { |
|
54 addLocationList(itr.next()); |
|
55 } |
|
56 } |
|
57 |
|
58 /** |
|
59 * Adds a location list to this wrapper |
|
60 * |
|
61 * @param list |
|
62 * the list |
|
63 * @return the wrapper to be updated |
|
64 */ |
|
65 WrapperBase addLocationList(TraceLocationList list) { |
|
66 TraceLocationListWrapper wrapper = new TraceLocationListWrapper(list, |
|
67 this, getUpdater()); |
|
68 if (list.hasLocations()) { |
|
69 add(wrapper); |
|
70 } else { |
|
71 hiddenWrappers.add(wrapper); |
|
72 } |
|
73 return this; |
|
74 } |
|
75 |
|
76 /** |
|
77 * Removes a location list from this wrapper |
|
78 * |
|
79 * @param list |
|
80 * the list to be removed |
|
81 * @return the wrapper to be updated |
|
82 */ |
|
83 WrapperBase removeLocationList(TraceLocationList list) { |
|
84 Iterator<WrapperBase> itr = getVisibleWrappers(); |
|
85 WrapperBase found = null; |
|
86 while (itr.hasNext() && found == null) { |
|
87 TraceLocationListWrapper wrapper = (TraceLocationListWrapper) itr |
|
88 .next(); |
|
89 if (wrapper.getLocationList() == list) { |
|
90 found = wrapper; |
|
91 } |
|
92 } |
|
93 if (found == null) { |
|
94 for (TraceLocationListWrapper wrapper : hiddenWrappers) { |
|
95 if (wrapper.getLocationList() == list) { |
|
96 found = wrapper; |
|
97 break; |
|
98 } |
|
99 } |
|
100 } |
|
101 if (found != null) { |
|
102 remove(found); |
|
103 } |
|
104 return this; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Shows the given location list wrapper |
|
109 * |
|
110 * @param wrapper |
|
111 * the wrapper to be shown |
|
112 * @return the wrapper to be updated |
|
113 */ |
|
114 WrapperBase showLocationList(TraceLocationListWrapper wrapper) { |
|
115 hiddenWrappers.remove(wrapper); |
|
116 add(wrapper); |
|
117 WrapperBase retval; |
|
118 TraceModelWrapper parent = (TraceModelWrapper) getParent(); |
|
119 if (!parent.contains(this)) { |
|
120 parent.add(this); |
|
121 retval = parent; |
|
122 } else { |
|
123 retval = this; |
|
124 } |
|
125 return retval; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Hides the given location list wrapper |
|
130 * |
|
131 * @param wrapper |
|
132 * the wrapper to be hidden |
|
133 * @return the wrapper to be updated |
|
134 */ |
|
135 WrapperBase hideLocationList(TraceLocationListWrapper wrapper) { |
|
136 hiddenWrappers.add(wrapper); |
|
137 hide(wrapper); |
|
138 WrapperBase retval; |
|
139 TraceModelWrapper parent = (TraceModelWrapper) getParent(); |
|
140 if (!hasChildren()) { |
|
141 parent.hide(this); |
|
142 retval = parent; |
|
143 } else { |
|
144 retval = this; |
|
145 } |
|
146 return retval; |
|
147 } |
|
148 |
|
149 /* |
|
150 * (non-Javadoc) |
|
151 * |
|
152 * @see com.nokia.tracebuilder.view.TraceObjectWrapper#delete() |
|
153 */ |
|
154 @Override |
|
155 void delete() { |
|
156 Iterator<TraceLocationListWrapper> itr = hiddenWrappers.iterator(); |
|
157 while (itr.hasNext()) { |
|
158 itr.next().delete(); |
|
159 } |
|
160 super.delete(); |
|
161 } |
|
162 |
|
163 } |