Skip to content

Package: AddRowAction

AddRowAction

nameinstructionbranchcomplexitylinemethod
AddRowAction(TableRendererViewerActionContext)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
canExecute()
M: 0 C: 14
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
execute()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getId()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * mat - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt.action;
15:
16: import org.eclipse.emf.ecore.EClass;
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecore.EReference;
19: import org.eclipse.emf.ecore.EStructuralFeature;
20: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
21: import org.eclipse.emfforms.spi.swt.table.action.ViewerActionContext;
22:
23: /**
24: * Action to add a row to a table viewer.
25: *
26: * @author Mat Hansen <mhansen@eclipsesource.com>
27: * @since 1.18
28: *
29: */
30: public abstract class AddRowAction extends TableRendererAction {
31:
32:         /**
33:          * The ID of this action.
34:          */
35:         public static final String ACTION_ID = PREFIX + "tablecontrol.add_row"; //$NON-NLS-1$
36:
37:         /**
38:          * The default key binding of this action.
39:          */
40:         public static final String DEFAULT_KEYBINDING = "M1+n"; //$NON-NLS-1$
41:
42:         /**
43:          * The constructor.
44:          *
45:          * @param actionContext the {@link ViewerActionContext}
46:          */
47:         public AddRowAction(TableRendererViewerActionContext actionContext) {
48:                 super(actionContext);
49:         }
50:
51:         @Override
52:         public String getId() {
53:                 return ACTION_ID;
54:         }
55:
56:         @Override
57:         public void execute() {
58:
59:                 final Setting setting = getActionContext().getSetting();
60:                 final EObject eObject = setting.getEObject();
61:                 final EStructuralFeature eStructuralFeature = setting.getEStructuralFeature();
62:                 final EClass eClass = ((EReference) eStructuralFeature).getEReferenceType();
63:
64:                 addRowLegacy(eClass, eStructuralFeature, eObject);
65:         }
66:
67:         /**
68:          * Delegate method to legacy addRow() implementation.
69:          *
70:          * TODO:
71:          * 1) deprecate addRow() within TableControlSWTRenderer
72:          * 2) move addRow() from TableControlSWTRenderer into this action
73:          * 3) remove this delegate method
74:          *
75:          * @param eObject the {@link EObject}
76:          * @param eStructuralFeature the {@link EStructuralFeature}
77:          * @param eClass the {@link EClass}
78:          */
79:         public abstract void addRowLegacy(EClass eClass, EStructuralFeature eStructuralFeature, EObject eObject);
80:
81:         @Override
82:         public boolean canExecute() {
83:•                if (isTableDisabled() || getVTableControl().isAddRemoveDisabled() || isUpperBoundReached()) {
84:                         return false;
85:                 }
86:                 return true;
87:         }
88:
89: }