Skip to content

Package: ECPRepositoryView$1

ECPRepositoryView$1

nameinstructionbranchcomplexitylinemethod
selectionChanged(SelectionChangedEvent)
M: 36 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH 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: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.ui.e4.view;
16:
17: import javax.annotation.PostConstruct;
18:
19: import org.eclipse.e4.ui.di.Focus;
20: import org.eclipse.e4.ui.services.EMenuService;
21: import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
22: import org.eclipse.emf.ecp.ui.common.ECPViewerFactory;
23: import org.eclipse.jface.viewers.ISelection;
24: import org.eclipse.jface.viewers.ISelectionChangedListener;
25: import org.eclipse.jface.viewers.IStructuredSelection;
26: import org.eclipse.jface.viewers.SelectionChangedEvent;
27: import org.eclipse.jface.viewers.TreeViewer;
28: import org.eclipse.swt.widgets.Composite;
29:
30: /**
31: * View to display available model repositories.
32: *
33: * @author Jonas
34: *
35: */
36: public class ECPRepositoryView {
37:
38:         private static final String POPUPMENU_REPOSITORY = "org.eclipse.emf.ecp.e4.application.popupmenu.repository"; //$NON-NLS-1$
39:         private TreeViewer repositoryTree;
40:
41:         /**
42:          * Creates the repository view.
43:          *
44:          * @param composite the parent {@link Composite}
45:          * @param menuService the menu service to register the context menu
46:          * @param selectionService the selection service to publish the selection of the tree viewer.
47:          */
48:         @PostConstruct
49:         public void create(Composite composite, EMenuService menuService,
50:                 final ESelectionService selectionService) {
51:                 repositoryTree = ECPViewerFactory.createRepositoryExplorerViewer(
52:                         composite, null);
53:                 menuService.registerContextMenu(repositoryTree.getTree(),
54:                         POPUPMENU_REPOSITORY);
55:                 repositoryTree
56:                         .addSelectionChangedListener(new ISelectionChangedListener() {
57:
58:                                 @Override
59:                                 public void selectionChanged(SelectionChangedEvent event) {
60:                                         final ISelection selection = event.getSelection();
61:•                                        if (IStructuredSelection.class.isInstance(selection)) {
62:                                                 final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
63:•                                                if (structuredSelection != null && !structuredSelection.isEmpty()) {
64:•                                                        if (structuredSelection.size() == 1) {
65:                                                                 selectionService
66:                                                                         .setSelection(structuredSelection.getFirstElement());
67:                                                         } else {
68:                                                                 selectionService
69:                                                                         .setSelection(structuredSelection.toList());
70:                                                         }
71:                                                 } else {
72:                                                         selectionService.setSelection(null);
73:                                                 }
74:                                         }
75:                                 }
76:                         });
77:         }
78:
79:         /**
80:          * Sets the focus to the tree.
81:          */
82:         @Focus
83:         public void setFocus() {
84:                 repositoryTree.getTree().setFocus();
85:         }
86:
87: }