-
Notifications
You must be signed in to change notification settings - Fork 96
/
PWTab.java
108 lines (94 loc) · 2.82 KB
/
PWTab.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
*******************************************************************************/
package org.eclipse.nebula.widgets.opal.preferencewindow;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWWidget;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
/**
* Instance of this class are tabs
*
*/
public class PWTab extends PWContainer {
private final Image image;
private final String text;
private final List<PWRowGroup> children;
/**
* Constructor
*
* @param image image associated to the tab
* @param text text associated to the tab
*/
PWTab(final Image image, final String text) {
this.image = image;
this.text = text;
this.children = new ArrayList<PWRowGroup>();
}
/**
* @see org.eclipse.nebula.widgets.opal.preferencewindow.PWContainer#add(org.eclipse.nebula.widgets.opal.preferencewindow.PWContainer)
*/
@Override
public PWContainer add(final PWContainer element) {
if (!(element instanceof PWGroup) && !(element instanceof PWRow)) {
throw new UnsupportedOperationException("Can only add a PWGroup or a PWRow.");
}
((PWRowGroup) element).setParent(this);
this.children.add((PWRowGroup) element);
return this;
}
@Override
public PWContainer add(final PWWidget widget) {
final PWRow row = new PWRow();
row.setParent(this);
row.add(widget);
this.children.add(row);
return this;
}
@Override
public void build(final Composite parent) {
final int numberOfColumns = computeNumberOfColums();
parent.setLayout(new GridLayout(numberOfColumns, false));
for (final PWRowGroup rowGroup : this.children) {
rowGroup.setParentNumberOfColumns(numberOfColumns);
rowGroup.build(parent);
}
PreferenceWindow.getInstance().fireEnablers();
}
/**
* @return the total number of columns in this tab
*/
private int computeNumberOfColums() {
int numberOfColumns = 1;
for (final PWRowGroup rowGroup : this.children) {
if (rowGroup instanceof PWRow) {
numberOfColumns = Math.max(numberOfColumns, rowGroup.getNumberOfColums());
}
}
return numberOfColumns;
}
/**
* @return the image associate to this tab
*/
public Image getImage() {
return this.image;
}
/**
* @return the text associated to this tab
*/
public String getText() {
return this.text;
}
}