Skip to content

Package: TableRendererActionBar

TableRendererActionBar

nameinstructionbranchcomplexitylinemethod
TableRendererActionBar(TableRendererViewerActionContext, ActionConfiguration, ViewModelContext)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addControl(String, Control)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addElementData(String, Control)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addLegacyElementData()
M: 0 C: 30
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
fillComposite(Composite, AbstractTableViewer)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
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.Collections;
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19: import java.util.Map.Entry;
20:
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emfforms.common.Optional;
23: import org.eclipse.emfforms.spi.swt.core.SWTDataElementIdHelper;
24: import org.eclipse.emfforms.spi.swt.table.action.ActionConfiguration;
25: import org.eclipse.emfforms.spi.swt.table.action.TableActionBar;
26: import org.eclipse.emfforms.spi.swt.table.action.ViewerActionContext;
27: import org.eclipse.jface.viewers.AbstractTableViewer;
28: import org.eclipse.swt.widgets.Composite;
29: import org.eclipse.swt.widgets.Control;
30:
31: /**
32: * A customized action bar for the table renderer.
33: *
34: * @author Mat Hansen <mhansen@eclipsesource.com>
35: * @since 1.18
36: *
37: */
38: public class TableRendererActionBar extends TableActionBar<AbstractTableViewer> {
39:
40:         /**
41:          * A map of historic element IDs used for UI testing.
42:          */
43:         private static final Map<String, String> LEGACY_ELEMENT_IDS;
44:         static {
45:                 final Map<String, String> tmp = new LinkedHashMap<String, String>();
46:                 tmp.put(AddRowAction.ACTION_ID, "table_add"); //$NON-NLS-1$
47:                 tmp.put(RemoveRowAction.ACTION_ID, "table_remove"); //$NON-NLS-1$
48:                 tmp.put(MoveRowUpAction.ACTION_ID, "table_moveUp"); //$NON-NLS-1$
49:                 tmp.put(MoveRowDownAction.ACTION_ID, "table_moveDown"); //$NON-NLS-1$
50:                 LEGACY_ELEMENT_IDS = Collections.unmodifiableMap(tmp);
51:         }
52:
53:         private final ViewModelContext viewModelContext;
54:         private final TableRendererViewerActionContext context;
55:
56:         /**
57:          * The constructor.
58:          *
59:          * @param context the {@link ViewerActionContext} to use
60:          * @param configuration the {@link ActionConfiguration} to use
61:          * @param viewModelContext the {@link ViewModelContext}
62:          */
63:         public TableRendererActionBar(
64:                 TableRendererViewerActionContext context, ActionConfiguration configuration,
65:                 ViewModelContext viewModelContext) {
66:                 super(configuration);
67:                 this.context = context;
68:                 this.viewModelContext = viewModelContext;
69:         }
70:
71:         @Override
72:         public void fillComposite(Composite composite, AbstractTableViewer viewer) {
73:                 super.fillComposite(composite, viewer);
74:                 addLegacyElementData();
75:         }
76:
77:         @Override
78:         public void addControl(String id, Control control) {
79:                 super.addControl(id, control);
80:                 addElementData(id, control);
81:         }
82:
83:         private void addElementData(String actionId, Control control) {
84:                 SWTDataElementIdHelper.setElementIdDataWithSubId(
85:                         control, context.getVElement(), actionId, viewModelContext);
86:         }
87:
88:         /**
89:          * Add legacy non-qualified SWT element data objects to maintain backward compatibility.
90:          */
91:         private void addLegacyElementData() {
92:•                for (final Entry<String, String> legacyMapping : LEGACY_ELEMENT_IDS.entrySet()) {
93:                         final Optional<Control> control = getControlById(legacyMapping.getKey());
94:•                        if (control.isPresent()) {
95:                                 addElementData(legacyMapping.getValue(), control.get());
96:                         }
97:                 }
98:         }
99:
100: }