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