Skip to content

Commit ba94913

Browse files
committed
Use auto-generated "disabled" icon when supported by SWT
SWT version 3.130.0 or newer is able to automatically generate a "disabled" icon. If such a version is used, it is no longer necessary to explicitly set it for e.g. an action. In short: If SWT < 3.130 is used, both "enabled" and "disabled" icons are set, otherwise only the "enabled" icon is set. Closes #732
1 parent 7fecea9 commit ba94913

File tree

11 files changed

+144
-30
lines changed

11 files changed

+144
-30
lines changed

org.eclipse.gef/src/org/eclipse/gef/internal/InternalGEFPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.lang.reflect.Constructor;
1818
import java.lang.reflect.InvocationTargetException;
1919

20+
import org.eclipse.swt.SWT;
2021
import org.eclipse.swt.graphics.Cursor;
2122
import org.eclipse.swt.graphics.Device;
2223
import org.eclipse.swt.graphics.Image;
@@ -38,13 +39,16 @@
3839
import org.eclipse.gef.GEFColorProvider;
3940

4041
import org.osgi.framework.BundleContext;
42+
import org.osgi.framework.FrameworkUtil;
43+
import org.osgi.framework.Version;
4144

4245
public class InternalGEFPlugin extends AbstractUIPlugin {
4346
/** Monitor scale property */
4447
public static final String MONITOR_SCALE_PROPERTY = "monitorScale"; //$NON-NLS-1$
4548

4649
private static BundleContext context;
4750
private static AbstractUIPlugin singleton;
51+
private static Boolean requiresDisabledIcons;
4852

4953
public InternalGEFPlugin() {
5054
singleton = this;
@@ -160,4 +164,16 @@ public void partDeactivated(EditPart editpart) {
160164
}
161165
};
162166
}
167+
168+
/**
169+
* With Eclipse 4.36 (and therefore SWT 3.130.0), it is no longer necessary to
170+
* set a "disabled" icon in e.g. {@code Actions}.
171+
*/
172+
public static boolean requiresDisabledIcon() {
173+
if (requiresDisabledIcons == null) {
174+
Version minVersion = new Version(3, 130, 0);
175+
requiresDisabledIcons = FrameworkUtil.getBundle(SWT.class).getVersion().compareTo(minVersion) < 0;
176+
}
177+
return requiresDisabledIcons;
178+
}
163179
}

org.eclipse.gef/src/org/eclipse/gef/internal/InternalImages.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,23 @@ public class InternalImages {
3030
public static final ImageDescriptor DESC_MATCH_WIDTH;
3131
public static final ImageDescriptor DESC_MATCH_HEIGHT;
3232

33+
/**
34+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
35+
* the minimum supported version.
36+
*/
37+
@Deprecated
3338
public static final ImageDescriptor DESC_MATCH_SIZE_DIS;
39+
/**
40+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
41+
* the minimum supported version.
42+
*/
43+
@Deprecated
3444
public static final ImageDescriptor DESC_MATCH_WIDTH_DIS;
45+
/**
46+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
47+
* the minimum supported version.
48+
*/
49+
@Deprecated
3550
public static final ImageDescriptor DESC_MATCH_HEIGHT_DIS;
3651

3752
public static final ImageDescriptor DESC_HORZ_ALIGN_CENTER;
@@ -42,12 +57,42 @@ public class InternalImages {
4257
public static final ImageDescriptor DESC_VERT_ALIGN_TOP;
4358
public static final ImageDescriptor DESC_VERT_ALIGN_BOTTOM;
4459

60+
/**
61+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
62+
* the minimum supported version.
63+
*/
64+
@Deprecated
4565
public static final ImageDescriptor DESC_HORZ_ALIGN_CENTER_DIS;
66+
/**
67+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
68+
* the minimum supported version.
69+
*/
70+
@Deprecated
4671
public static final ImageDescriptor DESC_HORZ_ALIGN_LEFT_DIS;
72+
/**
73+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
74+
* the minimum supported version.
75+
*/
76+
@Deprecated
4777
public static final ImageDescriptor DESC_HORZ_ALIGN_RIGHT_DIS;
4878

79+
/**
80+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
81+
* the minimum supported version.
82+
*/
83+
@Deprecated
4984
public static final ImageDescriptor DESC_VERT_ALIGN_MIDDLE_DIS;
85+
/**
86+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
87+
* the minimum supported version.
88+
*/
89+
@Deprecated
5090
public static final ImageDescriptor DESC_VERT_ALIGN_TOP_DIS;
91+
/**
92+
* @deprecated No longer needed with SWT 3.130.0. Can be removed once this is
93+
* the minimum supported version.
94+
*/
95+
@Deprecated
5196
public static final ImageDescriptor DESC_VERT_ALIGN_BOTTOM_DIS;
5297

5398
public static final ImageDescriptor DESC_SEPARATOR;

org.eclipse.gef/src/org/eclipse/gef/ui/actions/AlignmentAction.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -30,6 +30,7 @@
3030
import org.eclipse.gef.commands.Command;
3131
import org.eclipse.gef.commands.CompoundCommand;
3232
import org.eclipse.gef.internal.GEFMessages;
33+
import org.eclipse.gef.internal.InternalGEFPlugin;
3334
import org.eclipse.gef.internal.InternalImages;
3435
import org.eclipse.gef.requests.AlignmentRequest;
3536
import org.eclipse.gef.tools.ToolUtilities;
@@ -200,47 +201,59 @@ protected void initUI() {
200201
setText(GEFMessages.AlignLeftAction_Label);
201202
setToolTipText(GEFMessages.AlignLeftAction_Tooltip);
202203
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT);
203-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT_DIS);
204+
if (InternalGEFPlugin.requiresDisabledIcon()) {
205+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT_DIS);
206+
}
204207
break;
205208

