/
FormatDateTimeSection.java
110 lines (86 loc) · 3 KB
/
FormatDateTimeSection.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
109
110
package org.eclipse.birt.report.designer.internal.ui.views.attributes.section;
import org.eclipse.birt.report.designer.internal.ui.dialogs.IFormatChangeListener;
import org.eclipse.birt.report.designer.internal.ui.views.attributes.page.WidgetUtil;
import org.eclipse.birt.report.designer.internal.ui.views.attributes.provider.IDescriptorProvider;
import org.eclipse.birt.report.designer.internal.ui.views.attributes.widget.FormatDateTimeDescriptor;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
public class FormatDateTimeSection extends Section {
private int style;
private final boolean showLocale;
public FormatDateTimeSection(Composite parent, int style, boolean isFormStyle) {
this(parent, style, isFormStyle, true);
}
public FormatDateTimeSection(Composite parent, int style, boolean isFormStyle, boolean showLocale) {
super(" ", parent, isFormStyle); //$NON-NLS-1$
this.style = style;
this.showLocale = showLocale;
}
protected FormatDateTimeDescriptor format;
public void createSection() {
getFormatControl(parent);
getGridPlaceholder(parent);
}
public FormatDateTimeDescriptor getFormatControl() {
return format;
}
protected FormatDateTimeDescriptor getFormatControl(Composite parent) {
if (format == null) {
format = new FormatDateTimeDescriptor(style, isFormStyle, showLocale);
format.setDescriptorProvider(provider);
format.createControl(parent);
format.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
format.getControl().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
format = null;
}
});
} else {
checkParent(format.getControl(), parent);
}
return format;
}
public void layout() {
GridData gd = (GridData) format.getControl().getLayoutData();
if (getLayoutNum() > 0)
gd.horizontalSpan = getLayoutNum() - placeholder;
else
gd.horizontalSpan = ((GridLayout) parent.getLayout()).numColumns - placeholder;
}
public void addFormatChangeListener(IFormatChangeListener listener) {
format.addFormatChangeListener(listener);
}
public void load() {
if (format != null && !format.getControl().isDisposed())
format.load();
}
IDescriptorProvider provider;
public IDescriptorProvider getProvider() {
return provider;
}
public void setProvider(IDescriptorProvider provider) {
this.provider = provider;
if (format != null)
format.setDescriptorProvider(provider);
}
public void setInput(Object input) {
assert (input != null);
format.setInput(input);
}
public void setHidden(boolean isHidden) {
if (format != null)
WidgetUtil.setExcludeGridData(format.getControl(), isHidden);
}
public void setVisible(boolean isVisable) {
if (format != null)
format.getControl().setVisible(isVisable);
}
public void reset() {
if (format != null && !format.getControl().isDisposed()) {
format.reset();
}
}
}