1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.eclipse.ui;
17
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.graphics.Font;
22 import org.eclipse.swt.layout.FormAttachment;
23 import org.eclipse.swt.layout.FormData;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Text;
30
31
32 public class EclipseUiUtils {
33
34
35 public static void clear(Composite composite) {
36 for (Control child : composite.getChildren())
37 child.dispose();
38 }
39
40
41
42
43
44 public static void layout(Composite parent, Control... toUpdateControls) {
45 parent.layout(toUpdateControls);
46 }
47
48
49
50
51
52 public static Font getItalicFont(Composite parent) {
53 return JFaceResources.getFontRegistry().defaultFontDescriptor().setStyle(SWT.ITALIC)
54 .createFont(parent.getDisplay());
55 }
56
57
58 public static Font getBoldFont(Composite parent) {
59 return JFaceResources.getFontRegistry().defaultFontDescriptor().setStyle(SWT.BOLD)
60 .createFont(parent.getDisplay());
61 }
62
63
64 public static Font getBoldItalicFont(Composite parent) {
65 return JFaceResources.getFontRegistry().defaultFontDescriptor().setStyle(SWT.BOLD | SWT.ITALIC)
66 .createFont(parent.getDisplay());
67 }
68
69
70
71
72 public static GridLayout noSpaceGridLayout() {
73 return noSpaceGridLayout(new GridLayout());
74 }
75
76 public static GridLayout noSpaceGridLayout(int columns) {
77 return noSpaceGridLayout(new GridLayout(columns, false));
78 }
79
80 public static GridLayout noSpaceGridLayout(GridLayout layout) {
81 layout.horizontalSpacing = 0;
82 layout.verticalSpacing = 0;
83 layout.marginWidth = 0;
84 layout.marginHeight = 0;
85 return layout;
86 }
87
88 public static GridData fillWidth() {
89 return grabWidth(SWT.FILL, SWT.FILL);
90 }
91
92 public static GridData fillWidth(int colSpan) {
93 GridData gd = grabWidth(SWT.FILL, SWT.FILL);
94 gd.horizontalSpan = colSpan;
95 return gd;
96 }
97
98 public static GridData fillAll() {
99 return new GridData(SWT.FILL, SWT.FILL, true, true);
100 }
101
102 public static GridData fillAll(int colSpan, int rowSpan) {
103 return new GridData(SWT.FILL, SWT.FILL, true, true, colSpan, rowSpan);
104 }
105
106 public static GridData grabWidth(int horizontalAlignment, int verticalAlignment) {
107 return new GridData(horizontalAlignment, horizontalAlignment, true, false);
108 }
109
110
111
112
113
114
115
116
117
118 public static FormData fillFormData() {
119 FormData formData = new FormData();
120 formData.top = new FormAttachment(0, 0);
121 formData.left = new FormAttachment(0, 0);
122 formData.right = new FormAttachment(100, 0);
123 formData.bottom = new FormAttachment(100, 0);
124 return formData;
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 public static Text createGridLT(Composite parent, String label, ModifyListener modifyListener) {
145 Label lbl = new Label(parent, SWT.LEAD);
146 lbl.setText(label);
147 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
148 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
149 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
150 if (modifyListener != null)
151 txt.addModifyListener(modifyListener);
152 return txt;
153 }
154
155
156
157
158
159 public static Text createGridLT(Composite parent, String label) {
160 return createGridLT(parent, label, null);
161 }
162
163
164
165
166
167 public static Text createGridLL(Composite parent, String label, String text) {
168 Text txt = createGridLT(parent, label);
169 txt.setText(text);
170 txt.setEditable(false);
171 txt.setBackground(parent.getBackground());
172 return txt;
173 }
174
175
176
177
178
179 public static Text createGridLP(Composite parent, String label) {
180 return createGridLP(parent, label, null);
181 }
182
183
184
185
186
187
188 public static Text createGridLP(Composite parent, String label, ModifyListener modifyListener) {
189 Label lbl = new Label(parent, SWT.LEAD);
190 lbl.setText(label);
191 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
192 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
193 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
194 if (modifyListener != null)
195 txt.addModifyListener(modifyListener);
196 return txt;
197 }
198
199
200
201
202 public static boolean notEmpty(String stringToTest) {
203 return !(stringToTest == null || "".equals(stringToTest.trim()));
204 }
205
206
207 public static boolean isEmpty(String stringToTest) {
208 return stringToTest == null || "".equals(stringToTest.trim());
209 }
210 }