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);
}
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);
}
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();
}
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();
}
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);
}
Aggregations