Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.pde.internal.runtime.registry; |
13 |
|
14 |
import java.util.Iterator; |
15 |
import java.util.Map; |
16 |
import org.eclipse.pde.internal.runtime.registry.model.ServiceRegistration; |
17 |
import org.eclipse.ui.views.properties.*; |
18 |
|
19 |
public class ServiceRegistrationPropertySource implements IPropertySource { |
20 |
private final ServiceRegistration serviceRegistration; |
21 |
|
22 |
public ServiceRegistrationPropertySource(ServiceRegistration serviceRegistration) { |
23 |
this.serviceRegistration = serviceRegistration; |
24 |
} |
25 |
|
26 |
public Object getEditableValue() { |
27 |
return serviceRegistration; |
28 |
} |
29 |
|
30 |
public IPropertyDescriptor[] getPropertyDescriptors() { |
31 |
Map properties = serviceRegistration.getProperties(); |
32 |
IPropertyDescriptor[] descriptors = new IPropertyDescriptor[properties.size()]; |
33 |
Iterator it = properties.keySet().iterator(); |
34 |
for (int p = 0; it.hasNext(); p++) { |
35 |
String name = (String) it.next(); |
36 |
descriptors[p] = new PropertyDescriptor(name, name); |
37 |
} |
38 |
return descriptors; |
39 |
} |
40 |
|
41 |
public Object getPropertyValue(Object id) { |
42 |
return toString(serviceRegistration.getProperties().get(id)); |
43 |
} |
44 |
|
45 |
protected String toString(Object value) { |
46 |
if (value == null) { |
47 |
return ""; //$NON-NLS-1$ |
48 |
} else if (value instanceof CharSequence) { |
49 |
CharSequence charSequence = (CharSequence) value; |
50 |
return charSequence.toString(); |
51 |
} else if (value instanceof Object[]) { |
52 |
StringBuffer buff = new StringBuffer(); |
53 |
appendString(buff, value); |
54 |
|
55 |
return buff.toString(); |
56 |
} else { |
57 |
return value.toString(); |
58 |
} |
59 |
} |
60 |
|
61 |
protected void appendString(StringBuffer buff, Object value) { |
62 |
|
63 |
if (value == null) { |
64 |
// ignore |
65 |
} else if (value instanceof Object[]) { |
66 |
Object[] objects = (Object[]) value; |
67 |
buff.append("["); //$NON-NLS-1$ |
68 |
for (int o = 0; o < objects.length; o++) { |
69 |
Object object = objects[o]; |
70 |
if (o > 0) |
71 |
buff.append(", "); //$NON-NLS-1$ |
72 |
appendString(buff, object); |
73 |
} |
74 |
buff.append("]"); //$NON-NLS-1$ |
75 |
} else { |
76 |
buff.append(value.toString()); |
77 |
} |
78 |
} |
79 |
|
80 |
public boolean isPropertySet(Object id) { |
81 |
return serviceRegistration.getProperties().containsKey(id); |
82 |
} |
83 |
|
84 |
public void resetPropertyValue(Object id) { |
85 |
// ignore |
86 |
} |
87 |
|
88 |
public void setPropertyValue(Object id, Object value) { |
89 |
// ignore |
90 |
} |
91 |
} |