Skip to content

Package: AbstractMoveRowAction

AbstractMoveRowAction

nameinstructionbranchcomplexitylinemethod
AbstractMoveRowAction(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: 2 C: 16
89%
M: 4 C: 4
50%
M: 4 C: 1
20%
M: 1 C: 4
80%
M: 0 C: 1
100%
getContainments()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
sortSelectionBasedOnIndex(List, List)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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: * lucas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt.action;
15:
16: import java.util.Collections;
17: import java.util.Comparator;
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:
25: /**
26: * Abstract base type for actions which move rows inside a table.
27: *
28: * @author Lucas Koehler
29: * @since 1.18
30: *
31: */
32: public abstract class AbstractMoveRowAction extends TableRendererAction {
33:
34:         /**
35:          * The constructor.
36:          *
37:          * @param actionContext the {@link ViewerActionContext}
38:          */
39:         public AbstractMoveRowAction(TableRendererViewerActionContext actionContext) {
40:                 super(actionContext);
41:         }
42:
43:         /**
44:          * Sorting helper for a table viewer selection.
45:          *
46:          * @param selection the selection to sort
47:          * @param list the index list
48:          */
49:         public static void sortSelectionBasedOnIndex(List<?> selection, final List<?> list) {
50:                 Collections.sort(
51:                         selection,
52:                         new Comparator<Object>() {
53:                                 @Override
54:                                 public int compare(Object left, Object right) {
55:                                         return list.indexOf(left) - list.indexOf(right);
56:                                 }
57:                         });
58:         }
59:
60:         @Override
61:         public boolean canExecute() {
62:•                if (isTableDisabled() || !isOrdered()
63:•                        || getVTableControl().isMoveUpDownDisabled()
64:•                        || getNumberOfVisibleRows() <= 1) {
65:                         return false;
66:                 }
67:                 return true;
68:         }
69:
70:         /**
71:          * Returns the list containing all objects of the table viewer.
72:          *
73:          * @return the containments list
74:          */
75:         protected List<?> getContainments() {
76:                 final Setting setting = getActionContext().getSetting();
77:                 final EObject eObject = setting.getEObject();
78:                 final EStructuralFeature eStructuralFeature = setting.getEStructuralFeature();
79:
80:                 // TODO: will containments work in combination with viewer filters?
81:                 final List<?> containments = (List<?>) eObject.eGet(eStructuralFeature, true);
82:                 return containments;
83:         }
84: }