Skip to content

Package: DelegatingMasterDetailAction

DelegatingMasterDetailAction

nameinstructionbranchcomplexitylinemethod
DelegatingMasterDetailAction(EditingDomain)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
execute(ExecutionEvent)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
execute(List)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
executeOnKeyRelease(ISelection)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getDelegatedAction()
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%
getEMFEditLabel()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
shouldShow(List)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Stefan Dirix - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.swt.treemasterdetail.actions.delegating;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.commands.ExecutionEvent;
19: import org.eclipse.core.commands.ExecutionException;
20: import org.eclipse.emf.edit.domain.EditingDomain;
21: import org.eclipse.emfforms.spi.swt.treemasterdetail.actions.KeybindedMasterDetailAction;
22: import org.eclipse.jface.viewers.ISelection;
23: import org.eclipse.jface.viewers.IStructuredSelection;
24: import org.eclipse.jface.viewers.StructuredSelection;
25: import org.eclipse.ui.actions.BaseSelectionListenerAction;
26:
27: /**
28: * Abstract implementation of a {@link KeybindedMasterDetailAction} forwarding to a {@link BaseSelectionListenerAction}.
29: *
30: * @author Stefan Dirix
31: * @since 1.8
32: */
33: public abstract class DelegatingMasterDetailAction extends KeybindedMasterDetailAction {
34:
35:         /**
36:          * The {@link BaseSelectionListenerAction} to which this {@link KeybindedMasterDetailAction} forwards to.
37:          */
38:         private final BaseSelectionListenerAction delegatedAction;
39:
40:         /**
41:          * Constructor.
42:          *
43:          * @param editingDomain The {@link EditingDomain} which is used by the {@link BaseSelectionListenerAction}.
44:          */
45:         public DelegatingMasterDetailAction(EditingDomain editingDomain) {
46:                 delegatedAction = createDelegatedAction(editingDomain);
47:                 setLabel(delegatedAction.getText());
48:                 setImagePath(getEMFImagePath());
49:         }
50:
51:         /**
52:          * The label for the {@link KeybindedMasterDetailAction}.
53:          *
54:          * @return
55:          *                 The label for the {@link KeybindedMasterDetailAction}.
56:          */
57:         protected String getEMFEditLabel() {
58:                 return delegatedAction.getText();
59:         }
60:
61:         /**
62:          * The path to the image for the {@link BaseSelectionListenerAction}.
63:          *
64:          * @return
65:          *                 The path to the local image for the {@link BaseSelectionListenerAction}.
66:          */
67:         protected abstract String getEMFImagePath();
68:
69:         /**
70:          * Creates the {@link BaseSelectionListenerAction} to which this {@link KeybindedMasterDetailAction} forwards to.
71:          *
72:          * @param editingDomain
73:          * The {@link EditingDomain} which is used to create the {@link BaseSelectionListenerAction}.
74:          *
75:          * @return
76:          *                 The {@link BaseSelectionListenerAction} to which this {@link KeybindedMasterDetailAction} forwards to.
77:          */
78:         protected abstract BaseSelectionListenerAction createDelegatedAction(EditingDomain editingDomain);
79:
80:         @Override
81:         public Object execute(ExecutionEvent event) throws ExecutionException {
82:                 final IStructuredSelection selection = (IStructuredSelection) event.getTrigger();
83:                 delegatedAction.selectionChanged(selection);
84:•                if (delegatedAction.isEnabled()) {
85:                         delegatedAction.run();
86:                 }
87:                 return null;
88:         }
89:
90:         @Override
91:         public void execute(List<Object> objects) {
92:                 final IStructuredSelection selection = new StructuredSelection(objects);
93:                 delegatedAction.selectionChanged(selection);
94:•                if (delegatedAction.isEnabled()) {
95:                         delegatedAction.run();
96:                 }
97:         }
98:
99:         @Override
100:         public boolean shouldShow(List<Object> objects) {
101:                 final IStructuredSelection selection = new StructuredSelection(objects);
102:                 delegatedAction.selectionChanged(selection);
103:                 return delegatedAction.isEnabled();
104:         }
105:
106:         /**
107:          * Returns the {@link BaseSelectionListenerAction} to which this {@link KeybindedMasterDetailAction} forwards to.
108:          *
109:          * @return
110:          *                 The {@link BaseSelectionListenerAction} this {@link KeybindedMasterDetailAction} is forwarding to.
111:          */
112:         public BaseSelectionListenerAction getDelegatedAction() {
113:                 return delegatedAction;
114:         }
115:
116:         @Override
117:         protected void executeOnKeyRelease(ISelection currentSelection) {
118:•                if (currentSelection instanceof IStructuredSelection) {
119:                         delegatedAction.selectionChanged(IStructuredSelection.class.cast(currentSelection));
120:                 }
121:                 delegatedAction.run();
122:         }
123:
124: }