Lines 25-35
Link Here
|
25 |
import org.eclipse.mtj.core.model.jad.DescriptorPropertyDescription; |
25 |
import org.eclipse.mtj.core.model.jad.DescriptorPropertyDescription; |
26 |
import org.eclipse.mtj.ui.internal.MTJUIPlugin; |
26 |
import org.eclipse.mtj.ui.internal.MTJUIPlugin; |
27 |
import org.eclipse.mtj.ui.jadEditor.IJADDescriptorsProvider; |
27 |
import org.eclipse.mtj.ui.jadEditor.IJADDescriptorsProvider; |
28 |
import org.eclipse.mtj.ui.jadEditor.IVendorSpecTester; |
|
|
29 |
|
28 |
|
30 |
/** |
29 |
/** |
31 |
* Provide registry functionality for getting JAD attributes |
30 |
* Provide registry functionality for getting JAD attributes according to the |
32 |
* according to the specify device and editor page. |
31 |
* specify device and editor page. |
33 |
* |
32 |
* |
34 |
* @author gma |
33 |
* @author gma |
35 |
* |
34 |
* |
Lines 40-49
Link Here
|
40 |
*/ |
39 |
*/ |
41 |
public static final String JAD_ATTRIBUTE_EXTENSION = "jadAttributes"; |
40 |
public static final String JAD_ATTRIBUTE_EXTENSION = "jadAttributes"; |
42 |
|
41 |
|
43 |
/** |
42 |
// /** |
44 |
* use to store JAD Attributes configElements for different devices. |
43 |
// * use to store JAD Attributes configElements for different devices. |
45 |
*/ |
44 |
// */ |
46 |
private static Map<IDevice, JADAttributesConfigElement[]> deviceVendorJADAttrMap = new HashMap<IDevice, JADAttributesConfigElement[]>(); |
45 |
// private static Map<IDevice, JADAttributesConfigElement[]> deviceVendorJADAttrMap = new HashMap<IDevice, JADAttributesConfigElement[]>(); |
47 |
|
46 |
|
48 |
/** |
47 |
/** |
49 |
* use to store generic JAD attributes(not vendor specific) for each page. |
48 |
* use to store generic JAD attributes(not vendor specific) for each page. |
Lines 64-81
Link Here
|
64 |
* @return the vendor specific JAD descriptors |
63 |
* @return the vendor specific JAD descriptors |
65 |
*/ |
64 |
*/ |
66 |
public static DescriptorPropertyDescription[] getJADAttrDescriptorsByPage( |
65 |
public static DescriptorPropertyDescription[] getJADAttrDescriptorsByPage( |
67 |
String pageID, IDevice device) { |
66 |
String pageID) { |
68 |
JADAttributesConfigElement[] relatedElements = getRelatedAttrElements(pageID,device); |
67 |
JADAttributesConfigElement[] relatedElements = getRelatedAttrElements(pageID); |
69 |
DescriptorPropertyDescription[] resultAttributes = getDescriptorsFromElements(relatedElements,device); |
68 |
DescriptorPropertyDescription[] resultAttributes = getDescriptorsFromElements(relatedElements); |
70 |
return resultAttributes; |
69 |
return resultAttributes; |
71 |
} |
70 |
} |
|
|
71 |
|
72 |
/** |
72 |
/** |
73 |
* return the related jadAttributes configElements |
73 |
* return the related jadAttributes configElements |
74 |
*/ |
74 |
*/ |
75 |
private static JADAttributesConfigElement[] getRelatedAttrElements(String pageID,IDevice device){ |
75 |
private static JADAttributesConfigElement[] getRelatedAttrElements( |
|
|
76 |
String pageID) { |
76 |
JADAttributesConfigElement[] genericElements = null; |
77 |
JADAttributesConfigElement[] genericElements = null; |
77 |
JADAttributesConfigElement[] vendorSpecElements = null; |
78 |
// JADAttributesConfigElement[] vendorSpecElements = null; |
78 |
JADAttributesConfigElement[] resultElements = null; |
79 |
// JADAttributesConfigElement[] resultElements = null; |
79 |
// get the page's generic JAD attribute descriptors |
80 |
// get the page's generic JAD attribute descriptors |
80 |
if (!genericPageJADAttrMap.containsKey(pageID)) { |
81 |
if (!genericPageJADAttrMap.containsKey(pageID)) { |
81 |
genericPageJADAttrMap.put(pageID, getGenericElements(pageID)); |
82 |
genericPageJADAttrMap.put(pageID, getGenericElements(pageID)); |
Lines 82-140
Link Here
|
82 |
} |
83 |
} |
83 |
genericElements = genericPageJADAttrMap.get(pageID); |
84 |
genericElements = genericPageJADAttrMap.get(pageID); |
84 |
// get the page's vendor specific JAD attributes descriptors |
85 |
// get the page's vendor specific JAD attributes descriptors |
85 |
vendorSpecElements = getVendorSpecElements(pageID,device); |
86 |
// vendorSpecElements = getVendorSpecElements(pageID,device); |
86 |
|
87 |
// |
87 |
resultElements = new JADAttributesConfigElement[genericElements.length+vendorSpecElements.length]; |
88 |
// resultElements = new |
88 |
System.arraycopy(genericElements, 0, resultElements, 0, genericElements.length); |
89 |
// JADAttributesConfigElement[genericElements.length+vendorSpecElements.length]; |
89 |
System.arraycopy(vendorSpecElements, 0, resultElements, genericElements.length, vendorSpecElements.length); |
90 |
// System.arraycopy(genericElements, 0, resultElements, 0, |
90 |
|
91 |
// genericElements.length); |
91 |
return resultElements; |
92 |
// System.arraycopy(vendorSpecElements, 0, resultElements, |
|
|
93 |
// genericElements.length, vendorSpecElements.length); |
94 |
|
95 |
// return resultElements; |
96 |
return genericElements; |
92 |
} |
97 |
} |
93 |
/** |
98 |
|
94 |
* |
99 |
// /** |
95 |
* @param pageID |
100 |
// * |
96 |
* the JAD Editor page's ID |
101 |
// * @param pageID |
97 |
* @param device |
102 |
// * the JAD Editor page's ID |
98 |
* the device used |
103 |
// * @param device |
99 |
* @return |
104 |
// * the device used |
100 |
* the vendor specific jadAttributes configElements for specific page |
105 |
// * @return the vendor specific jadAttributes configElements for specific |
101 |
*/ |
106 |
// * page |
102 |
private static JADAttributesConfigElement[] getVendorSpecElements(String pageID,IDevice device){ |
107 |
// */ |
103 |
if (!deviceVendorJADAttrMap.containsKey(device)) { |
108 |
// private static JADAttributesConfigElement[] getVendorSpecElements( |
104 |
JADAttributesConfigElement[] elements = getAllJADAttributeElements(); |
109 |
// String pageID, IDevice device) { |
105 |
elements = filterElementsByDevice(elements,device); |
110 |
// if (!deviceVendorJADAttrMap.containsKey(device)) { |
106 |
deviceVendorJADAttrMap.put(device, elements); |
111 |
// JADAttributesConfigElement[] elements = getAllJADAttributeElements(); |
107 |
} |
112 |
// elements = filterElementsByDevice(elements, device); |
108 |
JADAttributesConfigElement[] allSpecVendorElements = deviceVendorJADAttrMap.get(device); |
113 |
// deviceVendorJADAttrMap.put(device, elements); |
109 |
|
114 |
// } |
110 |
return filterElementsByPage(allSpecVendorElements,pageID); |
115 |
// JADAttributesConfigElement[] allSpecVendorElements = deviceVendorJADAttrMap |
111 |
|
116 |
// .get(device); |
112 |
} |
117 |
// |
|
|
118 |
// return filterElementsByPage(allSpecVendorElements, pageID); |
119 |
// |
120 |
// } |
121 |
|
113 |
/** |
122 |
/** |
114 |
* |
123 |
* |
115 |
* @param pageID |
124 |
* @param pageID |
116 |
* the JAD Editor page's ID |
125 |
* the JAD Editor page's ID |
117 |
* @return |
126 |
* @return the generic jadAttributes configElements for specific page |
118 |
* the generic jadAttributes configElements for specific page |
|
|
119 |
*/ |
127 |
*/ |
120 |
private static JADAttributesConfigElement[] getGenericElements(String pageID){ |
128 |
private static JADAttributesConfigElement[] getGenericElements(String pageID) { |
121 |
JADAttributesConfigElement[] elements = getAllJADAttributeElements(); |
129 |
JADAttributesConfigElement[] elements = getAllJADAttributeElements(); |
122 |
return filterElementsByPageAndVendorSpec(elements,pageID,true); |
130 |
return filterElementsByPageAndVendorSpec(elements, pageID, true); |
123 |
|
131 |
|
124 |
} |
|
|
125 |
private static JADAttributesConfigElement[] filterElementsByDevice(JADAttributesConfigElement[] elements,IDevice device){ |
126 |
return filterElements(elements,device,null,false); |
127 |
} |
132 |
} |
128 |
|
133 |
|
129 |
private static JADAttributesConfigElement[] filterElementsByPage(JADAttributesConfigElement[] elements,String pageID){ |
134 |
// private static JADAttributesConfigElement[] filterElementsByDevice( |
130 |
return filterElements(elements,null,pageID,false); |
135 |
// JADAttributesConfigElement[] elements, IDevice device) { |
|
|
136 |
// return filterElements(elements, device, null, false); |
137 |
// } |
138 |
// |
139 |
// private static JADAttributesConfigElement[] filterElementsByPage( |
140 |
// JADAttributesConfigElement[] elements, String pageID) { |
141 |
// return filterElements(elements, null, pageID, false); |
142 |
// } |
143 |
|
144 |
private static JADAttributesConfigElement[] filterElementsByPageAndVendorSpec( |
145 |
JADAttributesConfigElement[] elements, String pageID, |
146 |
boolean excludeVendorSpec) { |
147 |
return filterElements(elements, null, pageID, excludeVendorSpec); |
131 |
} |
148 |
} |
132 |
|
149 |
|
133 |
private static JADAttributesConfigElement[] filterElementsByPageAndVendorSpec(JADAttributesConfigElement[] elements,String pageID,boolean excludeVendorSpec){ |
150 |
private static JADAttributesConfigElement[] filterElements( |
134 |
return filterElements(elements,null,pageID,excludeVendorSpec); |
151 |
JADAttributesConfigElement[] elements, IDevice device, |
135 |
} |
152 |
String pageID, boolean excludeVendorSpec) { |
136 |
|
|
|
137 |
private static JADAttributesConfigElement[] filterElements(JADAttributesConfigElement[] elements,IDevice device,String pageID,boolean excludeVendorSpec){ |
138 |
ArrayList<JADAttributesConfigElement> resultDescriptorList = new ArrayList<JADAttributesConfigElement>(); |
153 |
ArrayList<JADAttributesConfigElement> resultDescriptorList = new ArrayList<JADAttributesConfigElement>(); |
139 |
for (int i = 0; i < elements.length; i++) { |
154 |
for (int i = 0; i < elements.length; i++) { |
140 |
JADAttributesConfigElement element = elements[i]; |
155 |
JADAttributesConfigElement element = elements[i]; |
Lines 139-157
Link Here
|
139 |
for (int i = 0; i < elements.length; i++) { |
154 |
for (int i = 0; i < elements.length; i++) { |
140 |
JADAttributesConfigElement element = elements[i]; |
155 |
JADAttributesConfigElement element = elements[i]; |
141 |
boolean satisfied = true; |
156 |
boolean satisfied = true; |
142 |
if(device!=null) |
157 |
if (device != null) |
143 |
satisfied &= element.isVendorSpec()&&isDeviceMatchVendor(device, element); |
158 |
satisfied &= element.isVendorSpec() |
144 |
if(pageID!=null) |
159 |
&& isDeviceMatchVendor(device, element); |
145 |
satisfied &= element.getAttributesShowPage().equalsIgnoreCase(pageID); |
160 |
if (pageID != null) |
146 |
if(excludeVendorSpec) |
161 |
satisfied &= element.getAttributesShowPage().equalsIgnoreCase( |
|
|
162 |
pageID); |
163 |
if (excludeVendorSpec) |
147 |
satisfied &= !element.isVendorSpec(); |
164 |
satisfied &= !element.isVendorSpec(); |
148 |
|
165 |
|
149 |
if (satisfied) |
166 |
if (satisfied) |
150 |
resultDescriptorList.add(element); |
167 |
resultDescriptorList.add(element); |
151 |
|
168 |
|
152 |
} |
169 |
} |
153 |
return resultDescriptorList.toArray(new JADAttributesConfigElement[0]); |
170 |
return resultDescriptorList.toArray(new JADAttributesConfigElement[0]); |
154 |
} |
171 |
} |
|
|
172 |
|
155 |
/** |
173 |
/** |
156 |
* judge whether the configuration element is for the device |
174 |
* judge whether the configuration element is for the device |
157 |
* |
175 |
* |
Lines 161-199
Link Here
|
161 |
*/ |
179 |
*/ |
162 |
private static boolean isDeviceMatchVendor(IDevice device, |
180 |
private static boolean isDeviceMatchVendor(IDevice device, |
163 |
JADAttributesConfigElement element) { |
181 |
JADAttributesConfigElement element) { |
164 |
IVendorSpecTester vendorSpecTester = null; |
182 |
// IVendorSpecTester vendorSpecTester = null; |
165 |
try { |
183 |
// try { |
166 |
vendorSpecTester = element.getVendorSpecTester(); |
184 |
// vendorSpecTester = element.getVendorSpecTester(); |
167 |
} catch (CoreException e) { |
185 |
// } catch (CoreException e) { |
168 |
} |
186 |
// } |
169 |
boolean matched = false; |
187 |
// boolean matched = false; |
170 |
if (vendorSpecTester != null) { |
188 |
// if (vendorSpecTester != null) { |
171 |
try { |
189 |
// try { |
172 |
matched = vendorSpecTester.isVendorSpec(device); |
190 |
// matched = vendorSpecTester.isVendorSpec(device); |
173 |
} catch (Exception e) { |
191 |
// } catch (Exception e) { |
174 |
matched = false; |
192 |
// matched = false; |
175 |
MTJCorePlugin |
193 |
// MTJCorePlugin |
176 |
.log(IStatus.WARNING, |
194 |
// .log(IStatus.WARNING, |
177 |
"Errors happens while judging the device has vendor specifc JAD attributes", |
195 |
// "Errors happens while judging the device has vendor specifc JAD |
178 |
e); |
196 |
// attributes", |
179 |
} |
197 |
// e); |
180 |
} |
198 |
// } |
181 |
return matched; |
199 |
// } |
|
|
200 |
// return matched; |
201 |
return true; |
182 |
} |
202 |
} |
183 |
|
203 |
|
184 |
/** |
204 |
/** |
185 |
* |
205 |
* |
186 |
* @param elements |
206 |
* @param elements |
187 |
* config elements |
207 |
* config elements |
188 |
* @param pageID |
208 |
* @param pageID |
189 |
* editor page ID |
209 |
* editor page ID |
190 |
* @param device |
210 |
* @param device |
191 |
* target device |
211 |
* target device |
192 |
|
212 |
* |
193 |
* @return DescriptorPropertyDescription array |
213 |
* @return DescriptorPropertyDescription array |
194 |
*/ |
214 |
*/ |
195 |
private static DescriptorPropertyDescription[] getDescriptorsFromElements( |
215 |
private static DescriptorPropertyDescription[] getDescriptorsFromElements( |
196 |
JADAttributesConfigElement[] elements, IDevice device) { |
216 |
JADAttributesConfigElement[] elements) { |
197 |
ArrayList<DescriptorPropertyDescription> descriptorList = new ArrayList<DescriptorPropertyDescription>(); |
217 |
ArrayList<DescriptorPropertyDescription> descriptorList = new ArrayList<DescriptorPropertyDescription>(); |
198 |
for (int i = 0; i < elements.length; i++) { |
218 |
for (int i = 0; i < elements.length; i++) { |
199 |
JADAttributesConfigElement element = elements[i]; |
219 |
JADAttributesConfigElement element = elements[i]; |
Lines 201-212
Link Here
|
201 |
IJADDescriptorsProvider provider = element |
221 |
IJADDescriptorsProvider provider = element |
202 |
.getJadDescriptorsProvider(); |
222 |
.getJadDescriptorsProvider(); |
203 |
DescriptorPropertyDescription[] descriptorArray = provider |
223 |
DescriptorPropertyDescription[] descriptorArray = provider |
204 |
.getDescriptorPropertyDescriptions(device); |
224 |
.getDescriptorPropertyDescriptions(); |
205 |
descriptorList.addAll(Arrays.asList(descriptorArray)); |
225 |
descriptorList.addAll(Arrays.asList(descriptorArray)); |
206 |
|
226 |
|
207 |
} catch (Exception e) { |
227 |
} catch (Exception e) { |
208 |
MTJCorePlugin |
228 |
MTJCorePlugin |
209 |
.log(IStatus.WARNING, |
229 |
.log( |
|
|
230 |
IStatus.WARNING, |
210 |
"Errors happens while judging the device has vendor specifc JAD attributes", |
231 |
"Errors happens while judging the device has vendor specifc JAD attributes", |
211 |
e); |
232 |
e); |
212 |
} |
233 |
} |
Lines 212-220
Link Here
|
212 |
} |
233 |
} |
213 |
} |
234 |
} |
214 |
|
235 |
|
215 |
return descriptorList.toArray(new DescriptorPropertyDescription[0]); |
236 |
return descriptorList |
|
|
237 |
.toArray(new DescriptorPropertyDescription[descriptorList |
238 |
.size()]); |
216 |
} |
239 |
} |
217 |
|
|
|
218 |
|
240 |
|
219 |
private static JADAttributesConfigElement[] getAllJADAttributeElements() { |
241 |
private static JADAttributesConfigElement[] getAllJADAttributeElements() { |
220 |
if (allJADAttrElements == null) { |
242 |
if (allJADAttrElements == null) { |
Lines 246-252
Link Here
|
246 |
* |
268 |
* |
247 |
*/ |
269 |
*/ |
248 |
static class JADAttributesConfigElement { |
270 |
static class JADAttributesConfigElement { |
249 |
private static final String VENDOR_SPEC_TESTER = "vendorSpecTester"; |
|
|
250 |
private static final String JAD_DESCRIPTOR_PROVIDER_ELEMENT = "jadDescriptorsProvider"; |
271 |
private static final String JAD_DESCRIPTOR_PROVIDER_ELEMENT = "jadDescriptorsProvider"; |
251 |
private static final String JAD_DESCRIPTOR_PROVIDER_CLASS = "class"; |
272 |
private static final String JAD_DESCRIPTOR_PROVIDER_CLASS = "class"; |
252 |
private static final String JAD_ATTR_SHOW_PAGE = "pageID"; |
273 |
private static final String JAD_ATTR_SHOW_PAGE = "pageID"; |
Lines 253-259
Link Here
|
253 |
private static final String VENDOR_SPEC_ATTR = "vendorSpec"; |
274 |
private static final String VENDOR_SPEC_ATTR = "vendorSpec"; |
254 |
|
275 |
|
255 |
private IConfigurationElement element; |
276 |
private IConfigurationElement element; |
256 |
private IVendorSpecTester vendorSpecTester; |
277 |
// private IVendorSpecTester vendorSpecTester; |
257 |
private IJADDescriptorsProvider jadDescriptorsProvider; |
278 |
private IJADDescriptorsProvider jadDescriptorsProvider; |
258 |
|
279 |
|
259 |
public JADAttributesConfigElement(IConfigurationElement jadAttrElement) { |
280 |
public JADAttributesConfigElement(IConfigurationElement jadAttrElement) { |
Lines 260-272
Link Here
|
260 |
this.element = jadAttrElement; |
281 |
this.element = jadAttrElement; |
261 |
} |
282 |
} |
262 |
|
283 |
|
263 |
public IVendorSpecTester getVendorSpecTester() throws CoreException { |
284 |
// public IVendorSpecTester getVendorSpecTester() throws CoreException { |
264 |
if (vendorSpecTester == null) { |
285 |
// if (vendorSpecTester == null) { |
265 |
vendorSpecTester = (IVendorSpecTester) element |
286 |
// vendorSpecTester = (IVendorSpecTester) element |
266 |
.createExecutableExtension(VENDOR_SPEC_TESTER); |
287 |
// .createExecutableExtension(VENDOR_SPEC_TESTER); |
267 |
} |
288 |
// } |
268 |
return vendorSpecTester; |
289 |
// return vendorSpecTester; |
269 |
} |
290 |
// } |
270 |
|
291 |
|
271 |
public IJADDescriptorsProvider getJadDescriptorsProvider() |
292 |
public IJADDescriptorsProvider getJadDescriptorsProvider() |
272 |
throws CoreException { |
293 |
throws CoreException { |
Lines 284-293
Link Here
|
284 |
public String getAttributesShowPage() { |
305 |
public String getAttributesShowPage() { |
285 |
return element.getAttribute(JAD_ATTR_SHOW_PAGE); |
306 |
return element.getAttribute(JAD_ATTR_SHOW_PAGE); |
286 |
} |
307 |
} |
287 |
|
308 |
|
288 |
public boolean isVendorSpec(){ |
309 |
public boolean isVendorSpec() { |
289 |
String value = element.getAttribute(VENDOR_SPEC_ATTR); |
310 |
String value = element.getAttribute(VENDOR_SPEC_ATTR); |
290 |
return value == null?false:"true".equalsIgnoreCase(value); |
311 |
return value == null ? false : "true".equalsIgnoreCase(value); |
291 |
} |
312 |
} |
292 |
|
313 |
|
293 |
} |
314 |
} |