Skip to content

Package: CheckedSelectModelClassCompositeImpl

CheckedSelectModelClassCompositeImpl

nameinstructionbranchcomplexitylinemethod
CheckedSelectModelClassCompositeImpl(Collection, Collection, Collection)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createUI(Composite)
M: 100 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
getChecked()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getViewer()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isCheckedTree()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setChecked()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setInitialSelection(Object[])
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 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: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.spi.common.ui.composites;
16:
17: import java.util.ArrayList;
18: import java.util.Arrays;
19: import java.util.Collection;
20: import java.util.List;
21:
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EPackage;
24: import org.eclipse.emf.ecp.internal.common.ui.MessageKeys;
25: import org.eclipse.emf.ecp.spi.common.ui.CheckedModelClassComposite;
26: import org.eclipse.emfforms.spi.localization.LocalizationServiceHelper;
27: import org.eclipse.jface.layout.GridDataFactory;
28: import org.eclipse.jface.layout.GridLayoutFactory;
29: import org.eclipse.jface.viewers.CheckboxTreeViewer;
30: import org.eclipse.jface.viewers.ISelectionChangedListener;
31: import org.eclipse.jface.viewers.IStructuredContentProvider;
32: import org.eclipse.jface.viewers.SelectionChangedEvent;
33: import org.eclipse.swt.SWT;
34: import org.eclipse.swt.events.SelectionAdapter;
35: import org.eclipse.swt.events.SelectionEvent;
36: import org.eclipse.swt.widgets.Button;
37: import org.eclipse.swt.widgets.Composite;
38:
39: /**
40: * This class provides a CheckedTree that allows the user to select {@link EPackage EPackages} and {@link EClass
41: * EClasses}.
42: *
43: * @author Eugen Neufeld
44: *
45: */
46: public class CheckedSelectModelClassCompositeImpl extends AbstractEClassTreeSelectionComposite implements
47:         CheckedModelClassComposite {
48:         private Object[] checked;
49:
50:         private Object[] initialSelection;
51:
52:         /**
53:          * Constructor setting the necessary data for selecting the {@link EClass EClasses}.
54:          *
55:          * @param unsupportedEPackages {@link EPackage EPackages} that are not supported
56:          * @param filteredEPackages {@link EPackage EPackages} selected by the user
57:          * @param filteredEClasses {@link EClass EClasses} selected by the user
58:          */
59:         public CheckedSelectModelClassCompositeImpl(Collection<EPackage> unsupportedEPackages,
60:                 Collection<EPackage> filteredEPackages, Collection<EClass> filteredEClasses) {
61:                 super(unsupportedEPackages, filteredEPackages, filteredEClasses);
62:         }
63:
64:         @Override
65:         protected boolean isCheckedTree() {
66:                 return true;
67:         }
68:
69:         @Override
70:         public Composite createUI(Composite parent) {
71:                 final Composite composite = super.createUI(parent);
72:                 final Composite buttons = new Composite(composite, SWT.NONE);
73:                 GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(buttons);
74:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).span(2, 1).applyTo(buttons);
75:
76:                 final Button buttonAll = new Button(buttons, SWT.PUSH);
77:                 buttonAll.setText(LocalizationServiceHelper.getString(CheckedSelectModelClassCompositeImpl.class,
78:                         MessageKeys.CheckedModelElementHelper_SelectAllLabel));
79:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(buttonAll);
80:                 buttonAll.addSelectionListener(new SelectionAdapter() {
81:                         @Override
82:                         public void widgetSelected(SelectionEvent e) {
83:                                 getViewer().setCheckedElements(
84:                                         ((IStructuredContentProvider) getViewer().getContentProvider()).getElements(new Object()));
85:                                 setChecked();
86:                         }
87:                 });
88:                 final Button buttonNone = new Button(buttons, SWT.PUSH);
89:                 buttonNone.setText(LocalizationServiceHelper.getString(CheckedSelectModelClassCompositeImpl.class,
90:                         MessageKeys.CheckedModelElementHelper_DeselectAllLabel));
91:                 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(buttonNone);
92:                 buttonNone.addSelectionListener(new SelectionAdapter() {
93:                         @Override
94:                         public void widgetSelected(SelectionEvent e) {
95:                                 getViewer().setCheckedElements(new Object[0]);
96:                                 setChecked();
97:                         }
98:                 });
99:                 getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
100:                         @Override
101:                         public void selectionChanged(SelectionChangedEvent event) {
102:                                 setChecked();
103:                         }
104:                 });
105:
106:•                if (initialSelection != null) {
107:                         getViewer().setCheckedElements(initialSelection);
108:                         setChecked();
109:                 }
110:                 return composite;
111:         }
112:
113:         /**
114:          * @return the treeViewer
115:          */
116:         @Override
117:         public CheckboxTreeViewer getViewer() {
118:                 return (CheckboxTreeViewer) super.getViewer();
119:         }
120:
121:         private void setChecked() {
122:                 final List<Object> objects = new ArrayList<Object>(Arrays.asList(getViewer().getCheckedElements()));
123:                 objects.removeAll(Arrays.asList(getViewer().getGrayedElements()));
124:                 checked = objects.toArray();
125:         }
126:
127:         /**
128:          * Returns the checked Elements.
129:          *
130:          * @return an array containing the checked elements
131:          */
132:         @Override
133:         public Object[] getChecked() {
134:                 return checked;
135:
136:         }
137:
138:         /**
139:          * Initialize the selection by setting the checked elements.
140:          *
141:          * @param selection the objects to check
142:          */
143:         @Override
144:         public void setInitialSelection(Object[] selection) {
145:•                if (getViewer() != null) {
146:                         getViewer().setCheckedElements(selection);
147:                 } else {
148:                         initialSelection = selection;
149:                 }
150:         }
151: }