Search in sources :

Example 1 with DefaultCell

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());
}
Also used : CompatibilityModeFactory(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityModeFactory) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SourceTargetTypeSelector(eu.esdihumboldt.hale.ui.function.common.SourceTargetTypeSelector) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) CompatibilityService(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Composite(org.eclipse.swt.widgets.Composite) CompatibilityMode(eu.esdihumboldt.hale.common.align.compatibility.CompatibilityMode) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ExclusiveExtensionListener(de.fhg.igd.eclipse.util.extension.exclusive.ExclusiveExtension.ExclusiveExtensionListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map)

Example 2 with 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;
        }
    };
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) HashSet(java.util.HashSet) Set(java.util.Set) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 3 with DefaultCell

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
}
Also used : DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 4 with DefaultCell

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();
            }
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) XslVariableImpl(eu.esdihumboldt.hale.io.xslt.functions.impl.XslVariableImpl) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) XslVariable(eu.esdihumboldt.hale.io.xslt.functions.XslVariable) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with DefaultCell

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());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Aggregations

DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)47 Test (org.junit.Test)24 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)22 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)21 Cell (eu.esdihumboldt.hale.common.align.model.Cell)17 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)17 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)16 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)15 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)13 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 ArrayList (java.util.ArrayList)10 Property (eu.esdihumboldt.hale.common.align.model.Property)9 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)9 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)9 Entity (eu.esdihumboldt.hale.common.align.model.Entity)8 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)8 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 AssignHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler)6