|
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 */ |
|
17 |
|
18 package com.nokia.s60tools.creator.components.calendar; |
|
19 |
|
20 |
|
21 import java.util.Iterator; |
|
22 import java.util.Set; |
|
23 import java.util.Vector; |
|
24 |
|
25 import com.nokia.s60tools.creator.components.AbstractComponent; |
|
26 import com.nokia.s60tools.creator.components.AbstractValue; |
|
27 import com.nokia.s60tools.creator.components.AbstractVariables; |
|
28 import com.nokia.s60tools.creator.components.contact.ContactValue; |
|
29 import com.nokia.s60tools.creator.core.CreatorEditorSettings; |
|
30 |
|
31 |
|
32 /** |
|
33 * Class representing Calendar |
|
34 */ |
|
35 public class Calendar extends AbstractComponent { |
|
36 |
|
37 public Calendar(int id) { |
|
38 super(id); |
|
39 } |
|
40 |
|
41 public Calendar(int id, String eventType) { |
|
42 this(id); |
|
43 setEventType(eventType); |
|
44 } |
|
45 |
|
46 |
|
47 /** |
|
48 * Get type for this Calendar event |
|
49 * @return |
|
50 */ |
|
51 public String getEventType() { |
|
52 return getAdditionalParameter(TYPE_PARAMETER_ID); |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 /** |
|
58 * Set event type for this calendar event |
|
59 * @param eventType |
|
60 */ |
|
61 public void setEventType(String eventType) { |
|
62 addAdditionalParameter(TYPE_PARAMETER_ID, eventType); |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 /* (non-Javadoc) |
|
68 * @see com.nokia.s60tools.creator.components.config.AbstractComponent#getType() |
|
69 */ |
|
70 public String getType() { |
|
71 return CreatorEditorSettings.TYPE_CALENDAR; |
|
72 } |
|
73 |
|
74 |
|
75 /* (non-Javadoc) |
|
76 * @see com.nokia.s60tools.creator.components.AbstractComponent#isValid() |
|
77 */ |
|
78 public boolean isValid() { |
|
79 // Calendar must have type |
|
80 return getEventType() != null; |
|
81 } |
|
82 |
|
83 /* (non-Javadoc) |
|
84 * @see com.nokia.s60tools.creator.components.AbstractComponent#getIdByValue(java.lang.String) |
|
85 */ |
|
86 public String getIdByValue(String value) { |
|
87 return CalendarVariables.getInstance().getIdByValue(value); |
|
88 } |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 /* (non-Javadoc) |
|
94 * @see com.nokia.s60tools.creator.components.AbstractComponent#getValueById(java.lang.String) |
|
95 */ |
|
96 public String getValueById(String id) { |
|
97 return CalendarVariables.getInstance().getValueById(id); |
|
98 } |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 /* (non-Javadoc) |
|
104 * @see com.nokia.s60tools.creator.components.AbstractComponent#getXMLElementName() |
|
105 */ |
|
106 public String getXMLElementName() { |
|
107 return CreatorEditorSettings.TYPE_CALENDAR_XML_ELEMENT; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Component type must be separated from other data with COMPONENT_TYPE_SEPARATOR, and before |
|
112 * COMPONENT_TYPE_SEPARATOR there must not be any other information than component type. |
|
113 * @return component String. Format: |
|
114 * <code><Component type> COMPONENT_TYPE_SEPARATOR <Item label>=<Item value>, <Item label>=<Item value>... </code> |
|
115 */ |
|
116 public String toString() { |
|
117 |
|
118 Set<String> componentKeys = getKeys(); |
|
119 //Collection<String> values = comp.getAttributes().values(); |
|
120 |
|
121 StringBuffer allFieldsB = new StringBuffer(); |
|
122 allFieldsB.append(getValueById( getEventType())); |
|
123 allFieldsB.append( COMPONENT_TYPE_SEPARATOR); |
|
124 |
|
125 //Amount (how many of this component will be added) |
|
126 if(getAmount() > 0){ |
|
127 allFieldsB.append(" Amount="); |
|
128 allFieldsB.append(getAmount()); |
|
129 allFieldsB.append(COMPONENT_ITEM_SEPARATOR); |
|
130 } |
|
131 |
|
132 //Store all attendees found to here |
|
133 Vector <CalendarValue> attendees = new Vector<CalendarValue>(); |
|
134 |
|
135 String itemlabel = new String(); |
|
136 Vector<AbstractValue> itemValue; |
|
137 //Looping through one component, founding all fields from that component |
|
138 for (Iterator<String> compValuesIt = componentKeys.iterator(); compValuesIt.hasNext();) { |
|
139 itemlabel = (String) compValuesIt.next(); |
|
140 itemValue = getAttribute(itemlabel); |
|
141 //get all values from values vector |
|
142 for (Iterator<AbstractValue> iterator = itemValue.iterator(); iterator.hasNext();) { |
|
143 AbstractValue absVal = iterator.next(); |
|
144 CalendarValue calVal = (CalendarValue)absVal; |
|
145 |
|
146 //if value is not attendee, its a regular value |
|
147 if(!calVal.isAttendee()){ |
|
148 addOneItemToBuffer(allFieldsB, itemlabel, calVal); |
|
149 } |
|
150 //for attendee values, collecting them and gathering in the end all together |
|
151 else{ |
|
152 attendees.add(calVal); |
|
153 } |
|
154 |
|
155 } |
|
156 |
|
157 } |
|
158 |
|
159 //If ther is attendees, adding them |
|
160 if(attendees.size() > 0){ |
|
161 allFieldsB.append(CalendarVariables.ATTENDEES); |
|
162 allFieldsB.append(COMPONENT_LABEL_VALUE_SEPARATOR); |
|
163 for (Iterator<CalendarValue> iterator = attendees.iterator(); iterator.hasNext();) { |
|
164 CalendarValue val = (CalendarValue) iterator.next(); |
|
165 allFieldsB.append(val.getValue()); |
|
166 allFieldsB.append(COMPONENT_ITEM_SEPARATOR); |
|
167 } |
|
168 } |
|
169 |
|
170 |
|
171 //deleting last ", " from list |
|
172 if(allFieldsB.toString().endsWith(COMPONENT_ITEM_SEPARATOR)){ |
|
173 allFieldsB.delete(allFieldsB.length()-COMPONENT_ITEM_SEPARATOR.length(), allFieldsB.length()); |
|
174 } |
|
175 return CreatorEditorSettings.getInstance().replaceEntitiesWithChars(allFieldsB.toString()); |
|
176 } |
|
177 |
|
178 |
|
179 |
|
180 private void addOneItemToBuffer(StringBuffer allFieldsB, String itemlabel, |
|
181 CalendarValue calVal) { |
|
182 allFieldsB.append(itemlabel); |
|
183 allFieldsB.append(COMPONENT_LABEL_VALUE_SEPARATOR); |
|
184 //If value is random value, showing in UI only short description (<RND>) |
|
185 if(calVal.isRandom()){ |
|
186 allFieldsB.append(ContactValue.RANDOM_TEXT); |
|
187 }else{ |
|
188 allFieldsB.append(calVal.getValue()); |
|
189 } |
|
190 allFieldsB.append(COMPONENT_ITEM_SEPARATOR); |
|
191 } |
|
192 |
|
193 /* (non-Javadoc) |
|
194 * @see com.nokia.s60tools.creator.components.AbstractComponent#getValuesForItemType(java.lang.String) |
|
195 */ |
|
196 public String[] getValuesForItemType(String itemType) { |
|
197 //If there is not this type of item at all |
|
198 String idByValue = getIdByValue(itemType); |
|
199 if(idByValue == null){ |
|
200 return null; |
|
201 } |
|
202 return CalendarVariables.getInstance().getValuesForItemType(idByValue); |
|
203 |
|
204 } |
|
205 |
|
206 |
|
207 /* (non-Javadoc) |
|
208 * @see com.nokia.s60tools.creator.components.AbstractComponent#itemMaxOccur(java.lang.String) |
|
209 */ |
|
210 public int itemMaxOccur(String itemName) { |
|
211 return CalendarVariables.getInstance().itemMaxOccur(itemName); |
|
212 } |
|
213 |
|
214 /* (non-Javadoc) |
|
215 * @see com.nokia.s60tools.creator.components.AbstractComponent#getVariables() |
|
216 */ |
|
217 public AbstractVariables getVariables(){ |
|
218 return CalendarVariables.getInstance(); |
|
219 } |
|
220 } |