use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell in project hale by halestudio.
the class AlignmentView method createViewControl.
/**
* @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#createViewControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createViewControl(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(GridLayoutFactory.fillDefaults().create());
// create type relation selection control
sourceTargetSelector = new SourceTargetTypeSelector(page);
sourceTargetSelector.getControl().setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).create());
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getViewer().setInput(sourceTargetSelector.getSelectedCell());
if (deactivatedCellFilterAction != null) {
deactivatedCellFilterAction.setEnabled(sourceTargetSelector.isCellSelected());
if (!sourceTargetSelector.isCellSelected())
deactivatedCellFilterAction.setChecked(true);
}
refreshGraph();
}
});
// typeRelations = new ComboViewer(page, SWT.DROP_DOWN | SWT.READ_ONLY);
// typeRelations.setContentProvider(ArrayContentProvider.getInstance());
// typeRelations.setLabelProvider(new LabelProvider() {
//
// @Override
// public Image getImage(Object element) {
// if (element instanceof Cell) {
// // use function image if possible
// Cell cell = (Cell) element;
// String functionId = cell.getTransformationIdentifier();
// AbstractFunction<?> function = FunctionUtil.getFunction(functionId);
// if (function != null) {
// return functionLabels.getImage(function);
// }
// return null;
// }
//
// return super.getImage(element);
// }
//
// @Override
// public String getText(Object element) {
// if (element instanceof Cell) {
// Cell cell = (Cell) element;
//
// return CellUtil.getCellDescription(cell);
// }
//
// return super.getText(element);
// }
//
// });
// typeRelations.addSelectionChangedListener(new ISelectionChangedListener() {
//
// @Override
// public void selectionChanged(SelectionChangedEvent event) {
// updateGraph();
// }
// });
// typeRelations.getControl().setLayoutData(
// GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false)
// .create());
// create viewer
Composite viewerContainer = new Composite(page, SWT.NONE);
viewerContainer.setLayout(new FillLayout());
viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
super.createViewControl(viewerContainer);
updateLayout(false);
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
// update();
as.addListener(alignmentListener = new AlignmentServiceAdapter() {
@Override
public void alignmentCleared() {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
}
});
}
@Override
public void cellsRemoved(Iterable<Cell> cells) {
if (sourceTargetSelector.isCellSelected() && Iterables.contains(cells, sourceTargetSelector.getSelectedCell()))
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
refreshGraph();
}
@Override
public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
if (sourceTargetSelector.isCellSelected() && cells.keySet().contains(sourceTargetSelector.getSelectedCell()))
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
refreshGraph();
}
@Override
public void cellsAdded(Iterable<Cell> cells) {
refreshGraph();
}
@Override
public void alignmentChanged() {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
sourceTargetSelector.setSelection(StructuredSelection.EMPTY);
}
});
}
@Override
public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
refreshGraph();
}
@Override
public void customFunctionsChanged() {
refreshGraph();
}
});
TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
taskService.addListener(tasksListener = new TaskServiceListener() {
@Override
public void tasksRemoved(Iterable<Task<?>> tasks) {
refreshGraph();
}
@Override
public void tasksAdded(Iterable<Task<?>> tasks) {
refreshGraph();
}
@Override
public void taskUserDataChanged(ResolvedTask<?> task) {
refreshGraph();
}
});
// initialize compatibility checkup and display
CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
cs.addListener(compListener = new ExclusiveExtensionListener<CompatibilityMode, CompatibilityModeFactory>() {
@Override
public void currentObjectChanged(final CompatibilityMode arg0, final CompatibilityModeFactory arg1) {
refreshGraph();
}
});
// listen on SchemaSelections
getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!(selection instanceof SchemaSelection)) {
// only react on schema selections
return;
}
if (part != AlignmentView.this) {
updateRelation((SchemaSelection) selection);
}
}
});
// select type cell, if it is double clicked
getViewer().addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection.size() == 1) {
Object selected = selection.getFirstElement();
if (selected instanceof Cell && AlignmentUtil.isTypeCell((Cell) selected))
sourceTargetSelector.setSelection(selection);
}
}
});
// listen on size changes
getViewer().getControl().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
updateLayout(true);
}
});
getViewer().setInput(new DefaultCell());
}
use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell in project hale by halestudio.
the class MappingView method createLabelProvider.
@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {
@Override
protected boolean isInherited(Cell cell) {
// cannot inherit type cells
if (AlignmentUtil.isTypeCell(cell))
return false;
SchemaSelection selection = SchemaSelectionHelper.getSchemaSelection();
if (selection != null && !selection.isEmpty()) {
DefaultCell dummyTypeCell = new DefaultCell();
ListMultimap<String, Type> sources = ArrayListMultimap.create();
ListMultimap<String, Type> targets = ArrayListMultimap.create();
Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
for (EntityDefinition def : items.getFirst()) sources.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
for (EntityDefinition def : items.getSecond()) targets.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
dummyTypeCell.setSource(sources);
dummyTypeCell.setTarget(targets);
return AlignmentUtil.reparentCell(cell, dummyTypeCell, true) != cell;
} else
return false;
}
};
}
use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell in project hale by halestudio.
the class AbstractGenericFunctionWizard method init.
/**
* @see AbstractFunctionWizard#init(Cell)
*/
@Override
protected void init(Cell cell) {
// create a new cell even if a cell is already present
resultCell = new DefaultCell(cell);
// copy ID
resultCell.setId(cell.getId());
// XXX necessary to reset those?
resultCell.setSource(null);
resultCell.setTarget(null);
resultCell.setTransformationParameters(null);
// the cell configuration will be duplicated or changed by the wizard
// afterwards the old cell is replaced by the new cell in the alignment
}
use of eu.esdihumboldt.hale.common.align.model.impl.DefaultCell 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.DefaultCell in project hale by halestudio.
the class AppSchemaMappingTest method testNilReasonOnNotNillableElement.
@Test
public void testNilReasonOnNotNillableElement() {
final String nilReason = "missing";
final String nilReasonAssignCQL = "'" + nilReason + "'";
final String nilReasonRenameCQL = SOURCE_UUID_V1;
// --- test with a constant mapping --- //
DefaultCell assignNilReason = new DefaultCell();
assignNilReason.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(nilReason));
assignNilReason.setTarget(getDescriptionNilReasonTargetProperty());
assignNilReason.setTransformationParameters(parameters);
Cell typeCell = getDefaultTypeCell(unitType, landCoverUnitType);
AttributeMappingType attrMapping = null;
AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper);
AssignHandler assignHandler = new AssignHandler();
attrMapping = assignHandler.handlePropertyTransformation(typeCell, assignNilReason, context);
assertNotNull(attrMapping);
assertEquals("gml:description", attrMapping.getTargetAttribute());
assertNull(attrMapping.getSourceExpression());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
assertEquals(nilReasonAssignCQL, attrMapping.getClientProperty().get(0).getValue());
// encodeIfEmpty=true because we are using a constant mapping
assertTrue(attrMapping.isEncodeIfEmpty());
// --- test with a non-constant mapping --- //
DefaultCell rename = new DefaultCell();
rename.setTransformationIdentifier(RenameFunction.ID);
rename.setSource(getUuidSourceProperty(unitType));
rename.setTarget(getDescriptionNilReasonTargetProperty());
// reset mapping
initMapping();
context = new AppSchemaMappingContext(mappingWrapper);
// process rename
RenameHandler renameHandler = new RenameHandler();
attrMapping = renameHandler.handlePropertyTransformation(typeCell, rename, context);
assertNotNull(attrMapping);
assertEquals("gml:description", attrMapping.getTargetAttribute());
assertNull(attrMapping.getSourceExpression());
assertEquals(1, attrMapping.getClientProperty().size());
assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
assertEquals(nilReasonRenameCQL, attrMapping.getClientProperty().get(0).getValue());
// encodeIfEmpty has not been set, because we are using a mapping which
// is a function of the source value
assertNull(attrMapping.isEncodeIfEmpty());
}
Aggregations