Skip to content

Package: LayoutHelper

LayoutHelper

nameinstructionbranchcomplexitylinemethod
LayoutHelper()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
adjustForTableLayout(TableViewer)
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
adjustForTableLayout(TreeViewer)
M: 0 C: 30
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
adjustLayoutColumnData(Layout, Widget, int)
M: 0 C: 21
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createColumnWeightData(int)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016 RCP Vision (http://www.rcp-vision.com) and others.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Lorenzo Bettini - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.emf.parsley.viewers;
12:
13: import org.eclipse.jface.layout.AbstractColumnLayout;
14: import org.eclipse.jface.layout.TableColumnLayout;
15: import org.eclipse.jface.layout.TreeColumnLayout;
16: import org.eclipse.jface.viewers.ColumnWeightData;
17: import org.eclipse.jface.viewers.TableLayout;
18: import org.eclipse.jface.viewers.TableViewer;
19: import org.eclipse.jface.viewers.TreeViewer;
20: import org.eclipse.swt.widgets.Layout;
21: import org.eclipse.swt.widgets.Table;
22: import org.eclipse.swt.widgets.Tree;
23: import org.eclipse.swt.widgets.Widget;
24:
25: /**
26: * Some methods to adjust layout.
27: *
28: * @author Lorenzo Bettini - initial API and implementation
29: *
30: */
31: public class LayoutHelper {
32:
33:         public static final int MINIMUM_WEIGHT = 30;
34:
35:         public Layout adjustForTableLayout(TableViewer tableViewer) {
36:                 final Table table = tableViewer.getTable();
37:
38:                 Layout layout = null;
39:
40:                 final Layout parentLayout = table.getParent().getLayout();
41:•                if (parentLayout instanceof TableColumnLayout) {
42:                         layout = parentLayout;
43:                 } else {
44:                         layout = new TableLayout();
45:                         table.setLayout(layout);
46:                 }
47:                 table.setHeaderVisible(true);
48:                 table.setLinesVisible(true);
49:
50:                 return layout;
51:         }
52:
53:         public Layout adjustForTableLayout(TreeViewer treeViewer) {
54:                 final Tree tree = treeViewer.getTree();
55:
56:                 Layout layout = null;
57:
58:                 final Layout parentLayout = tree.getParent().getLayout();
59:•                if (parentLayout instanceof TreeColumnLayout) {
60:                         layout = parentLayout;
61:                 } else {
62:                         layout = new TableLayout();
63:                         tree.setLayout(layout);
64:                 }
65:                 tree.setHeaderVisible(true);
66:                 tree.setLinesVisible(true);
67:
68:                 return layout;
69:         }
70:
71:         public void adjustLayoutColumnData(Layout layout, Widget column, int weight) {
72:•                if (layout instanceof AbstractColumnLayout) {
73:                         ((AbstractColumnLayout) layout).setColumnData(column, createColumnWeightData(weight));
74:•                } else if (layout instanceof TableLayout) {
75:                         ((TableLayout) layout).addColumnData(createColumnWeightData(weight));
76:                 }
77:         }
78:
79:         protected ColumnWeightData createColumnWeightData(int weight) {
80:                 return new ColumnWeightData(weight, MINIMUM_WEIGHT, true);
81:         }
82: }