Skip to content

Commit b7b7c51

Browse files
committed
Fix:Layout preference page doesn't keep default layout
The input of the combo viewer needs to be set before the databinding is created. Otherwise the initial selection can't be restored. When unchecking an element in the table, the old selection of the combo viewer needs read before the new input is set, otherwise this information is lost. Fixes #785
1 parent b8e233c commit b7b7c51

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

org.eclipse.wb.core.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.wb.core.ui;singleton:=true
5-
Bundle-Version: 1.10.400.qualifier
5+
Bundle-Version: 1.10.500.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Require-Bundle: org.eclipse.ui,

org.eclipse.wb.core.ui/src/org/eclipse/wb/internal/core/preferences/LayoutsPreferencePage.java

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2022 Google, Inc.
2+
* Copyright (c) 2011, 2024 Google, Inc. and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -131,7 +131,38 @@ public int compare(LayoutDescription layout_1, LayoutDescription layout_2) {
131131
layoutCombo.add(layoutDescription.getName());
132132
}
133133
}
134+
new Label(this, SWT.NONE).setText(UiMessages.LayoutsPreferencePage_availableLayouts);
135+
m_table = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
136+
m_table.setContentProvider(ArrayContentProvider.getInstance());
137+
m_table.setLabelProvider(
138+
ColumnLabelProvider.createTextProvider(o -> ((LayoutDescription) o).getName()));
139+
m_table.setCheckStateProvider(new ICheckStateProvider() {
140+
@Override
141+
public boolean isChecked(Object element) {
142+
return m_layoutPreferences.getBoolean(((LayoutDescription) element).getLayoutClassName(), true);
143+
}
144+
145+
@Override
146+
public boolean isGrayed(Object element) {
147+
return false;
148+
}
149+
});
150+
m_table.setInput(layouts);
151+
m_table.addCheckStateListener(event -> {
152+
LayoutDescription layout = (LayoutDescription) event.getElement();
153+
m_layoutPreferences.putBoolean(layout.getLayoutClassName(), event.getChecked());
154+
// If default was set to a layout that is de-selected from available layouts.
155+
// The default layout is set back to implicit layout
156+
List<Object> input = getLayoutItems();
157+
Object selection = layoutCombo.getStructuredSelection().getFirstElement();
158+
layoutCombo.setInput(input);
159+
if (!input.contains(selection)) {
160+
layoutCombo.setSelection(implicitLayoutSelection);
161+
}
162+
});
163+
GridDataFactory.create(m_table.getTable()).fillH().spanH(gridLayoutColumns);
134164
// bind
165+
layoutCombo.setInput(getLayoutItems());
135166
m_bindManager.bind(new IDataEditor() {
136167
@Override
137168
public void setValue(Object value) {
@@ -155,42 +186,11 @@ public Object getValue() {
155186
if (layoutCombo.getStructuredSelection()
156187
.getFirstElement() instanceof LayoutDescription layout) {
157188
return layout.getId();
158-
}
189+
}
159190
// implicit layout
160191
return null;
161192
}
162-
},
163-
new StringPreferenceProvider(m_preferences, IPreferenceConstants.P_LAYOUT_DEFAULT), true);
164-
new Label(this, SWT.NONE).setText(UiMessages.LayoutsPreferencePage_availableLayouts);
165-
m_table = CheckboxTableViewer.newCheckList(this, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
166-
m_table.setContentProvider(ArrayContentProvider.getInstance());
167-
m_table.setLabelProvider(ColumnLabelProvider.createTextProvider(o -> ((LayoutDescription)o).getName()));
168-
m_table.setCheckStateProvider(new ICheckStateProvider() {
169-
@Override
170-
public boolean isChecked(Object element) {
171-
return m_layoutPreferences.getBoolean(((LayoutDescription) element).getLayoutClassName(), true);
172-
}
173-
174-
@Override
175-
public boolean isGrayed(Object element) {
176-
return false;
177-
}
178-
});
179-
m_table.setInput(layouts);
180-
m_table.addCheckStateListener(event -> {
181-
LayoutDescription layout = (LayoutDescription) event.getElement();
182-
m_layoutPreferences.putBoolean(layout.getLayoutClassName(), event.getChecked());
183-
// If default was set to a layout that is de-selected from available layouts.
184-
// The default layout is set back to implicit layout
185-
List<Object> layoutItems = new ArrayList<>();
186-
layoutItems.add(UiMessages.LayoutsPreferencePage_implicitLayout);
187-
layoutItems.addAll(List.of(m_table.getCheckedElements()));
188-
layoutCombo.setInput(layoutItems.toArray());
189-
if (layoutCombo.getStructuredSelection().isEmpty()) {
190-
layoutCombo.setSelection(implicitLayoutSelection);
191-
}
192-
});
193-
GridDataFactory.create(m_table.getTable()).fillH().spanH(gridLayoutColumns);
193+
}, new StringPreferenceProvider(m_preferences, IPreferenceConstants.P_LAYOUT_DEFAULT), true);
194194
}
195195
// boolean preferences
196196
checkButton(
@@ -199,5 +199,12 @@ public boolean isGrayed(Object element) {
199199
UiMessages.LayoutsPreferencePage_inheritLayout,
200200
IPreferenceConstants.P_LAYOUT_OF_PARENT);
201201
}
202+
203+
private List<Object> getLayoutItems() {
204+
List<Object> layoutItems = new ArrayList<>();
205+
layoutItems.add(UiMessages.LayoutsPreferencePage_implicitLayout);
206+
layoutItems.addAll(List.of(m_table.getCheckedElements()));
207+
return Collections.unmodifiableList(layoutItems);
208+
}
202209
}
203210
}

0 commit comments

Comments
 (0)