Skip to content

Package: PGroupRenderer$1

PGroupRenderer$1

nameinstructionbranchcomplexitylinemethod
itemCollapsed(ExpandEvent)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
itemExpanded(ExpandEvent)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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: * Eugen Neufeld - initial PGroup Renderer
13: * Johannes Faltermeier - adaptions to collapsible group model
14: *
15: */
16: package org.eclipse.emf.ecp.view.group.swt.internal.collapsible.pgroup;
17:
18: import java.util.Collection;
19:
20: import javax.inject.Inject;
21:
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
23: import org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer;
24: import org.eclipse.emf.ecp.view.spi.group.model.VGroup;
25: import org.eclipse.emf.ecp.view.spi.model.VContainedElement;
26: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
27: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
28: import org.eclipse.emf.ecp.view.spi.swt.layout.LayoutProviderHelper;
29: import org.eclipse.emfforms.spi.common.report.ReportService;
30: import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory;
31: import org.eclipse.emfforms.spi.swt.core.layout.EMFFormsSWTLayoutUtil;
32: import org.eclipse.emfforms.spi.swt.core.layout.GridDescriptionFactory;
33: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
34: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridDescription;
35: import org.eclipse.nebula.widgets.pgroup.PGroup;
36: import org.eclipse.swt.SWT;
37: import org.eclipse.swt.events.ExpandEvent;
38: import org.eclipse.swt.events.ExpandListener;
39: import org.eclipse.swt.graphics.Point;
40: import org.eclipse.swt.layout.FillLayout;
41: import org.eclipse.swt.widgets.Composite;
42: import org.eclipse.swt.widgets.Control;
43: import org.eclipse.swt.widgets.Layout;
44:
45: /**
46: * Renderer for a collapsible {@link VGroup} using {@link PGroup} from Nebula.
47: *
48: * @author jfaltermeier
49: *
50: */
51: public class PGroupRenderer extends ContainerSWTRenderer<VGroup> {
52:         private SWTGridDescription rendererGridDescription;
53:
54:         /**
55:          * Default constructor.
56:          *
57:          * @param vElement the view model element to be rendered
58:          * @param viewContext the view context
59:          * @param reportService the {@link ReportService}
60:          * @param factory the {@link EMFFormsRendererFactory}
61:          */
62:         @Inject
63:         public PGroupRenderer(VGroup vElement, ViewModelContext viewContext, ReportService reportService,
64:                 EMFFormsRendererFactory factory) {
65:                 super(vElement, viewContext, reportService, factory);
66:         }
67:
68:         @Override
69:         protected Collection<VContainedElement> getChildren() {
70:                 return getVElement().getChildren();
71:         }
72:
73:         @Override
74:         protected String getCustomVariant() {
75:                 return "PGroup"; //$NON-NLS-1$
76:         }
77:
78:         /**
79:          * {@inheritDoc}
80:          *
81:          * @see org.eclipse.emf.ecp.view.spi.core.swt.ContainerSWTRenderer#renderControl(org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell,
82:          * org.eclipse.swt.widgets.Composite)
83:          */
84:         @Override
85:         protected Control renderControl(SWTGridCell gridCell, Composite parent)
86:                 throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
87:
88:                 parent.setBackgroundMode(SWT.INHERIT_FORCE);
89:
90:                 final PGroup group = new PGroup(parent, SWT.SMOOTH);
91:                 group.setLayout(new FillLayout());
92:                 if (getVElement().getLabel() != null) {
93:                         group.setText(getVElement().getLabel());
94:                 }
95:
96:                 super.renderControl(gridCell, group);
97:
98:                 group.addExpandListener(new ExpandListener() {
99:
100:                         @Override
101:                         public void itemCollapsed(ExpandEvent e) {
102:                                 EMFFormsSWTLayoutUtil.adjustParentSize(group);
103:                                 getVElement().setCollapsed(true);
104:                         }
105:
106:                         @Override
107:                         public void itemExpanded(ExpandEvent e) {
108:                                 EMFFormsSWTLayoutUtil.adjustParentSize(group);
109:                                 getVElement().setCollapsed(false);
110:                         }
111:
112:                 });
113:
114:                 group.setExpanded(!getVElement().isCollapsed());
115:                 return group;
116:         }
117:
118:         @Override
119:         protected Layout getLayout(int numControls, boolean equalWidth) {
120:                 return LayoutProviderHelper.getColumnLayout(numControls, equalWidth, new Point(5, 5));
121:         }
122:
123:         @Override
124:         public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
125:                 if (rendererGridDescription == null) {
126:                         rendererGridDescription = GridDescriptionFactory.INSTANCE.createSimpleGrid(1, 1, this);
127:                         final SWTGridCell swtGridCell = rendererGridDescription.getGrid().get(0);
128:                         swtGridCell.setVerticalFill(false);
129:                         swtGridCell.setVerticalGrab(false);
130:                 }
131:                 return rendererGridDescription;
132:         }
133:
134: }