Skip to content

Package: RemoveRowAction

RemoveRowAction

nameinstructionbranchcomplexitylinemethod
RemoveRowAction(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: 17
100%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 4
100%
M: 0 C: 1
100%
execute()
M: 0 C: 41
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
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 Hansen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt.action;
15:
16: import java.util.ArrayList;
17: import java.util.Iterator;
18: import java.util.List;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature;
22: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
23: import org.eclipse.emfforms.spi.swt.table.action.ViewerActionContext;
24: import org.eclipse.jface.viewers.IStructuredSelection;
25:
26: /**
27: * Action to remove a row from a table viewer.
28: *
29: * @author Mat Hansen <mhansen@eclipsesource.com>
30: * @since 1.18
31: *
32: */
33: public abstract class RemoveRowAction extends TableRendererAction {
34:
35:         /**
36:          * The ID of this action.
37:          */
38:         public static final String ACTION_ID = PREFIX + "tablecontrol.remove_row"; //$NON-NLS-1$
39:
40:         /**
41:          * The default key binding of this action.
42:          */
43:         public static final String DEFAULT_KEYBINDING = "M1+r"; //$NON-NLS-1$
44:
45:         /**
46:          * The constructor.
47:          *
48:          * @param actionContext the {@link ViewerActionContext}
49:          */
50:         public RemoveRowAction(TableRendererViewerActionContext actionContext) {
51:                 super(actionContext);
52:         }
53:
54:         @Override
55:         public String getId() {
56:                 return ACTION_ID;
57:         }
58:
59:         @Override
60:         public void execute() {
61:
62:                 final ViewerActionContext<?> context = getActionContext();
63:                 final IStructuredSelection selection = (IStructuredSelection) context.getViewer().getSelection();
64:                 final List<EObject> itemsToRemove = new ArrayList<EObject>();
65:                 final Iterator<?> iterator = selection.iterator();
66:
67:•                while (iterator.hasNext()) {
68:                         itemsToRemove.add((EObject) iterator.next());
69:                 }
70:
71:                 final Setting setting = getActionContext().getSetting();
72:                 final EObject eObject = setting.getEObject();
73:                 final EStructuralFeature eStructuralFeature = setting.getEStructuralFeature();
74:
75:                 removeRowLegacy(itemsToRemove, eObject, eStructuralFeature);
76:
77:                 // TODO: select the last record before the removed row, see bug #536243
78:         }
79:
80:         @Override
81:         public boolean canExecute() {
82:•                if (isTableDisabled() || getVTableControl().isAddRemoveDisabled() || isLowerBoundReached()
83:•                        || isViewerSelectionInvalid()) {
84:                         return false;
85:                 }
86:                 return true;
87:         }
88:
89:         /**
90:          * Delegate method to legacy addRow() implementation.
91:          *
92:          * TODO:
93:          * 1) deprecate deleteRowUserConfirmDialog(), deleteRows(), removeElements() within TableControlSWTRenderer
94:          * 2) move deleteRowUserConfirmDialog(), deleteRows(), removeElements() from TableControlSWTRenderer
95:          * into this action
96:          * 3) remove this delegate method
97:          *
98:          * @param deletionList the elements to delete
99:          * @param eObject the {@link EObject}
100:          * @param eStructuralFeature the {@link EStructuralFeature}
101:          */
102:         public abstract void removeRowLegacy(List<EObject> deletionList,
103:                 EObject eObject, EStructuralFeature eStructuralFeature);
104:
105: }