Search in sources :

Example 1 with PropertyOrChildrenTypeCondition

use of eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition in project hale by halestudio.

the class PropertyParameter method createConditions.

private static List<PropertyCondition> createConditions(IConfigurationElement conf) {
    List<PropertyCondition> result = new ArrayList<PropertyCondition>();
    IConfigurationElement[] children = conf.getChildren();
    if (children != null) {
        for (IConfigurationElement child : children) {
            String name = child.getName();
            if (name.equals("propertyCondition")) {
                try {
                    PropertyCondition condition = (PropertyCondition) child.createExecutableExtension("class");
                    result.add(condition);
                } catch (CoreException e) {
                    log.error("Error creating property condition from extension", e);
                }
            } else if (name.equals("bindingCondition")) {
                BindingCondition bc = createBindingCondition(child);
                if (bc != null) {
                    result.add(new PropertyTypeCondition(bc));
                }
            } else if (name.equals("geometryCondition")) {
                GeometryCondition gc = createGeometryCondition(child);
                if (gc != null) {
                    result.add(new PropertyTypeCondition(gc));
                }
            } else if (name.equals("geometryOrParentCondition")) {
                GeometryCondition gc = createGeometryCondition(child);
                if (gc != null) {
                    result.add(new PropertyOrChildrenTypeCondition(gc));
                }
            } else if (name.equals("valueCondition")) {
                String attr = child.getAttribute("allowAugmented");
                boolean allowAugmented;
                if (attr == null || attr.isEmpty()) {
                    // default value
                    allowAugmented = true;
                } else {
                    allowAugmented = Boolean.parseBoolean(attr);
                }
                if (allowAugmented) {
                    result.add(VALUE_CONDITION);
                } else {
                    result.add(VALUE_CONDITION_STRICT);
                }
            } else {
                // ignore
                log.warn("Unrecognized property condition");
            }
        }
    }
    return result;
}
Also used : PropertyCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyCondition) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) BindingCondition(eu.esdihumboldt.hale.common.align.model.condition.impl.BindingCondition) PropertyTypeCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyTypeCondition) PropertyOrChildrenTypeCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition) GeometryCondition(eu.esdihumboldt.hale.common.align.model.condition.impl.GeometryCondition) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 2 with PropertyOrChildrenTypeCondition

use of eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition in project hale by halestudio.

the class GeoJSONConfigurationPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(final Composite page) {
    page.setLayout(new GridLayout(1, false));
    Label explanation = new Label(page, SWT.NONE);
    explanation.setText("If a geometry is set to \"none\", instances will still be included as GeoJSON features,\nbut without default geometries.");
    final DynamicScrolledComposite sc = new DynamicScrolledComposite(page, SWT.V_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setExpandHorizontal(true);
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(parent);
    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
    Set<TypeDefinition> types = is.getInstanceTypes(DataSet.TRANSFORMED);
    for (final TypeDefinition type : types) {
        Label label = new Label(parent, SWT.NONE);
        label.setText(type.getDisplayName() + ":");
        PropertyCondition condition = new PropertyOrChildrenTypeCondition(new GeometryCondition());
        PropertyParameterDefinition param = new PropertyParameter("", 0, 1, "Geometry", null, Collections.singletonList(condition), false);
        PropertyEntitySelector selector = new PropertyEntitySelector(SchemaSpaceID.TARGET, param, parent, new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
        selector.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
                    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                    PropertyEntityDefinition property = (PropertyEntityDefinition) selection.getFirstElement();
                    config.addDefaultGeometry(type, property);
                } else {
                    config.addDefaultGeometry(type, null);
                }
            }
        });
        selector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        // initial selection
        List<QName> path = gss.getDefaultGeometry(type);
        if (path != null) {
            EntityDefinition entityDef = new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null);
            for (QName child : path) entityDef = AlignmentUtil.getChild(entityDef, child);
            selector.setSelection(new StructuredSelection(entityDef));
        }
    }
    sc.setContent(parent);
}
Also used : Label(org.eclipse.swt.widgets.Label) PropertyEntitySelector(eu.esdihumboldt.hale.ui.function.common.PropertyEntitySelector) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) PropertyParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyParameterDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyCondition) PropertyOrChildrenTypeCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) QName(javax.xml.namespace.QName) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) GridData(org.eclipse.swt.layout.GridData) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) GeometryCondition(eu.esdihumboldt.hale.common.align.model.condition.impl.GeometryCondition) PropertyParameter(eu.esdihumboldt.hale.common.align.extension.function.PropertyParameter)

Aggregations

PropertyCondition (eu.esdihumboldt.hale.common.align.model.condition.PropertyCondition)2 PropertyOrChildrenTypeCondition (eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition)2 GeometryCondition (eu.esdihumboldt.hale.common.align.model.condition.impl.GeometryCondition)2 PropertyParameter (eu.esdihumboldt.hale.common.align.extension.function.PropertyParameter)1 PropertyParameterDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyParameterDefinition)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 PropertyTypeCondition (eu.esdihumboldt.hale.common.align.model.condition.PropertyTypeCondition)1 BindingCondition (eu.esdihumboldt.hale.common.align.model.condition.impl.BindingCondition)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 PropertyEntitySelector (eu.esdihumboldt.hale.ui.function.common.PropertyEntitySelector)1 GeometrySchemaService (eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService)1 InstanceService (eu.esdihumboldt.hale.ui.service.instance.InstanceService)1 DynamicScrolledComposite (eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1