Skip to content

Package: KeyListenerUtil

KeyListenerUtil

nameinstructionbranchcomplexitylinemethod
clearSelection(Grid, VControl, EMFFormsDatabindingEMF)
M: 65 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
unsetFeature(EMFFormsDatabindingEMF, VDomainModelReference, EObject)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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.emf.ecp.view.internal.table.nebula.grid;
15:
16: import org.eclipse.emf.common.command.Command;
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
19: import org.eclipse.emf.ecp.view.spi.model.VControl;
20: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
21: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
22: import org.eclipse.emf.edit.command.SetCommand;
23: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
24: import org.eclipse.emf.edit.domain.EditingDomain;
25: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
26: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
27: import org.eclipse.emfforms.spi.swt.table.TableConfiguration;
28: import org.eclipse.nebula.widgets.grid.Grid;
29: import org.eclipse.swt.graphics.Point;
30:
31: /**
32: * Util class for common functionality.
33: *
34: * @author Stefan Dirix
35: * @since 1.11
36: *
37: */
38: public final class KeyListenerUtil {
39:
40:         /**
41:          * Private Constructor for Util classes.
42:          */
43:         private KeyListenerUtil() {
44:         }
45:
46:         /**
47:          * Clears the selection from the grid.
48:          *
49:          * @param grid the {@link Grid}.
50:          * @param vControl the {@link VControl}.
51:          * @param dataBinding the {@link EMFFormsDatabindingEMF}.
52:          */
53:         @SuppressWarnings("restriction")
54:         public static void clearSelection(Grid grid, VControl vControl, EMFFormsDatabindingEMF dataBinding) {
55:•                if (grid.getCellSelection().length == 0 || !vControl.isEffectivelyEnabled()
56:•                        || vControl.isEffectivelyReadonly()) {
57:                         return;
58:                 }
59:
60:•                for (final Point itemCoord : grid.getCellSelection()) {
61:                         final int column = itemCoord.x;
62:                         final int row = itemCoord.y;
63:
64:                         final VDomainModelReference dmr = (VDomainModelReference) grid.getColumn(column)
65:                                 .getData(TableConfiguration.DMR);
66:
67:•                        if (dmr == null || vControl instanceof VTableControl
68:                                 && org.eclipse.emf.ecp.view.internal.table.swt.TableConfigurationHelper
69:•                                        .isReadOnly((VTableControl) vControl, dmr)) {
70:                                 continue;
71:                         }
72:
73:                         final EObject eObject = (EObject) grid.getItem(row).getData();
74:
75:                         try {
76:                                 unsetFeature(dataBinding, dmr, eObject);
77:                         } catch (final DatabindingFailedException ex) {
78:                                 // ignore
79:                         }
80:                 }
81:         }
82:
83:         /**
84:          * Unsets the feature referenced by the given DMR in the given {@link EObject}.
85:          *
86:          * @param dataBinding The {@link EMFFormsDatabindingEMF} used to resolve the feature
87:          * @param dmr The dmr referencing the feature
88:          * @param eObject The dmr's root object
89:          * @throws DatabindingFailedException If the data binding fails
90:          */
91:         static void unsetFeature(EMFFormsDatabindingEMF dataBinding, final VDomainModelReference dmr,
92:                 final EObject eObject) throws DatabindingFailedException {
93:                 final Setting setting = dataBinding.getSetting(dmr, eObject);
94:                 final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(setting.getEObject());
95:                 final Command command = SetCommand.create(domain, setting.getEObject(), setting.getEStructuralFeature(),
96:                         SetCommand.UNSET_VALUE);
97:                 domain.getCommandStack().execute(command);
98:         }
99: }