use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class OccurringValuesSection method createControls.
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite page = getWidgetFactory().createComposite(parent);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(page);
// refresh button
refresh = getWidgetFactory().createButton(page, null, SWT.PUSH);
refresh.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REFRESH));
refresh.setToolTipText("Update the occurring values");
refresh.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
service.updateOccurringValues((PropertyEntityDefinition) getEntity());
}
});
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(refresh);
// values table
values = new TableViewer(getWidgetFactory().createTable(page, SWT.MULTI | SWT.BORDER));
GridDataFactory.fillDefaults().grab(true, true).span(1, 2).applyTo(values.getControl());
values.setContentProvider(new ArrayContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof OccurringValues) {
return ((OccurringValues) inputElement).getValues().entrySet().toArray();
}
return new Object[] {};
}
});
values.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Entry) {
// XXX use styled label provider instead?
Entry<?> entry = (Entry<?>) element;
if (entry.getCount() > 1) {
return super.getText(entry.getElement()) + "\t(\u00d7" + entry.getCount() + ")";
} else
return super.getText(entry.getElement());
}
return super.getText(element);
}
});
values.setInput(null);
// values context menu
MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
// populate context menu
// get selection
ISelection selection = values.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object[] sels = ((IStructuredSelection) selection).toArray();
List<String> values = new ArrayList<String>();
for (Object sel : sels) {
if (sel instanceof Entry<?>) {
values.add(((Entry<?>) sel).getElement().toString());
}
}
if (!values.isEmpty()) {
manager.add(new AddConditionAction(getEntity(), values, false));
manager.add(new AddParentConditionAction(getEntity(), values, false));
if (values.size() > 1) {
manager.add(new Separator());
manager.add(new AddConditionAction(getEntity(), values, true));
manager.add(new AddParentConditionAction(getEntity(), values, true));
}
}
}
}
});
manager.setRemoveAllWhenShown(true);
final Menu valuesMenu = manager.createContextMenu(values.getControl());
values.getControl().setMenu(valuesMenu);
// copy button
copy = getWidgetFactory().createButton(page, null, SWT.PUSH);
copy.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
copy.setToolTipText("Copy values to the clipboard");
copy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
copyToClipboard();
}
});
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(copy);
// add listener to service
service.addListener(ovlistener = new OccurringValuesListener() {
@Override
public void occurringValuesUpdated(PropertyEntityDefinition property) {
if (property.equals(OccurringValuesSection.this.getEntity())) {
update();
}
}
@Override
public void occurringValuesInvalidated(SchemaSpaceID schemaSpace) {
if (schemaSpace.equals(OccurringValuesSection.this.getEntity().getSchemaSpace())) {
update();
}
}
});
update();
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class IndexJoinIterator method join.
/**
* Joins all direct children of the given type to currentInstances.
*/
@SuppressWarnings("javadoc")
private void join(FamilyInstance[] currentInstances, int currentType) {
// Join all types that are direct children of the last type.
for (int i = currentType + 1; i < joinDefinition.directParent.length; i++) {
if (joinDefinition.directParent[i] == currentType) {
// Get join condition for the direct child type.
Multimap<Integer, JoinCondition> joinConditions = joinDefinition.joinTable.get(i);
// Collect intersection of conditions. null marks beginning
// in contrast to an empty set.
Set<ResolvableInstanceReference> possibleInstances = null;
// ParentType -> JoinConditions
for (Map.Entry<Integer, JoinCondition> joinCondition : joinConditions.entries()) {
PropertyEntityDefinition baseProp = joinCondition.getValue().baseProperty;
QName baseTypeName = baseProp.getType().getName();
List<QName> basePropertyPath = baseProp.getPropertyPath().stream().map(pp -> pp.getChild().getName()).collect(Collectors.toList());
PropertyEntityDefinition joinProp = joinCondition.getValue().joinProperty;
QName joinTypeName = joinProp.getType().getName();
List<QName> joinPropertyPath = joinProp.getPropertyPath().stream().map(pp -> pp.getChild().getName()).collect(Collectors.toList());
List<IndexedPropertyValue> currentValues = index.getInstancePropertyValues(baseTypeName, basePropertyPath, currentInstances[joinCondition.getKey()].getId());
if (currentValues == null || currentValues.isEmpty()) {
possibleInstances = Collections.emptySet();
break;
}
HashSet<ResolvableInstanceReference> matches = new HashSet<ResolvableInstanceReference>();
for (IndexedPropertyValue currentValue : currentValues) {
if (currentValue.getValues() == null || currentValue.getValues().isEmpty()) {
continue;
}
// Find instances that have the current property value
Collection<ResolvableInstanceReference> instancesWithValues = index.getInstancesByValue(joinTypeName, joinPropertyPath, currentValue.getValues());
matches.addAll(instancesWithValues);
}
if (possibleInstances == null) {
possibleInstances = matches;
} else {
// Remove candidates that don't have the current
// property value
Iterator<ResolvableInstanceReference> it = possibleInstances.iterator();
while (it.hasNext()) {
ResolvableInstanceReference cand = it.next();
if (!matches.contains(cand)) {
it.remove();
}
}
}
if (possibleInstances.isEmpty()) {
break;
}
}
if (possibleInstances != null && !possibleInstances.isEmpty()) {
FamilyInstance parent = currentInstances[currentType];
for (ResolvableInstanceReference ref : possibleInstances) {
FamilyInstance child;
child = new FamilyInstanceImpl(ref.resolve());
parent.addChild(child);
currentInstances[i] = child;
join(currentInstances, i);
}
currentInstances[i] = null;
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class GroovyGreedyTransformation method createGroovyBinding.
/**
* Create a Groovy binding from the list of variables.
*
* @param vars the variable values
* @param varDefs definition of the assigned variables, in case some
* variable values are not set, may be <code>null</code>
* @param cell the cell the binding is created for
* @param typeCell the type cell the binding is created for, may be
* <code>null</code>
* @param builder the instance builder for creating target instances, or
* <code>null</code> if not applicable
* @param useInstanceVariables if instances should be used as variables for
* the binding instead of extracting the instance values
* @param log the transformation log
* @param context the execution context
* @param targetInstanceType the type of the target instance
* @return the binding for use with {@link GroovyShell}
*/
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
// collect definitions to check if all were provided
Set<EntityDefinition> notDefined = new HashSet<>();
if (varDefs != null) {
for (Entity entity : varDefs) {
notDefined.add(entity.getDefinition());
}
}
// keep only defs where no value is provided
if (!notDefined.isEmpty()) {
for (PropertyValue var : vars) {
notDefined.remove(var.getProperty());
}
}
// add empty lists to environment if necessary
if (!notDefined.isEmpty()) {
for (EntityDefinition entity : notDefined) {
GroovyTransformation.addToBinding(binding, (PropertyEntityDefinition) entity, Collections.emptyList());
}
}
Map<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> bindingMap = new HashMap<>();
// collect the values
for (PropertyValue var : vars) {
PropertyEntityDefinition property = var.getProperty();
InstanceAccessorArrayList<Object> valueList = bindingMap.get(property);
if (valueList == null) {
valueList = new InstanceAccessorArrayList<>();
bindingMap.put(property, valueList);
}
valueList.add(GroovyTransformation.getUseValue(var.getValue(), useInstanceVariables));
}
// add collected values to environment
for (Entry<PropertyEntityDefinition, InstanceAccessorArrayList<Object>> entry : bindingMap.entrySet()) {
GroovyTransformation.addToBinding(binding, entry.getKey(), entry.getValue());
}
return binding;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class CityGMLXsltExport method writeContainerIntro.
@Override
protected void writeContainerIntro(XMLStreamWriter writer, XsltGenerationContext context) throws XMLStreamException, IOException {
if (targetCityModel != null && sourceCityModel != null) {
// copy GML boundedBy
// do it in a special template
String template = context.reserveTemplateName("copyBoundedBy");
writer.writeStartElement(NS_URI_XSL, "call-template");
writer.writeAttribute("name", template);
writer.writeEndElement();
// find source property
PropertyDefinition sourceBB = null;
for (ChildDefinition<?> child : sourceCityModel.getType().getChildren()) {
if (child.asProperty() != null && child.getName().getLocalPart().equals("boundedBy") && child.getName().getNamespaceURI().startsWith(GML_NAMESPACE_CORE)) {
sourceBB = child.asProperty();
break;
}
}
// find target property
PropertyDefinition targetBB = null;
for (ChildDefinition<?> child : targetCityModel.getType().getChildren()) {
if (child.asProperty() != null && child.getName().getLocalPart().equals("boundedBy") && child.getName().getNamespaceURI().startsWith(GML_NAMESPACE_CORE)) {
targetBB = child.asProperty();
break;
}
}
if (sourceBB != null && targetBB != null) {
// create templated
OutputStreamWriter out = new OutputStreamWriter(context.addInclude().openBufferedStream(), getCharset());
try {
out.write("<xsl:template name=\"" + template + "\">");
StringBuilder selectSource = new StringBuilder();
selectSource.append('/');
selectSource.append(GroovyXslHelpers.asPrefixedName(sourceCityModel.getName(), context));
selectSource.append('/');
selectSource.append(GroovyXslHelpers.asPrefixedName(sourceBB.getName(), context));
selectSource.append("[1]");
out.write("<xsl:for-each select=\"" + selectSource.toString() + "\">");
String elementName = GroovyXslHelpers.asPrefixedName(targetBB.getName(), context);
out.write("<" + elementName + ">");
// create bogus rename cell
DefaultCell cell = new DefaultCell();
// source
ListMultimap<String, Entity> source = ArrayListMultimap.create();
List<ChildContext> sourcePath = new ArrayList<ChildContext>();
sourcePath.add(new ChildContext(sourceBB));
PropertyEntityDefinition sourceDef = new PropertyEntityDefinition(sourceCityModel.getType(), sourcePath, SchemaSpaceID.SOURCE, null);
source.put(null, new DefaultProperty(sourceDef));
cell.setSource(source);
// target
ListMultimap<String, Entity> target = ArrayListMultimap.create();
List<ChildContext> targetPath = new ArrayList<ChildContext>();
targetPath.add(new ChildContext(targetBB));
PropertyEntityDefinition targetDef = new PropertyEntityDefinition(targetCityModel.getType(), targetPath, SchemaSpaceID.TARGET, null);
target.put(null, new DefaultProperty(targetDef));
cell.setTarget(target);
// parameters
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(RenameFunction.PARAMETER_STRUCTURAL_RENAME, new ParameterValue("true"));
parameters.put(RenameFunction.PARAMETER_IGNORE_NAMESPACES, new ParameterValue("true"));
cell.setTransformationParameters(parameters);
// variables
ListMultimap<String, XslVariable> variables = ArrayListMultimap.create();
variables.put(null, new XslVariableImpl(sourceDef, "."));
try {
out.write(context.getPropertyTransformation(RenameFunction.ID).selectFunction(cell).getSequence(cell, variables, context, null));
} catch (TransformationException e) {
throw new IllegalStateException("Failed to create template for boundedBy copy.", e);
}
out.write("</" + elementName + ">");
out.write("</xsl:for-each>");
out.write("</xsl:template>");
} finally {
out.close();
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class FeatureChainingComplexTypeTest method testBackAndForth.
/**
* Tests converting a feature chaining configuration to DOM and back.
*/
@Test
public void testBackAndForth() {
FeatureChaining testConf = new FeatureChaining();
TypeDefinition fakeType = new DefaultTypeDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeType"));
PropertyDefinition fakeProperty0 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0PropertyType")));
PropertyDefinition fakeProperty1 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType0"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType0Type")));
List<ChildContext> path0 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1) });
ChainConfiguration chain0 = new ChainConfiguration();
chain0.setChainIndex(0);
chain0.setPrevChainIndex(-1);
chain0.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path0, SchemaSpaceID.TARGET, null));
PropertyDefinition fakeProperty2 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "fakeProperty1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1PropertyType")));
PropertyDefinition fakeProperty3 = new DefaultPropertyDefinition(new QName(AppSchemaIO.APP_SCHEMA_NAMESPACE, "FakeNestedType1"), fakeType, new DefaultTypeDefinition(new QName("FakeNestedType1Type")));
List<ChildContext> path1 = Arrays.asList(new ChildContext[] { new ChildContext(fakeProperty0), new ChildContext(fakeProperty1), new ChildContext(fakeProperty2), new ChildContext(fakeProperty3) });
ChainConfiguration chain1 = new ChainConfiguration();
chain1.setChainIndex(1);
chain1.setPrevChainIndex(0);
chain1.setNestedTypeTarget(new PropertyEntityDefinition(fakeType, path1, SchemaSpaceID.TARGET, null));
chain1.setMappingName("fakeMapping");
testConf.putChain("test-join", 0, chain0);
testConf.putChain("test-join", 1, chain1);
// convert to DOM
Element fragment = HaleIO.getComplexElement(testConf);
// convert back
FeatureChaining converted = HaleIO.getComplexValue(fragment, FeatureChaining.class, null);
assertNotNull(converted);
assertFalse(converted.equals(testConf));
Map<String, JoinConfiguration> joins = converted.getJoins();
assertNotNull(joins);
assertEquals(1, joins.size());
JoinConfiguration join = joins.get("test-join");
assertNotNull(join);
assertEquals(2, join.getChains().size());
ChainConfiguration convChain0 = join.getChain(0);
assertNotNull(convChain0);
assertEquals(0, convChain0.getChainIndex());
assertEquals(-1, convChain0.getPrevChainIndex());
assertTrue(convChain0.getMappingName() == null);
PropertyType convPropertyType0 = convChain0.getJaxbNestedTypeTarget();
assertNotNull(convPropertyType0);
assertEquals("FakeType", convPropertyType0.getType().getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getType().getNs());
assertEquals(2, convPropertyType0.getChild().size());
assertEquals("fakeProperty0", convPropertyType0.getChild().get(0).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(0).getNs());
assertEquals("FakeNestedType0", convPropertyType0.getChild().get(1).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType0.getChild().get(1).getNs());
ChainConfiguration convChain1 = join.getChain(1);
assertNotNull(convChain1);
assertEquals(1, convChain1.getChainIndex());
assertEquals(0, convChain1.getPrevChainIndex());
assertEquals("fakeMapping", convChain1.getMappingName());
PropertyType convPropertyType1 = convChain1.getJaxbNestedTypeTarget();
assertNotNull(convPropertyType1);
assertEquals("FakeType", convPropertyType1.getType().getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getType().getNs());
assertEquals(4, convPropertyType1.getChild().size());
assertEquals("fakeProperty0", convPropertyType1.getChild().get(0).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(0).getNs());
assertEquals("FakeNestedType0", convPropertyType1.getChild().get(1).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(1).getNs());
assertEquals("fakeProperty1", convPropertyType1.getChild().get(2).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(2).getNs());
assertEquals("FakeNestedType1", convPropertyType1.getChild().get(3).getName());
assertEquals(AppSchemaIO.APP_SCHEMA_NAMESPACE, convPropertyType1.getChild().get(3).getNs());
}
Aggregations