Skip to content

Package: ECPSelectionProviderService

ECPSelectionProviderService

nameinstructionbranchcomplexitylinemethod
createMasterDetailSelectionProvider(Viewer, Supplier)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.swt.services;
15:
16: import java.util.function.Supplier;
17:
18: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
19: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
20: import org.eclipse.emf.ecp.view.spi.model.VElement;
21: import org.eclipse.emf.ecp.view.spi.swt.selection.IMasterDetailSelectionProvider;
22: import org.eclipse.emf.ecp.view.spi.swt.selection.MasterDetailFocusAdapter;
23: import org.eclipse.emf.ecp.view.spi.swt.selection.MasterDetailSelectionProvider;
24: import org.eclipse.jface.viewers.ISelectionProvider;
25: import org.eclipse.jface.viewers.Viewer;
26: import org.eclipse.swt.widgets.Control;
27:
28: /**
29: * A mediator of selection providers for the {@link ViewModelContext}, to provide
30: * a coherent selection provider for the rendering of a view.
31: *
32: * @since 1.20
33: */
34: public interface ECPSelectionProviderService extends ViewModelService {
35:
36:         /**
37:          * Obtain a selection provider that aggregates the selection in the
38:          * view model context. This should be suitable for use as, for example,
39:          * the selection provider of an Eclipse workbench part site. The
40:          * selection provider is never {@code null}, but if there are no
41:          * registered providers to which it can delegate, it may have no useful effect.
42:          *
43:          * @return the selection provider
44:          */
45:         ISelectionProvider getSelectionProvider();
46:
47:         /**
48:          * Register a selection provider for a given {@code element}. The effect
49:          * is undefined if the {@code element} already has a provider registered.
50:          * It is probably a good practice that only the renderer of the {@code element}
51:          * be responsible for registering a selection provider for it.
52:          *
53:          * @param element an element in the view model
54:          * @param selectionProvider a selection provider to register for it
55:          *
56:          * @throws NullPointerException if the either the element or the selection provider is {@code null}
57:          */
58:         void registerSelectionProvider(VElement element, ISelectionProvider selectionProvider);
59:
60:         /**
61:          * Create a master-detail selection provider on the given {@code master} viewer.
62:          *
63:          * @param master the master viewer
64:          * @param detailSupplier the supplier of the detail view currently presented
65:          * for the selection in the {@code master}
66:          * @return a master-detail selection provider
67:          *
68:          * @since 1.21
69:          */
70:         default IMasterDetailSelectionProvider createMasterDetailSelectionProvider(Viewer master,
71:                 Supplier<? extends Control> detailSupplier) {
72:
73:                 final IMasterDetailSelectionProvider result = new MasterDetailSelectionProvider(master);
74:                 final MasterDetailFocusAdapter adapter = new MasterDetailFocusAdapter(result, detailSupplier);
75:                 master.getControl().addFocusListener(adapter);
76:                 return result;
77:         }
78: }