Skip to content

Commit 4394174

Browse files
committed
Replace Forms API with plain SWT in workspace dialogs
Remove dependency on FormToolkit, ExpandableComposite, and ScrolledForm in ChooseWorkspaceDialog and ChooseWorkspaceWithSettingsDialog. Replace with plain SWT composites and Labels with Unicode triangle characters (U+25B8 ▸ / U+25BE ▾) for the expand/collapse toggle. This improves dialog startup performance by eliminating the Forms overhead: extra decorated composites, global paint/focus listeners, color management, and recursive ScrolledForm reflow on each toggle. The Unicode triangles are from the Geometric Shapes block (Unicode 1.0) and render reliably on Windows, macOS, and Linux system fonts. Also fix layout data mismatch where the path Combo used GridData inside a BorderLayout container (now uses BorderData).
1 parent 1375cd4 commit 4394174

File tree

2 files changed

+118
-79
lines changed

2 files changed

+118
-79
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.jface.dialogs.IDialogConstants;
4040
import org.eclipse.jface.dialogs.IDialogSettings;
4141
import org.eclipse.jface.dialogs.TitleAreaDialog;
42+
import org.eclipse.jface.resource.JFaceResources;
4243
import org.eclipse.jface.util.Geometry;
4344
import org.eclipse.jface.window.Window;
4445
import org.eclipse.osgi.util.NLS;
@@ -70,11 +71,6 @@
7071
import org.eclipse.swt.widgets.Monitor;
7172
import org.eclipse.swt.widgets.Shell;
7273
import org.eclipse.ui.PlatformUI;
73-
import org.eclipse.ui.forms.events.ExpansionAdapter;
74-
import org.eclipse.ui.forms.events.ExpansionEvent;
75-
import org.eclipse.ui.forms.widgets.ExpandableComposite;
76-
import org.eclipse.ui.forms.widgets.Form;
77-
import org.eclipse.ui.forms.widgets.FormToolkit;
7874
import org.osgi.framework.FrameworkUtil;
7975