206209
case PositionConstants.RIGHT:
207210
setId(GEFActionConstants.ALIGN_RIGHT);
208211
setText(GEFMessages.AlignRightAction_Label);
209212
setToolTipText(GEFMessages.AlignRightAction_Tooltip);
210213
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT);
211-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS);
214+
if (InternalGEFPlugin.requiresDisabledIcon()) {
215+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS);
216+
}
212217
break;
213218

214219
case PositionConstants.TOP:
215220
setId(GEFActionConstants.ALIGN_TOP);
216221
setText(GEFMessages.AlignTopAction_Label);
217222
setToolTipText(GEFMessages.AlignTopAction_Tooltip);
218223
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP);
219-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS);
224+
if (InternalGEFPlugin.requiresDisabledIcon()) {
225+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS);
226+
}
220227
break;
221228

222229
case PositionConstants.BOTTOM:
223230
setId(GEFActionConstants.ALIGN_BOTTOM);
224231
setText(GEFMessages.AlignBottomAction_Label);
225232
setToolTipText(GEFMessages.AlignBottomAction_Tooltip);
226233
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM);
227-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS);
234+
if (InternalGEFPlugin.requiresDisabledIcon()) {
235+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS);
236+
}
228237
break;
229238

230239
case PositionConstants.CENTER:
231240
setId(GEFActionConstants.ALIGN_CENTER);
232241
setText(GEFMessages.AlignCenterAction_Label);
233242
setToolTipText(GEFMessages.AlignCenterAction_Tooltip);
234243
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER);
235-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS);
244+
if (InternalGEFPlugin.requiresDisabledIcon()) {
245+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS);
246+
}
236247
break;
237248

238249
case PositionConstants.MIDDLE:
239250
setId(GEFActionConstants.ALIGN_MIDDLE);
240251
setText(GEFMessages.AlignMiddleAction_Label);
241252
setToolTipText(GEFMessages.AlignMiddleAction_Tooltip);
242253
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE);
243-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS);
254+
if (InternalGEFPlugin.requiresDisabledIcon()) {
255+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS);
256+
}
244257
break;
245258
default:
246259
break;

org.eclipse.gef/src/org/eclipse/gef/ui/actions/AlignmentRetargetAction.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -17,6 +17,7 @@
1717
import org.eclipse.draw2d.PositionConstants;
1818

1919
import org.eclipse.gef.internal.GEFMessages;
20+
import org.eclipse.gef.internal.InternalGEFPlugin;
2021
import org.eclipse.gef.internal.InternalImages;
2122

