Search in sources :

Example 16 with Cell

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

the class OMLReaderTest method testAssign3.

/**
 * Test for assign function in alignment5
 */
@Test
@Ignore
public // because now NilReasonFunction also produces assign cells
void testAssign3() {
    Collection<? extends Cell> cells = alignment5.getCells();
    Iterator<? extends Cell> it = cells.iterator();
    List<Cell> assignCells = new ArrayList<Cell>();
    while (it.hasNext()) {
        Cell temp = it.next();
        if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.assign")) {
            assignCells.add(temp);
        }
    }
    // test all cells that have an assign function
    for (int i = 0; i < assignCells.size(); i++) {
        Cell cell = assignCells.get(i);
        ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
        List<ParameterValue> values = params.get("value");
        assertEquals(1, values.size());
        // size is always 1
        String temp = values.get(0).as(String.class);
        // test cell #1
        if (i == 0) {
            assertEquals("2000", temp);
        }
        // test cell #2
        if (i == 1) {
            assertEquals("20", temp);
        }
        // test cell #3
        if (i == 2) {
            assertEquals("20", temp);
        }
        // test cell #4
        if (i == 3) {
            assertEquals("2", temp);
        }
        // test cell #5
        if (i == 4) {
            assertEquals("Katastralgemeinde", temp);
        }
        // test cell #6
        if (i == 5) {
            assertEquals("m2", temp);
        }
        // test cell #7
        if (i == 6) {
            assertEquals("m2", temp);
        }
        // test cell #8
        if (i == 7) {
            assertEquals("m", temp);
        }
        // test cell #9
        if (i == 8) {
            assertEquals("m", temp);
        }
    }
    // check if all cells with an assign function were tested
    assertEquals(9, assignCells.size());
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with Cell

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

the class OMLReaderTest method testAssign2.

/**
 * Test for assign function in alignment2
 */
@Test
@Ignore
public // because now NilReasonFunction also produces assign cells
void testAssign2() {
    Collection<? extends Cell> cells = alignment2.getCells();
    Iterator<? extends Cell> it = cells.iterator();
    List<Cell> assignCells = new ArrayList<Cell>();
    while (it.hasNext()) {
        Cell temp = it.next();
        if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.hale.align.assign")) {
            assignCells.add(temp);
        }
    }
    // test all cells that have an assign function
    for (int i = 0; i < assignCells.size(); i++) {
        Cell cell = assignCells.get(i);
        ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
        List<ParameterValue> values = params.get("value");
        assertEquals(1, values.size());
        // size is always 1
        String temp = values.get(0).as(String.class);
        // test cell #1
        if (i == 0) {
            assertEquals("manMade", temp);
        }
        // test cell #2
        if (i == 1) {
            assertEquals("false", temp);
        }
        // test cell #3
        if (i == 2) {
            assertEquals("2009-12-23 12:13:14", temp);
        }
        // test cell #4
        if (i == 3) {
            assertEquals("m", temp);
        }
    }
    // check if all cells with an assign function were tested
    assertEquals(4, assignCells.size());
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with Cell

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

the class AlignmentView method createLabelProvider.

/**
 * @see AbstractMappingView#createLabelProvider(GraphViewer)
 */
@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
    return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#isInherited(eu.esdihumboldt.hale.common.align.model.Cell)
         */
        @Override
        protected boolean isInherited(Cell cell) {
            // cannot inherit type cells
            if (AlignmentUtil.isTypeCell(cell))
                return false;
            return AlignmentUtil.reparentCell(cell, sourceTargetSelector.getSelectedCell(), true) != cell;
        }

        private final Color cellDisabledBackgroundColor = new Color(Display.getCurrent(), 240, 240, 240);

        private final Color cellDisabledForegroundColor = new Color(Display.getCurrent(), 109, 109, 132);

        private final Color cellDisabledHighlightColor = new Color(Display.getCurrent(), (int) (getCellHighlightColor().getRed() * 0.7), (int) (getCellHighlightColor().getGreen() * 0.7), (int) (getCellHighlightColor().getBlue() * 0.7));

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getNodeHighlightColor(java.lang.Object)
         */
        @Override
        public Color getNodeHighlightColor(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledHighlightColor;
            return super.getNodeHighlightColor(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getBackgroundColour(java.lang.Object)
         */
        @Override
        public Color getBackgroundColour(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledBackgroundColor;
            return super.getBackgroundColour(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getForegroundColour(java.lang.Object)
         */
        @Override
        public Color getForegroundColour(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledForegroundColor;
            return super.getForegroundColour(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#dispose()
         */
        @Override
        public void dispose() {
            cellDisabledBackgroundColor.dispose();
            cellDisabledForegroundColor.dispose();
            cellDisabledHighlightColor.dispose();
            super.dispose();
        }
    };
}
Also used : GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) Color(org.eclipse.swt.graphics.Color) 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 19 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell 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 20 with Cell

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

the class AlignmentView method menuAboutToShow.

/**
 * @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
 */
@Override
protected void menuAboutToShow(IMenuManager manager) {
    ISelection cellSelection = getViewer().getSelection();
    final Cell typeCell = sourceTargetSelector.getSelectedCell();
    // is a type relation selected
    if (!sourceTargetSelector.isCellSelected())
        return;
    // is a cell selected?
    if (!(cellSelection instanceof IStructuredSelection) || ((IStructuredSelection) cellSelection).size() != 1 || !(((IStructuredSelection) cellSelection).getFirstElement() instanceof Cell))
        return;
    final Cell selectedCell = (Cell) ((IStructuredSelection) cellSelection).getFirstElement();
    // ignore type cell
    if (AlignmentUtil.isTypeCell(selectedCell))
        return;
    // check current disable status
    if (!selectedCell.getDisabledFor().contains(typeCell.getId())) {
        manager.add(new Action("Disable") {

            /**
             * @see org.eclipse.jface.action.Action#run()
             */
            @Override
            public void run() {
                AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
                as.setCellProperty(selectedCell.getId(), Cell.PROPERTY_DISABLE_FOR, typeCell);
            }
        });
    } else {
        manager.add(new Action("Enable") {

            /**
             * @see org.eclipse.jface.action.Action#run()
             */
            @Override
            public void run() {
                AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
                as.setCellProperty(selectedCell.getId(), Cell.PROPERTY_ENABLE_FOR, typeCell);
            }

            /**
             * @see org.eclipse.jface.action.Action#isEnabled()
             */
            @Override
            public boolean isEnabled() {
                // Still show the action for clarity.
                if (selectedCell instanceof BaseAlignmentCell)
                    return !((BaseAlignmentCell) selectedCell).getBaseDisabledFor().contains(typeCell.getId());
                return true;
            }
        });
    }
}
Also used : Action(org.eclipse.jface.action.Action) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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)

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