Search in sources :

Example 81 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class MergeParameterPage method createContent.

@Override
protected void createContent(Composite page) {
    // set layout of page
    page.setLayout(new GridLayout());
    Label name = new Label(page, SWT.NONE);
    name.setText(parameter.getDisplayName());
    // create checkbox tree viewer
    viewer = new CheckboxTreeViewer(page, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    // comparator
    viewer.setComparator(new DefinitionComparator());
    // label provider
    viewer.setLabelProvider(labelProvider);
    // content provider
    viewer.setContentProvider(new PropertyPathContentProvider(SchemaSpaceID.SOURCE));
    // check state listener
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            // add/remove it from/to set of selected properties
            EntityDefinition eventSource = (EntityDefinition) event.getElement();
            if (event.getChecked())
                selection.add(eventSource);
            else
                selection.remove(eventSource);
        }
    });
    // for now filter everything after first level
    viewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return parentElement == sourceType;
        }
    });
    if (parameter.getName().equals(PARAMETER_ADDITIONAL_PROPERTY))
        viewer.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                return !filtered.contains(element);
            }
        });
    Cell unfinishedCell = getWizard().getUnfinishedCell();
    if (unfinishedCell.getSource() != null) {
        sourceType = (TypeDefinition) unfinishedCell.getSource().values().iterator().next().getDefinition().getDefinition();
    }
    viewer.setInput(sourceType);
    // add initial selection
    if (sourceType != null && initialSelection != null) {
        for (String propertyPath : initialSelection) {
            EntityDefinition entity = getEntityDefinition(propertyPath, sourceType);
            if (entity != null) {
                selection.add(entity);
            } else {
                log.warn("Could not find child for property path " + propertyPath);
            }
        }
        viewer.setCheckedElements(selection.toArray());
    }
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyPathContentProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.PropertyPathContentProvider) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 82 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class MergeParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    setPageComplete(true);
    Cell unfinishedCell = getWizard().getUnfinishedCell();
    // selected target could've changed!
    TypeDefinition newSourceType = (TypeDefinition) unfinishedCell.getSource().values().iterator().next().getDefinition().getDefinition();
    if (!newSourceType.equals(sourceType)) {
        selection = new HashSet<EntityDefinition>();
        sourceType = newSourceType;
        viewer.setInput(sourceType);
    }
    // for additional_property: selected properties can change!
    if (parameter.getName().equals(PARAMETER_ADDITIONAL_PROPERTY)) {
        filtered = new HashSet<EntityDefinition>();
        List<ParameterValue> properties = unfinishedCell.getTransformationParameters().get(PARAMETER_PROPERTY);
        boolean oldSelectionChanged = false;
        for (ParameterValue propertyPath : properties) {
            EntityDefinition def = getEntityDefinition(propertyPath.as(String.class), sourceType);
            filtered.add(def);
            if (selection.remove(def))
                oldSelectionChanged = true;
        }
        if (oldSelectionChanged) {
            viewer.setCheckedElements(selection.toArray());
        }
        viewer.refresh();
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Cell(eu.esdihumboldt.hale.common.align.model.Cell) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 83 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class AlignmentView method updateRelation.

/**
 * Update the selected type relation to a cell that is related to the given
 * schema selection.
 *
 * @param selection the schema selection
 */
private void updateRelation(SchemaSelection selection) {
    Cell typeCell = sourceTargetSelector.getSelectedCell();
    if (typeCell != null && (associatedWithType(typeCell.getSource(), selection.getSourceItems()) && associatedWithType(typeCell.getTarget(), selection.getTargetItems()))) {
        // type cell is associated with source and target, don't change
        return;
    }
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    // find type cell associated with both source and target
    for (Cell cell : alignment.getTypeCells()) {
        if ((associatedWithType(cell.getSource(), selection.getSourceItems())) && associatedWithType(cell.getTarget(), selection.getTargetItems())) {
            // typeRelations.setSelection(new StructuredSelection(cell));
            sourceTargetSelector.setSelection(new StructuredSelection(cell));
            return;
        }
    }
    if (typeCell != null && (associatedWithType(typeCell.getSource(), selection.getSourceItems()) || associatedWithType(typeCell.getTarget(), selection.getTargetItems()))) {
        // type cell is associated with source or target, don't change
        return;
    }
    // find type cell associated with source or target
    for (Cell cell : alignment.getTypeCells()) {
        if ((associatedWithType(cell.getSource(), selection.getSourceItems())) || associatedWithType(cell.getTarget(), selection.getTargetItems())) {
            sourceTargetSelector.setSelection(new StructuredSelection(cell));
            // typeRelations.setSelection(new StructuredSelection(cell));
            return;
        }
    }
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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)

Example 84 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class PropertiesLabelProvider method getImage.

/**
 * @see LabelProvider#getImage(Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof IStructuredSelection) {
        element = ((IStructuredSelection) element).getFirstElement();
    }
    element = TransformationTreeUtil.extractObject(element);
    if (element instanceof Entity) {
        element = ((Entity) element).getDefinition();
    }
    if (element instanceof EntityDefinition || element instanceof Definition<?>) {
        return definitionLabels.getImage(element);
    }
    if (element instanceof Cell) {
        Cell cell = (Cell) element;
        FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), HaleUI.getServiceProvider());
        if (function != null) {
            element = function;
        }
    }
    if (element instanceof FunctionDefinition) {
        return functionLabels.getImage(element);
    }
    return super.getImage(element);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 85 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell in project hale by halestudio.

the class HtmlExplanationCellSection method refresh.

@Override
public void refresh() {
    super.refresh();
    String text = null;
    Cell cell = getCell();
    if (cell != null) {
        FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), HaleUI.getServiceProvider());
        if (function != null) {
            CellExplanation explanation = function.getExplanation();
            if (explanation != null) {
                if (browser != null) {
                    text = explanation.getExplanationAsHtml(cell, HaleUI.getServiceProvider());
                    if (text == null) {
                        text = explanation.getExplanation(cell, HaleUI.getServiceProvider());
                    }
                } else if (textField != null) {
                    text = explanation.getExplanation(cell, HaleUI.getServiceProvider());
                }
            }
        }
    }
    if (text == null) {
        text = "Sorry, no explanation available.";
    }
    if (browser != null) {
        browser.setText(text);
    } else if (textField != null) {
        textField.setText(text);
    }
}
Also used : CellExplanation(eu.esdihumboldt.hale.common.align.model.CellExplanation) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)123 ArrayList (java.util.ArrayList)33 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)28 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)28 Test (org.junit.Test)27 Entity (eu.esdihumboldt.hale.common.align.model.Entity)24 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)18 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)13 HashSet (java.util.HashSet)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 List (java.util.List)11 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)9 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)9 Property (eu.esdihumboldt.hale.common.align.model.Property)8