Search in sources :

Example 11 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class DefinitionLabelProvider method getText.

/**
 * @see LabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof EntityDefinition) {
        EntityDefinition entityDef = (EntityDefinition) element;
        element = entityDef.getDefinition();
        List<ChildContext> path = entityDef.getPropertyPath();
        if (path != null && !path.isEmpty()) {
            if (!longNames) {
                path = Collections.singletonList(path.get(path.size() - 1));
            }
            StringBuffer name = new StringBuffer();
            boolean first = true;
            for (ChildContext context : path) {
                if (first) {
                    first = false;
                } else {
                    name.append('.');
                }
                boolean defContext = context.getContextName() == null && context.getIndex() == null && context.getCondition() == null;
                if (!defContext) {
                    name.append('(');
                }
                name.append(getText(context.getChild()));
                if (!defContext) {
                    name.append(')');
                }
            }
            return name.toString();
        } else {
            if (entityDef.getFilter() != null) {
                return "(" + getText(element) + ")";
            }
        }
    }
    if (element instanceof Definition<?>) {
        return ((Definition<?>) element).getDisplayName();
    }
    return super.getText(element);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 12 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class XmlSchemaReader method getTypeForAttribute.

/**
 * Get the named type to use for a specific XML attribute.
 *
 * @param typeName the name of the referenced type
 * @param declaringGroup the declaring group of the attribute
 * @param attributeName the attribute name
 * @return the type definition that should be used as the attribute type
 */
