Skip to content

Package: TableActionIconButton

TableActionIconButton

nameinstructionbranchcomplexitylinemethod
TableActionIconButton(String, Image)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
configureIconButton(Button)
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%
createControl(Composite, Action)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createIconButton(Composite, Action)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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.emfforms.spi.swt.table.action.Action;
17: import org.eclipse.emfforms.spi.swt.table.action.ActionControlCreator;
18: import org.eclipse.swt.SWT;
19: import org.eclipse.swt.events.SelectionAdapter;
20: import org.eclipse.swt.events.SelectionEvent;
21: import org.eclipse.swt.graphics.Image;
22: import org.eclipse.swt.widgets.Button;
23: import org.eclipse.swt.widgets.Composite;
24:
25: /**
26: * Action icon default implementation for table actions.
27: *
28: * @author Mat Hansen <mhansen@eclipsesource.com>
29: * @since 1.18
30: *
31: */
32: public class TableActionIconButton implements ActionControlCreator<Button> {
33:
34:         private final String tooltipText;
35:         private final Image icon;
36:
37:         /**
38:          * The constructor.
39:          *
40:          * @param tooltipText the tooltip text to use
41:          * @param icon the icon to use
42:          */
43:         public TableActionIconButton(String tooltipText, Image icon) {
44:                 super();
45:                 this.tooltipText = tooltipText;
46:                 this.icon = icon;
47:         }
48:
49:         @Override
50:         public Button createControl(Composite parent, Action action) {
51:                 final Button button = createIconButton(parent, action);
52:                 configureIconButton(button);
53:                 return button;
54:         }
55:
56:         private Button createIconButton(Composite parent, final Action action) {
57:                 final Button button = new Button(parent, SWT.None);
58:                 button.addSelectionListener(new SelectionAdapter() {
59:                         @Override
60:                         public void widgetSelected(SelectionEvent e) {
61:                                 if (action.canExecute()) {
62:                                         action.execute();
63:                                 }
64:                         }
65:                 });
66:                 return button;
67:         }
68:
69:         private void configureIconButton(Button button) {
70:                 button.setImage(icon);
71:                 button.setToolTipText(tooltipText);
72:         }
73:
74: }