|
1 /* |
|
2 * Copyright (c) 2009 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 */ |
|
17 package com.nokia.s60tools.memspy.model; |
|
18 |
|
19 import java.util.ArrayList; |
|
20 import java.util.Iterator; |
|
21 import java.util.List; |
|
22 |
|
23 import com.nokia.s60tools.memspy.ui.dialogs.SWMTCategoryEntry; |
|
24 |
|
25 /** |
|
26 * Singleton Class for holding SWMT Category profiles |
|
27 */ |
|
28 public class SWMTCategorys { |
|
29 |
|
30 |
|
31 private static SWMTCategorys instance=null; |
|
32 |
|
33 |
|
34 /** |
|
35 * Private constructor |
|
36 */ |
|
37 private SWMTCategorys(){ |
|
38 initializeCategoryEntries(); |
|
39 initializeCategoryProfiles(); |
|
40 } |
|
41 |
|
42 |
|
43 |
|
44 /** |
|
45 * Stores the category entries. |
|
46 */ |
|
47 private List<SWMTCategoryEntry> categoryEntries; |
|
48 |
|
49 private List<CategoryProfile> categoryProfiles; |
|
50 |
|
51 /** |
|
52 * Get only instance of this object |
|
53 * @return instance |
|
54 */ |
|
55 public static SWMTCategorys getInstance(){ |
|
56 if(instance==null){ |
|
57 instance = new SWMTCategorys(); |
|
58 } |
|
59 return instance; |
|
60 } |
|
61 |
|
62 private void initializeCategoryProfiles() { |
|
63 categoryProfiles = new ArrayList<CategoryProfile>(); |
|
64 |
|
65 CategoryProfile profile0 = new CategoryProfile("Basic", SWMTCategoryConstants.PROFILE_BASIC); |
|
66 getCategoryProfiles().add(profile0); |
|
67 |
|
68 CategoryProfile profile1 = new CategoryProfile("RAM & Disk Profile", SWMTCategoryConstants.PROFILE_RAM_DISK); |
|
69 getCategoryProfiles().add(profile1); |
|
70 |
|
71 CategoryProfile profile2 = new CategoryProfile("RAM, Disk & Heap Profile", SWMTCategoryConstants.PROFILE_RAM_DISK_HEAP); |
|
72 getCategoryProfiles().add(profile2); |
|
73 |
|
74 CategoryProfile profile3 = new CategoryProfile("RAM, Disk, Heap & Handles Profile", SWMTCategoryConstants.PROFILE_RAM_DISK_HEAP_HANDLES); |
|
75 getCategoryProfiles().add(profile3); |
|
76 |
|
77 CategoryProfile profile4 = new CategoryProfile("All", SWMTCategoryConstants.CATEGORY_ALL); |
|
78 getCategoryProfiles().add(profile4); |
|
79 |
|
80 } |
|
81 |
|
82 |
|
83 |
|
84 /** |
|
85 * Initializes category entry list. |
|
86 */ |
|
87 private void initializeCategoryEntries() { |
|
88 // Creating entry array |
|
89 categoryEntries = new ArrayList< SWMTCategoryEntry>(); |
|
90 // Initializing value for the array |
|
91 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_USERHEAP, SWMTCategoryConstants.USER_HEAP_TXT)); |
|
92 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_KERNELHEAP, SWMTCategoryConstants.KERNEL_HEAP_TXT)); |
|
93 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_USERSTACKS, SWMTCategoryConstants.USER_STACKS_TXT)); |
|
94 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_GLOBALDATA, SWMTCategoryConstants.GLOBAL_DATA_TXT)); |
|
95 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_DISKUSAGE, SWMTCategoryConstants.DISK_USAGE_TXT)); |
|
96 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_OPENFILES, SWMTCategoryConstants.OPEN_FILES_TXT)); |
|
97 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_RAMLOADEDCODE, SWMTCategoryConstants.RAM_LOADED_CODE_TXT)); |
|
98 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_SYSTEMMEMORY, SWMTCategoryConstants.SYSTEM_MEMORY_TXT)); |
|
99 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_LOCALCHUNKS, SWMTCategoryConstants.LOCAL_CHUNKS_TXT)); |
|
100 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_GLOBALCHUNKS, SWMTCategoryConstants.GLOBAL_CHUNKS_TXT)); |
|
101 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_RAMDRIVE, SWMTCategoryConstants.RAM_DRIVE_TXT)); |
|
102 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_FILESERVERCACHE, SWMTCategoryConstants.FILE_SERVER_CACHE_TXT)); |
|
103 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_BITMAPHANDLES, SWMTCategoryConstants.BITMAP_HANDLES_TXT)); |
|
104 categoryEntries.add( new SWMTCategoryEntry(SWMTCategoryConstants.CATEGORY_WINDOWGROUPS, SWMTCategoryConstants.WINDOW_GROUPS_TXT)); |
|
105 |
|
106 } |
|
107 |
|
108 |
|
109 /** |
|
110 * Get all category entries exist |
|
111 * @return the categoryEntries |
|
112 */ |
|
113 public List<SWMTCategoryEntry> getCategoryEntries() { |
|
114 return categoryEntries; |
|
115 } |
|
116 |
|
117 /** |
|
118 * Get a category entry by ID |
|
119 * @return the categoryEntry or <code>null</code> if not found |
|
120 */ |
|
121 public SWMTCategoryEntry getCategoryEntry(int entryID) { |
|
122 |
|
123 |
|
124 for (Iterator<SWMTCategoryEntry> iterator = categoryEntries.iterator(); iterator.hasNext();) { |
|
125 SWMTCategoryEntry entry = (SWMTCategoryEntry) iterator.next(); |
|
126 if(entry.getCategoryId() == entryID){ |
|
127 return entry; |
|
128 } |
|
129 } |
|
130 |
|
131 return null; |
|
132 } |
|
133 |
|
134 |
|
135 /** |
|
136 * Get all category profiles created |
|
137 * @return the categoryProfiles |
|
138 */ |
|
139 public List<CategoryProfile> getCategoryProfiles() { |
|
140 return categoryProfiles; |
|
141 } |
|
142 |
|
143 /** |
|
144 * Get wanted SWMT Categorys by IDs |
|
145 * @param categories |
|
146 * @return {@link List} of {@link SWMTCategoryEntry}'s |
|
147 */ |
|
148 public List<SWMTCategoryEntry> getCategoryEntries(int categories) { |
|
149 |
|
150 List<SWMTCategoryEntry> wantedCategories = new ArrayList<SWMTCategoryEntry>(); |
|
151 for (Iterator<SWMTCategoryEntry> iterator = categoryEntries.iterator(); iterator.hasNext();) { |
|
152 SWMTCategoryEntry entry = (SWMTCategoryEntry) iterator.next(); |
|
153 if((entry.getCategoryId() & categories) != 0){ |
|
154 wantedCategories.add(entry); |
|
155 } |
|
156 } |
|
157 return wantedCategories; |
|
158 } |
|
159 |
|
160 /** |
|
161 * Get profile by it's name |
|
162 * @param profileName |
|
163 * @return profile int or <code>null</code> if not found |
|
164 */ |
|
165 public CategoryProfile getProfile(String profileName){ |
|
166 |
|
167 for (Iterator<CategoryProfile> iterator = categoryProfiles.iterator(); iterator |
|
168 .hasNext();) { |
|
169 CategoryProfile profile = (CategoryProfile) iterator.next(); |
|
170 if(profileName.equals(profile.getName())){ |
|
171 return profile; |
|
172 } |
|
173 |
|
174 } |
|
175 return null; |
|
176 } |
|
177 |
|
178 |
|
179 |
|
180 } |