private XmlTypeDefinition getTypeForAttribute(QName typeName, DefinitionGroup declaringGroup, QName attributeName) {
    // detect nilReason attribute TODO check GML namespace?
    if (attributeName.getLocalPart().equals("nilReason") && "NilReasonType".equals(typeName.getLocalPart()) && declaringGroup instanceof Definition<?>) {
        Definition<?> parentDef = (Definition<?>) declaringGroup;
        // determine if parent is defined in INSPIRE
        if (parentDef.getName().getNamespaceURI() != null && parentDef.getName().getNamespaceURI().startsWith("http://inspire.ec.europa.eu/schemas")) {
            // get or create custom INSPIRE NilReason type
            XmlTypeDefinition customType = (XmlTypeDefinition) this.index.getType(INSPIRE_NILREASON_TYPENAME);
            if (customType == null) {
                // not yet created, configure now
                customType = this.index.getOrCreateType(INSPIRE_NILREASON_TYPENAME);
                // use the original type as super type
                customType.setSuperType(this.index.getOrCreateType(typeName));
                // description with documentation of the values
                customType.setDescription("Virtual type representing the GML NilReasonType adapted for the valid values specified by INSPIRE:\n\n" + "unknown:\nThe correct value for the specific spatial object is not known to, and not computable by, the data provider. However, a correct value may exist.\n" + "NOTE 'unknown' is applied on an object-by-object basis in a spatial data set.\n\n" + "unpopulated:\nThe characteristic is not part of the dataset maintained by the data provider. However, the characteristic may exist in the real world.\n" + "NOTE The characteristic receives this value for all objects in the spatial data set.\n\n" + "withheld:\nThe characteristic may exist, but is confidential and not divulged by the data provider.");
                // define a custom enumeration based on valid INSPIRE void
                // reasons
                customType.setConstraint(new Enumeration<String>(INSPIRE_NILREASON_VALUES, true));
            }
            return customType;
        }
    }
    // default case
    return this.index.getOrCreateType(typeName);
}
Also used : XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) XmlTypeDefinition(eu.esdihumboldt.hale.io.xsd.reader.internal.XmlTypeDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) AbstractDefinition(eu.esdihumboldt.hale.common.schema.model.impl.AbstractDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 13 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class RootElementPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    page.setLayout(new GridLayout(1, false));
    // add filter text
    filterText = new Text(page, SWT.SINGLE | SWT.BORDER);
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    // $NON-NLS-1$
    filterText.setText("");
    // add filtered list
    list = new ListViewer(page, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    list.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof XmlElement) {
                QName name = ((XmlElement) element).getName();
                return name.getLocalPart() + " (" + name.getNamespaceURI() + ")";
            }
            if (element instanceof Definition) {
                return ((Definition<?>) element).getDisplayName();
            }
            return super.getText(element);
        }
    });
    list.setContentProvider(ArrayContentProvider.getInstance());
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
    layoutData.widthHint = SWT.DEFAULT;
    layoutData.heightHint = 8 * list.getList().getItemHeight();
    list.getControl().setLayoutData(layoutData);
    // page status update
    list.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            setPageComplete(!selection.isEmpty());
        }
    });
    list.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (canFlipToNextPage()) {
                getContainer().showPage(getNextPage());
                return;
            }
        }
    });
    // search filter & update
    list.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            String filter = filterText.getText();
            // handle empty filter
            if (filter == null || filter.isEmpty()) {
                return true;
            }
            if (element instanceof Definition) {
                Definition<?> def = (Definition<?>) element;
                filter = filter.toLowerCase();
                if (def.getDisplayName().toLowerCase().contains(filter)) {
                    return true;
                }
            }
            return false;
        }
    });
    list.setComparator(new ViewerComparator());
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            // refilter
            list.refresh();
        }
    });
    updateList();
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ModifyListener(org.eclipse.swt.events.ModifyListener) QName(javax.xml.namespace.QName) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 14 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class SpatialDataSetConfigurationPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(page);
    // Get the property definitions of localId and namespace.
    String action = getWizard().getActionId();
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    SchemaSpaceID ssid = SchemaSpaceID.TARGET;
    if (InstanceIO.ACTION_SAVE_SOURCE_DATA.equals(action)) {
        ssid = SchemaSpaceID.SOURCE;
    }
    SchemaSpace target = ss.getSchemas(ssid);
    XmlIndex index = StreamGmlWriter.getXMLIndex(target);
    XmlElement sdsElement = InspireUtil.findSpatialDataSet(index);
    TypeDefinition sdsType = null;
    if (sdsElement != null) {
        sdsType = sdsElement.getType();
    }
    // applicable.
    if (sdsType == null)
        return;
    // find localId and namespace definitions
    Path<Definition<?>> localIdPath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
    List<Definition<?>> localIdDefs = localIdPath.getElements();
    PropertyDefinition localIdDef = (PropertyDefinition) localIdDefs.get(localIdDefs.size() - 1);
    Path<Definition<?>> namespacePath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("namespace").eval(false);
    List<Definition<?>> namespaceDefs = namespacePath.getElements();
    PropertyDefinition nsDef = (PropertyDefinition) namespaceDefs.get(namespaceDefs.size() - 1);
    IPropertyChangeListener changeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(AttributeEditor.IS_VALID) || event.getProperty().equals(FileFieldEditor.IS_VALID))
                updateState();
        }
    };
    // inspire identifier
    Label inspireId = new Label(page, SWT.NONE);
    inspireId.setText("Please specify the local ID and the namespace as part of the INSPIRE identifier of the Spatial Data Set:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(inspireId);
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    Composite localIdtitle = new Composite(page, SWT.NONE);
    localIdtitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
    dlf.createLabel(localIdtitle, localIdDef, false);
    Label label = new Label(localIdtitle, SWT.NONE);
    label.setText(" = ");
    localIdEditor = aef.createEditor(page, localIdDef, null, false);
    localIdEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    localIdEditor.setPropertyChangeListener(changeListener);
    Composite namespacetitle = new Composite(page, SWT.NONE);
    namespacetitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    dlf.createLabel(namespacetitle, nsDef, false);
    label = new Label(namespacetitle, SWT.NONE);
    label.setText(" = ");
    namespaceEditor = aef.createEditor(page, nsDef, null, false);
    namespaceEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    namespaceEditor.setPropertyChangeListener(changeListener);
    // spacer
    Composite spacer = new Composite(page, SWT.NONE);
    GridDataFactory.fillDefaults().hint(0, 8).applyTo(spacer);
    // metadata file
    Label metadataLabel = new Label(page, SWT.NONE);
    metadataLabel.setText("You can include metadata in the Spatial Data Set from a XML file with a MD_Metadata element:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(metadataLabel);
    // source file
    Composite fileFieldComposite = new Composite(page, SWT.NONE);
    fileFieldComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    metadataFile = new OpenFileFieldEditor("metadataFile", "ISO Geographic MetaData XML", true, FileFieldEditor.VALIDATE_ON_KEY_STROKE, fileFieldComposite);
    metadataFile.setPage(this);
    metadataFile.setEmptyStringAllowed(true);
    metadataFile.setFileExtensions(new String[] { "*.xml" });
    metadataFile.setPropertyChangeListener(changeListener);
    // isValid starts with false even if emptyStringAllowed is true.
    // -> force validation hack
    metadataFile.setStringValue(" ");
    metadataFile.setStringValue("");
    updateState();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Label(org.eclipse.swt.widgets.Label) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) OpenFileFieldEditor(eu.esdihumboldt.hale.ui.util.io.OpenFileFieldEditor) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) GridData(org.eclipse.swt.layout.GridData) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 15 with Definition

