Skip to content

Package: ModelQuickFixContextMenuContribution

ModelQuickFixContextMenuContribution

nameinstructionbranchcomplexitylinemethod
ModelQuickFixContextMenuContribution()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
aboutToShow(List, Diagnostic, EModelService)
M: 58 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getModelQuickFixes(Diagnostic)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.quickfix.ui.e4.internal;
15:
16: import java.util.List;
17:
18: import javax.inject.Inject;
19: import javax.inject.Named;
20:
21: import org.eclipse.e4.core.di.annotations.Optional;
22: import org.eclipse.e4.ui.di.AboutToShow;
23: import org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem;
24: import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
25: import org.eclipse.e4.ui.services.IServiceConstants;
26: import org.eclipse.e4.ui.workbench.modeling.EModelService;
27: import org.eclipse.emf.common.util.Diagnostic;
28: import org.eclipse.emf.ecore.EObject;
29: import org.eclipse.emf.ecp.quickfix.ModelQuickFix;
30: import org.eclipse.emf.ecp.quickfix.ModelQuickFixRegistry;
31:
32: /** Context Menu entries for Model Quick Fixes. */
33: public class ModelQuickFixContextMenuContribution {
34:         @Inject
35:         private ModelQuickFixRegistry registry;
36:
37:         /**
38:          * @see org.eclipse.e4.ui.di.AboutToShow
39:          * @param items - the list of dynamically shown menu elements
40:          * @param diagnostic - the selected diagnostic
41:          * @param modelService - the e4 EModelService
42:          */
43:         @AboutToShow
44:         public void aboutToShow(List<MMenuElement> items,
45:                 @Named(IServiceConstants.ACTIVE_SELECTION) @Optional Diagnostic diagnostic, EModelService modelService) {
46:
47:                 final List<ModelQuickFix> fixes = getModelQuickFixes(diagnostic);
48:•                if (fixes == null) {
49:                         return;
50:                 }
51:•                for (final ModelQuickFix fix : fixes) {
52:                         final List<?> data = diagnostic.getData();
53:•                        if (data != null && data.size() > 0) {
54:                                 final Object object = data.get(0);
55:•                                if (!EObject.class.isInstance(object)) {
56:                                         return;
57:                                 }
58:                                 final MDirectMenuItem menuItem = modelService.createModelElement(MDirectMenuItem.class);
59:                                 menuItem.setLabel(fix.getLabel(diagnostic));
60:                                 menuItem.setObject(new ModelQuickFixContextMenuItemHandler(fix, (EObject) object));
61:                                 items.add(menuItem);
62:                         }
63:                 }
64:         }
65:
66:         private List<ModelQuickFix> getModelQuickFixes(Diagnostic diagnostic) {
67:•                if (registry == null) {
68:                         return null;
69:                 }
70:                 return registry.getApplicableModelQuickFixes(diagnostic);
71:         }
72: }