Skip to content

Package: CreateChildActionWithAccelerator

CreateChildActionWithAccelerator

nameinstructionbranchcomplexitylinemethod
CreateChildActionWithAccelerator(EObject, EditingDomain, ISelectionProvider, CommandParameter, CreateElementCallback)
M: 35 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 59 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 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: * Clemens Elflein - initial API and implementation
13: ******************************************************************************/
14:
15: package org.eclipse.emfforms.internal.editor.ecore;
16:
17: import java.util.LinkedHashMap;
18:
19: import org.eclipse.emf.ecore.EAnnotation;
20: import org.eclipse.emf.ecore.EAttribute;
21: import org.eclipse.emf.ecore.EClass;
22: import org.eclipse.emf.ecore.EDataType;
23: import org.eclipse.emf.ecore.EEnum;
24: import org.eclipse.emf.ecore.EEnumLiteral;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.EOperation;
27: import org.eclipse.emf.ecore.EPackage;
28: import org.eclipse.emf.ecore.EReference;
29: import org.eclipse.emf.edit.command.CommandParameter;
30: import org.eclipse.emf.edit.domain.EditingDomain;
31: import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateChildAction;
32: import org.eclipse.emfforms.spi.swt.treemasterdetail.util.CreateElementCallback;
33: import org.eclipse.jface.viewers.ISelectionProvider;
34:
35: /**
36: * The Class CreateChildActionWithAccelerator.
37: * It extends the CreateChildAction to allow to run with a keyboard shortcut.
38: */
39: // TODO actually this should be only available in the ecore editor
40: public final class CreateChildActionWithAccelerator extends CreateChildAction {
41:
42:         private static final LinkedHashMap<Class<?>, Character> ACCELERATORS = new LinkedHashMap<Class<?>, Character>();
43:
44:         static {
45:                 ACCELERATORS.put(EClass.class, 'c');
46:                 ACCELERATORS.put(EPackage.class, 'p');
47:                 ACCELERATORS.put(EEnum.class, 'e');
48:                 ACCELERATORS.put(EDataType.class, 'd');
49:                 ACCELERATORS.put(EAttribute.class, 'a');
50:                 ACCELERATORS.put(EReference.class, 'r');
51:                 ACCELERATORS.put(EAnnotation.class, 'n');
52:                 ACCELERATORS.put(EOperation.class, 'o');
53:                 ACCELERATORS.put(EEnumLiteral.class, 'l');
54:         }
55:
56:         /**
57:          * Instantiates a new creates the child action with accelerator.
58:          *
59:          * @param parent the Parent EObject
60:          * @param editingDomain the editing domain
61:          * @param selectionProvider the selectionProvider
62:          * @param descriptor the descriptor
63:          * @param createElementCallback the callback, null if not present.
64:          */
65:         public CreateChildActionWithAccelerator(EObject parent, EditingDomain editingDomain,
66:                 ISelectionProvider selectionProvider, CommandParameter descriptor,
67:                 CreateElementCallback createElementCallback) {
68:                 super(parent, editingDomain, selectionProvider, descriptor, createElementCallback);
69:                 final Object value = descriptor.getValue();
70:
71:•                for (final Class<?> c : ACCELERATORS.keySet()) {
72:•                        if (c.isInstance(value)) {
73:                                 setAccelerator(ACCELERATORS.get(c));
74:                                 break;
75:                         }
76:                 }
77:         }
78:
79: }