use of eu.esdihumboldt.hale.common.schema.model.Definition in project hale by halestudio.

the class JaxbToEntityDefinition method convert.

/**
 * Converts the given property to a property entity definition.
 *
 * @param property the property to convert
 * @param types the type index to use
 * @param schemaSpace the schema space to assign
 * @return the property entity definition
 */
public static PropertyEntityDefinition convert(PropertyType property, TypeIndex types, SchemaSpaceID schemaSpace) {
    TypeDefinition typeDef = types.getType(asName(property.getType()));
    Filter filter = getTypeFilter(property);
    List<ChildContext> path = new ArrayList<ChildContext>();
    DefinitionGroup parent = typeDef;
    for (ChildContextType childContext : property.getChild()) {
        if (parent == null) {
            throw new IllegalStateException("Could not resolve property entity definition: child not present");
        }
        Pair<ChildDefinition<?>, List<ChildDefinition<?>>> childs = PropertyBean.findChild(parent, asName(childContext));
        // if the child is still null throw an exception
        if (childs == null || childs.getFirst() == null) {
            String childName = asName(childContext).getLocalPart();
            String parentName;
            if (parent instanceof Definition<?>) {
                parentName = ((Definition<?>) parent).getName().getLocalPart();
            } else {
                parentName = parent.getIdentifier();
            }
            throw new IllegalStateException(MessageFormat.format("Could not resolve property entity definition: child {0} not found in parent {1}", childName, parentName));
        }
        ChildDefinition<?> child = childs.getFirst();
        if (childs.getSecond() != null) {
            for (ChildDefinition<?> pathElems : childs.getSecond()) {
                path.add(new ChildContext(contextName(childContext.getContext()), contextIndex(childContext.getIndex()), createCondition(childContext.getCondition()), pathElems));
            }
        }
        path.add(new ChildContext(contextName(childContext.getContext()), contextIndex(childContext.getIndex()), createCondition(childContext.getCondition()), child));
        if (child instanceof DefinitionGroup) {
            parent = (DefinitionGroup) child;
        } else if (child.asProperty() != null) {
            parent = child.asProperty().getPropertyType();
        } else {
            parent = null;
        }
    }
    return new PropertyEntityDefinition(typeDef, path, schemaSpace, filter);
}
Also used : ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefinitionGroup(eu.esdihumboldt.hale.common.schema.model.DefinitionGroup) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContextType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Definition (eu.esdihumboldt.hale.common.schema.model.Definition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)4 QName (javax.xml.namespace.QName)4 DefinitionAccessor (eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor)3 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)3 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 InstanceValidationMessage (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationMessage)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)2 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)2 Pair (eu.esdihumboldt.util.Pair)2 List (java.util.List)2 GridData (org.eclipse.swt.layout.GridData)2 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)1 ChildContextType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ChildContextType)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1