8076
/**
@@ -99,7 +95,7 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog {
9995

10096
private Map<String, Link> recentWorkspacesLinks;
10197

102-
private Form recentWorkspacesForm;
98+
private Composite recentWorkspacesForm;
10399

104100
private Button defaultButton;
105101

@@ -312,34 +308,61 @@ protected void cancelPressed() {
312308
* Workspace
313309
*/
314310
private void createRecentWorkspacesComposite(final Composite composite) {
315-
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
316-
composite.addDisposeListener(c -> toolkit.dispose());
317-
recentWorkspacesForm = toolkit.createForm(composite);
311+
recentWorkspacesForm = new Composite(composite, SWT.NONE);
318312
recentWorkspacesForm.setBackground(composite.getBackground());
319-
recentWorkspacesForm.getBody().setLayout(new GridLayout());
320-
ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(),
321-
ExpandableComposite.TWISTIE);
313+
recentWorkspacesForm.setLayout(new GridLayout());
322314
recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
323-
recentWorkspacesExpandable.setBackground(composite.getBackground());
324-
recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
325-
recentWorkspacesExpandable.setExpanded(launchData.isShowRecentWorkspaces());
326-
recentWorkspacesExpandable.addExpansionListener(new ExpansionAdapter() {
327-
@Override
328-
public void expansionStateChanged(ExpansionEvent e) {
329-
launchData.setShowRecentWorkspaces(((ExpandableComposite) e.getSource()).isExpanded());
330-
Point size = getInitialSize();
331-
Shell shell = getShell();
332-
shell.setBounds(getConstrainedShellBounds(
333-
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
334-
}
335-
});
336315

337-
Composite panel = new Composite(recentWorkspacesExpandable, SWT.NONE);
338-
recentWorkspacesExpandable.setClient(panel);
316+
Composite header = new Composite(recentWorkspacesForm, SWT.NONE);
317+
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
318+
GridLayout headerLayout = new GridLayout(2, false);
319+
headerLayout.marginWidth = 0;
320+
headerLayout.marginHeight = 0;
321+
header.setLayout(headerLayout);
322+
header.setBackground(composite.getBackground());
323+
324+
Label toggle = new Label(header, SWT.NONE);
325+
toggle.setBackground(composite.getBackground());
326+
toggle.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
327+
328+
Label label = new Label(header, SWT.NONE);
329+
label.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
330+
label.setBackground(composite.getBackground());
331+
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
332+
label.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
333+
334+
Composite panel = new Composite(recentWorkspacesForm, SWT.NONE);
335+
panel.setBackground(composite.getBackground());
336+
GridData panelData = new GridData(SWT.FILL, SWT.FILL, true, false);
337+
panel.setLayoutData(panelData);
338+
339339
RowLayout layout = new RowLayout(SWT.VERTICAL);
340340
layout.marginLeft = 14;
341341
layout.spacing = 6;
342342
panel.setLayout(layout);
343+
344+
boolean expanded = launchData.isShowRecentWorkspaces();
345+
panel.setVisible(expanded);
346+
panelData.exclude = !expanded;
347+
toggle.setText(expanded ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
348+
349+
Listener toggleListener = e -> {
350+
boolean newState = !panel.getVisible();
351+
panel.setVisible(newState);
352+
((GridData) panel.getLayoutData()).exclude = !newState;
353+
toggle.setText(newState ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
354+
launchData.setShowRecentWorkspaces(newState);
355+
recentWorkspacesForm.requestLayout();
356+
357+
Point size = getInitialSize();
358+
Shell shell = getShell();
359+
shell.setBounds(getConstrainedShellBounds(
360+
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
361+
};
362+
363+
toggle.addListener(SWT.MouseDown, toggleListener);
364+
label.addListener(SWT.MouseDown, toggleListener);
365+
343366
List<String> recentWorkspaces = getRecentWorkspaces();
344367
recentWorkspacesLinks = new HashMap<>(recentWorkspaces.size());
345368
Map<String, String> uniqueWorkspaceNames = createUniqueWorkspaceNameMap();
@@ -526,7 +549,7 @@ protected Combo createPathCombo(Composite panel) {
526549
new DirectoryProposalContentAssist().apply(combo);
527550
combo.setTextDirection(SWT.AUTO_TEXT_DIRECTION);
528551
combo.setFocus();
529-
combo.setLayoutData(new GridData(400, SWT.DEFAULT));
552+
combo.setLayoutData(new BorderData(SWT.CENTER));
530553
combo.addModifyListener(e -> {
531554
Button okButton = getButton(Window.OK);
532555
if(okButton != null && !okButton.isDisposed()) {
@@ -705,9 +728,9 @@ public Combo getCombo() {
705728
/**
706729
* Get the "Recent Workspaces" form or null if not initialized.
707730
*
708-
* @return Form
731+
* @return Composite
709732
*/
710-
public Form getRecentWorkspacesForm() {
733+
public Composite getRecentWorkspacesForm() {
711734
return recentWorkspacesForm;
712735
}
713736

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import org.eclipse.jface.dialogs.IDialogSettings;
3434
import org.eclipse.jface.fieldassist.ControlDecoration;
3535
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
36+
import org.eclipse.jface.resource.JFaceResources;
3637
import org.eclipse.osgi.util.NLS;
3738
import org.eclipse.swt.SWT;
39+
import org.eclipse.swt.custom.ScrolledComposite;
3840
import org.eclipse.swt.events.SelectionAdapter;
3941
import org.eclipse.swt.events.SelectionEvent;
4042
import org.eclipse.swt.graphics.Image;
@@ -46,13 +48,10 @@
4648
import org.eclipse.swt.widgets.Button;
4749
import org.eclipse.swt.widgets.Composite;
4850
import org.eclipse.swt.widgets.Control;
51+
import org.eclipse.swt.widgets.Label;
52+
import org.eclipse.swt.widgets.Listener;
4953
import org.eclipse.swt.widgets.Shell;
5054
import org.eclipse.ui.PlatformUI;
51-
import org.eclipse.ui.forms.events.ExpansionEvent;
52-
import org.eclipse.ui.forms.events.IExpansionListener;
53-
import org.eclipse.ui.forms.widgets.ExpandableComposite;
54-
import org.eclipse.ui.forms.widgets.FormToolkit;
55-
import org.eclipse.ui.forms.widgets.ScrolledForm;
5655
import org.eclipse.ui.internal.WorkbenchPlugin;
5756
import org.eclipse.ui.preferences.SettingsTransfer;
5857
import org.osgi.framework.FrameworkUtil;
@@ -116,55 +115,72 @@ protected Control createDialogArea(Composite parent) {
116115
* Create the controls for selecting the controls we are going to export.
117116
*/
118117
private void createSettingsControls(Composite workArea) {
119-
final FormToolkit toolkit = new FormToolkit(workArea.getDisplay());
120-
workArea.addDisposeListener(e -> toolkit.dispose());
121-
final ScrolledForm form = toolkit.createScrolledForm(workArea);
122-
form.getBody().setBackground(workArea.getBackground());
123-
form.getBody().setLayout(new GridLayout());
124-
form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
125-
126-
final ExpandableComposite copySettingsExpandable =
127-
toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TWISTIE);
128-
129-
copySettingsExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceWithSettingsDialog_SettingsGroupName);
130-
copySettingsExpandable.setBackground(workArea.getBackground());
131-
copySettingsExpandable.setLayout(new GridLayout());
132-
copySettingsExpandable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
133-
copySettingsExpandable.addExpansionListener(new IExpansionListener() {
134-
135-
@Override
136-
public void expansionStateChanged(ExpansionEvent e) {
137-
form.reflow(true);
138-
Point size = getInitialSize();
139-
Shell shell = getShell();
140-
shell.setBounds(getConstrainedShellBounds(
141-
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
142-
}
143-
144-
@Override
145-
public void expansionStateChanging(ExpansionEvent e) {
146-
// Nothing to do here
147-
148-
}
149-
});
150-
151-
Composite sectionClient = toolkit.createComposite(copySettingsExpandable);
118+
final ScrolledComposite sc = new ScrolledComposite(workArea, SWT.V_SCROLL | SWT.H_SCROLL);
119+
sc.setExpandHorizontal(true);
120+
sc.setExpandVertical(true);
121+
sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
122+
123+
Composite body = new Composite(sc, SWT.NONE);
124+
body.setBackground(workArea.getBackground());
125+
body.setLayout(new GridLayout());
126+
sc.setContent(body);
127+
128+
Composite header = new Composite(body, SWT.NONE);
129+
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
130+
GridLayout headerLayout = new GridLayout(2, false);
131+
headerLayout.marginWidth = 0;
132+
headerLayout.marginHeight = 0;
133+
header.setLayout(headerLayout);
134+
header.setBackground(workArea.getBackground());
135+
136+
Label toggle = new Label(header, SWT.NONE);
137+
toggle.setBackground(workArea.getBackground());
138+
toggle.setCursor(workArea.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
139+
140+
Label label = new Label(header, SWT.NONE);
141+
label.setText(IDEWorkbenchMessages.ChooseWorkspaceWithSettingsDialog_SettingsGroupName);
142+
label.setBackground(workArea.getBackground());
143+
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
144+
label.setCursor(workArea.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
145+
146+
Composite sectionClient = new Composite(body, SWT.NONE);
152147
sectionClient.setBackground(workArea.getBackground());
153-
154-
if (createButtons(toolkit, sectionClient)) {
155-
copySettingsExpandable.setExpanded(true);
156-
}
157-
158-
copySettingsExpandable.setClient(sectionClient);
159-
148+
GridData clientData = new GridData(SWT.FILL, SWT.FILL, true, false);
149+
sectionClient.setLayoutData(clientData);
150+
151+
boolean expanded = createButtons(sectionClient);
152+
sectionClient.setVisible(expanded);
153+
clientData.exclude = !expanded;
154+
toggle.setText(expanded ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
155+
156+
Listener toggleListener = e -> {
157+
boolean newState = !sectionClient.getVisible();
158+
sectionClient.setVisible(newState);
159+
((GridData) sectionClient.getLayoutData()).exclude = !newState;
160+
toggle.setText(newState ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
161+
162+
body.layout(true);
163+
sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT));
164+
165+
Point size = getInitialSize();
166+
Shell shell = getShell();
167+
shell.setBounds(getConstrainedShellBounds(
168+
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
169+
};
170+
171+
toggle.addListener(SWT.MouseDown, toggleListener);
172+
label.addListener(SWT.MouseDown, toggleListener);
173+
174+
body.layout(true);
175+
sc.setMinSize(body.computeSize(SWT.DEFAULT, SWT.DEFAULT));
160176
}
161177

162178
/**
163179
* Create the buttons for the settings transfer.
164180
*
165181
* @return boolean <code>true</code> if any were selected
166182
*/
167-
private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
183+
private boolean createButtons(Composite sectionClient) {
168184
String[] enabledSettings = getEnabledSettings(
169185
PlatformUI.getDialogSettingsProvider(FrameworkUtil.getBundle(ChooseWorkspaceWithSettingsDialog.class))
170186
.getDialogSettings()
@@ -176,8 +192,9 @@ private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
176192
sectionClient.setLayout(layout);
177193

178194
for (final IConfigurationElement settingsTransfer : SettingsTransfer.getSettingsTransfers()) {
179-
final Button button = toolkit.createButton(sectionClient,
180-
settingsTransfer.getAttribute(ATT_NAME), SWT.CHECK);
195+
final Button button = new Button(sectionClient, SWT.CHECK);
196+
button.setText(settingsTransfer.getAttribute(ATT_NAME));
197+
button.setBackground(sectionClient.getBackground());
181198

182199
ControlDecoration deco = new ControlDecoration(button, SWT.TOP | SWT.RIGHT);
183200
Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING)
@@ -206,7 +223,6 @@ private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
206223
}
207224
}
208225

209-
button.setBackground(sectionClient.getBackground());
210226
button.addSelectionListener(new SelectionAdapter() {
211227

212228
@Override

0 commit comments

Comments
 (0)