Skip to content

Commit e828660

Browse files
committed
Deprecate CSpinner in favor of native SWT Spinner
The CSpinner is not properly rendered on Linux. There is no real benefit for maintaining our own implementation, so we should just go back to the one provided by SWT.
1 parent db655bc commit e828660

File tree

12 files changed

+195
-123
lines changed

12 files changed

+195
-123
lines changed

org.eclipse.wb.core/src/org/eclipse/wb/core/controls/CSpinner.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -39,7 +39,10 @@
3939
*
4040
* @author scheglov_ke
4141
* @coverage core.control
42+
* @Deprecated Use the native {@link Spinner} directly. This class will be
43+
* removed after the 2028-03 release.
4244
*/
45+
@Deprecated(since = "2026-03", forRemoval = true)
4346
public class CSpinner extends Composite {
4447
private static final Color COLOR_VALID = Display.getCurrent().getSystemColor(
4548
SWT.COLOR_LIST_BACKGROUND);
@@ -66,6 +69,7 @@ public class CSpinner extends Composite {
6669
// Constructor
6770
//
6871
////////////////////////////////////////////////////////////////////////////
72+
@Deprecated
6973
public CSpinner(Composite parent, int style) {
7074
super(parent, style);
7175
m_button = new Button(this, SWT.ARROW | SWT.DOWN);
@@ -165,6 +169,7 @@ public void widgetSelected(SelectionEvent e) {
165169
// Access
166170
//
167171
////////////////////////////////////////////////////////////////////////////
172+
@Deprecated
168173
@Override
169174
public void setEnabled(boolean enabled) {
170175
super.setEnabled(enabled);
@@ -177,6 +182,7 @@ public void setEnabled(boolean enabled) {
177182
* <p>
178183
* See {@link Spinner#setDigits(int)}.
179184
*/
185+
@Deprecated
180186
public void setDigits(int digits) {
181187
m_formatPattern = "0.";
182188
m_multiplier = 1;
@@ -191,6 +197,7 @@ public void setDigits(int digits) {
191197
/**
192198
* Sets minimum and maximum using single invocation.
193199
*/
200+
@Deprecated
194201
public void setRange(int minimum, int maximum) {
195202
setMinimum(minimum);
196203
setMaximum(maximum);
@@ -199,13 +206,15 @@ public void setRange(int minimum, int maximum) {
199206
/**
200207
* @return the minimum value that the receiver will allow.
201208
*/
209+
@Deprecated
202210
public int getMinimum() {
203211
return m_minimum;
204212
}
205213

206214
/**
207215
* Sets the minimum value that the receiver will allow.
208216
*/
217+
@Deprecated
209218
public void setMinimum(int minimum) {
210219
m_minimum = minimum;
211220
setSelection(Math.max(m_value, m_minimum));
@@ -214,6 +223,7 @@ public void setMinimum(int minimum) {
214223
/**
215224
* Sets the maximum value that the receiver will allow.
216225
*/
226+
@Deprecated
217227
public void setMaximum(int maximum) {
218228
m_maximum = maximum;
219229
setSelection(Math.min(m_value, m_maximum));
@@ -223,6 +233,7 @@ public void setMaximum(int maximum) {
223233
* Sets the amount that the receiver's value will be modified by when the up/down arrows are
224234
* pressed to the argument, which must be at least one.
225235
*/
236+
@Deprecated
226237
public void setIncrement(int increment) {
227238
m_increment = increment;
228239
}
@@ -232,6 +243,7 @@ public void setIncrement(int increment) {
232243
* not within the range specified by minimum and maximum, it will be adjusted to fall within this
233244
* range.
234245
*/
246+
@Deprecated
235247
public void setSelection(int newValue) {
236248
newValue = Math.min(Math.max(m_minimum, newValue), m_maximum);
237249
if (newValue != m_value || m_text.getText().length() == 0) {
@@ -251,6 +263,7 @@ private void updateText() {
251263
/**
252264
* @return the <em>selection</em>, which is the receiver's position.
253265
*/
266+
@Deprecated
254267
public int getSelection() {
255268
return m_value;
256269
}
Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -13,8 +13,6 @@
1313
package org.eclipse.wb.core.controls;
1414

1515
import org.eclipse.swt.SWT;
16-
import org.eclipse.swt.widgets.Display;
17-
import org.eclipse.swt.widgets.Event;
1816
import org.eclipse.swt.widgets.Listener;
1917

2018
/**
@@ -23,52 +21,14 @@
2321
* @author scheglov_ke
2422
* @author lobas_av
2523
* @coverage core.control
24+
* @deprecated Use {@link SpinnerDeferredNotifier} instead. This class will be
25+
* removed after the 2028-03 release.
2626
*/
27-
public final class CSpinnerDeferredNotifier {
28-
private final CSpinner m_spinner;
29-
private final Display m_display;
30-
private final int m_timeout;
31-
private final Listener m_listener;
27+
@Deprecated(since = "2026-03", forRemoval = true)
28+
public final class CSpinnerDeferredNotifier extends SpinnerDeferredNotifier {
3229

33-
////////////////////////////////////////////////////////////////////////////
34-
//
35-
// Constructor
36-
//
37-
////////////////////////////////////////////////////////////////////////////
38-
public CSpinnerDeferredNotifier(CSpinner spinner, int timeout, Listener listener) {
39-
m_spinner = spinner;
40-
m_display = m_spinner.getDisplay();
41-
m_timeout = timeout;
42-
m_listener = listener;
43-
addListener();
44-
}
45-
46-
////////////////////////////////////////////////////////////////////////////
47-
//
48-
// Listener
49-
//
50-
////////////////////////////////////////////////////////////////////////////
51-
private final int[] m_eventId = new int[1];
52-
53-
/**
54-
* Handler for single {@link SWT#Selection} event.
55-
*/
56-
private void addListener() {
57-
m_spinner.addListener(SWT.Selection, new Listener() {
58-
@Override
59-
public void handleEvent(final Event event) {
60-
m_eventId[0]++;
61-
m_display.timerExec(m_timeout, new Runnable() {
62-
int m_id = m_eventId[0];
63-
64-
@Override
65-
public void run() {
66-
if (m_id == m_eventId[0]) {
67-
m_listener.handleEvent(event);
68-
}
69-
}
70-
});
71-
}
72-
});
30+
@Deprecated
31+
public CSpinnerDeferredNotifier(@SuppressWarnings("removal") CSpinner spinner, int timeout, Listener listener) {
32+
super(spinner, timeout, listener);
7333
}
7434
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Google, Inc. - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.wb.core.controls;
14+
15+
import org.eclipse.swt.SWT;
16+
import org.eclipse.swt.widgets.Control;
17+
import org.eclipse.swt.widgets.Display;
18+
import org.eclipse.swt.widgets.Event;
19+
import org.eclipse.swt.widgets.Listener;
20+
import org.eclipse.swt.widgets.Spinner;
21+
22+
/**
23+
* Helper for sending single {@link SWT#Selection} event after some timeout.
24+
*
25+
* @author scheglov_ke
26+
* @author lobas_av
27+
* @coverage core.control
28+
*/
29+
@SuppressWarnings("removal")
30+
public sealed class SpinnerDeferredNotifier permits CSpinnerDeferredNotifier {
31+
private final Control m_spinner;
32+
private final Display m_display;
33+
private final int m_timeout;
34+
private final Listener m_listener;
35+
36+
////////////////////////////////////////////////////////////////////////////
37+
//
38+
// Constructor
39+
//
40+
////////////////////////////////////////////////////////////////////////////
41+
public SpinnerDeferredNotifier(Spinner spinner, int timeout, Listener listener) {
42+
m_spinner = spinner;
43+
m_display = m_spinner.getDisplay();
44+
m_timeout = timeout;
45+
m_listener = listener;
46+
addListener();
47+
}
48+
49+
/* package */ SpinnerDeferredNotifier(CSpinner spinner, int timeout, Listener listener) {
50+
m_spinner = spinner;
51+
m_display = m_spinner.getDisplay();
52+
m_timeout = timeout;
53+
m_listener = listener;
54+
addListener();
55+
}
56+
57+
////////////////////////////////////////////////////////////////////////////
58+
//
59+
// Listener
60+
//
61+
////////////////////////////////////////////////////////////////////////////
62+
private final int[] m_eventId = new int[1];
63+
64+
/**
65+
* Handler for single {@link SWT#Selection} event.
66+
*/
67+
private void addListener() {
68+
m_spinner.addListener(SWT.Selection, new Listener() {
69+
@Override
70+
public void handleEvent(final Event event) {
71+
m_eventId[0]++;
72+
m_display.timerExec(m_timeout, new Runnable() {
73+
int m_id = m_eventId[0];
74+
75+
@Override
76+
public void run() {
77+
if (m_id == m_eventId[0]) {
78+
m_listener.handleEvent(event);
79+
}
80+
}
81+
});
82+
}
83+
});
84+
}
85+
}

org.eclipse.wb.core/src/org/eclipse/wb/core/controls/test/CSpinnerTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011 Google, Inc.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -34,10 +34,14 @@
3434
*
3535
* @author scheglov_ke
3636
* @coverage core.test
37+
* @deprecated Obsolete. This class will be removed after the 2028-03 release.
3738
*/
39+
@Deprecated(since = "2026-03", forRemoval = true)
3840
public class CSpinnerTest {
41+
@Deprecated
3942
protected Shell shell;
4043

44+
@Deprecated
4145
public static void main(String[] args) {
4246
try {
4347
CSpinnerTest window = new CSpinnerTest();
@@ -47,6 +51,7 @@ public static void main(String[] args) {
4751
}
4852
}
4953

54+
@Deprecated
5055
public void open() {
5156
final Display display = Display.getDefault();
5257
createContents();
@@ -59,6 +64,8 @@ public void open() {
5964
}
6065
}
6166

67+
@Deprecated
68+
@SuppressWarnings("removal")
6269
protected void createContents() {
6370
shell = new Shell();
6471
shell.setSize(500, 375);

org.eclipse.wb.core/src/org/eclipse/wb/core/editor/actions/assistant/AbstractAssistantPage.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2025 Google, Inc. and others.
2+
* Copyright (c) 2011, 2026 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -12,8 +12,7 @@
1212
*******************************************************************************/
1313
package org.eclipse.wb.core.editor.actions.assistant;
1414

15-
import org.eclipse.wb.core.controls.CSpinner;
16-
import org.eclipse.wb.core.controls.CSpinnerDeferredNotifier;
15+
import org.eclipse.wb.core.controls.SpinnerDeferredNotifier;
1716
import org.eclipse.wb.core.model.ObjectInfo;
1817
import org.eclipse.wb.internal.core.DesignerPlugin;
1918
import org.eclipse.wb.internal.core.model.property.Property;
@@ -35,6 +34,7 @@
3534
import org.eclipse.swt.widgets.Group;
3635
import org.eclipse.swt.widgets.Label;
3736
import org.eclipse.swt.widgets.Listener;
37+
import org.eclipse.swt.widgets.Spinner;
3838
import org.eclipse.swt.widgets.Text;
3939

4040
import org.apache.commons.lang3.StringUtils;
@@ -735,7 +735,7 @@ protected final Group addStaticFieldsProperty(Composite parent,
735735
* Adapter for <code>int</code> property.
736736
*/
737737
private final class IntegerPropertyInfo extends PropertyInfo {
738-
private final CSpinner m_spinner;
738+
private final Spinner m_spinner;
739739
private final Listener m_listener = new Listener() {
740740
@Override
741741
public void handleEvent(Event event) {
@@ -750,10 +750,10 @@ public void handleEvent(Event event) {
750750
// Constructor
751751
//
752752
////////////////////////////////////////////////////////////////////////////
753-
public IntegerPropertyInfo(String property, CSpinner spinner) {
753+
public IntegerPropertyInfo(String property, Spinner spinner) {
754754
super(property);
755755
m_spinner = spinner;
756-
new CSpinnerDeferredNotifier(m_spinner, 500, m_listener);
756+
new SpinnerDeferredNotifier(m_spinner, 500, m_listener);
757757
}
758758

759759
////////////////////////////////////////////////////////////////////////////
@@ -787,7 +787,7 @@ protected final void addIntegerProperty(Composite parent,
787787
int maxValue) {
788788
new Label(parent, SWT.NONE).setText(title);
789789
//
790-
CSpinner spinner = new CSpinner(parent, SWT.BORDER);
790+
Spinner spinner = new Spinner(parent, SWT.BORDER);
791791
GridDataFactory.create(spinner).hintHC(10);
792792
spinner.setMinimum(minValue);
793793
spinner.setMaximum(maxValue);
@@ -873,7 +873,7 @@ protected final Group addIntegerProperties(Composite parent,
873873
* Adapter for <code>double</code> property.
874874
*/
875875
private final class DoublePropertyInfo extends PropertyInfo {
876-
private final CSpinner m_spinner;
876+
private final Spinner m_spinner;
877877
private final double m_multiplier;
878878
private final Listener m_listener = new Listener() {
879879
@Override
@@ -889,11 +889,11 @@ public void handleEvent(Event event) {
889889
// Constructor
890890
//
891891
////////////////////////////////////////////////////////////////////////////
892-
public DoublePropertyInfo(String property, CSpinner spinner, double multiplier) {
892+
public DoublePropertyInfo(String property, Spinner spinner, double multiplier) {
893893
super(property);
894894
m_spinner = spinner;
895895
m_multiplier = multiplier;
896-
new CSpinnerDeferredNotifier(m_spinner, 500, m_listener);
896+
new SpinnerDeferredNotifier(m_spinner, 500, m_listener);
897897
}
898898

899899
////////////////////////////////////////////////////////////////////////////
@@ -929,7 +929,7 @@ protected final void addDoubleProperty(Composite parent,
929929
int multiplier = (int) Math.pow(10, digits);
930930
new Label(parent, SWT.NONE).setText(title);
931931
//
932-
CSpinner spinner = new CSpinner(parent, SWT.BORDER);
932+
Spinner spinner = new Spinner(parent, SWT.BORDER);
933933
GridDataFactory.create(spinner).hintHC(10);
934934
spinner.setMinimum((int) (minValue * multiplier));
935935
spinner.setMaximum((int) (maxValue * multiplier));

0 commit comments

Comments
 (0)