1 package org.argeo.connect.ui;
2
3 import javax.jcr.Node;
4
5 import org.argeo.cms.Localized;
6 import org.argeo.cms.util.CmsUtils;
7 import org.argeo.connect.util.ConnectJcrUtils;
8 import org.argeo.connect.util.ConnectUtils;
9
10 import org.argeo.eclipse.ui.EclipseUiUtils;
11 import org.eclipse.jface.viewers.TableViewer;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.layout.FormAttachment;
14 import org.eclipse.swt.layout.FormData;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.layout.RowData;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.Table;
22 import org.eclipse.swt.widgets.Text;
23
24
25 public class ConnectUiUtils {
26
27 public static Label addEmptyLine(Composite parent, int height, int colSpan) {
28
29 Label emptyLbl = new Label(parent, SWT.NONE);
30 emptyLbl.setText("");
31 GridData gd = EclipseUiUtils.fillWidth(colSpan);
32 gd.heightHint = height;
33 emptyLbl.setLayoutData(gd);
34 return emptyLbl;
35 }
36
37
38
39
40
41
42 public static String getRwtCompliantString(Node node, String propName) {
43 String value = ConnectJcrUtils.get(node, propName);
44 value = ConnectUtils.replaceAmpersand(value);
45 return value;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public static boolean isNumbers(String content) {
62 int length = content.length();
63 for (int i = 0; i < length; i++) {
64 char ch = content.charAt(i);
65 if (!Character.isDigit(ch)) {
66 return false;
67 }
68 }
69 return true;
70 }
71
72
73
74
75
76
77 public static GridLayout noSpaceGridLayout(int nbOfCol) {
78 GridLayout gl = new GridLayout(nbOfCol, false);
79 gl.marginWidth = gl.marginHeight = gl.horizontalSpacing = gl.verticalSpacing = 0;
80 return gl;
81 }
82
83
84
85
86
87 public static String refreshTextWidgetValue(Text text, Node entity, String propName) {
88 String tmpStr = ConnectJcrUtils.get(entity, propName);
89 if (EclipseUiUtils.notEmpty(tmpStr))
90 text.setText(tmpStr);
91 return tmpStr;
92 }
93
94
95
96
97
98 public static String replaceAmpersandforSWTLink(String value) {
99 value = value.replaceAll("&", "&&");
100 return value;
101 }
102
103
104
105
106
107 public static Label createBoldLabel(Composite parent, String value) {
108 Label label = new Label(parent, SWT.LEAD);
109 label.setText(" " + value);
110 label.setFont(EclipseUiUtils.getBoldFont(parent));
111 label.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false));
112 return label;
113 }
114
115 public static Label createBoldLabel(Composite parent, Localized localized) {
116 Label label = new Label(parent, SWT.LEAD);
117 label.setText(localized.lead());
118 label.setFont(EclipseUiUtils.getBoldFont(parent));
119 label.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, false, false));
120 return label;
121 }
122
123
124
125
126
127 public static Label createBoldLabel(Composite parent, String value, int verticalAlign) {
128 Label label = new Label(parent, SWT.LEAD);
129 label.setText(" " + value);
130 label.setFont(EclipseUiUtils.getBoldFont(parent));
131 label.setLayoutData(new GridData(SWT.LEAD, verticalAlign, false, false));
132 return label;
133 }
134
135
136
137
138
139 public static Button createDeleteButton(Composite parent) {
140 Button button = new Button(parent, SWT.FLAT | SWT.PUSH);
141 CmsUtils.style(button, ConnectUiStyles.SMALL_DELETE_BTN);
142 RowData rd = new RowData();
143 rd.height = 8;
144 rd.width = 8;
145 button.setLayoutData(rd);
146 return button;
147 }
148
149
150 public static Text createRDText(Object toolkit, Composite parent, String msg, String toolTip, int width) {
151 Text text = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.LEFT);
152 text.setText("");
153 text.setMessage(msg);
154 text.setToolTipText(toolTip);
155 text.setLayoutData(width == 0 ? new RowData() : new RowData(width, SWT.DEFAULT));
156 return text;
157 }
158
159
160
161
162
163 public static Label createBoldLabel(Object toolkit, Composite parent, String value) {
164
165
166
167 Label label = new Label(parent, SWT.RIGHT);
168 label.setText(" " + value);
169 label.setFont(EclipseUiUtils.getBoldFont(parent));
170 label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
171 return label;
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185 @Deprecated
186 public static Text createGDText(Object toolkit, Composite parent, String msg, String toolTip, int width,
187 int colSpan) {
188 Text text = new Text(parent, SWT.BORDER | SWT.SINGLE | SWT.LEFT);
189 text.setText("");
190 text.setMessage(msg);
191 text.setToolTipText(toolTip);
192 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
193 gd.widthHint = width;
194 gd.horizontalSpan = colSpan;
195 text.setLayoutData(gd);
196 return text;
197 }
198
199 public static void setTableDefaultStyle(Table table, int customItemHeight) {
200 table.setLinesVisible(true);
201 table.setHeaderVisible(false);
202 CmsUtils.setItemHeight(table, customItemHeight);
203 CmsUtils.markup(table);
204 }
205
206 public static void setTableDefaultStyle(TableViewer viewer, int customItemHeight) {
207 setTableDefaultStyle(viewer.getTable(), customItemHeight);
208 }
209
210
211 public static void setSwitchingFormData(Composite composite) {
212 FormData fdLabel = new FormData();
213 fdLabel.top = new FormAttachment(0, 0);
214 fdLabel.left = new FormAttachment(0, 0);
215 fdLabel.right = new FormAttachment(100, 0);
216 fdLabel.bottom = new FormAttachment(100, 0);
217 composite.setLayoutData(fdLabel);
218 }
219
220
221
222
223
224
225
226
227
228
229 public static FormData createformData(int left, int top, int right, int bottom) {
230 FormData formData = new FormData();
231 formData.left = new FormAttachment(left, 0);
232 formData.top = new FormAttachment(top, 0);
233 formData.right = new FormAttachment(right, 0);
234 formData.bottom = new FormAttachment(bottom, 0);
235 return formData;
236 }
237
238 }