Search in sources :

Example 6 with AttributeDefinition

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;
}
Also used : Dictionary(java.util.Dictionary) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) Entry(java.util.Map.Entry) Filter(org.osgi.framework.Filter) Iterator(java.util.Iterator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Example 7 with AttributeDefinition

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();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) LinkedList(java.util.LinkedList) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) HashSet(java.util.HashSet)

Example 8 with AttributeDefinition

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);
}
Also used : AttributeDefinition(org.osgi.service.metatype.AttributeDefinition)

Aggregations

AttributeDefinition (org.osgi.service.metatype.AttributeDefinition)8 ObjectClassDefinition (org.osgi.service.metatype.ObjectClassDefinition)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Hashtable (java.util.Hashtable)3 Dictionary (java.util.Dictionary)2 Map (java.util.Map)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2 MetaTypeInformation (org.osgi.service.metatype.MetaTypeInformation)2 MetaTypeService (org.osgi.service.metatype.MetaTypeService)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 XmlParser (org.codice.ddf.parser.xml.XmlParser)1 RegistryObjectMetacardType (org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType)1