Search in sources :

Example 6 with AlignmentService

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

the class AlignmentViewContentProvider method getEdges.

/**
 * Get all edges for the given type cell and its property cells.
 *
 * @param typeCell the type cell to show
 * @return the array of edges
 */
private Object[] getEdges(Cell typeCell) {
    List<Edge> edges = new ArrayList<Edge>();
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    boolean dummyCell;
    if (typeCell.getId() != null) {
        // XXX really filter type cell out?
        if (select(typeCell)) {
            addEdges(typeCell, edges);
        }
        dummyCell = false;
    } else {
        // dummy cell, look for matching type cells
        for (Cell cell : alignment.getTypeCells(typeCell)) if (select(cell))
            addEdges(cell, edges);
        dummyCell = true;
    }
    for (Cell cell : sortCells(as.getAlignment().getPropertyCells(typeCell, true, dummyCell))) {
        if (!select(cell))
            continue;
        Cell reparentCell = AlignmentUtil.reparentCell(cell, typeCell, false);
        // to the original cell
        if (reparentCell == cell)
            addEdges(cell, edges);
        else {
            // add edges leading to the cell for each source entity
            if (reparentCell.getSource() != null) {
                for (Entry<String, ? extends Entity> entry : reparentCell.getSource().entries()) {
                    edges.add(new Edge(entry.getValue(), cell, entry.getKey()));
                }
            }
            // add edges leading to the target entities from the cell
            for (Entry<String, ? extends Entity> entry : reparentCell.getTarget().entries()) {
                edges.add(new Edge(cell, entry.getValue(), entry.getKey()));
            }
        }
    }
    return edges.toArray();
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) Edge(eu.esdihumboldt.hale.ui.common.graph.content.Edge) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 7 with AlignmentService

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

the class FunctionsView method dispose.

@Override
public void dispose() {
    if (compListener != null) {
        CompatibilityService cs = PlatformUI.getWorkbench().getService(CompatibilityService.class);
        cs.removeListener(compListener);
    }
    if (alignListener != null) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        as.removeListener(alignListener);
    }
    super.dispose();
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) CompatibilityService(eu.esdihumboldt.hale.ui.common.service.compatibility.CompatibilityService)

Example 8 with AlignmentService

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

the class TypeEntityDialog method addToolBarActions.

/**
 * @see eu.esdihumboldt.hale.ui.function.common.EntityDialog#addToolBarActions(org.eclipse.jface.action.ToolBarManager)
 */
@Override
protected void addToolBarActions(ToolBarManager manager) {
    // filter to only show mapped types
    manager.add(new FilterAction("Hide unmapped types", "Show unmapped types", HALEUIPlugin.getImageDescriptor("icons/empty.gif"), getViewer(), new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            if (element instanceof TreePath)
                element = ((TreePath) element).getLastSegment();
            return isMapped((ITreeContentProvider) ((TreeViewer) viewer).getContentProvider(), element, alignment);
        }

        private boolean isMapped(ITreeContentProvider cp, Object element, Alignment align) {
            if (element instanceof EntityDefinition) {
                boolean mapped = AlignmentUtil.entityOrChildMapped((EntityDefinition) element, align);
                if (mapped)
                    return true;
            }
            // recursively check children
            Object[] children = cp.getChildren(element);
            if (children != null)
                for (Object child : children) if (isMapped(cp, child, align))
                    return true;
            return false;
        }
    }, true, true));
    // do not add choice if only mapping relevant types should be selected
    if (onlyMappingRelevant)
        return;
    manager.add(new Separator());
    // MappingRelevant types only, flat
    manager.add(new ContentProviderAction("Mapping relevant types as list", HALEUIPlugin.getImageDescriptor("icons/flat_relevant.png"), getViewer(), flatRelevantProvider, false));
    // MappingRelevant types only, hierarchical
    manager.add(new ContentProviderAction("Mapping relevant types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_relevant.png"), getViewer(), hierarchicalRelevantProvider, false));
    // Mappable types, flat
    manager.add(new ContentProviderAction("All types as list", HALEUIPlugin.getImageDescriptor("icons/flat_all.png"), getViewer(), flatAllProvider, true));
    // Mappable types, hierarchical
    manager.add(new ContentProviderAction("All types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_all.png"), getViewer(), hierarchicalAllProvider, false));
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentProviderAction(eu.esdihumboldt.hale.ui.service.entity.util.ContentProviderAction) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TreePath(org.eclipse.jface.viewers.TreePath) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) FilterAction(eu.esdihumboldt.hale.ui.util.viewer.FilterAction) Separator(org.eclipse.jface.action.Separator)

Example 9 with AlignmentService

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

the class EditRelationHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();
        if (selected instanceof Cell) {
            final Cell originalCell = (Cell) selected;
            FunctionWizard wizard = null;
            List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {

                @Override
                public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
                    return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
                }

                @Override
                public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
                    return true;
                }
            });
            if (!factories.isEmpty()) {
                // create registered wizard
                FunctionWizardDescriptor<?> fwd = factories.get(0);
                wizard = fwd.createEditWizard(originalCell);
            }
            if (wizard == null) {
                FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
                if (function == null) {
                    log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
                    return null;
                }
                // create generic wizard
                if (function instanceof TypeFunction) {
                    wizard = new GenericTypeFunctionWizard(originalCell);
                } else {
                    wizard = new GenericPropertyFunctionWizard(originalCell);
                }
            }
            // initialize wizard
            wizard.init();
            HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
            if (dialog.open() == WizardDialog.OK) {
                MutableCell cell = wizard.getResult();
                AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
                // remove the original cell
                // and add the new cell
                alignmentService.replaceCell(originalCell, cell);
            }
        }
    }
    return null;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) FunctionWizardFactory(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardFactory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) TypeFunction(eu.esdihumboldt.hale.common.align.extension.function.TypeFunction) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 10 with AlignmentService

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

the class AlignmentImportAdvisor method handleResults.

/**
 * @see AbstractIOAdvisor#handleResults(IOProvider)
 */
@Override
public void handleResults(AlignmentReader provider) {
    super.handleResults(provider);
    AlignmentService as = getService(AlignmentService.class);
    // XXX clear old mapping?
    // FIXME merging alignments not supported yet
    as.addOrUpdateAlignment(provider.getAlignment());
}
Also used : AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

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