Skip to content

Commit 258b96d

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 1baf984 commit 258b96d

File tree

2 files changed

+118
-86
lines changed

2 files changed

+118
-86
lines changed

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

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.eclipse.jface.dialogs.IDialogSettings;
4141
import org.eclipse.jface.dialogs.TitleAreaDialog;
4242
import org.eclipse.jface.resource.JFaceColors;
43+
import org.eclipse.jface.resource.JFaceResources;
4344
import org.eclipse.jface.util.Geometry;
4445
import org.eclipse.jface.window.Window;
4546
import org.eclipse.osgi.util.NLS;
@@ -71,11 +72,6 @@
7172
import org.eclipse.swt.widgets.Monitor;
7273
import org.eclipse.swt.widgets.Shell;
7374
import org.eclipse.ui.PlatformUI;
74-
import org.eclipse.ui.forms.events.ExpansionAdapter;
75-
import org.eclipse.ui.forms.events.ExpansionEvent;
76-
import org.eclipse.ui.forms.widgets.ExpandableComposite;
77-
import org.eclipse.ui.forms.widgets.Form;
78-
import org.eclipse.ui.forms.widgets.FormToolkit;
7975
import org.osgi.framework.FrameworkUtil;
8076

8177
/**
@@ -100,7 +96,7 @@ public class ChooseWorkspaceDialog extends TitleAreaDialog {
10096

10197
private Map<String, Link> recentWorkspacesLinks;
10298

103-
private Form recentWorkspacesForm;
99+
private Composite recentWorkspacesForm;
104100

105101
private Button defaultButton;
106102

@@ -313,38 +309,61 @@ protected void cancelPressed() {
313309
* Workspace
314310
*/
315311
private void createRecentWorkspacesComposite(final Composite composite) {
316-
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
317-
composite.addDisposeListener(c -> toolkit.dispose());
318-
recentWorkspacesForm = toolkit.createForm(composite);
312+
recentWorkspacesForm = new Composite(composite, SWT.NONE);
319313
recentWorkspacesForm.setBackground(composite.getBackground());
320-
recentWorkspacesForm.getBody().setLayout(new GridLayout());
321-
ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(),
322-
ExpandableComposite.TWISTIE);
323-
recentWorkspacesExpandable.setTitleBarForeground(composite.getForeground());
324-
recentWorkspacesExpandable.setForeground(composite.getForeground());
325-
recentWorkspacesExpandable.setToggleColor(composite.getForeground());
326-
recentWorkspacesExpandable.setActiveToggleColor(composite.getForeground());
314+
recentWorkspacesForm.setLayout(new GridLayout());
327315
recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
328-
recentWorkspacesExpandable.setBackground(composite.getBackground());
329-
recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
330-
recentWorkspacesExpandable.setExpanded(launchData.isShowRecentWorkspaces());
331-
recentWorkspacesExpandable.addExpansionListener(new ExpansionAdapter() {
332-
@Override
333-
public void expansionStateChanged(ExpansionEvent e) {
334-
launchData.setShowRecentWorkspaces(((ExpandableComposite) e.getSource()).isExpanded());
335-
Point size = getInitialSize();
336-
Shell shell = getShell();
337-
shell.setBounds(getConstrainedShellBounds(
338-
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
339-
}
340-
});
341316

342-
Composite panel = new Composite(recentWorkspacesExpandable, SWT.NONE);
343-
recentWorkspacesExpandable.setClient(panel);
317+
Composite header = new Composite(recentWorkspacesForm, SWT.NONE);
318+
header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
319+
GridLayout headerLayout = new GridLayout(2, false);
320+
headerLayout.marginWidth = 0;
321+
headerLayout.marginHeight = 0;
322+
header.setLayout(headerLayout);
323+
header.setBackground(composite.getBackground());
324+
325+
Label toggle = new Label(header, SWT.NONE);
326+
toggle.setBackground(composite.getBackground());
327+
toggle.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
328+
329+
Label label = new Label(header, SWT.NONE);
330+
label.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
331+
label.setBackground(composite.getBackground());
332+
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT));
333+
label.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
334+
335+
Composite panel = new Composite(recentWorkspacesForm, SWT.NONE);
336+
panel.setBackground(composite.getBackground());
337+
GridData panelData = new GridData(SWT.FILL, SWT.FILL, true, false);
338+
panel.setLayoutData(panelData);
339+
344340
RowLayout layout = new RowLayout(SWT.VERTICAL);
345341
layout.marginLeft = 14;
346342
layout.spacing = 6;
347343
panel.setLayout(layout);
344+
345+
boolean expanded = launchData.isShowRecentWorkspaces();
346+
panel.setVisible(expanded);
347+
panelData.exclude = !expanded;
348+
toggle.setText(expanded ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
349+
350+
Listener toggleListener = e -> {
351+
boolean newState = !panel.getVisible();
352+
panel.setVisible(newState);
353+
((GridData) panel.getLayoutData()).exclude = !newState;
354+
toggle.setText(newState ? "\u25BE" : "\u25B8"); //$NON-NLS-1$ //$NON-NLS-2$
355+
launchData.setShowRecentWorkspaces(newState);
356+
recentWorkspacesForm.requestLayout();
357+
358+
Point size = getInitialSize();
359+
Shell shell = getShell();
360+
shell.setBounds(getConstrainedShellBounds(
361+
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
362+
};
363+
364+
toggle.addListener(SWT.MouseDown, toggleListener);
365+
label.addListener(SWT.MouseDown, toggleListener);
366+
348367
List<String> recentWorkspaces = getRecentWorkspaces();
349368
recentWorkspacesLinks = new HashMap<>(recentWorkspaces.size());
350369
Map<String, String> uniqueWorkspaceNames = createUniqueWorkspaceNameMap();
@@ -532,7 +551,7 @@ protected Combo createPathCombo(Composite panel) {
532551
new DirectoryProposalContentAssist().apply(combo);
533552
combo.setTextDirection(SWT.AUTO_TEXT_DIRECTION);
534553
combo.setFocus();
535-
combo.setLayoutData(new GridData(400, SWT.DEFAULT));
554+
combo.setLayoutData(new BorderData(SWT.CENTER));
536555
combo.addModifyListener(e -> {
537556
Button okButton = getButton(Window.OK);
538557
if(okButton != null && !okButton.isDisposed()) {
@@ -711,9 +730,9 @@ public Combo getCombo() {
711730
/**
712731
* Get the "Recent Workspaces" form or null if not initialized.
713732
*
714-
* @return Form
733+
* @return Composite
715734
*/
716-
public Form getRecentWorkspacesForm() {
735+
public Composite getRecentWorkspacesForm() {
717736
return recentWorkspacesForm;
718737
}
719738

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

Lines changed: 65 additions & 52 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,58 +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.setTitleBarForeground(workArea.getForeground());
132-
copySettingsExpandable.setToggleColor(workArea.getForeground());
133-
copySettingsExpandable.setActiveToggleColor(workArea.getForeground());
134-
copySettingsExpandable.setLayout(new GridLayout());
135-
copySettingsExpandable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
136-
copySettingsExpandable.addExpansionListener(new IExpansionListener() {
137-
138-
@Override
139-
public void expansionStateChanged(ExpansionEvent e) {
140-
form.reflow(true);
141-
Point size = getInitialSize();
142-
Shell shell = getShell();
143-
shell.setBounds(getConstrainedShellBounds(
144-
new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
145-
}
146-
147-
@Override
148-
public void expansionStateChanging(ExpansionEvent e) {
149-
// Nothing to do here
150-
151-
}
152-
});
153-
154-
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);
155147
sectionClient.setBackground(workArea.getBackground());
156-
157-
if (createButtons(toolkit, sectionClient)) {
158-
copySettingsExpandable.setExpanded(true);
159-
}
160-
161-
copySettingsExpandable.setClient(sectionClient);
162-
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));
163176
}
164177

165178
/**
166179
* Create the buttons for the settings transfer.
167180
*
168181
* @return boolean <code>true</code> if any were selected
169182
*/
170-
private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
183+
private boolean createButtons(Composite sectionClient) {
171184
String[] enabledSettings = getEnabledSettings(
172185
PlatformUI.getDialogSettingsProvider(FrameworkUtil.getBundle(ChooseWorkspaceWithSettingsDialog.class))
173186
.getDialogSettings()
@@ -179,8 +192,9 @@ private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
179192
sectionClient.setLayout(layout);
180193

181194
for (final IConfigurationElement settingsTransfer : SettingsTransfer.getSettingsTransfers()) {
182-
final Button button = toolkit.createButton(sectionClient,
183-
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());
184198

185199
ControlDecoration deco = new ControlDecoration(button, SWT.TOP | SWT.RIGHT);
186200
Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING)
@@ -209,7 +223,6 @@ private boolean createButtons(FormToolkit toolkit, Composite sectionClient) {
209223
}
210224
}
211225

212-
button.setBackground(sectionClient.getBackground());
213226
button.addSelectionListener(new SelectionAdapter() {
214227

215228
@Override

0 commit comments

Comments
 (0)