use of org.osgi.service.metatype.AttributeDefinition in project ddf by codice.
the class ConfigurationAdminExt method addMetaTypeNamesToMap.
public List<Map<String, Object>> addMetaTypeNamesToMap(final Map ocdCollection, final String filterSpec, final String type) {
Filter filter = null;
if (filterSpec != null) {
try {
filter = getBundleContext().createFilter(filterSpec);
} catch (InvalidSyntaxException ignore) {
// don't care
}
}
List<Map<String, Object>> metatypeList = new ArrayList<Map<String, Object>>();
Iterator ei = ocdCollection.entrySet().iterator();
while (ei.hasNext()) {
Entry ociEntry = (Entry) ei.next();
final String pid = (String) ociEntry.getKey();
final ObjectClassDefinition ocd = (ObjectClassDefinition) ociEntry.getValue();
if (filter == null) {
Map<String, Object> metatype = new HashMap<String, Object>();
metatype.put(MAP_ENTRY_ID, pid);
metatype.put(MAP_ENTRY_NAME, ocd.getName());
AttributeDefinition[] defs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
metatype.put(MAP_ENTRY_METATYPE, createMetatypeMap(defs));
metatypeList.add(metatype);
} else {
final Dictionary props = new Hashtable();
props.put(type, pid);
if (filter.match(props)) {
Map<String, Object> metatype = new HashMap<String, Object>();
metatype.put(MAP_ENTRY_ID, pid);
metatype.put(MAP_ENTRY_NAME, ocd.getName());
AttributeDefinition[] defs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
metatype.put(MAP_ENTRY_METATYPE, createMetatypeMap(defs));
metatypeList.add(metatype);
}
}
}
return metatypeList;
}
use of org.osgi.service.metatype.AttributeDefinition in project bndtools by bndtools.
the class TemplateParamsWizardPage method updateUI.
void updateUI() {
if (currentPanel != null && !currentPanel.isDisposed()) {
currentPanel.dispose();
currentPanel = null;
}
Composite panel = new Composite(container, SWT.NONE);
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
skip = true;
if (template == null) {
setErrorMessage(null);
setMessage("No template is loaded", WARNING);
} else {
GridLayout layout = new GridLayout(2, false);
layout.horizontalSpacing = 15;
panel.setLayout(layout);
List<Control> fieldControls = new LinkedList<>();
try {
ocd = template.getMetadata();
int count = 0;
Set<String> requiredIds = new HashSet<>();
for (AttributeDefinition ad : ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED)) {
requiredIds.add(ad.getID());
}
AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
for (AttributeDefinition ad : ads) {
String attrib = ad.getID();
if (!fixedAttribs.contains(attrib)) {
Label label = new Label(panel, SWT.NONE);
String labelText = ad.getID();
if (requiredIds.contains(ad.getID())) {
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
}
label.setText(labelText);
Control fieldControl = createFieldControl(panel, ad);
fieldControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
fieldControls.add(fieldControl);
skip = false;
count++;
}
}
if (count == 0) {
setMessage("No editable parameters for template: " + ocd.getName(), INFORMATION);
} else {
setMessage("Edit parameters for template: " + ocd.getDescription(), INFORMATION);
}
setErrorMessage(null);
} catch (Exception e) {
setErrorMessage("Error loading template metadata: " + e.getMessage());
for (Control fieldControl : fieldControls) {
fieldControl.setEnabled(false);
}
}
}
currentPanel = panel;
container.layout(true, true);
updateValidation();
}
use of org.osgi.service.metatype.AttributeDefinition in project bndtools by bndtools.
the class TemplateParamsWizardPage method updateValidation.
private void updateValidation() {
boolean complete = true;
// Check required attribs
AttributeDefinition[] ads = ocd != null ? ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED) : new AttributeDefinition[0];
for (AttributeDefinition ad : ads) {
// Skip attribs provided the wizard
if (fixedAttribs.contains(ad.getID()))
continue;
String value = values.get(ad.getID());
if (value == null || value.trim().isEmpty()) {
complete = false;
break;
}
}
// Validate values
// TODO
setPageComplete(complete);
}
Aggregations