2223
/**
@@ -41,42 +42,54 @@ public AlignmentRetargetAction(int align) {
4142
setText(GEFMessages.AlignBottomAction_Label);
4243
setToolTipText(GEFMessages.AlignBottomAction_Tooltip);
4344
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM);
44-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS);
45+
if (InternalGEFPlugin.requiresDisabledIcon()) {
46+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_BOTTOM_DIS);
47+
}
4548
break;
4649
case PositionConstants.CENTER:
4750
setId(GEFActionConstants.ALIGN_CENTER);
4851
setText(GEFMessages.AlignCenterAction_Label);
4952
setToolTipText(GEFMessages.AlignCenterAction_Tooltip);
5053
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER);
51-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS);
54+
if (InternalGEFPlugin.requiresDisabledIcon()) {
55+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_CENTER_DIS);
56+
}
5257
break;
5358
case PositionConstants.LEFT:
5459
setId(GEFActionConstants.ALIGN_LEFT);
5560
setText(GEFMessages.AlignLeftAction_Label);
5661
setToolTipText(GEFMessages.AlignLeftAction_Tooltip);
5762
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT);
58-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT_DIS);
63+
if (InternalGEFPlugin.requiresDisabledIcon()) {
64+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_LEFT_DIS);
65+
}
5966
break;
6067
case PositionConstants.MIDDLE:
6168
setId(GEFActionConstants.ALIGN_MIDDLE);
6269
setText(GEFMessages.AlignMiddleAction_Label);
6370
setToolTipText(GEFMessages.AlignMiddleAction_Tooltip);
6471
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE);
65-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS);
72+
if (InternalGEFPlugin.requiresDisabledIcon()) {
73+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_MIDDLE_DIS);
74+
}
6675
break;
6776
case PositionConstants.RIGHT:
6877
setId(GEFActionConstants.ALIGN_RIGHT);
6978
setText(GEFMessages.AlignRightAction_Label);
7079
setToolTipText(GEFMessages.AlignRightAction_Tooltip);
7180
setImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT);
72-
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS);
81+
if (InternalGEFPlugin.requiresDisabledIcon()) {
82+
setDisabledImageDescriptor(InternalImages.DESC_HORZ_ALIGN_RIGHT_DIS);
83+
}
7384
break;
7485
case PositionConstants.TOP:
7586
setId(GEFActionConstants.ALIGN_TOP);
7687
setText(GEFMessages.AlignTopAction_Label);
7788
setToolTipText(GEFMessages.AlignTopAction_Tooltip);
7889
setImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP);
79-
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS);
90+
if (InternalGEFPlugin.requiresDisabledIcon()) {
91+
setDisabledImageDescriptor(InternalImages.DESC_VERT_ALIGN_TOP_DIS);
92+
}
8093
break;
8194
}
8295
}

org.eclipse.gef/src/org/eclipse/gef/ui/actions/MatchHeightAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -17,6 +17,7 @@
1717
import org.eclipse.draw2d.geometry.PrecisionRectangle;
1818

1919
import org.eclipse.gef.internal.GEFMessages;
20+
import org.eclipse.gef.internal.InternalGEFPlugin;
2021
import org.eclipse.gef.internal.InternalImages;
2122

2223
/**
@@ -35,7 +36,9 @@ public MatchHeightAction(IWorkbenchPart part) {
3536
super(part);
3637
setText(GEFMessages.MatchHeightAction_Label);
3738
setImageDescriptor(InternalImages.DESC_MATCH_HEIGHT);
38-
setDisabledImageDescriptor(InternalImages.DESC_MATCH_HEIGHT_DIS);
39+
if (InternalGEFPlugin.requiresDisabledIcon()) {
40+
setDisabledImageDescriptor(InternalImages.DESC_MATCH_HEIGHT_DIS);
41+
}
3942
setToolTipText(GEFMessages.MatchHeightAction_Tooltip);
4043
setId(GEFActionConstants.MATCH_HEIGHT);
4144
}

org.eclipse.gef/src/org/eclipse/gef/ui/actions/MatchHeightRetargetAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -15,6 +15,7 @@
1515
import org.eclipse.ui.actions.LabelRetargetAction;
1616

1717
import org.eclipse.gef.internal.GEFMessages;
18+
import org.eclipse.gef.internal.InternalGEFPlugin;
1819
import org.eclipse.gef.internal.InternalImages;
1920

2021
/**
@@ -28,7 +29,9 @@ public class MatchHeightRetargetAction extends LabelRetargetAction {
2829
public MatchHeightRetargetAction() {
2930
super(GEFActionConstants.MATCH_HEIGHT, GEFMessages.MatchHeightAction_Label);
3031
setImageDescriptor(InternalImages.DESC_MATCH_HEIGHT);
31-
setDisabledImageDescriptor(InternalImages.DESC_MATCH_HEIGHT_DIS);
32+
if (InternalGEFPlugin.requiresDisabledIcon()) {
33+
setDisabledImageDescriptor(InternalImages.DESC_MATCH_HEIGHT_DIS);
34+
}
3235
setToolTipText(GEFMessages.MatchHeightAction_Tooltip);
3336
}
3437

org.eclipse.gef/src/org/eclipse/gef/ui/actions/MatchSizeAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -25,6 +25,7 @@
2525
import org.eclipse.gef.commands.Command;
2626
import org.eclipse.gef.commands.CompoundCommand;
2727
import org.eclipse.gef.internal.GEFMessages;
28+
import org.eclipse.gef.internal.InternalGEFPlugin;
2829
import org.eclipse.gef.internal.InternalImages;
2930
import org.eclipse.gef.requests.ChangeBoundsRequest;
3031

@@ -46,7 +47,9 @@ public MatchSizeAction(IWorkbenchPart part) {
4647
super(part);
4748
setText(GEFMessages.MatchSizeAction_Label);
4849
setImageDescriptor(InternalImages.DESC_MATCH_SIZE);
49-
setDisabledImageDescriptor(InternalImages.DESC_MATCH_SIZE_DIS);
50+
if (InternalGEFPlugin.requiresDisabledIcon()) {
51+
setDisabledImageDescriptor(InternalImages.DESC_MATCH_SIZE_DIS);
52+
}
5053
setToolTipText(GEFMessages.MatchSizeAction_Tooltip);
5154
setId(GEFActionConstants.MATCH_SIZE);
5255
}

org.eclipse.gef/src/org/eclipse/gef/ui/actions/MatchSizeRetargetAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -15,6 +15,7 @@
1515
import org.eclipse.ui.actions.LabelRetargetAction;
1616

1717
import org.eclipse.gef.internal.GEFMessages;
18+
import org.eclipse.gef.internal.InternalGEFPlugin;
1819
import org.eclipse.gef.internal.InternalImages;
1920

2021
/**
@@ -30,7 +31,9 @@ public class MatchSizeRetargetAction extends LabelRetargetAction {
3031
public MatchSizeRetargetAction() {
3132
super(GEFActionConstants.MATCH_SIZE, GEFMessages.MatchSizeAction_Label);
3233
setImageDescriptor(InternalImages.DESC_MATCH_SIZE);
33-
setDisabledImageDescriptor(InternalImages.DESC_MATCH_SIZE_DIS);
34+
if (InternalGEFPlugin.requiresDisabledIcon()) {
35+
setDisabledImageDescriptor(InternalImages.DESC_MATCH_SIZE_DIS);
36+
}
3437
setToolTipText(GEFMessages.MatchSizeAction_Tooltip);
3538
}
3639

org.eclipse.gef/src/org/eclipse/gef/ui/actions/MatchWidthAction.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2010 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation 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
@@ -17,6 +17,7 @@
1717
import org.eclipse.draw2d.geometry.PrecisionRectangle;
1818

1919
import org.eclipse.gef.internal.GEFMessages;
20+
import org.eclipse.gef.internal.InternalGEFPlugin;
2021
import org.eclipse.gef.internal.InternalImages;
2122

2223
/**
@@ -35,7 +36,9 @@ public MatchWidthAction(IWorkbenchPart part) {
3536
super(part);
3637
setText(GEFMessages.MatchWidthAction_Label);
3738
setImageDescriptor(InternalImages.DESC_MATCH_WIDTH);
38-
setDisabledImageDescriptor(InternalImages.DESC_MATCH_WIDTH_DIS);
39+
if (InternalGEFPlugin.requiresDisabledIcon()) {
40+
setDisabledImageDescriptor(InternalImages.DESC_MATCH_WIDTH_DIS);
41+
}
3942
setToolTipText(GEFMessages.MatchWidthAction_Tooltip);
4043
setId(GEFActionConstants.MATCH_WIDTH);
4144
}

0 commit comments

Comments
 (0)