Search in sources :

Example 21 with AlignmentService

use of eu.esdihumboldt.hale.ui.service.align.AlignmentService 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)

Example 22 with AlignmentService

use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.

the class MappingView method dispose.

/**
 * @see WorkbenchPart#dispose()
 */
@Override
public void dispose() {
    if (alignmentListener != null) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        as.removeListener(alignmentListener);
    }
    if (selectionListener != null) {
        getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
    }
    super.dispose();
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

Example 23 with AlignmentService

use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.

the class MappingView method update.

/**
 * Update the view
 *
 * @param selection the selection
 */
protected void update(SchemaSelection selection) {
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    List<Cell> cells = new ArrayList<Cell>();
    Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
    // find cells associated with the selection
    for (Cell cell : alignment.getCells()) {
        if ((cell.getSource() != null && associatedWith(items.getFirst(), cell)) || associatedWith(items.getSecond(), cell)) {
            cells.add(cell);
        }
    }
    getViewer().setInput(cells);
    updateLayout(true);
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) HashSet(java.util.HashSet) Set(java.util.Set) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 24 with AlignmentService

use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.

the class MappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    super.createViewControl(parent);
    updateLayout(false);
    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 != MappingView.this) {
                update((SchemaSelection) selection);
            }
        }
    });
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    // update();
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            List<Cell> changedCells = new ArrayList<Cell>(2);
            changedCells.addAll(cells.keySet());
            changedCells.addAll(cells.values());
            updateViewWithCurrentSelection(changedCells);
        }

        @Override
        public void customFunctionsChanged() {
            SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
            if (current != null) {
                update(current);
            }
        }

        @Override
        public void cellsAdded(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            updateViewWithCurrentSelection(cells);
        }
    });
    TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
    taskService.addListener(new TaskServiceListener() {

        @Override
        public void tasksRemoved(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void tasksAdded(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void taskUserDataChanged(ResolvedTask<?> task) {
            updateViewWithCurrentSelection(getAffectedCells(Collections.singleton(task)));
        }

        private List<Cell> getAffectedCells(Iterable<Task<?>> tasks) {
            List<Cell> affectedCells = new ArrayList<>();
            tasks.forEach(t -> {
                if (t.getMainContext() instanceof Cell) {
                    affectedCells.add((Cell) t.getMainContext());
                }
            });
            return affectedCells;
        }
    });
    SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
    if (current != null) {
        update(current);
    }
    // listen on size changes
    getViewer().getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            updateLayout(true);
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Dimension(org.eclipse.draw2d.geometry.Dimension) ListMultimap(com.google.common.collect.ListMultimap) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IToolBarManager(org.eclipse.jface.action.IToolBarManager) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) MappingViewPlugin(eu.esdihumboldt.hale.ui.views.mapping.internal.MappingViewPlugin) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Type(eu.esdihumboldt.hale.common.align.model.Type) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) Pair(eu.esdihumboldt.util.Pair) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) WorkbenchPart(org.eclipse.ui.part.WorkbenchPart) PlatformUI(org.eclipse.ui.PlatformUI) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) Collection(java.util.Collection) Set(java.util.Set) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) Action(org.eclipse.jface.action.Action) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) List(java.util.List) AlignmentServiceListener(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ISelection(org.eclipse.jface.viewers.ISelection) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Task(eu.esdihumboldt.hale.common.tasks.Task) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) SchemaSelectionHelper(eu.esdihumboldt.hale.ui.selection.SchemaSelectionHelper) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ArrayList(java.util.ArrayList) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 25 with AlignmentService

use of eu.esdihumboldt.hale.ui.service.align.AlignmentService in project hale by halestudio.

the class TransformationReportPage method onDoubleClick.

@Override
protected void onDoubleClick(Message m) {
    if (m instanceof TransformationMessage) {
        TransformationMessage tm = (TransformationMessage) m;
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        if (as != null && as.getAlignment().getCell(tm.getCellId()) != null) {
            IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            // pin the property sheet if possible
            IViewReference ref = activeWindow.getActivePage().findViewReference(IPageLayout.ID_PROP_SHEET);
            if (ref != null) {
                IViewPart part = ref.getView(false);
                if (part instanceof PropertySheet) {
                    PropertySheet sheet = (PropertySheet) part;
                    if (!sheet.isPinned()) {
                        sheet.setPinned(true);
                    }
                }
            }
            // show cell in mapping view
            try {
                IViewPart part = activeWindow.getActivePage().showView(MappingView.ID);
                if (part instanceof MappingView) {
                    ((MappingView) part).selectCell(tm.getCellId());
                }
            } catch (PartInitException e) {
            // ignore
            }
        }
    }
    super.onDoubleClick(m);
}
Also used : TransformationMessage(eu.esdihumboldt.hale.common.align.transformation.report.TransformationMessage) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) PropertySheet(org.eclipse.ui.views.properties.PropertySheet) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) IViewReference(org.eclipse.ui.IViewReference) MappingView(eu.esdihumboldt.hale.ui.views.mapping.MappingView) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)43 Cell (eu.esdihumboldt.hale.common.align.model.Cell)16 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 ArrayList (java.util.ArrayList)8 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)6 ISelection (org.eclipse.jface.viewers.ISelection)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 AlignmentServiceAdapter (eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter)5 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)5 IContributionItem (org.eclipse.jface.action.IContributionItem)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)4 CompatibilityService (eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService)4 HashSet (java.util.HashSet)4 Display (org.eclipse.swt.widgets.Display)4 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)3 IAction (org.eclipse.jface.action.IAction)3 ControlAdapter (org.eclipse.swt.events.ControlAdapter)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3